-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathkeybinding.h
146 lines (131 loc) · 7.36 KB
/
keybinding.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
// Copyright 2020 - 2024, project-repo and the cagebreak contributors
// SPDX-License-Identifier: MIT
#ifndef KEYBINDING_H
#define KEYBINDING_H
#include "config.h"
#include <stdbool.h>
#include <stdint.h>
#include <xkbcommon/xkbcommon.h>
struct cg_server;
#define FOREACH_KEYBINDING(KEYBINDING) \
KEYBINDING(KEYBINDING_RUN_COMMAND, \
exec) /* data.c is the string to execute */ \
KEYBINDING(KEYBINDING_CLOSE_VIEW, close) \
KEYBINDING(KEYBINDING_SPLIT_VERTICAL, vsplit) \
KEYBINDING(KEYBINDING_SPLIT_HORIZONTAL, hsplit) \
KEYBINDING(KEYBINDING_CHANGE_TTY, switchvt) /*data.u is the desired tty*/ \
KEYBINDING(KEYBINDING_LAYOUT_FULLSCREEN, only) \
KEYBINDING(KEYBINDING_CYCLE_VIEWS, \
cycle_views) /* data.b is 0 if forward, 1 if reverse */ \
KEYBINDING(KEYBINDING_CYCLE_TILES, \
cycle_tiles) /* data.b is 0 if forward, 1 if reverse */ \
KEYBINDING(KEYBINDING_CYCLE_OUTPUT, \
cycle_outputs) /* data.b is 0 if forward, 1 if reverse */ \
KEYBINDING(KEYBINDING_CONFIGURE_OUTPUT, \
output) /* data.o_cfg is the desired output */ \
\
KEYBINDING(KEYBINDING_CONFIGURE_MESSAGE, \
configure_message) /* data.m_cfg is the desired config */ \
KEYBINDING(KEYBINDING_CONFIGURE_INPUT, \
input) /* data.i_cfg is the desired input configuration */ \
\
KEYBINDING(KEYBINDING_QUIT, quit) \
KEYBINDING(KEYBINDING_NOOP, abort) \
KEYBINDING(KEYBINDING_SWITCH_OUTPUT, \
screen) /* data.u is the desired output */ \
KEYBINDING(KEYBINDING_SWITCH_WORKSPACE, \
workspace) /* data.u is the desired workspace */ \
KEYBINDING(KEYBINDING_SWITCH_MODE, mode) /* data.u is the desired mode */ \
KEYBINDING(KEYBINDING_SWITCH_DEFAULT_MODE, \
setmode) /* data.u is the desired mode */ \
KEYBINDING( \
KEYBINDING_RESIZE_TILE_HORIZONTAL, \
resize_tile_horizontal) /* data.i is the number of pixels to add */ \
\
KEYBINDING( \
KEYBINDING_RESIZE_TILE_VERTICAL, \
resize_tile_vertical) /* data.i is the number of pixels to add to */ \
\
KEYBINDING(KEYBINDING_MOVE_VIEW_TO_WORKSPACE, \
movetoworkspace) /* data.u is the desired workspace */ \
KEYBINDING(KEYBINDING_MOVE_VIEW_TO_OUTPUT, \
movetoscreen) /* data.u is the desired output */ \
KEYBINDING(KEYBINDING_MOVE_VIEW_TO_CYCLE_OUTPUT, \
move_view_to_cycle_output) /* data.b is 0 if forward, 1 if */ \
\
KEYBINDING(KEYBINDING_DUMP, dump) \
KEYBINDING(KEYBINDING_SHOW_TIME, time) \
KEYBINDING(KEYBINDING_SHOW_INFO, show_info) \
KEYBINDING(KEYBINDING_DISPLAY_MESSAGE, message) \
KEYBINDING(KEYBINDING_SEND_CUSTOM_EVENT, custom_event) \
KEYBINDING(KEYBINDING_CURSOR, cursor) \
\
KEYBINDING(KEYBINDING_SWAP_LEFT, exchangeleft) \
KEYBINDING(KEYBINDING_SWAP_RIGHT, exchangeright) \
KEYBINDING(KEYBINDING_SWAP_TOP, exchangeup) \
KEYBINDING(KEYBINDING_SWAP_BOTTOM, exchangedown) \
\
KEYBINDING(KEYBINDING_FOCUS_LEFT, focusleft) \
KEYBINDING(KEYBINDING_FOCUS_RIGHT, focusright) \
KEYBINDING(KEYBINDING_FOCUS_TOP, focusup) \
KEYBINDING(KEYBINDING_FOCUS_BOTTOM, focusdown) \
\
KEYBINDING(KEYBINDING_DEFINEKEY, \
definekey) /* data.kb is the keybinding definition */ \
KEYBINDING(KEYBINDING_SETMODECURSOR, \
setmodecursor) /* data.c is the name of ther cursor */ \
KEYBINDING(KEYBINDING_BACKGROUND, \
background) /* data.color is the background color */ \
KEYBINDING(KEYBINDING_DEFINEMODE, \
definemode) /* data.c is the mode name */ \
KEYBINDING(KEYBINDING_WORKSPACES, \
workspaces) /* data.i is the number of workspaces */
#define GENERATE_ENUM(ENUM, NAME) ENUM,
#define GENERATE_STRING(STRING, NAME) #NAME,
/* Important: if you add a keybinding which uses data.c or requires "free"
* to be called, don't forget to add it to the function "keybinding_list_free"
* in keybinding.c */
enum keybinding_action { FOREACH_KEYBINDING(GENERATE_ENUM) };
extern char *keybinding_action_string[];
union keybinding_params {
char *c;
uint32_t u;
int32_t i;
bool b;
float color[3];
struct keybinding *kb;
struct cg_output_config *o_cfg;
struct cg_input_config *i_cfg;
struct cg_message_config *m_cfg;
};
struct keybinding {
uint16_t mode;
xkb_mod_mask_t modifiers;
xkb_keysym_t key;
enum keybinding_action action;
union keybinding_params data; // See enum keybinding_action for details
};
struct keybinding_list {
uint32_t length;
uint32_t capacity;
struct keybinding **keybindings;
};
int
keybinding_list_push(struct keybinding_list *list,
struct keybinding *keybinding);
void
keybinding_list_free(struct keybinding_list *list);
void
keybinding_cycle_outputs(struct cg_server *server, bool reverse,
bool trigger_event);
struct keybinding **
find_keybinding(const struct keybinding_list *list,
const struct keybinding *keybinding);
struct keybinding_list *
keybinding_list_init(void);
int
run_action(enum keybinding_action action, struct cg_server *server,
union keybinding_params data);
void
keybinding_free(struct keybinding *keybinding, bool recursive);
#endif /* end of include guard KEYBINDINGS_H */