Merge lp:~smspillaz/compiz-core/compiz-core.cleanup-modifierhandler into lp:compiz-core/0.9.5

Proposed by Sam Spilsbury
Status: Superseded
Proposed branch: lp:~smspillaz/compiz-core/compiz-core.cleanup-modifierhandler
Merge into: lp:compiz-core/0.9.5
Prerequisite: lp:~smspillaz/compiz-core/compiz-core.cleanup-modifierhandler-propertywriter
Diff against target: 609 lines (+180/-142) (has conflicts)
9 files modified
include/core/modifierhandler.h (+77/-78)
include/core/screen.h (+0/-1)
plugins/resize/src/resize.cpp (+5/-2)
src/action.cpp (+32/-37)
src/event.cpp (+7/-2)
src/modifierhandler.cpp (+50/-17)
src/privatescreen.h (+1/-1)
src/screen.cpp (+5/-3)
src/window.cpp (+3/-1)
Text conflict in include/core/screen.h
Text conflict in src/action.cpp
To merge this branch: bzr merge lp:~smspillaz/compiz-core/compiz-core.cleanup-modifierhandler
Reviewer Review Type Date Requested Status
Daniel van Vugt Needs Resubmitting
Alan Griffiths Approve
Review via email: mp+89841@code.launchpad.net

This proposal supersedes a proposal from 2012-01-24.

Description of the change

Clean up the ModifierHandler class , remove #define, remove duplication etc etc

To post a comment you must log in.
Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

yes

review: Approve
Revision history for this message
Daniel van Vugt (vanvugt) wrote :

Changed status back to Needs review, while the prereq branch "Needs fixing".

Revision history for this message
Daniel van Vugt (vanvugt) wrote :

Please resubmit for target branch lp:compiz-core (0.9.7)

review: Needs Resubmitting

Unmerged revisions

2953. By Sam Spilsbury

Clean up ModifierHandler

2952. By Sam Spilsbury

Break the dependency of CompAction and CompScreen - use ModifierHandler instead

2951. By Sam Spilsbury

