]> git.sur5r.net Git - i3/i3/commitdiff
Implement fullscreen mode (Mod1+f)
authorMichael Stapelberg <michael+git@stapelberg.de>
Sat, 14 Feb 2009 19:12:50 +0000 (20:12 +0100)
committerMichael Stapelberg <michael+git@stapelberg.de>
Sat, 14 Feb 2009 19:12:50 +0000 (20:12 +0100)
TODO
include/util.h
src/commands.c
src/handlers.c
src/mainx.c
src/util.c

diff --git a/TODO b/TODO
index 43cd8bf994dd7a8c1d9ddc59c500f6d6ca633967..3d5b770816b0a4775536580082537cdfd5324dd3 100644 (file)
--- a/TODO
+++ b/TODO
@@ -2,7 +2,6 @@ TODO list, in order of importance:
 
  * freely resizable (e.g. using your mouse, for now) percentage of rows/cols
  * fullscreen (handling of applications, mplayer, firefox, xpdf, wmctrl)
- * fullscreen (implementing a mode, like default, stacked)
  * xinerama
  * document stuff!
  * more documentation!
index 479e0cedd2deea67bd3cf59f385c8db31b789b0c..f194da8624783c9a214de559d731a8cdcbcd294b 100644 (file)
@@ -8,10 +8,16 @@
  * See file LICENSE for license information.
  *
  */
+#include <xcb/xcb.h>
+
+#include "data.h"
+
 #ifndef _UTIL_H
 #define _UTIL_H
 
 void start_application(const char *command);
 void check_error(xcb_connection_t *connection, xcb_void_cookie_t cookie, char *err_message);
+void set_focus(xcb_connection_t *conn, Client *client);
+void toggle_fullscreen(xcb_connection_t *conn, Client *client);
 
 #endif
index 95475dfb2946c16bb473c41c439b4f38a3a7da29..7f63f9b130aba2bd32f4cff1d297582707b48192 100644 (file)
@@ -301,6 +301,14 @@ void parse_command(xcb_connection_t *conn, const char *command) {
                 return;
         }
 
