move wlr dependent input handler to sway

Moves input handling code that uses headers from wlroots from the common
code to sway proper, to allow for removing the wlroots dependency from
clients
This commit is contained in:
Markus Ongyerth 2018-05-24 21:52:35 +02:00
parent c7c1cf31f7
commit acae6ad40f
6 changed files with 77 additions and 76 deletions

View file

@ -9,7 +9,6 @@
#include <string.h> #include <string.h>
#include <strings.h> #include <strings.h>
#include <xkbcommon/xkbcommon-names.h> #include <xkbcommon/xkbcommon-names.h>
#include <wlr/types/wlr_keyboard.h>
#include "log.h" #include "log.h"
#include "readline.h" #include "readline.h"
#include "util.h" #include "util.h"
@ -25,58 +24,6 @@ int numlen(int n) {
return log10(n) + 1; return log10(n) + 1;
} }
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 get_parent_pid(pid_t child) {
pid_t parent = -1; pid_t parent = -1;
char file_name[100]; char file_name[100];

View file

@ -5,6 +5,28 @@
#define SWAY_KEYBOARD_PRESSED_KEYSYMS_CAP 32 #define SWAY_KEYBOARD_PRESSED_KEYSYMS_CAP 32
/**
* Get modifier mask from modifier name.
*
* Returns the modifer mask or 0 if the name isn't found.
*/
uint32_t get_modifier_mask_by_name(const char *name);
/**
* Get modifier name from modifier mask.
*
* Returns the modifier name or NULL if it isn't found.
*/
const char *get_modifier_name_by_mask(uint32_t modifier);
/**
* Get an array of modifier names from modifier_masks
*
* Populates the names array and return the number of names added.
*/
int get_modifier_names(const char **names, uint32_t modifier_masks);
struct sway_keyboard { struct sway_keyboard {
struct sway_seat_device *seat_device; struct sway_seat_device *seat_device;

View file

@ -16,27 +16,6 @@ int wrap(int i, int max);
*/ */
int numlen(int n); int numlen(int n);
/**
* Get modifier mask from modifier name.
*
* Returns the modifer mask or 0 if the name isn't found.
*/
uint32_t get_modifier_mask_by_name(const char *name);
/**
* Get modifier name from modifier mask.
*
* Returns the modifier name or NULL if it isn't found.
*/
const char *get_modifier_name_by_mask(uint32_t modifier);
/**
* Get an array of modifier names from modifier_masks
*
* Populates the names array and return the number of names added.
*/
int get_modifier_names(const char **names, uint32_t modifier_masks);
/** /**
* Get the pid of a parent process given the pid of a child process. * Get the pid of a parent process given the pid of a child process.
* *

View file

@ -2,7 +2,7 @@
#include "sway/commands.h" #include "sway/commands.h"
#include "log.h" #include "log.h"
#include "stringop.h" #include "stringop.h"
#include "util.h" #include "sway/input/keyboard.h"
struct cmd_results *bar_cmd_modifier(int argc, char **argv) { struct cmd_results *bar_cmd_modifier(int argc, char **argv) {
struct cmd_results *error = NULL; struct cmd_results *error = NULL;

View file

@ -11,7 +11,7 @@
#include "list.h" #include "list.h"
#include "log.h" #include "log.h"
#include "stringop.h" #include "stringop.h"
#include "util.h" #include "sway/input/keyboard.h"
int binding_order = 0; int binding_order = 0;

View file

@ -1,5 +1,6 @@
#include <assert.h> #include <assert.h>
#include <limits.h> #include <limits.h>
#include <strings.h>
#include <wlr/backend/multi.h> #include <wlr/backend/multi.h>
#include <wlr/backend/session.h> #include <wlr/backend/session.h>
#include <wlr/types/wlr_idle.h> #include <wlr/types/wlr_idle.h>
@ -9,6 +10,58 @@
#include "sway/commands.h" #include "sway/commands.h"
#include "log.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;
}
static bool keysym_is_modifier(xkb_keysym_t keysym) { static bool keysym_is_modifier(xkb_keysym_t keysym) {
switch (keysym) { switch (keysym) {
case XKB_KEY_Shift_L: case XKB_KEY_Shift_R: case XKB_KEY_Shift_L: case XKB_KEY_Shift_R: