#include "util.h"
#include "queue.h"
#include "layout.h"
+#include "client.h"
/*
* Removes the given client from the container, either because it will be inserted into another
bool client_matches_class_name(Client *client, char *to_class, char *to_title,
char *to_title_ucs, int to_title_ucs_len) {
/* Check if the given class is part of the window class */
- if (strcasestr(client->window_class, to_class) == NULL)
+ if (client->window_class == NULL || strcasestr(client->window_class, to_class) == NULL)
return false;
/* If no title was given, we’re done */
if (client->name_len > -1) {
/* UCS-2 converted window titles */
- if (memmem(client->name, (client->name_len * 2), to_title_ucs, (to_title_ucs_len * 2)) == NULL)
+ if (client->name == NULL || memmem(client->name, (client->name_len * 2), to_title_ucs, (to_title_ucs_len * 2)) == NULL)
return false;
} else {
/* Legacy hints */
- if (strcasestr(client->name, to_title) == NULL)
+ if (client->name == NULL || strcasestr(client->name, to_title) == NULL)
return false;
}
return true;
}
+/*
+ * Enters fullscreen mode for the given client. This is called by toggle_fullscreen
+ * and when moving a fullscreen client to another screen.
+ *
+ */
+void client_enter_fullscreen(xcb_connection_t *conn, Client *client) {
+ Workspace *workspace = client->workspace;
+
+ if (workspace->fullscreen_client != NULL) {
+ LOG("Not entering fullscreen mode, there already is a fullscreen client.\n");
+ return;
+ }
+
+ client->fullscreen = true;
+ workspace->fullscreen_client = client;
+ LOG("Entering fullscreen mode...\n");
+ /* We just entered fullscreen mode, let’s configure the window */
+ uint32_t mask = XCB_CONFIG_WINDOW_X |
+ XCB_CONFIG_WINDOW_Y |
+ XCB_CONFIG_WINDOW_WIDTH |
+ XCB_CONFIG_WINDOW_HEIGHT;
+ uint32_t values[4] = {workspace->rect.x,
+ workspace->rect.y,
+ workspace->rect.width,
+ workspace->rect.height};
+
+ LOG("child itself will be at %dx%d with size %dx%d\n",
+ values[0], values[1], values[2], values[3]);
+
+ xcb_configure_window(conn, client->frame, mask, values);
+
+ /* Child’s coordinates are relative to the parent (=frame) */
+ values[0] = 0;
+ values[1] = 0;
+ xcb_configure_window(conn, client->child, mask, values);
+
+ /* Raise the window */
+ values[0] = XCB_STACK_MODE_ABOVE;
+ xcb_configure_window(conn, client->frame, XCB_CONFIG_WINDOW_STACK_MODE, values);
+
+ Rect child_rect = workspace->rect;
+ child_rect.x = child_rect.y = 0;
+ fake_configure_notify(conn, child_rect, client->child);
+
+ xcb_flush(conn);
+}
+
/*
* Toggles fullscreen mode for the given client. It updates the data structures and
* reconfigures (= resizes/moves) the client and its frame to the full size of the
Workspace *workspace = client->workspace;
if (!client->fullscreen) {
- if (workspace->fullscreen_client != NULL) {
- LOG("Not entering fullscreen mode, there already is a fullscreen client.\n");
- return;
- }
- client->fullscreen = true;
- workspace->fullscreen_client = client;
- LOG("Entering fullscreen mode...\n");
- /* We just entered fullscreen mode, let’s configure the window */
- uint32_t mask = XCB_CONFIG_WINDOW_X |
- XCB_CONFIG_WINDOW_Y |
- XCB_CONFIG_WINDOW_WIDTH |
- XCB_CONFIG_WINDOW_HEIGHT;
- uint32_t values[4] = {workspace->rect.x,
- workspace->rect.y,
- workspace->rect.width,
- workspace->rect.height};
-
- LOG("child itself will be at %dx%d with size %dx%d\n",
- values[0], values[1], values[2], values[3]);
-
- xcb_configure_window(conn, client->frame, mask, values);
-
- /* Child’s coordinates are relative to the parent (=frame) */
- values[0] = 0;
- values[1] = 0;
- xcb_configure_window(conn, client->child, mask, values);
-
- /* Raise the window */
- values[0] = XCB_STACK_MODE_ABOVE;
- xcb_configure_window(conn, client->frame, XCB_CONFIG_WINDOW_STACK_MODE, values);
-
- Rect child_rect = workspace->rect;
- child_rect.x = child_rect.y = 0;
- fake_configure_notify(conn, child_rect, client->child);
+ client_enter_fullscreen(conn, client);
+ return;
+ }
+
+ LOG("leaving fullscreen mode\n");
+ client->fullscreen = false;
+ workspace->fullscreen_client = NULL;
+ if (client_is_floating(client)) {
+ /* For floating clients it’s enough if we just reconfigure that window (in fact,
+ * re-rendering the layout will not update the client.) */
+ reposition_client(conn, client);
+ resize_client(conn, client);
+ /* redecorate_window flushes */
+ redecorate_window(conn, client);
} else {
- LOG("leaving fullscreen mode\n");
- client->fullscreen = false;
- workspace->fullscreen_client = NULL;
- if (client->floating >= FLOATING_AUTO_ON) {
- /* For floating clients it’s enough if we just reconfigure that window (in fact,
- * re-rendering the layout will not update the client.) */
- reposition_client(conn, client);
- resize_client(conn, client);
- /* redecorate_window flushes */
- redecorate_window(conn, client);
- } else {
- /* Because the coordinates of the window haven’t changed, it would not be
- re-configured if we don’t set the following flag */
- client->force_reconfigure = true;
- /* We left fullscreen mode, redraw the whole layout to ensure enternotify events are disabled */
- render_layout(conn);
- }
+ client_set_below_floating(conn, client);
+
+ /* Because the coordinates of the window haven’t changed, it would not be
+ re-configured if we don’t set the following flag */
+ client->force_reconfigure = true;
+ /* We left fullscreen mode, redraw the whole layout to ensure enternotify events are disabled */
+ render_layout(conn);
}
xcb_flush(conn);
}
+
+/*
+ * Sets the position of the given client in the X stack to the highest (tiling layer is always
+ * on the same position, so this doesn’t matter) below the first floating client, so that
+ * floating windows are always on top.
+ *
+ */
+void client_set_below_floating(xcb_connection_t *conn, Client *client) {
+ /* Ensure that it is below all floating clients */
+ Client *first_floating = TAILQ_FIRST(&(client->workspace->floating_clients));
+ if (first_floating != TAILQ_END(&(client->workspace->floating_clients))) {
+ LOG("Setting below floating\n");
+ uint32_t values[] = { first_floating->frame, XCB_STACK_MODE_BELOW };
+ xcb_configure_window(conn, client->frame, XCB_CONFIG_WINDOW_SIBLING | XCB_CONFIG_WINDOW_STACK_MODE, values);
+ }
+}
+
+/*
+ * Returns true if the client is floating. Makes the code more beatiful, as floating
+ * is not simply a boolean, but also saves whether the user selected the current state
+ * or whether it was automatically set.
+ *
+ */
+bool client_is_floating(Client *client) {
+ return (client->floating >= FLOATING_AUTO_ON);
+}