]> git.sur5r.net Git - i3/i3/commitdiff
Use a different color for focused windows in not focused containers, includes bugfixe...
authorMichael Stapelberg <michael+x200@stapelberg.de>
Tue, 3 Mar 2009 01:28:26 +0000 (02:28 +0100)
committerMichael Stapelberg <michael+x200@stapelberg.de>
Tue, 3 Mar 2009 01:28:26 +0000 (02:28 +0100)
include/layout.h
src/commands.c
src/layout.c
src/util.c

index fe2c2d9a11b6e8e207cbd3be87c54abaab80bc22..165a943944ff8e809eeca8d73a83ac7782005b56 100644 (file)
@@ -15,6 +15,7 @@
 
 Rect get_unoccupied_space(Workspace *workspace);
 void decorate_window(xcb_connection_t *conn, Client *client, xcb_drawable_t drawable, xcb_gcontext_t gc, int offset);
+void redecorate_window(xcb_connection_t *conn, Client *client);
 void render_container(xcb_connection_t *connection, Container *container);
 void render_layout(xcb_connection_t *conn);
 
index c38ad58b18dd7cffacd7fa943e28e0d1d76514fe..e9be6a77e1e9d3e829ed1e2993dc012e3b310511 100644 (file)
@@ -48,6 +48,10 @@ static bool focus_window_in_container(xcb_connection_t *connection, Container *c
 
 static void focus_window(xcb_connection_t *connection, direction_t direction) {
         printf("focusing direction %d\n", direction);
+
+        int new_row = current_row,
+            new_col = current_col;
+
         /* TODO: for horizontal default layout, this has to be expanded to LEFT/RIGHT */
         if (direction == D_UP || direction == D_DOWN) {
                 /* Let’s see if we can perform up/down focus in the current container */
@@ -60,14 +64,14 @@ static void focus_window(xcb_connection_t *connection, direction_t direction) {
                         return;
 
                 if (direction == D_DOWN && cell_exists(current_col, current_row+1))
-                        current_row++;
+                        new_row++;
                 else if (direction == D_UP && cell_exists(current_col, current_row-1))
-                        current_row--;
+                        new_row--;
         } else if (direction == D_LEFT || direction == D_RIGHT) {
                 if (direction == D_RIGHT && cell_exists(current_col+1, current_row))
-                        current_col++;
+                        new_col++;
                 else if (direction == D_LEFT && cell_exists(current_col-1, current_row))
-                        current_col--;
+                        new_col--;
                 else {
                         printf("nah, not possible\n");
                         return;
@@ -77,8 +81,8 @@ static void focus_window(xcb_connection_t *connection, direction_t direction) {
                 return;
         }
 
-        if (CUR_CELL->currently_focused != NULL)
-                set_focus(connection, CUR_CELL->currently_focused);
+        if (c_ws->table[new_col][new_row]->currently_focused != NULL)
+                set_focus(connection, c_ws->table[new_col][new_row]->currently_focused);
 }
 
 /*
index 5019552404cb147d2d5f360303ec5083d7583ba8..55df8a45b09b7f848a569a7a508a68d8056a57f4 100644 (file)
@@ -23,6 +23,7 @@
 #include "table.h"
 #include "util.h"
 #include "xinerama.h"
+#include "layout.h"
 
 /* This macro copies the old value of the given variable, changes the variable to contain
    th new one and returns true if it changed */
@@ -77,6 +78,20 @@ int get_unoccupied_y(Workspace *workspace, int col) {
         return unoccupied;
 }
 
+/*
+ * Redecorates the given client correctly by checking if it’s in a stacking container and
+ * re-rendering the stack window or just calling decorate_window if it’s not in a stacking
+ * container.
+ *
+ */
+void redecorate_window(xcb_connection_t *conn, Client *client) {
+        if (client->container->mode == MODE_STACK) {
+                render_container(conn, client->container);
+                xcb_flush(conn);
+        } else decorate_window(conn, client, client->frame, client->titlegc, 0);
+}
+
+
 /*
  * (Re-)draws window decorations for a given Client onto the given drawable/graphic context.
  * When in stacking mode, the window decorations are drawn onto an own window.
@@ -93,7 +108,12 @@ void decorate_window(xcb_connection_t *conn, Client *client, xcb_drawable_t draw
                 return;
 
         if (client->container->currently_focused == client) {
-                background_color = get_colorpixel(conn, client, client->frame, "#285577");
+                /* Distinguish if the window is currently focused… */
+                if (CUR_CELL->currently_focused == client)
+                        background_color = get_colorpixel(conn, client, client->frame, "#285577");
+                /* …or if it is the focused window in a not focused container */
+                else background_color = get_colorpixel(conn, client, client->frame, "#555555");
+
                 text_color = get_colorpixel(conn, client, client->frame, "#ffffff");
                 border_color = get_colorpixel(conn, client, client->frame, "#4c7899");
         } else {
index 995d3a54c3727bd8de518f9e884f9474242b9e6d..1eda374f774ceb196618850c1cdba3665d384bf7 100644 (file)
@@ -127,6 +127,9 @@ void set_focus(xcb_connection_t *conn, Client *client) {
         if (client->dock)
                 return;
 
+        /* Store the old client */
+        Client *old_client = CUR_CELL->currently_focused;
+
         /* TODO: check if the focus needs to be changed at all */
         /* Store current_row/current_col */
         c_ws->current_row = current_row;
@@ -134,7 +137,6 @@ void set_focus(xcb_connection_t *conn, Client *client) {
         c_ws = client->container->workspace;
 
         /* Update container */
-        Client *old_client = client->container->currently_focused;
         client->container->currently_focused = client;
 
         current_col = client->container->col;
@@ -145,18 +147,13 @@ void set_focus(xcb_connection_t *conn, Client *client) {
         xcb_set_input_focus(conn, XCB_INPUT_FOCUS_POINTER_ROOT, client->child, XCB_CURRENT_TIME);
         //xcb_warp_pointer(conn, XCB_NONE, client->child, 0, 0, 0, 0, 10, 10);
 
-        /* If we’re in stacking mode, we render the container to update changes in the title
+        /* If we’re in stacking mode, this renders the container to update changes in the title
            bars and to raise the focused client */
-        if (client->container->mode == MODE_STACK)
-                render_container(conn, client->container);
-        else {
-                /* Update last/current client’s titlebar */
-                if (old_client != NULL)
-                        decorate_window(conn, old_client, old_client->frame, old_client->titlegc, 0);
-                decorate_window(conn, client, client->frame, client->titlegc, 0);
-        }
+        if (old_client != NULL)
+                redecorate_window(conn, old_client);
 
-        xcb_flush(conn);
+        /* redecorate_window flushes, so we don’t need to */
+        redecorate_window(conn, client);
 }
 
 /*