[wiki] [sites] [dwm][patch][ipc] Update patch to v1.5.4 || Mihir Lad

From: <git_AT_suckless.org>
Date: Thu, 30 Jul 2020 02:01:09 +0200

commit 2d8059d726d4954e0f69461cd88aa116b0f9c18f
Author: Mihir Lad <mihirlad55_AT_gmail.com>
Date: Wed Jul 29 20:00:41 2020 -0400

    [dwm][patch][ipc] Update patch to v1.5.4

diff --git a/dwm.suckless.org/patches/ipc/dwm-ipc-20200726-f04cac6.diff b/dwm.suckless.org/patches/ipc/dwm-ipc-20200729-f04cac6.diff
similarity index 97%
rename from dwm.suckless.org/patches/ipc/dwm-ipc-20200726-f04cac6.diff
rename to dwm.suckless.org/patches/ipc/dwm-ipc-20200729-f04cac6.diff
index 75c98e65..2ac88365 100644
--- a/dwm.suckless.org/patches/ipc/dwm-ipc-20200726-f04cac6.diff
+++ b/dwm.suckless.org/patches/ipc/dwm-ipc-20200729-f04cac6.diff
_AT_@ -1,6 +1,6 @@
-From 930156d1771a2af6c572856ea97b113e537cf13d Mon Sep 17 00:00:00 2001
+From 1db4901625c20669b8e448b5c78b642fb792c844 Mon Sep 17 00:00:00 2001
 From: mihirlad55 <mihirlad55_AT_gmail.com>
-Date: Sun, 26 Jul 2020 03:51:15 +0000
+Date: Wed, 29 Jul 2020 23:56:25 +0000
 Subject: [PATCH] Add IPC support through a unix socket
 
 This patch currently supports the following requests:
_AT__AT_ -34,7 +34,7 @@ https://github.com/mihirlad55/dwm-ipc
  Makefile | 10 +-
  config.def.h | 19 +
  config.mk | 8 +-
- dwm-msg.c | 519 ++++++++++++++++++++++
+ dwm-msg.c | 543 +++++++++++++++++++++++
  dwm.c | 150 ++++++-
  ipc.c | 1202 ++++++++++++++++++++++++++++++++++++++++++++++++++
  ipc.h | 320 ++++++++++++++
_AT__AT_ -42,7 +42,7 @@ https://github.com/mihirlad55/dwm-ipc
  util.h | 10 +
  yajl_dumps.c | 351 +++++++++++++++
  yajl_dumps.h | 65 +++
- 13 files changed, 2903 insertions(+), 13 deletions(-)
+ 13 files changed, 2927 insertions(+), 13 deletions(-)
  create mode 100644 IPCClient.c
  create mode 100644 IPCClient.h
  create mode 100644 dwm-msg.c
_AT_@ -276,10 +276,10 @@ index 7084c33..8570938 100644
  CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_POSIX_C_SOURCE=200809L -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS}
 diff --git a/dwm-msg.c b/dwm-msg.c
 new file mode 100644
-index 0000000..c957adf
+index 0000000..606f6ce
 --- /dev/null
 +++ b/dwm-msg.c
-_AT_@ -0,0 +1,519 @@
+_AT_@ -0,0 +1,543 @@
 +#include <ctype.h>
 +#include <errno.h>
 +#include <inttypes.h>
_AT_@ -328,6 +328,7 @@ index 0000000..c957adf
 +
 +const char *DEFAULT_SOCKET_PATH = "/tmp/dwm.sock";
 +static int sock_fd = -1;
++static unsigned int ignore_reply = 0;
 +
 +typedef enum IPCMessageType {
 + IPC_TYPE_RUN_COMMAND = 0,
_AT_@ -556,6 +557,18 @@ index 0000000..c957adf
 +}
 +
 +static void
