From 89c0caaec418d0b3328cf692ffba2d4324e63a14 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Fri, 19 Jun 2009 13:59:29 +0200 Subject: [PATCH] Implement a command for hiding all floating windows (and showing them again) --- include/data.h | 2 ++ include/floating.h | 7 +++++++ src/commands.c | 15 +++++++++------ src/floating.c | 28 ++++++++++++++++++++++++++++ 4 files changed, 46 insertions(+), 6 deletions(-) diff --git a/include/data.h b/include/data.h index a31b6982..87dd4995 100644 --- a/include/data.h +++ b/include/data.h @@ -163,6 +163,8 @@ struct Workspace { /* Should clients on this workspace be automatically floating? */ bool auto_float; + /* Are the floating clients on this workspace currently hidden? */ + bool floating_hidden; Client *fullscreen_client; diff --git a/include/floating.h b/include/floating.h index 020e91ff..edc11a95 100644 --- a/include/floating.h +++ b/include/floating.h @@ -52,4 +52,11 @@ void floating_focus_direction(xcb_connection_t *conn, Client *currently_focused, */ void floating_move(xcb_connection_t *conn, Client *currently_focused, direction_t direction); +/** + * Hides all floating clients (or show them if they are currently hidden) on + * the specified workspace. + * + */ +void floating_toggle_hide(xcb_connection_t *conn, Workspace *workspace); + #endif diff --git a/src/commands.c b/src/commands.c index d809c81a..fb3c5422 100644 --- a/src/commands.c +++ b/src/commands.c @@ -625,12 +625,9 @@ void show_workspace(xcb_connection_t *conn, int workspace) { xcb_map_window(conn, client->frame); /* Map all floating clients */ - SLIST_FOREACH(client, &(c_ws->focus_stack), focus_clients) { - if (client->floating <= FLOATING_USER_OFF) - continue; - - xcb_map_window(conn, client->frame); - } + if (!c_ws->floating_hidden) + TAILQ_FOREACH(client, &(c_ws->floating_clients), floating_clients) + xcb_map_window(conn, client->frame); /* Map all stack windows, if any */ struct Stack_Window *stack_win; @@ -854,6 +851,12 @@ void parse_command(xcb_connection_t *conn, const char *command) { return; } + if (command[0] == 'H') { + LOG("Hiding all floating windows\n"); + floating_toggle_hide(conn, c_ws); + return; + } + enum { WITH_WINDOW, WITH_CONTAINER, WITH_WORKSPACE } with = WITH_WINDOW; /* Is it a ? */ diff --git a/src/floating.c b/src/floating.c index fb5c9511..c65f516e 100644 --- a/src/floating.c +++ b/src/floating.c @@ -355,3 +355,31 @@ void floating_move(xcb_connection_t *conn, Client *currently_focused, direction_ fake_absolute_configure_notify(conn, currently_focused); /* fake_absolute_configure_notify flushes */ } + +/* + * Hides all floating clients (or show them if they are currently hidden) on + * the specified workspace. + * + */ +void floating_toggle_hide(xcb_connection_t *conn, Workspace *workspace) { + Client *client; + + workspace->floating_hidden = !workspace->floating_hidden; + LOG("floating_hidden is now: %d\n", workspace->floating_hidden); + TAILQ_FOREACH(client, &(workspace->floating_clients), floating_clients) { + if (workspace->floating_hidden) + xcb_unmap_window(conn, client->frame); + else xcb_map_window(conn, client->frame); + } + + /* If we just unmapped all floating windows we should ensure that the focus + * is set correctly, that ist, to the first non-floating client in stack */ + if (workspace->floating_hidden) + SLIST_FOREACH(client, &(workspace->focus_stack), focus_clients) + if (client->floating <= FLOATING_USER_OFF) { + set_focus(conn, client, true); + return; + } + + xcb_flush(conn); +}