Skip to content

Commit

Permalink
client: new command: window_focus_last
Browse files Browse the repository at this point in the history
  • Loading branch information
tudurom committed Mar 9, 2017
1 parent 34df3e0 commit 3af678c
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 27 deletions.
1 change: 1 addition & 0 deletions client.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ static struct Command c[] = {
{ "window_rev_cycle_in_group" , IPCWindowRevCycleInGroup , 0 , NULL } ,
{ "window_cardinal_focus" , IPCWindowCardinalFocus , 1 , fn_direction} ,
{ "window_focus" , IPCWindowFocus , 1 , fn_hex } ,
{ "window_focus_last" , IPCWindowFocusLast , 0 , NULL } ,
{ "group_add_window" , IPCGroupAddWindow , 1 , fn_naturals } ,
{ "group_remove_window" , IPCGroupRemoveWindow , 0 , NULL } ,
{ "group_remove_all_windows" , IPCGroupRemoveAllWindows , 1 , fn_naturals } ,
Expand Down
7 changes: 5 additions & 2 deletions examples/sxhkdrc
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,11 @@ alt + Tab
alt + shift + Tab
waitron window_rev_cycle

super + {_,shift +}{1-10}
waitron {group_toggle,group_add_window} {1-10}
alt + ctrl + Tab
waitron window_focus_last

super + {_,shift +}{1-9}
waitron {group_toggle,group_add_window} {1-9}

super + ctrl + r
waitron group_remove_window
Expand Down
2 changes: 1 addition & 1 deletion examples/windowchefrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ waitron wm_config color_unfocused 0x393638
waitron wm_config gap_width all 0
waitron wm_config grid_gap_width 0
waitron wm_config cursor_position middle
waitron wm_config groups_nr 10
waitron wm_config groups_nr 9
waitron wm_config enable_sloppy_focus true
waitron wm_config sticky_windows false
waitron wm_config enable_borders true
1 change: 1 addition & 0 deletions ipc.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ enum IPCCommand {
IPCWindowRevCycleInGroup,
IPCWindowCardinalFocus,
IPCWindowFocus,
IPCWindowFocusLast,
IPCGroupAddWindow,
IPCGroupRemoveWindow,
IPCGroupRemoveAllWindows,
Expand Down
6 changes: 5 additions & 1 deletion man/waitron.1
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.\" generated with Ronn/v0.7.3
.\" https://github.com/rtomayko/ronn/tree/0.7.3
.
.TH "WAITRON" "1" "February 2017" "Windowchef" "Windowchef Manual"
.TH "WAITRON" "1" "March 2017" "Windowchef" "Windowchef Manual"
.
.SH "NAME"
\fBwaitron\fR \- A client for windowchef(1)
Expand Down Expand Up @@ -106,6 +106,10 @@ Reverse cycle through mapped windows that belong to the same group as the focuse
Focus window by \fIid\fR\. The \fIid\fR can be found using pfw(1) or lsw(1) from wmutils \fIhttps://github\.com/wmutils/core/\fR\.
.
.TP
\fBwindow_focus_last\fR
Focus the window that was focused before the currently focused window\.
.
.TP
\fBwindow_cardinal_focus\fR \fIDIRECTION\fR
Focus the closest window in a direction, relative to the currently currently focused window\. Does nothing if there is no window focused\.
.
Expand Down
3 changes: 2 additions & 1 deletion man/waitron.1.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions man/waitron.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ anything on `stdout`.
Focus window by <id>. The <id> can be found using pfw(1) or lsw(1) from
[wmutils](https://github.com/wmutils/core/).

* `window_focus_last`:
Focus the window that was focused before the currently focused window.

* `window_cardinal_focus` <DIRECTION>:
Focus the closest window in a direction, relative to the currently
currently focused window. Does nothing if there is no window focused.
Expand Down
52 changes: 31 additions & 21 deletions wm.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ static void ipc_window_cycle_in_group(uint32_t *);
static void ipc_window_rev_cycle_in_group(uint32_t *);
static void ipc_window_cardinal_focus(uint32_t *);
static void ipc_window_focus(uint32_t *);
static void ipc_window_focus_last(uint32_t *);
static void ipc_group_add_window(uint32_t *);
static void ipc_group_remove_window(uint32_t *);
static void ipc_group_remove_all_windows(uint32_t *);
Expand Down Expand Up @@ -649,7 +650,7 @@ setup_window(xcb_window_t win)

/* initialize variables */
focus_item->data = client;
client->focus_item = focus_item;
client->focus_item = focus_item;
item->data = client;
client->item = item;
client->window = win;
Expand Down Expand Up @@ -712,8 +713,8 @@ set_focused_no_raise(struct client *client)
set_borders(focused_win, conf.unfocus_color);
}

if (client->focus_item != NULL)
list_move_to_head(&focus_list, client->focus_item);
if (client->focus_item != NULL)
list_move_to_head(&focus_list, client->focus_item);

focused_win = client;
}
Expand All @@ -736,21 +737,21 @@ set_focused(struct client *client)
static void
set_focused_last_best()
{
struct list_item *focused_item;
struct client *client;
struct list_item *focused_item;
struct client *client;

focused_item = focus_list->next;
focused_item = focus_list->next;

while (focused_item != NULL) {
client = focused_item->data;
while (focused_item != NULL) {
client = focused_item->data;

if (client != NULL && client->mapped) {
set_focused(client);
return;
}
if (client != NULL && client->mapped) {
set_focused(client);
return;
}

focused_item = focused_item->next;
}
focused_item = focused_item->next;
}
}

/*
Expand Down Expand Up @@ -2088,8 +2089,8 @@ event_destroy_notify(xcb_generic_event_t *ev)
client = find_client(&e->window);
if (focused_win != NULL && focused_win == client) {
focused_win = NULL;
set_focused_last_best();
}
set_focused_last_best();
}

if (client != NULL) {
free_window(client);
Expand Down Expand Up @@ -2210,10 +2211,10 @@ event_unmap_notify(xcb_generic_event_t *ev)

client->mapped = false;

if (focused_win != NULL && client->window == focused_win->window) {
focused_win = NULL;
set_focused_last_best();
}
if (focused_win != NULL && client->window == focused_win->window) {
focused_win = NULL;
set_focused_last_best();
}

update_client_list();
}
Expand Down Expand Up @@ -2354,6 +2355,7 @@ register_ipc_handlers(void)
ipc_handlers[IPCWindowRevCycleInGroup] = ipc_window_rev_cycle_in_group;
ipc_handlers[IPCWindowCardinalFocus] = ipc_window_cardinal_focus;
ipc_handlers[IPCWindowFocus] = ipc_window_focus;
ipc_handlers[IPCWindowFocusLast] = ipc_window_focus_last;
ipc_handlers[IPCGroupAddWindow] = ipc_group_add_window;
ipc_handlers[IPCGroupRemoveWindow] = ipc_group_remove_window;
ipc_handlers[IPCGroupRemoveAllWindows] = ipc_group_remove_all_windows;
Expand Down Expand Up @@ -2750,10 +2752,18 @@ ipc_window_focus(uint32_t *d)
set_focused(client);
}

static void
ipc_window_focus_last(uint32_t *d)
{
(void)(d);
if (focused_win != NULL)
set_focused_last_best();
}

static void
ipc_group_add_window(uint32_t *d)
{
if (focused_win!= NULL)
if (focused_win != NULL)
group_add_window(focused_win, d[0] - 1);
}

Expand Down
2 changes: 1 addition & 1 deletion xephyr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ cp examples/sxhkdrc sxhkdrc
cp examples/windowchefrc windowchefrc
sed -i 's/waitron/.\/waitron/g' sxhkdrc windowchefrc
sxhkd -c sxhkdrc &
./windowchef -c examples/windowchefrc
./windowchef -c windowchefrc

0 comments on commit 3af678c

Please sign in to comment.