Assorted cleanups - remove header dependencies from ModifierHandler and PropertyWriter

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'include/core/modifierhandler.h'
2--- include/core/modifierhandler.h 2012-01-24 08:30:14 +0000
3+++ include/core/modifierhandler.h 2012-01-24 08:30:15 +0000
4@@ -30,39 +30,15 @@
5 #define _COMPIZ_MODIFIERHANDLER_H
6
7 #include <X11/Xlib-xcb.h>
8-
9-const unsigned int CompModAlt = 0;
10-const unsigned int CompModMeta = 1;
11-const unsigned int CompModSuper = 2;
12-const unsigned int CompModHyper = 3;
13-const unsigned int CompModModeSwitch = 4;
14-const unsigned int CompModNumLock = 5;
15-const unsigned int CompModScrollLock = 6;
16-const unsigned int CompModNum = 7;
17-
18-const unsigned int CompAltMask = (1 << 16);
19-const unsigned int CompMetaMask = (1 << 17);
20-const unsigned int CompSuperMask = (1 << 18);
21-const unsigned int CompHyperMask = (1 << 19);
22-const unsigned int CompModeSwitchMask = (1 << 20);
23-const unsigned int CompNumLockMask = (1 << 21);
24-const unsigned int CompScrollLockMask = (1 << 22);
25-const unsigned int CompNoMask = (1 << 25);
26-
27-/**
28- * Toplevel class which provides access to display
29- * level modifier information
30- */
31-class ModifierHandler
32+#include <string>
33+
34+namespace compiz
35 {
36- public:
37-
38- ModifierHandler (Display *);
39- ~ModifierHandler ();
40-
41+ namespace modifiers
42+ {
43 typedef enum
44 {
45- Alt = 1,
46+ Alt = 0,
47 Meta,
48 Super,
49 Hyper,
50@@ -84,53 +60,76 @@
51 NoMask = (1 << 25),
52 } ModMask;
53
54- public:
55-
56-
57- /**
58- * Takes an X11 Keycode and returns a bitmask
59- * with modifiers that have been pressed
60- */
61- unsigned int keycodeToModifiers (int keycode);
62-
63- /**
64- * Updates X11 Modifier mappings
65- */
66- bool updateModifierMappings ();
67-
68- /**
69- * Takes a virtual modMask and returns a real modifier mask
70- * by removing unused bits
71- */
72- unsigned int virtualToRealModMask (unsigned int modMask);
73-
74- /**
75- * Returns a bit modifier mask for a Motifier enum
76- */
77- unsigned int modMask (Modifier);
78-
79- /**
80- * Returns a const bit modifier mask for what should be ignored
81- */
82- unsigned int ignoredModMask ();
83-
84- /**
85- * Returns a const XModifierKeymap for compiz
86- */
87- const XModifierKeymap * modMap ();
88-
89- static ModifierHandler *
90- Default ();
91-
92- static void
93- SetDefault (ModifierHandler *);
94- private:
95-
96- ModMask mModMask[ModNum];
97- unsigned int mIgnoredModMask;
98- XModifierKeymap *mModMap;
99-
100- Display *mDisplay;
101-};
102+ /**
103+ * Toplevel class which provides access to display
104+ * level modifier information
105+ */
106+ class ModifierHandler
107+ {
108+ public:
109+
110+ ModifierHandler (Display *);
111+ ~ModifierHandler ();
112+
113+ public:
114+
115+
116+ /**
117+ * Takes an X11 Keycode and returns a bitmask
118+ * with modifiers that have been pressed
119+ */
120+ unsigned int keycodeToModifiers (int keycode);
121+
122+ /**
123+ * Updates X11 Modifier mappings
124+ */
125+ bool updateModifierMappings ();
126+
127+ /**
128+ * Takes a virtual modMask and returns a real modifier mask
129+ * by removing unused bits
130+ */
131+ unsigned int virtualToRealModMask (unsigned int modMask);
132+
133+ /**
134+ * Takes a key string and returns a keycode
135+ */
136+ int stringToKeycode (const std::string &) const;
137+
138+ /**
139+ * Takes a keycode and returns a key string
140+ */
141+ std::string keycodeToString (int keycode) const;
142+
143+ /**
144+ * Returns a bit modifier mask for a Motifier enum
145+ */
146+ unsigned int modMask (Modifier);
147+
148+ /**
149+ * Returns a const bit modifier mask for what should be ignored
150+ */
151+ unsigned int ignoredModMask ();
152+
153+ /**
154+ * Returns a const XModifierKeymap for compiz
155+ */
156+ const XModifierKeymap * modMap ();
157+
158+ static ModifierHandler *
159+ Default ();
160+
161+ static void
162+ SetDefault (ModifierHandler *);
163+ private:
164+
165+ ModMask mModMask[ModNum];
166+ unsigned int mIgnoredModMask;
167+ XModifierKeymap *mModMap;
168+
169+ Display *mDisplay;
170+ };
171+ }
172+}
173
174 #endif
175
176=== modified file 'include/core/screen.h'
177--- include/core/screen.h 2012-01-24 08:30:14 +0000
178+++ include/core/screen.h 2012-01-24 08:30:15 +0000
179@@ -65,7 +65,6 @@
180 extern bool debugOutput;
181
182 extern CompScreen *screen;
183-extern ModifierHandler *modHandler;
184
185 extern int lastPointerX;
186 extern int lastPointerY;
187
188=== modified file 'plugins/resize/src/resize.cpp'
189--- plugins/resize/src/resize.cpp 2012-01-18 16:26:45 +0000
190+++ plugins/resize/src/resize.cpp 2012-01-24 08:30:15 +0000
191@@ -32,8 +32,11 @@
192 #include <X11/cursorfont.h>
193
194 #include <core/atoms.h>
195+#include <core/modifierhandler.h>
196 #include "resize.h"
197
198+using namespace compiz::modifiers;
199+
200 COMPIZ_PLUGIN_20090315 (resize, ResizePluginVTable)
201
202 void
203@@ -1713,11 +1716,11 @@
204 if (valueMask & ResizeModeShiftMask)
205 *mask |= ShiftMask;
206 if (valueMask & ResizeModeAltMask)
207- *mask |= CompAltMask;
208+ *mask |= AltMask;
209 if (valueMask & ResizeModeControlMask)
210 *mask |= ControlMask;
211 if (valueMask & ResizeModeMetaMask)
212- *mask |= CompMetaMask;
213+ *mask |= MetaMask;
214 }
215
216 void
217
218=== modified file 'src/action.cpp'
219--- src/action.cpp 2012-01-24 08:24:18 +0000
220+++ src/action.cpp 2012-01-24 08:30:15 +0000
221@@ -33,10 +33,15 @@
222 #include "privateaction.h"
223 #include "privatescreen.h"
224
225+<<<<<<< TREE
226+=======
227+using namespace compiz;
228+
229+>>>>>>> MERGE-SOURCE
230 struct _Modifier {
231 const char *name;
232 int modifier;
233-} modifiers[] = {
234+} allModifiers[] = {
235 { "<Shift>", ShiftMask },
236 { "<Control>", ControlMask },
237 { "<Mod1>", Mod1Mask },
238@@ -44,14 +49,14 @@
239 { "<Mod3>", Mod3Mask },
240 { "<Mod4>", Mod4Mask },
241 { "<Mod5>", Mod5Mask },
242- { "<Alt>", CompAltMask },
243- { "<Meta>", CompMetaMask },
244- { "<Super>", CompSuperMask },
245- { "<Hyper>", CompHyperMask },
246- { "<ModeSwitch>", CompModeSwitchMask }
247+ { "<Alt>", modifiers::AltMask },
248+ { "<Meta>", modifiers::MetaMask },
249+ { "<Super>", modifiers::SuperMask },
250+ { "<Hyper>", modifiers::HyperMask },
251+ { "<ModeSwitch>", modifiers::ModeSwitchMask }
252 };
253
254-#define N_MODIFIERS (sizeof (modifiers) / sizeof (struct _Modifier))
255+#define N_MODIFIERS (sizeof (allModifiers) / sizeof (struct _Modifier))
256
257 struct _Edge {
258 const char *name;
259@@ -74,8 +79,8 @@
260
261 for (unsigned int i = 0; i < N_MODIFIERS; i++)
262 {
263- if (modMask & modifiers[i].modifier)
264- binding += modifiers[i].name;
265+ if (modMask & allModifiers[i].modifier)
266+ binding += allModifiers[i].name;
267 }
268
269 return binding;
270@@ -88,8 +93,8 @@
271
272 for (unsigned int i = 0; i < N_MODIFIERS; i++)
273 {
274- if (str.find (modifiers[i].name) != std::string::npos)
275- mods |= modifiers[i].modifier;
276+ if (str.find (allModifiers[i].name) != std::string::npos)
277+ mods |= allModifiers[i].modifier;
278 }
279
280 return mods;
281@@ -156,7 +161,7 @@
282 CompString sStr;
283 unsigned int mods;
284 size_t pos, start = 0;
285- KeySym keysym;
286+ int keycode;
287
288 if (!screen)
289 return false;
290@@ -184,31 +189,25 @@
291 }
292
293 sStr = str.substr (start);
294- keysym = XStringToKeysym (sStr.c_str ());
295+ keycode = modifiers::ModifierHandler::Default ()->stringToKeycode (sStr);
296
297- if (keysym != NoSymbol)
298+ if (!keycode)
299 {
300- KeyCode keycode;
301-
302- keycode = XKeysymToKeycode (screen->dpy (), keysym);
303- if (keycode)
304+ if (sStr.compare (0, 2, "0x") == 0)
305 {
306- mKeycode = keycode;
307+ mKeycode = strtol (sStr.c_str (), NULL, 0);
308 mModifiers = mods;
309
310 return true;
311 }
312- }
313-
314- if (sStr.compare (0, 2, "0x") == 0)
315- {
316- mKeycode = strtol (sStr.c_str (), NULL, 0);
317- mModifiers = mods;
318-
319- return true;
320- }
321-
322- return false;
323+ else
324+ return false;
325+ }
326+
327+ mModifiers = mods;
328+ mKeycode = keycode;
329+
330+ return true;
331 }
332
333 CompString
334@@ -223,13 +222,9 @@
335
336 if (mKeycode != 0)
337 {
338- KeySym keysym;
339- char *keyname;
340-
341- keysym = XKeycodeToKeysym (screen->dpy (), mKeycode, 0);
342- keyname = XKeysymToString (keysym);
343-
344- if (keyname)
345+ std::string keyname (modifiers::ModifierHandler::Default ()->keycodeToString (mKeycode));
346+
347+ if (!keyname.empty ())
348 binding += keyname;
349 else
350 binding += compPrintf ("0x%x", mKeycode);
351
352=== modified file 'src/event.cpp'
353--- src/event.cpp 2012-01-24 08:30:14 +0000
354+++ src/event.cpp 2012-01-24 08:30:15 +0000
355@@ -37,10 +37,13 @@
356 #include <X11/extensions/Xfixes.h>
357
358 #include <core/atoms.h>
359+#include <core/modifierhandler.h>
360 #include "privatescreen.h"
361 #include "privatewindow.h"
362 #include "privatestackdebugger.h"
363
364+using namespace compiz::modifiers;
365+
366 bool
367 PrivateWindow::handleSyncAlarm ()
368 {
369@@ -80,8 +83,10 @@
370 return false;
371 }
372
373-#define REAL_MOD_MASK (ShiftMask | ControlMask | Mod1Mask | Mod2Mask | \
374- Mod3Mask | Mod4Mask | Mod5Mask | CompNoMask)
375+const unsigned int REAL_MOD_MASK = (ShiftMask | ControlMask |
376+ Mod1Mask | Mod2Mask |
377+ Mod3Mask | Mod4Mask |
378+ Mod5Mask | compiz::modifiers::NoMask);
379
380 static bool
381 isCallBackBinding (CompOption &option,
382
383=== modified file 'src/modifierhandler.cpp'
384--- src/modifierhandler.cpp 2012-01-24 08:30:14 +0000
385+++ src/modifierhandler.cpp 2012-01-24 08:30:15 +0000
386@@ -31,11 +31,21 @@
387 #include <X11/keysym.h>
388 #include <cstring>
389
390+using namespace compiz;
391+
392+typedef modifiers::ModifierHandler ModifierHandler;
393+
394 namespace
395 {
396+
397 const unsigned int virtualModMask[7] = {
398- CompAltMask, CompMetaMask, CompSuperMask, CompHyperMask,
399- CompModeSwitchMask, CompNumLockMask, CompScrollLockMask
400+ modifiers::AltMask,
401+ modifiers::MetaMask,
402+ modifiers::SuperMask,
403+ modifiers::HyperMask,
404+ modifiers::ModeSwitchMask,
405+ modifiers::NumLockMask,
406+ modifiers::ScrollLockMask
407 };
408 const int maskTable[8] = {
409 ShiftMask, LockMask, ControlMask, Mod1Mask,
410@@ -61,11 +71,11 @@
411 bool
412 ModifierHandler::updateModifierMappings ()
413 {
414- unsigned int modMask[CompModNum];
415+ unsigned int modMask[modifiers::ModNum];
416 int minKeycode, maxKeycode, keysymsPerKeycode = 0;
417 KeySym* key;
418
419- for (unsigned int i = 0; i < CompModNum; i++)
420+ for (unsigned int i = 0; i < modifiers::ModNum; i++)
421 modMask[i] = 0;
422
423 XDisplayKeycodes (mDisplay, &minKeycode, &maxKeycode);
424@@ -104,42 +114,42 @@
425 if (keysym == XK_Alt_L ||
426 keysym == XK_Alt_R)
427 {
428- modMask[CompModAlt] |= mask;
429+ modMask[modifiers::Alt] |= mask;
430 }
431 else if (keysym == XK_Meta_L ||
432 keysym == XK_Meta_R)
433 {
434- modMask[CompModMeta] |= mask;
435+ modMask[modifiers::Meta] |= mask;
436 }
437 else if (keysym == XK_Super_L ||
438 keysym == XK_Super_R)
439 {
440- modMask[CompModSuper] |= mask;
441+ modMask[modifiers::Super] |= mask;
442 }
443 else if (keysym == XK_Hyper_L ||
444 keysym == XK_Hyper_R)
445 {
446- modMask[CompModHyper] |= mask;
447+ modMask[modifiers::Hyper] |= mask;
448 }
449 else if (keysym == XK_Mode_switch)
450 {
451- modMask[CompModModeSwitch] |= mask;
452+ modMask[modifiers::ModeSwitch] |= mask;
453 }
454 else if (keysym == XK_Scroll_Lock)
455 {
456- modMask[CompModScrollLock] |= mask;
457+ modMask[modifiers::ScrollLock] |= mask;
458 }
459 else if (keysym == XK_Num_Lock)
460 {
461- modMask[CompModNumLock] |= mask;
462+ modMask[modifiers::NumLock] |= mask;
463 }
464 }
465 }
466
467- for (unsigned int i = 0; i < CompModNum; i++)
468+ for (unsigned int i = 0; i < modifiers::ModNum; i++)
469 {
470 if (!modMask[i])
471- modMask[i] = CompNoMask;
472+ modMask[i] = modifiers::NoMask;
473 }
474
475 if (memcmp (modMask, mModMask, sizeof (modMask)))
476@@ -147,8 +157,8 @@
477 memcpy (mModMask, modMask, sizeof (modMask));
478
479 mIgnoredModMask = LockMask |
480- (modMask[CompModNumLock] & ~CompNoMask) |
481- (modMask[CompModScrollLock] & ~CompNoMask);
482+ (modMask[modifiers::NumLock] & ~modifiers::NoMask) |
483+ (modMask[modifiers::ScrollLock] & ~modifiers::NoMask);
484
485 if (key)
486 XFree (key);
487@@ -163,7 +173,7 @@
488 unsigned int
489 ModifierHandler::virtualToRealModMask (unsigned int modMask)
490 {
491- for (unsigned int i = 0; i < CompModNum; i++)
492+ for (unsigned int i = 0; i < modifiers::ModNum; i++)
493 {
494 if (modMask & virtualModMask[i])
495 {
496@@ -194,6 +204,29 @@
497 return mods;
498 }
499
500+int
501+ModifierHandler::stringToKeycode (const std::string &str) const
502+{
503+ KeySym keysym = XStringToKeysym (str.c_str ());
504+
505+ if (keysym != NoSymbol)
506+ return static_cast <int> (XKeysymToKeycode (mDisplay, keysym));
507+
508+ return 0;
509+}
510+
511+std::string
512+ModifierHandler::keycodeToString (int keycode) const
513+{
514+ KeySym keysym;
515+ std::string keyname;
516+
517+ keysym = XKeycodeToKeysym (mDisplay, keycode, 0);
518+ keyname = std::string (XKeysymToString (keysym));
519+
520+ return keyname;
521+}
522+
523 ModifierHandler *
524 ModifierHandler::Default ()
525 {
526@@ -212,7 +245,7 @@
527 mModMap (0),
528 mDisplay (display)
529 {
530- for (int i = 0; i < ModNum; i++)
531+ for (int i = 0; i < modifiers::ModNum; i++)
532 mModMask[i] = NoMask;
533 }
534
535
536=== modified file 'src/privatescreen.h'
537--- src/privatescreen.h 2012-01-24 08:30:14 +0000
538+++ src/privatescreen.h 2012-01-24 08:30:15 +0000
539@@ -407,7 +407,7 @@
540 std::list< CompWatchFd * > watchFds;
541 CompWatchFdHandle lastWatchFdHandle;
542
543- ModifierHandler *modHandler;
544+ compiz::modifiers::ModifierHandler *modHandler;
545
546 std::map<CompString, CompPrivate> valueMap;
547
548
549=== modified file 'src/screen.cpp'
550--- src/screen.cpp 2012-01-24 08:30:14 +0000
551+++ src/screen.cpp 2012-01-24 08:30:15 +0000
552@@ -61,6 +61,8 @@
553 #include "privateaction.h"
554 #include "privatestackdebugger.h"
555
556+using namespace compiz::modifiers;
557+
558 bool inHandleEvent = false;
559
560 bool screenInitalized = false;
561@@ -3069,7 +3071,7 @@
562
563
564
565- if (!(mask & CompNoMask))
566+ if (!(mask & compiz::modifiers::NoMask))
567 {
568 if (!grabUngrabKeys (mask, key.keycode (), true))
569 return false;
570@@ -3103,7 +3105,7 @@
571
572 it = keyGrabs.erase (it);
573
574- if (!(mask & CompNoMask))
575+ if (!(mask & compiz::modifiers::NoMask))
576 grabUngrabKeys (mask, key.keycode (), false);
577 }
578 }
579@@ -3118,7 +3120,7 @@
580
581 for (it = keyGrabs.begin (); it != keyGrabs.end (); it++)
582 {
583- if (!((*it).modifiers & CompNoMask))
584+ if (!((*it).modifiers & compiz::modifiers::NoMask))
585 {
586 grabUngrabKeys ((*it).modifiers,
587 (*it).keycode, true);
588
589=== modified file 'src/window.cpp'
590--- src/window.cpp 2012-01-24 08:30:14 +0000
591+++ src/window.cpp 2012-01-24 08:30:15 +0000
592@@ -46,6 +46,8 @@
593 #include "privatescreen.h"
594 #include "privatestackdebugger.h"
595
596+using namespace compiz::modifiers;
597+
598 PluginClassStorage::Indices windowPluginClassIndices (0);
599
600 unsigned int
601@@ -5872,7 +5874,7 @@
602 {
603 unsigned int mods = ModifierHandler::Default ()->virtualToRealModMask (bind.modifiers);
604
605- if (mods & CompNoMask)
606+ if (mods & compiz::modifiers::NoMask)
607 continue;
608
609 for (unsigned int ignore = 0;

Subscribers

People subscribed via source and target branches