]> git.sur5r.net Git - i3/i3/commitdiff
Call all ewmh_update_* functions together when necessary 3697/head
authorOrestis Floros <orestisf1993@gmail.com>
Fri, 3 May 2019 12:46:38 +0000 (15:46 +0300)
committerOrestis Floros <orestisf1993@gmail.com>
Fri, 3 May 2019 13:19:11 +0000 (16:19 +0300)
The testcase is changed because it was actually incorrect. Easy to
verify because:
> _NET_CURRENT_DESKTOP
> …
> The index of the current desktop. This is always an integer between 0
> and _NET_NUMBER_OF_DESKTOPS - 1.

Fixes #3696.
Also updates the viewports.

Finally, fixes an issue with _NET_CURRENT_DESKTOP not being updated
after a workspace rename. Example:
- workspaces 1, 2, 3
- rename workspace 1 to 5
- All workspaces changed their index but _NET_CURRENT_DESKTOP was not
updated

include/ewmh.h
src/commands.c
src/ewmh.c
src/main.c
src/tree.c
src/workspace.c
testcases/t/294-update-ewmh-atoms.t

index 01ae67f969c943392ab8506b583cd3b911d5e019..f616eb840abe48fc39b63dcb38e4ca3a1465c5ac 100644 (file)
 
 #include <config.h>
 
+/**
+ * Updates all the EWMH desktop properties.
+ *
+ */
+void ewmh_update_desktop_properties(void);
+
 /**
  * Updates _NET_CURRENT_DESKTOP with the current desktop number.
  *
  */
 void ewmh_update_current_desktop(void);
 
-/**
- * Updates _NET_NUMBER_OF_DESKTOPS which we interpret as the number of
- * noninternal workspaces.
- */
-void ewmh_update_number_of_desktops(void);
-
-/**
- * Updates _NET_DESKTOP_NAMES: "The names of all virtual desktops. This is a
- * list of NULL-terminated strings in UTF-8 encoding"
- */
-void ewmh_update_desktop_names(void);
-
-/**
- * Updates _NET_DESKTOP_VIEWPORT, which is an array of pairs of cardinals that
- * define the top left corner of each desktop's viewport.
- */
-void ewmh_update_desktop_viewport(void);
-
 /**
  * Updates _NET_WM_DESKTOP for all windows.
  * A request will only be made if the cached value differs from the calculated value.
index 624c27dbd8f4c59dbf198b87aed5ec603653bcc1..db0b075d93964bacc2ff5e1253a8ac2677563668 100644 (file)
@@ -2002,9 +2002,7 @@ void cmd_rename_workspace(I3_CMD, const char *old_name, const char *new_name) {
     cmd_output->needs_tree_render = true;
     ysuccess(true);
 
-    ewmh_update_desktop_names();
-    ewmh_update_desktop_viewport();
-    ewmh_update_current_desktop();
+    ewmh_update_desktop_properties();
 
     startup_sequence_rename_workspace(old_name_copy, new_name);
     free(old_name_copy);
index a26eef39c491931033fb932a6bfbe4bf54d41593..7bd23fb78f47931206c6025fdf9473bae2d0ee09 100644 (file)
@@ -39,7 +39,7 @@ void ewmh_update_current_desktop(void) {
  * Updates _NET_NUMBER_OF_DESKTOPS which we interpret as the number of
  * noninternal workspaces.
  */