++flush_socket_reply()
++{
++ IPCMessageType reply_type;
++ uint32_t reply_size;
++ char *reply;
++
++ read_socket(&reply_type, &reply_size, &reply);
++
++ free(reply);
++}
++
++static void
 +print_socket_reply()
 +{
 + IPCMessageType reply_type;
_AT_@ -565,6 +578,7 @@ index 0000000..c957adf
 + read_socket(&reply_type, &reply_size, &reply);
 +
 + printf("%.*s
", reply_size, reply);
++ fflush(stdout);
 + free(reply);
 +}
 +
_AT_@ -604,7 +618,10 @@ index 0000000..c957adf
 +
 + send_message(IPC_TYPE_RUN_COMMAND, msg_size, (uint8_t *)msg);
 +
-+ print_socket_reply();
++ if (!ignore_reply)
++ print_socket_reply();
++ else
++ flush_socket_reply();
 +
 + yajl_gen_free(gen);
 +
_AT_@ -690,7 +707,10 @@ index 0000000..c957adf
 +
 + send_message(IPC_TYPE_SUBSCRIBE, msg_size, (uint8_t *)msg);
 +
-+ print_socket_reply();
++ if (!ignore_reply)
++ print_socket_reply();
++ else
++ flush_socket_reply();
 +
 + yajl_gen_free(gen);
 +
_AT_@ -715,7 +735,7 @@ index 0000000..c957adf
 +static void
 +print_usage(const char *name)
 +{
-+ printf("usage: %s <command> [...]
", name);
++ printf("usage: %s [options] <command> [...]
", name);
 + puts("");
 + puts("Commands:");
 + puts(" run_command <name> [args...] Run an IPC command");
_AT_@ -738,14 +758,16 @@ index 0000000..c957adf
 + puts("");
 + puts(" help Display this message");
 + puts("");
++ puts("Options:");
++ puts(" --ignore-reply Don't print reply messages from");
++ puts(" run_command and subscribe.");
++ puts("");
 +}
 +
 +int
 +main(int argc, char *argv[])
 +{
 + const char *prog_name = argv[0];
-+ // Need at least command argument
-+ if (argc < 2) usage_error(prog_name, "Expected an argument, got none");
 +
 + connect_to_socket();
 + if (sock_fd == -1) {
_AT_@ -753,51 +775,53 @@ index 0000000..c957adf
 + return 1;
 + }
 +
-+ for (int i = 1; i < argc; i++) {
-+ if (strcmp(argv[i], "help") == 0) {
-+ print_usage(prog_name);
-+ return 0;
-+ } else if (strcmp(argv[i], "run_command") == 0) {
-+ if (++i >= argc) usage_error(prog_name, "No command specified");
-+ // Command name
-+ char *command = argv[i];
-+ // Command arguments are everything after command name
-+ char **command_args = argv + ++i;
-+ // Number of command arguments
-+ int command_argc = argc - i;
-+ run_command(command, command_args, command_argc);
-+ return 0;
-+ } else if (strcmp(argv[i], "get_monitors") == 0) {
-+ get_monitors();
-+ return 0;
-+ } else if (strcmp(argv[i], "get_tags") == 0) {
-+ get_tags();
-+ return 0;
-+ } else if (strcmp(argv[i], "get_layouts") == 0) {
-+ get_layouts();
-+ return 0;
-+ } else if (strcmp(argv[i], "get_dwm_client") == 0) {
-+ if (++i < argc) {
-+ if (is_unsigned_int(argv[i])) {
-+ Window win = atol(argv[i]);
-+ get_dwm_client(win);
-+ } else
-+ usage_error(prog_name, "Expected unsigned integer argument");
-+ } else
-+ usage_error(prog_name, "Expected the window id");
-+ return 0;
-+ } else if (strcmp(argv[i], "subscribe") == 0) {
-+ if (++i < argc) {
-+ for (int j = i; j < argc; j++) subscribe(argv[j]);
++ int i = 1;
++ if (strcmp(argv[i], "--ignore-reply") == 0) {
++ ignore_reply = 1;
++ i++;
++ }
++
++ if (i >= argc) usage_error(prog_name, "Expected an argument, got none");
++
++ if (strcmp(argv[i], "help") == 0)
++ print_usage(prog_name);
++ else if (strcmp(argv[i], "run_command") == 0) {
++ if (++i >= argc) usage_error(prog_name, "No command specified");
++ // Command name
++ char *command = argv[i];
++ // Command arguments are everything after command name
++ char **command_args = argv + ++i;
++ // Number of command arguments
++ int command_argc = argc - i;
++ run_command(command, command_args, command_argc);
++ } else if (strcmp(argv[i], "get_monitors") == 0) {
++ get_monitors();
++ } else if (strcmp(argv[i], "get_tags") == 0) {
++ get_tags();
++ } else if (strcmp(argv[i], "get_layouts") == 0) {
++ get_layouts();
++ } else if (strcmp(argv[i], "get_dwm_client") == 0) {
++ if (++i < argc) {
++ if (is_unsigned_int(argv[i])) {
++ Window win = atol(argv[i]);
++ get_dwm_client(win);
 + } else
-+ usage_error(prog_name, "Expected event name");
-+ // Keep listening for events forever
-+ while (1) {
-+ print_socket_reply();
-+ }
++ usage_error(prog_name, "Expected unsigned integer argument");
 + } else
-+ usage_error(prog_name, "Invalid argument '%s'", argv[i]);
-+ }
++ usage_error(prog_name, "Expected the window id");
++ } else if (strcmp(argv[i], "subscribe") == 0) {
++ if (++i < argc) {
++ for (int j = i; j < argc; j++) subscribe(argv[j]);
++ } else
++ usage_error(prog_name, "Expected event name");
++ // Keep listening for events forever
++ while (1) {
++ print_socket_reply();
++ }
++ } else
++ usage_error(prog_name, "Invalid argument '%s'", argv[i]);
++
++ return 0;
 +}
 diff --git a/dwm.c b/dwm.c
 index 9fd0286..c90c61a 100644
diff --git a/dwm.suckless.org/patches/ipc/dwm-ipc-v1.5.2-to-v1.5.3.diff b/dwm.suckless.org/patches/ipc/dwm-ipc-v1.5.2-to-v1.5.3.diff
deleted file mode 100644
index c18054d1..00000000
--- a/dwm.suckless.org/patches/ipc/dwm-ipc-v1.5.2-to-v1.5.3.diff
+++ /dev/null
_AT_@ -1,28 +0,0 @@
-From c76d3cc2f68961b05c6c1a509c24e71ab7473c47 Mon Sep 17 00:00:00 2001
-From: mihirlad55 <mihirlad55_AT_gmail.com>
-Date: Sun, 26 Jul 2020 03:51:16 +0000
-Subject: [PATCH] Update from v1.5.2 to v1.5.3
-
-- Fix a major bug where events would not be raised for any monitors after the
- first monitor if the first monitor did not have a selected client (i.e. was
- viewing an unoccupied tag)
----
- ipc.c | 2 +-
- 1 file changed, 1 insertion(+), 1 deletion(-)
-
-diff --git a/ipc.c b/ipc.c
-index 1d435dc..e527e23 100644
---- a/ipc.c
-+++ b/ipc.c
-_AT_@ -1124,7 +1124,7 @@ ipc_send_events(Monitor *mons, Monitor **lastselmon, Monitor *selmon)
-     }
- 
-     Client *sel = m->sel;
--    if (!sel) return;
-+    if (!sel) continue;
-     ClientState *o = &m->sel->prevstate;
-     ClientState n = {.oldstate = sel->oldstate,
-                      .isfixed = sel->isfixed,
--- 
-2.27.0
-
diff --git a/dwm.suckless.org/patches/ipc/dwm-ipc-v1.5.3-to-v1.5.4.diff b/dwm.suckless.org/patches/ipc/dwm-ipc-v1.5.3-to-v1.5.4.diff
new file mode 100644
index 00000000..dca3ca16
--- /dev/null
+++ b/dwm.suckless.org/patches/ipc/dwm-ipc-v1.5.3-to-v1.5.4.diff
_AT_@ -0,0 +1,203 @@
+From 29ed50543dd31718fc55f9106dfc79aada72289d Mon Sep 17 00:00:00 2001
+From: mihirlad55 <mihirlad55_AT_gmail.com>
+Date: Wed, 29 Jul 2020 23:56:24 +0000
+Subject: [PATCH] Update from v1.5.3 to v1.5.4
+
+- Fix redirection of dwm-msg not working. This was caused by stdout never being
+  flushed. stdout is now flushed after every event message is received.
+- Add --ignore-reply option to dwm-msg which ignores the initial success/failure
+  reply from the run_command and subscribe commands. This is most useful for
+  subscribing to events and ignoring the initial success reply.
+---
+ dwm-msg.c | 120 ++++++++++++++++++++++++++++++++----------------------
+ 1 file changed, 72 insertions(+), 48 deletions(-)
+
+diff --git a/dwm-msg.c b/dwm-msg.c
+index c957adf..606f6ce 100644
+--- a/dwm-msg.c
++++ b/dwm-msg.c
+_AT_@ -46,6 +46,7 @@ typedef unsigned long Window;
+ 
+ const char *DEFAULT_SOCKET_PATH = "/tmp/dwm.sock";
+ static int sock_fd = -1;
++static unsigned int ignore_reply = 0;
+ 
+ typedef enum IPCMessageType {
+   IPC_TYPE_RUN_COMMAND = 0,
+_AT_@ -273,6 +274,18 @@ is_signed_int(const char *s)
+   return 1;
+ }
+ 
++static void
++flush_socket_reply()
++{
++  IPCMessageType reply_type;
++  uint32_t reply_size;
++  char *reply;
++
++  read_socket(&reply_type, &reply_size, &reply);
++
++  free(reply);
++}
++
+ static void
+ print_socket_reply()
+ {
+_AT_@ -283,6 +296,7 @@ print_socket_reply()
+   read_socket(&reply_type, &reply_size, &reply);
+ 
+   printf("%.*s
", reply_size, reply);
++  fflush(stdout);
+   free(reply);
+ }
+ 
+_AT_@ -322,7 +336,10 @@ run_command(const char *name, char *args[], int argc)
+ 
+   send_message(IPC_TYPE_RUN_COMMAND, msg_size, (uint8_t *)msg);
+ 
+-  print_socket_reply();
++  if (!ignore_reply)
++    print_socket_reply();
++  else
++    flush_socket_reply();
+ 
+   yajl_gen_free(gen);
+ 
+_AT_@ -408,7 +425,10 @@ subscribe(const char *event)
+ 
+   send_message(IPC_TYPE_SUBSCRIBE, msg_size, (uint8_t *)msg);
+ 
+-  print_socket_reply();
++  if (!ignore_reply)
++    print_socket_reply();
++  else
++    flush_socket_reply();
+ 
+   yajl_gen_free(gen);
+ 
+_AT_@ -433,7 +453,7 @@ usage_error(const char *prog_name, const char *format, ...)
+ static void
+ print_usage(const char *name)
+ {
+-  printf("usage: %s <command> [...]
", name);
++  printf("usage: %s [options] <command> [...]
", name);
+   puts("");
+   puts("Commands:");
+   puts("  run_command <name> [args...]    Run an IPC command");
+_AT_@ -456,14 +476,16 @@ print_usage(const char *name)
+   puts("");
+   puts("  help                            Display this message");
+   puts("");
++  puts("Options:");
++  puts("  --ignore-reply                  Don't print reply messages from");
++  puts("                                  run_command and subscribe.");
++  puts("");
+ }
+ 
+ int
+ main(int argc, char *argv[])
+ {
+   const char *prog_name = argv[0];
+-  // Need at least command argument
+-  if (argc < 2) usage_error(prog_name, "Expected an argument, got none");
+ 
+   connect_to_socket();
+   if (sock_fd == -1) {
+_AT_@ -471,49 +493,51 @@ main(int argc, char *argv[])
+     return 1;
+   }
+ 
+-  for (int i = 1; i < argc; i++) {
+-    if (strcmp(argv[i], "help") == 0) {
+-      print_usage(prog_name);
+-      return 0;
+-    } else if (strcmp(argv[i], "run_command") == 0) {
+-      if (++i >= argc) usage_error(prog_name, "No command specified");
+-      // Command name
+-      char *command = argv[i];
+-      // Command arguments are everything after command name
+-      char **command_args = argv + ++i;
+-      // Number of command arguments
+-      int command_argc = argc - i;
+-      run_command(command, command_args, command_argc);
+-      return 0;
+-    } else if (strcmp(argv[i], "get_monitors") == 0) {
+-      get_monitors();
+-      return 0;
+-    } else if (strcmp(argv[i], "get_tags") == 0) {
+-      get_tags();
+-      return 0;
+-    } else if (strcmp(argv[i], "get_layouts") == 0) {
+-      get_layouts();
+-      return 0;
+-    } else if (strcmp(argv[i], "get_dwm_client") == 0) {
+-      if (++i < argc) {
+-        if (is_unsigned_int(argv[i])) {
+-          Window win = atol(argv[i]);
+-          get_dwm_client(win);
+-        } else
+-          usage_error(prog_name, "Expected unsigned integer argument");
+-      } else
+-        usage_error(prog_name, "Expected the window id");
+-      return 0;
+-    } else if (strcmp(argv[i], "subscribe") == 0) {
+-      if (++i < argc) {
+-        for (int j = i; j < argc; j++) subscribe(argv[j]);
++  int i = 1;
++  if (strcmp(argv[i], "--ignore-reply") == 0) {
++    ignore_reply = 1;
++    i++;
++  }
++
++  if (i >= argc) usage_error(prog_name, "Expected an argument, got none");
++
++  if (strcmp(argv[i], "help") == 0)
++    print_usage(prog_name);
++  else if (strcmp(argv[i], "run_command") == 0) {
++    if (++i >= argc) usage_error(prog_name, "No command specified");
++    // Command name
++    char *command = argv[i];
++    // Command arguments are everything after command name
++    char **command_args = argv + ++i;
++    // Number of command arguments
++    int command_argc = argc - i;
++    run_command(command, command_args, command_argc);
++  } else if (strcmp(argv[i], "get_monitors") == 0) {
++    get_monitors();
++  } else if (strcmp(argv[i], "get_tags") == 0) {
++    get_tags();
++  } else if (strcmp(argv[i], "get_layouts") == 0) {
++    get_layouts();
++  } else if (strcmp(argv[i], "get_dwm_client") == 0) {
++    if (++i < argc) {
++      if (is_unsigned_int(argv[i])) {
++        Window win = atol(argv[i]);
++        get_dwm_client(win);
+       } else
+-        usage_error(prog_name, "Expected event name");
+-      // Keep listening for events forever
+-      while (1) {
+-        print_socket_reply();
+-      }
++        usage_error(prog_name, "Expected unsigned integer argument");
+     } else
+-      usage_error(prog_name, "Invalid argument '%s'", argv[i]);
+-  }
++      usage_error(prog_name, "Expected the window id");
++  } else if (strcmp(argv[i], "subscribe") == 0) {
++    if (++i < argc) {
++      for (int j = i; j < argc; j++) subscribe(argv[j]);
++    } else
++      usage_error(prog_name, "Expected event name");
++    // Keep listening for events forever
++    while (1) {
++      print_socket_reply();
++    }
++  } else
++    usage_error(prog_name, "Invalid argument '%s'", argv[i]);
++
++  return 0;
+ }
+-- 
+2.27.0
+
diff --git a/dwm.suckless.org/patches/ipc/index.md b/dwm.suckless.org/patches/ipc/index.md
index e7c22333..7275ab77 100644
--- a/dwm.suckless.org/patches/ipc/index.md
+++ b/dwm.suckless.org/patches/ipc/index.md
_AT_@ -64,10 +64,10 @@ creating custom shell scripts to control dwm.
 
 Download
 --------
-* IPC Patch v1.5.3:
-  [dwm-ipc-20200726-f04cac6.diff](dwm-ipc-20200726-f04cac6.diff)
-* IPC Patch v1.5.2 to v1.5.3 Update:
-  [dwm-ipc-v1.5.2-to-v1.5.3.diff](dwm-ipc-v1.5.2-to-v1.5.3.diff)
+* IPC Patch v1.5.4:
+  [dwm-ipc-20200729-f04cac6.diff](dwm-ipc-20200729-f04cac6.diff)
+* IPC Patch v1.5.3 to v1.5.4 Update:
+  [dwm-ipc-v1.5.3-to-v1.5.4.diff](dwm-ipc-v1.5.3-to-v1.5.4.diff)
 
 The latest releases of the patch will always be available first on the project
 [Releases](https://github.com/mihirlad55/dwm-ipc/releases) page. There are also
Received on Thu Jul 30 2020 - 02:01:09 CEST

This archive was generated by hypermail 2.3.0 : Thu Jul 30 2020 - 02:12:44 CEST