+        /* Is it 'f' for fullscreen? */
+        if (command[0] == 'f') {
+                if (CUR_CELL->currently_focused == NULL)
+                        return;
+                toggle_fullscreen(conn, CUR_CELL->currently_focused);
+                return;
+        }
+
         /* Is it a <with>? */
         if (command[0] == 'w') {
                 /* TODO: implement */
@@ -315,7 +323,7 @@ void parse_command(xcb_connection_t *conn, const char *command) {
         direction_t direction;
         times = strtol(command, &rest, 10);
         if (rest == NULL) {
-                printf("Invalid command: Consists only of a movement\n");
+                printf("Invalid command (\"%s\")\n", command);
                 return;
         }
         if (*rest == 'm' || *rest == 's') {
index 01f5efef047132531eb24af840fa677ed9131be6..6de25e73e21cc8e6f034d4a686a43289ebe02b3c 100644 (file)
 #include "data.h"
 #include "font.h"
 #include "xcb.h"
-
-static void set_focus(xcb_connection_t *conn, Client *client) {
-        /* Update container */
-        Client *old_client = client->container->currently_focused;
-        client->container->currently_focused = client;
-
-        current_col = client->container->col;
-        current_row = client->container->row;
-
-        /* Set focus to the entered window, and flush xcb buffer immediately */
-        xcb_set_input_focus(conn, XCB_INPUT_FOCUS_NONE, client->child, XCB_CURRENT_TIME);
-        /* Update last/current client’s titlebar */
-        if (old_client != NULL)
-                decorate_window(conn, old_client);
-        decorate_window(conn, client);
-        xcb_flush(conn);
-}
-
-static void toggle_fullscreen(xcb_connection_t *conn, Client *client) {
-        Workspace *workspace = client->container->workspace;
-
-        workspace->fullscreen_client = (client->fullscreen ? NULL : client);
-
-        client->fullscreen = !client->fullscreen;
-
-        if (client->fullscreen) {
-                printf("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->x,
-                                      workspace->y,
-                                      workspace->width,
-                                      workspace->height};
-
-                printf("child itself will be at %dx%d with size %dx%d\n",
-                                values[0], values[1], values[2], values[3]);
-
-                /* Raise the window */
-                xcb_circulate_window(conn, XCB_CIRCULATE_RAISE_LOWEST, client->frame);
-
-                xcb_configure_window(conn, client->frame, mask, values);
-                xcb_configure_window(conn, client->child, mask, values);
-
-                xcb_flush(conn);
-        } else {
-                printf("left fullscreen\n");
-                client->force_reconfigure = true;
-                /* We left fullscreen mode, redraw the layout */
-                render_layout(conn);
-        }
-}
+#include "util.h"
 
 /*
  * Due to bindings like Mode_switch + <a>, we need to bind some keys in XCB_GRAB_MODE_SYNC.
index 92b9468f8b85a82663f5a0c9761f8f54d407fcdb..ef371f559b4169d8619c5434d3942e88897c0015 100644 (file)
@@ -396,6 +396,8 @@ int main(int argc, char *argv[], char *env[]) {
 
         BIND(30, 0, "exec /usr/pkg/bin/urxvt");
 
+        BIND(41, BIND_MOD_1, "f");
+
         BIND(44, BIND_MOD_1, "h");
         BIND(45, BIND_MOD_1, "j");
         BIND(46, BIND_MOD_1, "k");
index 525fb4342f2110dae1df9207b5b9f0751f2b3a04..6a33ffbe230e658f2526cfd195773083b8e9fd60 100644 (file)
@@ -15,6 +15,9 @@
 #include <sys/wait.h>
 
 #include "i3.h"
+#include "data.h"
+#include "table.h"
+#include "layout.h"
 
 /*
  * Starts the given application by passing it through a shell. We use double fork
@@ -59,3 +62,71 @@ void check_error(xcb_connection_t *connection, xcb_void_cookie_t cookie, char *e
                 exit(-1);
         }
 }
+
+/*
+ * Sets the given client as focused by updating the data structures correctly,
+ * updating the X input focus and finally re-decorating both windows (to signalize
+ * the user the new focus situation)
+ *
+ */
+void set_focus(xcb_connection_t *conn, Client *client) {
+        /* Update container */
+        Client *old_client = client->container->currently_focused;
+        client->container->currently_focused = client;
+
+        current_col = client->container->col;
+        current_row = client->container->row;
+
+        /* Set focus to the entered window, and flush xcb buffer immediately */
+        xcb_set_input_focus(conn, XCB_INPUT_FOCUS_NONE, client->child, XCB_CURRENT_TIME);
+        /* Update last/current client’s titlebar */
+        if (old_client != NULL)
+                decorate_window(conn, old_client);
+        decorate_window(conn, client);
+        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
+ * screen. When leaving fullscreen, re-rendering the layout is forced.
+ *
+ */
+void toggle_fullscreen(xcb_connection_t *conn, Client *client) {
+        Workspace *workspace = client->container->workspace;
+
+        workspace->fullscreen_client = (client->fullscreen ? NULL : client);
+
+        client->fullscreen = !client->fullscreen;
+
+        if (client->fullscreen) {
+                printf("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->x,
+                                      workspace->y,
+                                      workspace->width,
+                                      workspace->height};
+
+                printf("child itself will be at %dx%d with size %dx%d\n",
+                                values[0], values[1], values[2], values[3]);
+
+                /* Raise the window */
+                xcb_circulate_window(conn, XCB_CIRCULATE_RAISE_LOWEST, client->frame);
+
+                xcb_configure_window(conn, client->frame, mask, values);
+                xcb_configure_window(conn, client->child, mask, values);
+
+                xcb_flush(conn);
+        } else {
+                printf("left fullscreen\n");
+                /* 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 layout */
+                render_layout(conn);
+        }
+}