-void ewmh_update_number_of_desktops(void) {
+static void ewmh_update_number_of_desktops(void) {
     Con *output, *ws;
     static uint32_t old_idx = 0;
     uint32_t idx = 0;
@@ -61,7 +61,7 @@ void ewmh_update_number_of_desktops(void) {
  * Updates _NET_DESKTOP_NAMES: "The names of all virtual desktops. This is a
  * list of NULL-terminated strings in UTF-8 encoding"
  */
-void ewmh_update_desktop_names(void) {
+static void ewmh_update_desktop_names(void) {
     Con *output, *ws;
     int msg_length = 0;
 
@@ -88,7 +88,7 @@ void ewmh_update_desktop_names(void) {
  * Updates _NET_DESKTOP_VIEWPORT, which is an array of pairs of cardinals that
  * define the top left corner of each desktop's viewport.
  */
-void ewmh_update_desktop_viewport(void) {
+static void ewmh_update_desktop_viewport(void) {
     Con *output, *ws;
     int num_desktops = 0;
     /* count number of desktops */
@@ -109,6 +109,18 @@ void ewmh_update_desktop_viewport(void) {
                         A__NET_DESKTOP_VIEWPORT, XCB_ATOM_CARDINAL, 32, current_position, &viewports);
 }
 
+/*
+ * Updates all the EWMH desktop properties.
+ *
+ */
+void ewmh_update_desktop_properties(void) {
+    ewmh_update_number_of_desktops();
+    ewmh_update_desktop_viewport();
+    ewmh_update_current_desktop();
+    ewmh_update_desktop_names();
+    ewmh_update_wm_desktop();
+}
+
 static void ewmh_update_wm_desktop_recursively(Con *con, const uint32_t desktop) {
     Con *child;
 
index 3ebdbf0cc0a2667f4cc4bf9c98e85d59fa8a1b90..9f69834fdc5bf1db6a586a272c8a0112ed5f6261 100644 (file)
@@ -852,10 +852,7 @@ int main(int argc, char *argv[]) {
     ewmh_update_workarea();
 
     /* Set the ewmh desktop properties. */
-    ewmh_update_current_desktop();
-    ewmh_update_number_of_desktops();
-    ewmh_update_desktop_names();
-    ewmh_update_desktop_viewport();
+    ewmh_update_desktop_properties();
 
     struct ev_io *xcb_watcher = scalloc(1, sizeof(struct ev_io));
     xcb_prepare = scalloc(1, sizeof(struct ev_prepare));
index f93b2262e817da7ac48639891e84009adedc6f68..4057d177b60246f9bcf60b609ce692ba8a13431e 100644 (file)
@@ -301,9 +301,7 @@ bool tree_close_internal(Con *con, kill_window_t kill_window, bool dont_kill_par
 
     if (ws == con) {
         DLOG("Closing workspace container %s, updating EWMH atoms\n", ws->name);
-        ewmh_update_number_of_desktops();
-        ewmh_update_desktop_names();
-        ewmh_update_wm_desktop();
+        ewmh_update_desktop_properties();
     }
 
     con_free(con);
index 3cf7475424b9015d76fded271fdb06261de842b4..597057985934becb1b3a916e802c72381a14cee1 100644 (file)
@@ -161,10 +161,7 @@ Con *workspace_get(const char *num, bool *created) {
         con_attach(workspace, content, false);
 
         ipc_send_workspace_event("init", workspace, NULL);
-        ewmh_update_number_of_desktops();
-        ewmh_update_desktop_names();
-        ewmh_update_desktop_viewport();
-        ewmh_update_wm_desktop();
+        ewmh_update_desktop_properties();
         if (created != NULL)
             *created = true;
     } else if (created != NULL) {
@@ -520,10 +517,7 @@ void workspace_show(Con *workspace) {
                 old_focus = NULL;
             }
 
-            ewmh_update_number_of_desktops();
-            ewmh_update_desktop_names();
-            ewmh_update_desktop_viewport();
-            ewmh_update_wm_desktop();
+            ewmh_update_desktop_properties();
         }
     }
 
index 047cc1197360f11d42c7b6c7a46ebb4fb2741a44..f13b1764518540c93ae8f76fda1f0f4087f5dfde 100644 (file)
@@ -101,11 +101,19 @@ is_deeply(\@actual_names, \@expected_names);
 # Kill first window to close a workspace.
 cmd '[id="' . $second->id . '"] kill';
 
-is(get_current_desktop, 2, '_NET_CURRENT_DESKTOP should be updated');
+is(get_current_desktop, 1, '_NET_CURRENT_DESKTOP should be updated');
 is(get_num_of_desktops, 2, '_NET_NUMBER_OF_DESKTOPS should be updated');
 my @actual_names = get_desktop_names;
 my @expected_names = ('0', '2');
 is_deeply(\@actual_names, \@expected_names, '_NET_DESKTOP_NAMES should be updated');
 
+# Rename workspace to reorder them.
+cmd 'rename workspace 0 to 5';
+
+is(get_current_desktop, 0, '_NET_CURRENT_DESKTOP should be updated');
+is(get_num_of_desktops, 2, '_NET_NUMBER_OF_DESKTOPS should remain the same');
+my @actual_names = get_desktop_names;
+my @expected_names = ('2', '5');
+is_deeply(\@actual_names, \@expected_names, '_NET_DESKTOP_NAMES should be updated');
 
 done_testing;