[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 1/4] New command: focus_nth - frame_current_set_selection()
- To: herbstluftwm _minus_ devel _at_ lists _dot_ sourceforge _dot_ net
- Subject: [PATCH 1/4] New command: focus_nth - frame_current_set_selection()
- From: Gabor Adam Toth <tg _at_ tgbit _dot_ net>
- Date: Tue, 7 Aug 2012 00:34:04 +0200
---
NEWS | 1 +
doc/herbstluftwm.txt | 5 +++++
src/command.c | 1 +
src/layout.c | 22 ++++++++++++++++++++++
src/layout.h | 1 +
src/main.c | 1 +
6 files changed, 31 insertions(+), 0 deletions(-)
diff --git a/NEWS b/NEWS
index a66d8a7..6948c9f 100644
--- a/NEWS
+++ b/NEWS
@@ -40,6 +40,7 @@ Changes:
* start system wide autostart file if there is no working user defined one
* clients are restored (i.e. managed) from _NET_CLIENT_LIST even if they
are not visible
+ * new command: focus_nth
Release 0.3 on 2012-04-12
-------------------------
diff --git a/doc/herbstluftwm.txt b/doc/herbstluftwm.txt
index 5bb6214..5d76951 100644
--- a/doc/herbstluftwm.txt
+++ b/doc/herbstluftwm.txt
@@ -192,6 +192,11 @@ wmexec ['WINDOWMANAGER' ['ARGS ...']]::
* wmexec openbox
+focus_nth 'INDEX'::
+ Focuses nth window in a frame. The first window has 'INDEX' 0, if INDEX is
+ negative or greater than the last window index, then the last window is
+ focused.
+
cycle ['DELTA']::
Cycles the selection within the current frame by 'DELTA'. If 'DELTA' is
omitted, 'DELTA' = 1 will be used. 'DELTA' can be negative; 'DELTA' = -1
diff --git a/src/command.c b/src/command.c
index 2b8495f..f70fa73 100644
--- a/src/command.c
+++ b/src/command.c
@@ -54,6 +54,7 @@ struct {
{ "list_commands", 0, no_completion },
{ "list_keybinds", 0, no_completion },
{ "add_monitor", 7, no_completion },
+ { "focus_nth", 2, no_completion },
{ "cycle", 2, no_completion },
{ "cycle_all", 3, no_completion },
{ "cycle_layout", LAYOUT_COUNT+2, no_completion },
diff --git a/src/layout.c b/src/layout.c
index 0a34b79..9856638 100644
--- a/src/layout.c
+++ b/src/layout.c
@@ -900,6 +900,28 @@ HSFrame* frame_current_selection() {
return frame;
}
+int frame_current_set_selection(int argc, char** argv) {
+ int index = 0;
+ if (argc >= 2) {
+ index = atoi(argv[1]);
+ } else {
+ return HERBST_INVALID_ARGUMENT;
+ }
+ // find current selection
+ HSFrame* frame = frame_current_selection();
+ if (frame->content.clients.count == 0) {
+ // nothing to do
+ return 0;
+ }
+ if (index < 0 || index >= frame->content.clients.count) {
+ index = frame->content.clients.count - 1;
+ }
+ frame->content.clients.selection = index;
+ Window window = frame->content.clients.buf[index];
+ window_focus(window);
+ return 0;
+}
+
int frame_current_cycle_selection(int argc, char** argv) {
int delta = 1;
if (argc >= 2) {
diff --git a/src/layout.h b/src/layout.h
index c3f7956..9685c76 100644
--- a/src/layout.h
+++ b/src/layout.h
@@ -126,6 +126,7 @@ char* load_frame_tree(HSFrame* frame, char* description, GString** errormsg);
int find_layout_by_name(char* name);
int find_align_by_name(char* name);
+int frame_current_set_selection(int argc, char** argv);
int frame_current_cycle_selection(int argc, char** argv);
int cycle_all_command(int argc, char** argv);
diff --git a/src/main.c b/src/main.c
index 69b846e..8cb3042 100644
--- a/src/main.c
+++ b/src/main.c
@@ -95,6 +95,7 @@ CommandBinding g_commands[] = {
CMD_BIND_NO_OUTPUT( "spawn", spawn),
CMD_BIND_NO_OUTPUT( "wmexec", wmexec),
CMD_BIND_NO_OUTPUT( "emit_hook", custom_hook_emit),
+ CMD_BIND_NO_OUTPUT( "focus_nth", frame_current_set_selection),
CMD_BIND_NO_OUTPUT( "cycle", frame_current_cycle_selection),
CMD_BIND_NO_OUTPUT( "cycle_all", cycle_all_command),
CMD_BIND_NO_OUTPUT( "cycle_layout", frame_current_cycle_client_layout),
--
1.7.8.6