From d7ff776552bef524e905d85c2a5e7651c8408658 Mon Sep 17 00:00:00 2001 From: M Stoeckl Date: Mon, 21 Jan 2019 12:39:16 -0500 Subject: Move sway-specific functions in common/util.c into sway/ Modifier handling functions were moved into sway/input/keyboard.c; opposite_direction for enum wlr_direction into sway/tree/output.c; and get_parent_pid into sway/tree/root.c . --- common/util.c | 105 ---------------------------------------------------------- 1 file changed, 105 deletions(-) (limited to 'common') diff --git a/common/util.c b/common/util.c index 27039dcb..60f2f160 100644 --- a/common/util.c +++ b/common/util.c @@ -1,17 +1,9 @@ #define _POSIX_C_SOURCE 200809L -#include -#include -#include -#include #include #include -#include -#include #include #include #include -#include -#include #include "log.h" #include "util.h" @@ -27,88 +19,6 @@ int numlen(int n) { return log10(abs(n)) + (n > 0 ? 1 : 2); } -static struct modifier_key { - char *name; - uint32_t mod; -} modifiers[] = { - { XKB_MOD_NAME_SHIFT, WLR_MODIFIER_SHIFT }, - { XKB_MOD_NAME_CAPS, WLR_MODIFIER_CAPS }, - { XKB_MOD_NAME_CTRL, WLR_MODIFIER_CTRL }, - { "Ctrl", WLR_MODIFIER_CTRL }, - { XKB_MOD_NAME_ALT, WLR_MODIFIER_ALT }, - { "Alt", WLR_MODIFIER_ALT }, - { XKB_MOD_NAME_NUM, WLR_MODIFIER_MOD2 }, - { "Mod3", WLR_MODIFIER_MOD3 }, - { XKB_MOD_NAME_LOGO, WLR_MODIFIER_LOGO }, - { "Mod5", WLR_MODIFIER_MOD5 }, -}; - -uint32_t get_modifier_mask_by_name(const char *name) { - int i; - for (i = 0; i < (int)(sizeof(modifiers) / sizeof(struct modifier_key)); ++i) { - if (strcasecmp(modifiers[i].name, name) == 0) { - return modifiers[i].mod; - } - } - - return 0; -} - -const char *get_modifier_name_by_mask(uint32_t modifier) { - int i; - for (i = 0; i < (int)(sizeof(modifiers) / sizeof(struct modifier_key)); ++i) { - if (modifiers[i].mod == modifier) { - return modifiers[i].name; - } - } - - return NULL; -} - -int get_modifier_names(const char **names, uint32_t modifier_masks) { - int length = 0; - int i; - for (i = 0; i < (int)(sizeof(modifiers) / sizeof(struct modifier_key)); ++i) { - if ((modifier_masks & modifiers[i].mod) != 0) { - names[length] = modifiers[i].name; - ++length; - modifier_masks ^= modifiers[i].mod; - } - } - - return length; -} - -pid_t get_parent_pid(pid_t child) { - pid_t parent = -1; - char file_name[100]; - char *buffer = NULL; - char *token = NULL; - const char *sep = " "; - FILE *stat = NULL; - size_t buf_size = 0; - - sprintf(file_name, "/proc/%d/stat", child); - - if ((stat = fopen(file_name, "r"))) { - if (getline(&buffer, &buf_size, stat) != -1) { - token = strtok(buffer, sep); // pid - token = strtok(NULL, sep); // executable name - token = strtok(NULL, sep); // state - token = strtok(NULL, sep); // parent pid - parent = strtol(token, NULL, 10); - } - free(buffer); - fclose(stat); - } - - if (parent) { - return (parent == child) ? -1 : parent; - } - - return -1; -} - uint32_t parse_color(const char *color) { if (color[0] == '#') { ++color; @@ -152,18 +62,3 @@ float parse_float(const char *value) { } return flt; } - -enum wlr_direction opposite_direction(enum wlr_direction d) { - switch (d) { - case WLR_DIRECTION_UP: - return WLR_DIRECTION_DOWN; - case WLR_DIRECTION_DOWN: - return WLR_DIRECTION_UP; - case WLR_DIRECTION_RIGHT: - return WLR_DIRECTION_LEFT; - case WLR_DIRECTION_LEFT: - return WLR_DIRECTION_RIGHT; - } - assert(false); - return 0; -} -- cgit v1.2.3 From c040defd5f5cf5beed264dd057097625d9c0d423 Mon Sep 17 00:00:00 2001 From: M Stoeckl Date: Mon, 21 Jan 2019 12:46:45 -0500 Subject: Fix edge case bug in numlen, dropping use of math.h functions (Specifically, numlen when called with INT_MIN gave an incorrect result, because abs(INT_MIN) == INT_MIN < 0.) --- common/util.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'common') diff --git a/common/util.c b/common/util.c index 60f2f160..bd7bed2d 100644 --- a/common/util.c +++ b/common/util.c @@ -12,11 +12,12 @@ int wrap(int i, int max) { } int numlen(int n) { - if (n == 0) { - return 1; + int j = n <= 0 ? 1 : 0; + while (n) { + j++; + n /= 10; } - // Account for the '-' in negative numbers. - return log10(abs(n)) + (n > 0 ? 1 : 2); + return j; } uint32_t parse_color(const char *color) { -- cgit v1.2.3 From 4b1eaaf731b0e29497edc4c85153f2cf417fb5ce Mon Sep 17 00:00:00 2001 From: M Stoeckl Date: Mon, 21 Jan 2019 13:01:09 -0500 Subject: Removed unused wlroots dependency for sway(bg|bar|msg|nag) Also remove direct libm dependency where unused. --- client/meson.build | 3 +-- common/meson.build | 3 +-- include/cairo.h | 2 +- swaybar/meson.build | 3 +-- swaybg/meson.build | 4 +--- swaymsg/meson.build | 2 +- swaynag/meson.build | 2 -- 7 files changed, 6 insertions(+), 13 deletions(-) (limited to 'common') diff --git a/client/meson.build b/client/meson.build index 2bdda457..abe6f1eb 100644 --- a/client/meson.build +++ b/client/meson.build @@ -8,8 +8,7 @@ lib_sway_client = static_library( gdk_pixbuf, pango, pangocairo, - wlroots, - wayland_client, + wayland_client ], link_with: [lib_sway_common], include_directories: sway_inc diff --git a/common/meson.build b/common/meson.build index 3af1f1d5..8561d6cf 100644 --- a/common/meson.build +++ b/common/meson.build @@ -15,8 +15,7 @@ lib_sway_common = static_library( cairo, gdk_pixbuf, pango, - pangocairo, - wlroots + pangocairo ], include_directories: sway_inc ) diff --git a/include/cairo.h b/include/cairo.h index f28c072f..d1b9b8d7 100644 --- a/include/cairo.h +++ b/include/cairo.h @@ -4,7 +4,7 @@ #include "config.h" #include #include -#include +#include #if HAVE_GDK_PIXBUF #include #endif diff --git a/swaybar/meson.build b/swaybar/meson.build index b35f8169..469145ae 100644 --- a/swaybar/meson.build +++ b/swaybar/meson.build @@ -16,8 +16,7 @@ swaybar_deps = [ pangocairo, rt, wayland_client, - wayland_cursor, - wlroots, + wayland_cursor ] if have_tray if systemd.found() diff --git a/swaybg/meson.build b/swaybg/meson.build index 8704de6d..2b93da47 100644 --- a/swaybg/meson.build +++ b/swaybg/meson.build @@ -7,11 +7,9 @@ executable( client_protos, gdk_pixbuf, jsonc, - math, pango, pangocairo, - wayland_client, - wlroots, + wayland_client ], link_with: [lib_sway_common, lib_sway_client], install: true diff --git a/swaymsg/meson.build b/swaymsg/meson.build index b78e6cb0..3a27fa9f 100644 --- a/swaymsg/meson.build +++ b/swaymsg/meson.build @@ -2,7 +2,7 @@ executable( 'swaymsg', 'main.c', include_directories: [sway_inc], - dependencies: [jsonc, wlroots], + dependencies: [jsonc], link_with: [lib_sway_common], install: true ) diff --git a/swaynag/meson.build b/swaynag/meson.build index 2ba3ed95..9c29fd1a 100644 --- a/swaynag/meson.build +++ b/swaynag/meson.build @@ -11,12 +11,10 @@ executable( cairo, client_protos, gdk_pixbuf, - math, pango, pangocairo, wayland_client, wayland_cursor, - wlroots, ], link_with: [lib_sway_common, lib_sway_client], install: true -- cgit v1.2.3