-
Notifications
You must be signed in to change notification settings - Fork 0
/
bindings.c
150 lines (126 loc) · 3.82 KB
/
bindings.c
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
147
148
149
150
#include <unistd.h>
#include <linux/input.h>
#include <stdio.h>
#include <xkbcommon/xkbcommon.h>
#include "bindings.h"
#include "logmsg.h"
#include "venowm.h"
#include "workspace.h"
#include "split.h"
#include "backend.h"
static void exec(const char *shcmd){
logmsg("called exec\n");
pid_t pid = fork();
if(pid < 0){
perror("fork");
return;
}
if(pid == 0){
// child
execl("/bin/sh", "/bin/sh", "-c", shcmd, NULL);
perror("execl");
exit(127);
}
// parent continues with whatever it was doing
return;
}
#define DEFINE_KEY_HANDLER(func_name) \
bool func_name(backend_t *be, void *data){ \
bool retval = true; \
(void)data;
#define FINISH_KEY_HANDLER \
be_repaint(be); \
return retval; \
}
DEFINE_KEY_HANDLER(quit)
logmsg("called quit\n");
backend_stop(be);
FINISH_KEY_HANDLER
DEFINE_KEY_HANDLER(exec_weston_terminal)
exec("weston-terminal");
FINISH_KEY_HANDLER
DEFINE_KEY_HANDLER(dohsplit)
workspace_hsplit(g_workspace, g_workspace->focus, 0.5);
FINISH_KEY_HANDLER
DEFINE_KEY_HANDLER(dovsplit)
workspace_vsplit(g_workspace, g_workspace->focus, 0.5);
FINISH_KEY_HANDLER
DEFINE_KEY_HANDLER(goleft)
split_t *new = split_move_left(g_workspace->focus);
workspace_focus_frame(g_workspace, new);
FINISH_KEY_HANDLER
DEFINE_KEY_HANDLER(goright)
split_t *new = split_move_right(g_workspace->focus);
workspace_focus_frame(g_workspace, new);
FINISH_KEY_HANDLER
DEFINE_KEY_HANDLER(goup)
split_t *new = split_move_up(g_workspace->focus);
workspace_focus_frame(g_workspace, new);
FINISH_KEY_HANDLER
DEFINE_KEY_HANDLER(godown)
split_t *new = split_move_down(g_workspace->focus);
workspace_focus_frame(g_workspace, new);
FINISH_KEY_HANDLER
DEFINE_KEY_HANDLER(remove_frame)
workspace_remove_frame(g_workspace, g_workspace->focus);
FINISH_KEY_HANDLER
DEFINE_KEY_HANDLER(swapleft)
split_t *new = split_move_left(g_workspace->focus);
workspace_swap_windows_from_frames(g_workspace->focus, new);
FINISH_KEY_HANDLER
DEFINE_KEY_HANDLER(swapright)
split_t *new = split_move_right(g_workspace->focus);
workspace_swap_windows_from_frames(g_workspace->focus, new);
FINISH_KEY_HANDLER
DEFINE_KEY_HANDLER(swapup)
split_t *new = split_move_up(g_workspace->focus);
workspace_swap_windows_from_frames(g_workspace->focus, new);
FINISH_KEY_HANDLER
DEFINE_KEY_HANDLER(swapdown)
split_t *new = split_move_down(g_workspace->focus);
workspace_swap_windows_from_frames(g_workspace->focus, new);
FINISH_KEY_HANDLER
DEFINE_KEY_HANDLER(next_win)
workspace_next_hidden_win_at(g_workspace, g_workspace->focus);
FINISH_KEY_HANDLER
DEFINE_KEY_HANDLER(prev_win)
workspace_prev_hidden_win_at(g_workspace, g_workspace->focus);
FINISH_KEY_HANDLER
DEFINE_KEY_HANDLER(close_window)
if(g_workspace->focus->win_info){
be_window_close(g_workspace->focus->win_info->window->be_window);
}
FINISH_KEY_HANDLER
#define ADD_KEY(xkey, func) \
if(be_handle_key(be, MOD_CTRL, \
XKB_KEY_ ## xkey, \
&func, be)){ \
goto fail; \
}
#define ADD_KEY_SHIFT(xkey, func) \
if(be_handle_key(be, MOD_CTRL | MOD_SHIFT, \
XKB_KEY_ ## xkey, \
&func, be)){ \
goto fail; \
}
int add_bindings(backend_t *be){
ADD_KEY(q, quit);
ADD_KEY(Return, exec_weston_terminal);
ADD_KEY(backslash, dohsplit);
ADD_KEY(minus, dovsplit);
ADD_KEY(h, goleft);
ADD_KEY(j, godown);
ADD_KEY(k, goup);
ADD_KEY(l, goright);
ADD_KEY(y, remove_frame);
ADD_KEY(i, close_window);
ADD_KEY_SHIFT(h, swapleft);
ADD_KEY_SHIFT(j, swapdown);
ADD_KEY_SHIFT(k, swapup);
ADD_KEY_SHIFT(l, swapright);
ADD_KEY(space, next_win);
ADD_KEY_SHIFT(space, prev_win);
return 0;
fail:
return -1;
}