diff options
author | M Stoeckl <code@mstoeckl.com> | 2019-01-21 12:39:16 -0500 |
---|---|---|
committer | M Stoeckl <code@mstoeckl.com> | 2019-01-21 12:39:16 -0500 |
commit | d7ff776552bef524e905d85c2a5e7651c8408658 (patch) | |
tree | ae20feac64f93f776e9c9e136c62459705e97987 /sway | |
parent | swaybar: fix setting floating watcher slots (diff) | |
download | sway-d7ff776552bef524e905d85c2a5e7651c8408658.tar.gz sway-d7ff776552bef524e905d85c2a5e7651c8408658.tar.zst sway-d7ff776552bef524e905d85c2a5e7651c8408658.zip |
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 .
Diffstat (limited to 'sway')
-rw-r--r-- | sway/commands/bar/modifier.c | 2 | ||||
-rw-r--r-- | sway/commands/bind.c | 1 | ||||
-rw-r--r-- | sway/commands/floating_modifier.c | 2 | ||||
-rw-r--r-- | sway/config/bar.c | 4 | ||||
-rw-r--r-- | sway/input/keyboard.c | 54 | ||||
-rw-r--r-- | sway/ipc-server.c | 1 | ||||
-rw-r--r-- | sway/tree/output.c | 16 | ||||
-rw-r--r-- | sway/tree/root.c | 35 |
8 files changed, 111 insertions, 4 deletions
diff --git a/sway/commands/bar/modifier.c b/sway/commands/bar/modifier.c index 62ec681f..c95250d1 100644 --- a/sway/commands/bar/modifier.c +++ b/sway/commands/bar/modifier.c | |||
@@ -1,8 +1,8 @@ | |||
1 | #include <string.h> | 1 | #include <string.h> |
2 | #include "sway/commands.h" | 2 | #include "sway/commands.h" |
3 | #include "sway/input/keyboard.h" | ||
3 | #include "log.h" | 4 | #include "log.h" |
4 | #include "stringop.h" | 5 | #include "stringop.h" |
5 | #include "util.h" | ||
6 | 6 | ||
7 | struct cmd_results *bar_cmd_modifier(int argc, char **argv) { | 7 | struct cmd_results *bar_cmd_modifier(int argc, char **argv) { |
8 | struct cmd_results *error = NULL; | 8 | struct cmd_results *error = NULL; |
diff --git a/sway/commands/bind.c b/sway/commands/bind.c index ce087fd0..59116d67 100644 --- a/sway/commands/bind.c +++ b/sway/commands/bind.c | |||
@@ -8,6 +8,7 @@ | |||
8 | #include "sway/commands.h" | 8 | #include "sway/commands.h" |
9 | #include "sway/config.h" | 9 | #include "sway/config.h" |
10 | #include "sway/input/cursor.h" | 10 | #include "sway/input/cursor.h" |
11 | #include "sway/input/keyboard.h" | ||
11 | #include "sway/ipc-server.h" | 12 | #include "sway/ipc-server.h" |
12 | #include "list.h" | 13 | #include "list.h" |
13 | #include "log.h" | 14 | #include "log.h" |
diff --git a/sway/commands/floating_modifier.c b/sway/commands/floating_modifier.c index 3674971a..fd606281 100644 --- a/sway/commands/floating_modifier.c +++ b/sway/commands/floating_modifier.c | |||
@@ -1,7 +1,7 @@ | |||
1 | #include "strings.h" | 1 | #include "strings.h" |
2 | #include "sway/commands.h" | 2 | #include "sway/commands.h" |
3 | #include "sway/config.h" | 3 | #include "sway/config.h" |
4 | #include "util.h" | 4 | #include "sway/input/keyboard.h" |
5 | 5 | ||
6 | struct cmd_results *cmd_floating_modifier(int argc, char **argv) { | 6 | struct cmd_results *cmd_floating_modifier(int argc, char **argv) { |
7 | struct cmd_results *error = NULL; | 7 | struct cmd_results *error = NULL; |
diff --git a/sway/config/bar.c b/sway/config/bar.c index 0fdac5d8..2e28fa1e 100644 --- a/sway/config/bar.c +++ b/sway/config/bar.c | |||
@@ -11,12 +11,12 @@ | |||
11 | #include <strings.h> | 11 | #include <strings.h> |
12 | #include <signal.h> | 12 | #include <signal.h> |
13 | #include "sway/config.h" | 13 | #include "sway/config.h" |
14 | #include "sway/input/keyboard.h" | ||
14 | #include "sway/output.h" | 15 | #include "sway/output.h" |
15 | #include "config.h" | 16 | #include "config.h" |
16 | #include "stringop.h" | ||
17 | #include "list.h" | 17 | #include "list.h" |
18 | #include "log.h" | 18 | #include "log.h" |
19 | #include "util.h" | 19 | #include "stringop.h" |
20 | 20 | ||
21 | static void terminate_swaybar(pid_t pid) { | 21 | static void terminate_swaybar(pid_t pid) { |
22 | sway_log(SWAY_DEBUG, "Terminating swaybar %d", pid); | 22 | sway_log(SWAY_DEBUG, "Terminating swaybar %d", pid); |
diff --git a/sway/input/keyboard.c b/sway/input/keyboard.c index c1fc60f7..12c57366 100644 --- a/sway/input/keyboard.c +++ b/sway/input/keyboard.c | |||
@@ -1,9 +1,11 @@ | |||
1 | #include <assert.h> | 1 | #include <assert.h> |
2 | #include <limits.h> | 2 | #include <limits.h> |
3 | #include <strings.h> | ||
3 | #include <wlr/backend/multi.h> | 4 | #include <wlr/backend/multi.h> |
4 | #include <wlr/backend/session.h> | 5 | #include <wlr/backend/session.h> |
5 | #include <wlr/types/wlr_idle.h> | 6 | #include <wlr/types/wlr_idle.h> |
6 | #include <wlr/interfaces/wlr_keyboard.h> | 7 | #include <wlr/interfaces/wlr_keyboard.h> |
8 | #include <xkbcommon/xkbcommon-names.h> | ||
7 | #include "sway/commands.h" | 9 | #include "sway/commands.h" |
8 | #include "sway/desktop/transaction.h" | 10 | #include "sway/desktop/transaction.h" |
9 | #include "sway/input/input-manager.h" | 11 | #include "sway/input/input-manager.h" |
@@ -12,6 +14,58 @@ | |||
12 | #include "sway/ipc-server.h" | 14 | #include "sway/ipc-server.h" |
13 | #include "log.h" | 15 | #include "log.h" |
14 | 16 | ||
17 | static struct modifier_key { | ||
18 | char *name; | ||
19 | uint32_t mod; | ||
20 | } modifiers[] = { | ||
21 | { XKB_MOD_NAME_SHIFT, WLR_MODIFIER_SHIFT }, | ||
22 | { XKB_MOD_NAME_CAPS, WLR_MODIFIER_CAPS }, | ||
23 | { XKB_MOD_NAME_CTRL, WLR_MODIFIER_CTRL }, | ||
24 | { "Ctrl", WLR_MODIFIER_CTRL }, | ||
25 | { XKB_MOD_NAME_ALT, WLR_MODIFIER_ALT }, | ||
26 | { "Alt", WLR_MODIFIER_ALT }, | ||
27 | { XKB_MOD_NAME_NUM, WLR_MODIFIER_MOD2 }, | ||
28 | { "Mod3", WLR_MODIFIER_MOD3 }, | ||
29 | { XKB_MOD_NAME_LOGO, WLR_MODIFIER_LOGO }, | ||
30 | { "Mod5", WLR_MODIFIER_MOD5 }, | ||
31 | }; | ||
32 | |||
33 | uint32_t get_modifier_mask_by_name(const char *name) { | ||
34 | int i; | ||
35 | for (i = 0; i < (int)(sizeof(modifiers) / sizeof(struct modifier_key)); ++i) { | ||
36 | if (strcasecmp(modifiers[i].name, name) == 0) { | ||
37 | return modifiers[i].mod; | ||
38 | } | ||
39 | } | ||
40 | |||
41 | return 0; | ||
42 | } | ||
43 | |||
44 | const char *get_modifier_name_by_mask(uint32_t modifier) { | ||
45 | int i; | ||
46 | for (i = 0; i < (int)(sizeof(modifiers) / sizeof(struct modifier_key)); ++i) { | ||
47 | if (modifiers[i].mod == modifier) { | ||
48 | return modifiers[i].name; | ||
49 | } | ||
50 | } | ||
51 | |||
52 | return NULL; | ||
53 | } | ||
54 | |||
55 | int get_modifier_names(const char **names, uint32_t modifier_masks) { | ||
56 | int length = 0; | ||
57 | int i; | ||
58 | for (i = 0; i < (int)(sizeof(modifiers) / sizeof(struct modifier_key)); ++i) { | ||
59 | if ((modifier_masks & modifiers[i].mod) != 0) { | ||
60 | names[length] = modifiers[i].name; | ||
61 | ++length; | ||
62 | modifier_masks ^= modifiers[i].mod; | ||
63 | } | ||
64 | } | ||
65 | |||
66 | return length; | ||
67 | } | ||
68 | |||
15 | /** | 69 | /** |
16 | * Remove all key ids associated to a keycode from the list of pressed keys | 70 | * Remove all key ids associated to a keycode from the list of pressed keys |
17 | */ | 71 | */ |
diff --git a/sway/ipc-server.c b/sway/ipc-server.c index 82e144b7..c99f34a9 100644 --- a/sway/ipc-server.c +++ b/sway/ipc-server.c | |||
@@ -23,6 +23,7 @@ | |||
23 | #include "sway/output.h" | 23 | #include "sway/output.h" |
24 | #include "sway/server.h" | 24 | #include "sway/server.h" |
25 | #include "sway/input/input-manager.h" | 25 | #include "sway/input/input-manager.h" |
26 | #include "sway/input/keyboard.h" | ||
26 | #include "sway/input/seat.h" | 27 | #include "sway/input/seat.h" |
27 | #include "sway/tree/root.h" | 28 | #include "sway/tree/root.h" |
28 | #include "sway/tree/view.h" | 29 | #include "sway/tree/view.h" |
diff --git a/sway/tree/output.c b/sway/tree/output.c index 7fbeeebd..50a2c535 100644 --- a/sway/tree/output.c +++ b/sway/tree/output.c | |||
@@ -1,4 +1,5 @@ | |||
1 | #define _POSIX_C_SOURCE 200809L | 1 | #define _POSIX_C_SOURCE 200809L |
2 | #include <assert.h> | ||
2 | #include <ctype.h> | 3 | #include <ctype.h> |
3 | #include <string.h> | 4 | #include <string.h> |
4 | #include <strings.h> | 5 | #include <strings.h> |
@@ -12,6 +13,21 @@ | |||
12 | #include "log.h" | 13 | #include "log.h" |
13 | #include "util.h" | 14 | #include "util.h" |
14 | 15 | ||
16 | enum wlr_direction opposite_direction(enum wlr_direction d) { | ||
17 | switch (d) { | ||
18 | case WLR_DIRECTION_UP: | ||
19 | return WLR_DIRECTION_DOWN; | ||
20 | case WLR_DIRECTION_DOWN: | ||
21 | return WLR_DIRECTION_UP; | ||
22 | case WLR_DIRECTION_RIGHT: | ||
23 | return WLR_DIRECTION_LEFT; | ||
24 | case WLR_DIRECTION_LEFT: | ||
25 | return WLR_DIRECTION_RIGHT; | ||
26 | } | ||
27 | assert(false); | ||
28 | return 0; | ||
29 | } | ||
30 | |||
15 | static void restore_workspaces(struct sway_output *output) { | 31 | static void restore_workspaces(struct sway_output *output) { |
16 | // Workspace output priority | 32 | // Workspace output priority |
17 | for (int i = 0; i < root->outputs->length; i++) { | 33 | for (int i = 0; i < root->outputs->length; i++) { |
diff --git a/sway/tree/root.c b/sway/tree/root.c index 08ce7942..d4b97be3 100644 --- a/sway/tree/root.c +++ b/sway/tree/root.c | |||
@@ -169,6 +169,41 @@ struct pid_workspace { | |||
169 | 169 | ||
170 | static struct wl_list pid_workspaces; | 170 | static struct wl_list pid_workspaces; |
171 | 171 | ||
172 | /** | ||
173 | * Get the pid of a parent process given the pid of a child process. | ||
174 | * | ||
175 | * Returns the parent pid or NULL if the parent pid cannot be determined. | ||
176 | */ | ||
177 | static pid_t get_parent_pid(pid_t child) { | ||
178 | pid_t parent = -1; | ||
179 | char file_name[100]; | ||
180 | char *buffer = NULL; | ||
181 | char *token = NULL; | ||
182 | const char *sep = " "; | ||
183 | FILE *stat = NULL; | ||
184 | size_t buf_size = 0; | ||
185 | |||
186 | sprintf(file_name, "/proc/%d/stat", child); | ||
187 | |||
188 | if ((stat = fopen(file_name, "r"))) { | ||
189 | if (getline(&buffer, &buf_size, stat) != -1) { | ||
190 | token = strtok(buffer, sep); // pid | ||
191 | token = strtok(NULL, sep); // executable name | ||
192 | token = strtok(NULL, sep); // state | ||
193 | token = strtok(NULL, sep); // parent pid | ||
194 | parent = strtol(token, NULL, 10); | ||
195 | } | ||
196 | free(buffer); | ||
197 | fclose(stat); | ||
198 | } | ||
199 | |||
200 | if (parent) { | ||
201 | return (parent == child) ? -1 : parent; | ||
202 | } | ||
203 | |||
204 | return -1; | ||
205 | } | ||
206 | |||
172 | struct sway_workspace *root_workspace_for_pid(pid_t pid) { | 207 | struct sway_workspace *root_workspace_for_pid(pid_t pid) { |
173 | if (!pid_workspaces.prev && !pid_workspaces.next) { | 208 | if (!pid_workspaces.prev && !pid_workspaces.next) { |
174 | wl_list_init(&pid_workspaces); | 209 | wl_list_init(&pid_workspaces); |