aboutsummaryrefslogtreecommitdiff
path: root/sway
diff options
context:
space:
mode:
Diffstat (limited to 'sway')
-rw-r--r--sway/commands/bar/modifier.c2
-rw-r--r--sway/commands/bind.c1
-rw-r--r--sway/commands/floating_modifier.c2
-rw-r--r--sway/config/bar.c4
-rw-r--r--sway/input/keyboard.c54
-rw-r--r--sway/ipc-server.c1
-rw-r--r--sway/tree/output.c16
-rw-r--r--sway/tree/root.c35
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 @@
#include <string.h>
#include "sway/commands.h"
+#include "sway/input/keyboard.h"
#include "log.h"
#include "stringop.h"
-#include "util.h"
struct cmd_results *bar_cmd_modifier(int argc, char **argv) {
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 @@
#include "sway/commands.h"
#include "sway/config.h"
#include "sway/input/cursor.h"
+#include "sway/input/keyboard.h"
#include "sway/ipc-server.h"
#include "list.h"
#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 @@
#include "strings.h"
#include "sway/commands.h"
#include "sway/config.h"
-#include "util.h"
+#include "sway/input/keyboard.h"
struct cmd_results *cmd_floating_modifier(int argc, char **argv) {
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 @@
#include <strings.h>
#include <signal.h>
#include "sway/config.h"
+#include "sway/input/keyboard.h"
#include "sway/output.h"
#include "config.h"
-#include "stringop.h"
#include "list.h"
#include "log.h"
-#include "util.h"
+#include "stringop.h"
static void terminate_swaybar(pid_t pid) {
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 @@
#include <assert.h>
#include <limits.h>
+#include <strings.h>
#include <wlr/backend/multi.h>
#include <wlr/backend/session.h>
#include <wlr/types/wlr_idle.h>
#include <wlr/interfaces/wlr_keyboard.h>
+#include <xkbcommon/xkbcommon-names.h>
#include "sway/commands.h"
#include "sway/desktop/transaction.h"
#include "sway/input/input-manager.h"
@@ -12,6 +14,58 @@
#include "sway/ipc-server.h"
#include "log.h"
+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;
+}
+
/**
* Remove all key ids associated to a keycode from the list of pressed keys
*/
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 @@
#include "sway/output.h"
#include "sway/server.h"
#include "sway/input/input-manager.h"
+#include "sway/input/keyboard.h"
#include "sway/input/seat.h"
#include "sway/tree/root.h"
#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 @@
#define _POSIX_C_SOURCE 200809L
+#include <assert.h>
#include <ctype.h>
#include <string.h>
#include <strings.h>
@@ -12,6 +13,21 @@
#include "log.h"
#include "util.h"
+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;
+}
+
static void restore_workspaces(struct sway_output *output) {
// Workspace output priority
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 {
static struct wl_list pid_workspaces;
+/**
+ * Get the pid of a parent process given the pid of a child process.
+ *
+ * Returns the parent pid or NULL if the parent pid cannot be determined.
+ */
+static 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;
+}
+
struct sway_workspace *root_workspace_for_pid(pid_t pid) {
if (!pid_workspaces.prev && !pid_workspaces.next) {
wl_list_init(&pid_workspaces);