From ed5ac7f41dd3b650026e13a2b9c0c77b7fbf07de Mon Sep 17 00:00:00 2001 From: Axel Wagner Date: Thu, 21 Apr 2011 20:24:02 +0200 Subject: [PATCH] =?utf8?q?Implement=20disabling=20the=20workspace=20button?= =?utf8?q?s=20(=E2=80=9Ethx=E2=80=9C=20sECuRE)?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- i3bar/include/config.h | 1 + i3bar/src/ipc.c | 10 ++++++++-- i3bar/src/main.c | 12 ++++++++++-- i3bar/src/xcb.c | 14 ++++++++++---- 4 files changed, 29 insertions(+), 8 deletions(-) diff --git a/i3bar/include/config.h b/i3bar/include/config.h index d6abb45c..b3473917 100644 --- a/i3bar/include/config.h +++ b/i3bar/include/config.h @@ -14,6 +14,7 @@ typedef struct config_t { dockpos_t dockpos; int verbose; xcb_colors_t *colors; + int disable_ws; } config_t; config_t config; diff --git a/i3bar/src/ipc.c b/i3bar/src/ipc.c index c6a85cf5..d06864c7 100644 --- a/i3bar/src/ipc.c +++ b/i3bar/src/ipc.c @@ -121,7 +121,9 @@ void got_workspace_event(char *event) { void got_output_event(char *event) { DLOG("Got Output Event!\n"); i3_send_msg(I3_IPC_MESSAGE_TYPE_GET_OUTPUTS, NULL); - i3_send_msg(I3_IPC_MESSAGE_TYPE_GET_WORKSPACES, NULL); + if (!config.disable_ws) { + i3_send_msg(I3_IPC_MESSAGE_TYPE_GET_WORKSPACES, NULL); + } } /* Data-structure to easily call the reply-handlers later */ @@ -311,5 +313,9 @@ void destroy_connection() { * */ void subscribe_events() { - i3_send_msg(I3_IPC_MESSAGE_TYPE_SUBSCRIBE, "[ \"workspace\", \"output\" ]"); + if (config.disable_ws) { + i3_send_msg(I3_IPC_MESSAGE_TYPE_SUBSCRIBE, "[ \"output\" ]"); + } else { + i3_send_msg(I3_IPC_MESSAGE_TYPE_SUBSCRIBE, "[ \"workspace\", \"output\" ]"); + } } diff --git a/i3bar/src/main.c b/i3bar/src/main.c index ad8a9993..4a859254 100644 --- a/i3bar/src/main.c +++ b/i3bar/src/main.c @@ -89,6 +89,7 @@ void print_usage(char *elf_name) { printf("\t\tIf -c is specified, the childprocess is sent a SIGSTOP on hiding,\n"); printf("\t\tand a SIGCONT on unhiding of the bars\n"); printf("-f \tUse X-Core-Font for display\n"); + printf("-w\t\tDisable workspace-buttons\n"); printf("-V\t\tBe (very) verbose with the debug-output\n"); printf("-h\t\tDisplay this help-message and exit\n"); } @@ -125,6 +126,7 @@ int main(int argc, char **argv) { /* Definition of the standard-config */ config.hide_on_modifier = 0; config.dockpos = DOCKPOS_NONE; + config.disable_ws = 0; static struct option long_opt[] = { { "socket", required_argument, 0, 's' }, @@ -132,6 +134,7 @@ int main(int argc, char **argv) { { "hide", no_argument, 0, 'm' }, { "dock", optional_argument, 0, 'd' }, { "font", required_argument, 0, 'f' }, + { "nows", no_argument, 0, 'w' }, { "help", no_argument, 0, 'h' }, { "version", no_argument, 0, 'v' }, { "verbose", no_argument, 0, 'V' }, @@ -148,7 +151,7 @@ int main(int argc, char **argv) { { NULL, 0, 0, 0} }; - while ((opt = getopt_long(argc, argv, "s:c:d::mf:hvVA:B:C:D:E:F:G:H:I:J:", long_opt, &option_index)) != -1) { + while ((opt = getopt_long(argc, argv, "s:c:d::mf:whvVA:B:C:D:E:F:G:H:I:J:", long_opt, &option_index)) != -1) { switch (opt) { case 's': socket_path = expand_path(optarg); @@ -177,6 +180,9 @@ int main(int argc, char **argv) { case 'f': fontname = strdup(optarg); break; + case 'w': + config.disable_ws = 1; + break; case 'v': printf("i3bar version " I3BAR_VERSION " © 2010 Axel Wagner and contributors\n"); exit(EXIT_SUCCESS); @@ -263,7 +269,9 @@ int main(int argc, char **argv) { * workspaces. Everything else (creating the bars, showing the right workspace- * buttons and more) is taken care of by the event-driveniness of the code */ i3_send_msg(I3_IPC_MESSAGE_TYPE_GET_OUTPUTS, NULL); - i3_send_msg(I3_IPC_MESSAGE_TYPE_GET_WORKSPACES, NULL); + if (!config.disable_ws) { + i3_send_msg(I3_IPC_MESSAGE_TYPE_GET_WORKSPACES, NULL); + } /* The name of this function is actually misleading. Even if no -c is specified, * this function initiates the watchers to listen on stdin and react accordingly */ diff --git a/i3bar/src/xcb.c b/i3bar/src/xcb.c index 2da2e6f7..e7c08060 100644 --- a/i3bar/src/xcb.c +++ b/i3bar/src/xcb.c @@ -744,8 +744,10 @@ void reconfig_windows() { /* If hide_on_modifier is set, i3 is not supposed to manage our bar-windows */ values[1] = config.hide_on_modifier; /* The events we want to receive */ - values[2] = XCB_EVENT_MASK_EXPOSURE | - XCB_EVENT_MASK_BUTTON_PRESS; + values[2] = XCB_EVENT_MASK_EXPOSURE; + if (!config.disable_ws) { + values[2] |= XCB_EVENT_MASK_BUTTON_PRESS; + } xcb_void_cookie_t win_cookie = xcb_create_window_checked(xcb_connection, xcb_screen->root_depth, walk->bar, @@ -932,6 +934,10 @@ void draw_bars() { MIN(outputs_walk->rect.w - 4, statusline_width), font_height); } + if (config.disable_ws) { + continue; + } + i3_ws *ws_walk; TAILQ_FOREACH(ws_walk, outputs_walk->workspaces, tailq) { DLOG("Drawing Button for WS %s at x = %d\n", ws_walk->name, i); @@ -978,10 +984,10 @@ void draw_bars() { i += 10 + ws_walk->name_width; } - redraw_bars(); - i = 0; } + + redraw_bars(); } /* -- 2.39.2