-
Notifications
You must be signed in to change notification settings - Fork 10
/
Hotkeys.C
370 lines (320 loc) · 9.29 KB
/
Hotkeys.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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
// Hotkeys.C
// If you want to change what the hotkeys are, see the table at the bottom!
#include "config.h"
#include "Frame.H"
#include "Desktop.H"
#include <stdio.h>
extern void ShowMenu();
extern void ShowTabMenu(int tab);
#if STANDARD_HOTKEYS
static void NextWindow() { // Alt+Tab
ShowTabMenu(1);
}
static void PreviousWindow() { // Alt+Shift+Tab
ShowTabMenu(-1);
}
#endif
#if DESKTOPS
static void NextDesk() {
if (Desktop::current()) {
Desktop::current(Desktop::current()->next?
Desktop::current()->next:Desktop::first);
} else {
Desktop::current(Desktop::first);
}
}
static void PreviousDesk() {
Desktop* search=Desktop::first;
while (search->next && search->next!=Desktop::current()){
search=search->next;
}
Desktop::current(search);
}
// warning: this assummes it is bound to Fn key:
static void DeskNumber() {
Desktop::current(Desktop::number(Fl::event_key()-FL_F, 1));
}
#endif
#if WMX_HOTKEYS || CDE_HOTKEYS
static void Raise() { // Alt+Up
Frame* f = Frame::activeFrame();
if (f) f->raise();
}
static void Lower() { // Alt+Down
Frame* f = Frame::activeFrame();
if (f) f->lower();
}
static void Iconize() { // Alt+F1
Frame* f = Frame::activeFrame();
if (f) f->iconize();
else ShowMenu(); // so they can deiconize stuff
}
static void Close() { // Alt+Delete
Frame* f = Frame::activeFrame();
if (f) f->close();
}
#endif
#ifdef ML_HOTKEYS
static void MoveFrame(int xbump, int ybump) {
int xincr, yincr, nx, ny, xspace, yspace;
Frame* f = Frame::activeFrame();
if (f) {
xspace = Fl::w() - f->w();
xincr = xspace / 20;
if (xincr < 4) {
xincr = 4;
}
nx = f->x() + (xbump * xincr);
if (nx < 0) nx = 0;
if (nx > xspace) nx = xspace;
yspace = Fl::h() - f->h();
yincr = yspace / 20;
if (yincr < 4) {
yincr = 4;
}
ny = f->y() + (ybump * yincr);
if (ny < 0) ny = 0;
if (ny > yspace) ny = yspace;
f->set_size(nx, ny, f->w(), f->h());
}
}
static void MoveLeft(void) { // Ctrl+Alt+Left
MoveFrame(-1, 0);
}
static void MoveUp(void) { // Ctrl+Alt+Up
MoveFrame(0, -1);
}
static void MoveRight(void) { // Ctrl+Alt+Right
MoveFrame(+1, 0);
}
static void MoveDown(void) { // Ctrl+Alt+Down
MoveFrame(0, +1);
}
static void GrowFrame(int wbump, int hbump) {
int nx, ny, nw, nh;
Frame* f = Frame::activeFrame();
if (f) {
int minw = 8 * BUTTON_W;
int minh = 4 * BUTTON_H;
nx = f->x();
ny = f->y();
nw = f->w();
nh = f->h();
if (wbump != 0 && f->w() >= minw) {
nw += wbump * 32;
if (nw < minw) nw = minw;
if (nw > Fl::w()) nw = Fl::w();
if (nx + nw > Fl::w())
nx = Fl::w() - nw;
}
if (hbump != 0 && f->h() >= minh) {
nh += hbump * 32;
if (nh < minh) nh = minh;
if (nh > Fl::h()) nh = Fl::h();
ny = f->y();
if (ny + nh > Fl::h())
ny = Fl::h() - nh;
else
ny = f->y() + f->h() - nh;
}
f->set_size(nx, ny, nw, nh);
}
}
static void GrowBigger(void) { // Ctrl+Alt+Plus
GrowFrame(+1, +1);
}
static void GrowSmaller(void) { // Ctrl+Alt+Minus
GrowFrame(-1, -1);
}
static void GrowWider(void) { // Ctrl+Alt+Gt.Than
GrowFrame(+1, 0);
}
static void GrowNarrower(void) { // Ctrl+Alt+LessThan
GrowFrame(-1, 0);
}
static void GrowTaller(void) { // Ctrl+Alt+PageUp
GrowFrame(0, +1);
}
static void GrowShorter(void) { // Ctrl+Alt+PageDn
GrowFrame(0, -1);
}
static void ToggleVertMax(void) {// Ctrl+Alt+V
static int nonmax_h = Fl::h() - 64;
static int nonmax_y = 32;
Frame* f = Frame::activeFrame();
if (f->h() < Fl::h() - 16) {
nonmax_h = f->h();
nonmax_y = f->y();
f->set_size(f->x(), 0, f->w(), Fl::h());
}
else {
f->set_size(f->x(), nonmax_y, f->w(), nonmax_h);
}
}
static void ToggleHorzMax(void) {// Ctrl+Alt+H
static int nonmax_w = Fl::w() - 64;
static int nonmax_x = 32;
Frame* f = Frame::activeFrame();
if (f->w() < Fl::w() - 16) {
nonmax_w = f->w();
nonmax_x = f->x();
f->set_size(0, f->y(), Fl::w(), f->h());
}
else {
f->set_size(nonmax_x, f->y(), nonmax_w, f->h());
}
}
static void ToggleWinMax(void) {// Ctrl+Alt+M
Frame* f = Frame::activeFrame();
int is_hmax = -1;
int is_vmax = -1;
if (f->w() > Fl::w() - 16) is_hmax = 1;
if (f->h() > Fl::h() - 16) is_vmax = 1;
if ((is_hmax * is_vmax) > 0 || is_hmax > 0) ToggleVertMax();
if ((is_hmax * is_vmax) > 0 || is_vmax > 0) ToggleHorzMax();
}
#endif
////////////////////////////////////////////////////////////////
static struct {int key; void (*func)();} keybindings[] = {
#if STANDARD_HOTKEYS || MINIMUM_HOTKEYS
// these are very common and tend not to conflict, due to Windoze:
{FL_ALT+FL_Escape, ShowMenu},
{FL_ALT+FL_Menu, ShowMenu},
#endif
#if STANDARD_HOTKEYS
{FL_ALT+FL_Tab, NextWindow},
{FL_ALT+FL_SHIFT+FL_Tab,PreviousWindow},
{FL_ALT+FL_SHIFT+0xfe20,PreviousWindow}, // XK_ISO_Left_Tab
#endif
#if KWM_HOTKEYS && DESKTOPS // KWM uses these to switch desktops
{FL_CTRL+FL_Tab, NextDesk},
{FL_CTRL+FL_SHIFT+FL_Tab,PreviousDesk},
{FL_CTRL+FL_SHIFT+0xfe20,PreviousDesk}, // XK_ISO_Left_Tab
{FL_CTRL+FL_F+1, DeskNumber},
{FL_CTRL+FL_F+2, DeskNumber},
{FL_CTRL+FL_F+3, DeskNumber},
{FL_CTRL+FL_F+4, DeskNumber},
{FL_CTRL+FL_F+5, DeskNumber},
{FL_CTRL+FL_F+6, DeskNumber},
{FL_CTRL+FL_F+7, DeskNumber},
{FL_CTRL+FL_F+8, DeskNumber},
{FL_CTRL+FL_F+9, DeskNumber},
{FL_CTRL+FL_F+10, DeskNumber},
{FL_CTRL+FL_F+11, DeskNumber},
{FL_CTRL+FL_F+12, DeskNumber},
#endif
#if WMX_HOTKEYS
// wmx also sets all these, they seem pretty useful:
{FL_ALT+FL_Up, Raise},
{FL_ALT+FL_Down, Lower},
//{FL_ALT+FL_Enter, Iconize},
{FL_ALT+FL_F+1, Iconize},
{FL_ALT+FL_Delete, Close},
//{FL_ALT+FL_Page_Up, ToggleMaxH},
//{FL_ALT+FL_Page_Down, ToggleMaxW},
#endif
#if WMX_DESK_HOTKEYS && DESKTOPS
// these wmx keys are not set by default as they break NetScape:
{FL_ALT+FL_Left, PreviousDesk},
{FL_ALT+FL_Right, NextDesk},
#endif
#if CDE_HOTKEYS
// CDE hotkeys (or at least what SGI's 4DWM uses):
//{FL_ALT+FL_F+1, Raise}, // used above to iconize
//{FL_ALT+FL_F+2, unknown}, // KWM uses this to run a typed-in command
{FL_ALT+FL_F+3, Lower},
{FL_ALT+FL_F+4, Close}, // this matches KWM
//{FL_ALT+FL_F+5, Restore}, // useless because no icons visible
//{FL_ALT+FL_F+6, unknown}, // ?
//{FL_ALT+FL_F+7, Move}, // grabs the window for movement
//{FL_ALT+FL_F+8, Resize}, // grabs the window for resizing
{FL_ALT+FL_F+9, Iconize},
//{FL_ALT+FL_F+10, Maximize},
//{FL_ALT+FL_F+11, unknown}, // ?
{FL_ALT+FL_F+12, Close}, // actually does "quit"
#else
#if DESKTOPS && DESKTOP_HOTKEYS
// seem to be common to Linux window managers
{FL_ALT+FL_F+1, DeskNumber},
{FL_ALT+FL_F+2, DeskNumber},
{FL_ALT+FL_F+3, DeskNumber},
{FL_ALT+FL_F+4, DeskNumber},
{FL_ALT+FL_F+5, DeskNumber},
{FL_ALT+FL_F+6, DeskNumber},
{FL_ALT+FL_F+7, DeskNumber},
{FL_ALT+FL_F+8, DeskNumber},
{FL_ALT+FL_F+9, DeskNumber},
{FL_ALT+FL_F+10, DeskNumber},
{FL_ALT+FL_F+11, DeskNumber},
{FL_ALT+FL_F+12, DeskNumber},
#endif
#endif
#ifdef ML_HOTKEYS
{FL_CTRL+FL_ALT+FL_Left, MoveLeft},
{FL_CTRL+FL_ALT+FL_Up, MoveUp},
{FL_CTRL+FL_ALT+FL_Right, MoveRight},
{FL_CTRL+FL_ALT+FL_Down, MoveDown},
{FL_CTRL+FL_ALT+'=', GrowBigger}, // = is also + key
{FL_CTRL+FL_ALT+'-', GrowSmaller},
{FL_CTRL+FL_ALT+'.', GrowWider}, // . is also > key
{FL_CTRL+FL_ALT+',', GrowNarrower}, // , is also < key
{FL_CTRL+FL_ALT+FL_Page_Up, GrowTaller},
{FL_CTRL+FL_ALT+FL_Page_Down, GrowShorter},
{FL_CTRL+FL_ALT+'t', GrowTaller},
{FL_CTRL+FL_ALT+'s', GrowShorter},
{FL_CTRL+FL_ALT+'v', ToggleVertMax},
{FL_CTRL+FL_ALT+'h', ToggleHorzMax},
{FL_CTRL+FL_ALT+'m', ToggleWinMax},
#endif
{0}};
#if FL_MAJOR_VERSION > 1
// Define missing function, this should get put in fltk2.0:
namespace fltk {
int test_shortcut(int shortcut) {
if (!shortcut) return 0;
int shift = Fl::event_state();
// see if any required shift flags are off:
if ((shortcut&shift) != (shortcut&0x7fff0000)) return 0;
// record shift flags that are wrong:
int mismatch = (shortcut^shift)&0x7fff0000;
// these three must always be correct:
if (mismatch&(FL_META|FL_ALT|FL_CTRL)) return 0;
int key = shortcut & 0xffff;
// if shift is also correct, check for exactly equal keysyms:
if (!(mismatch&(FL_SHIFT)) && unsigned(key) == Fl::event_key()) return 1;
// try matching ascii, ignore shift:
if (key == event_text()[0]) return 1;
// kludge so that Ctrl+'_' works (as opposed to Ctrl+'^_'):
if ((shift&FL_CTRL) && key >= 0x3f && key <= 0x5F
&& event_text()[0]==(key^0x40)) return 1;
return 0;
}
}
#endif
int Handle_Hotkey() {
for (int i = 0; keybindings[i].key; i++) {
if (Fl::test_shortcut(keybindings[i].key) ||
((keybindings[i].key & 0xFFFF) == FL_Delete
&& Fl::event_key() == FL_BackSpace)// fltk bug?
) {
keybindings[i].func();
return 1;
}
}
return 0;
}
extern Fl_Window* Root;
void Grab_Hotkeys() {
XWindow root = fl_xid(Root);
for (int i = 0; keybindings[i].key; i++) {
int k = keybindings[i].key;
int keycode = XKeysymToKeycode(fl_display, k & 0xFFFF);
if (!keycode) continue;
// Silly X! we need to ignore caps lock & numlock keys by grabbing
// all the combinations:
XGrabKey(fl_display, keycode, k>>16, root, 0, 1, 1);
XGrabKey(fl_display, keycode, (k>>16)|2, root, 0, 1, 1); // CapsLock
XGrabKey(fl_display, keycode, (k>>16)|16, root, 0, 1, 1); // NumLock
XGrabKey(fl_display, keycode, (k>>16)|18, root, 0, 1, 1); // both
}
}