2
* Compiz vpswitch plugin
6
* Copyright (c) 2007 Dennis Kasprzyk <onestone@opencompositing.org>
8
* Go-to-numbered-viewport functionality by
10
* Copyright (c) 2007 Robert Carr <racarr@opencompositing.org>
11
* (c) 2007 Danny Baumann <maniac@opencompositing.org>
13
* Go-to-specific-viewport functionality by
15
* Copyright (c) 2007 Michael Vogt <mvo@ubuntu.com>
17
* This program is free software; you can redistribute it and/or
18
* modify it under the terms of the GNU General Public License
19
* as published by the Free Software Foundation; either version 2
20
* of the License, or (at your option) any later version.
22
* This program is distributed in the hope that it will be useful,
23
* but WITHOUT ANY WARRANTY; without even the implied warranty of
24
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25
* GNU General Public License for more details.
31
COMPIZ_PLUGIN_20090315 (vpswitch, VPSwitchPluginVTable);
34
VPSwitchScreen::initPluginAction (CompAction *action,
35
CompAction::State state,
36
CompOption::Vector &options)
40
CompPlugin *plugin = CompPlugin::find (optionGetInitPlugin ().c_str ());
46
foreach (CompOption &opt, plugin->vTable->getOptions ())
48
if (opt.type () == CompOption::TypeAction ||
49
opt.type () == CompOption::TypeKey ||
50
opt.type () == CompOption::TypeButton ||
51
opt.type () == CompOption::TypeEdge ||
52
opt.type () == CompOption::TypeBell)
53
if (opt.name () == optionGetInitAction () &&
54
opt.value ().action ().initiate ())
56
rv = opt.value ().action ().initiate ()
57
(action, state, options);
63
action->setState(action->state () | CompAction::StateTermButton);
69
VPSwitchScreen::termPluginAction (CompAction *action,
70
CompAction::State state,
71
CompOption::Vector &options)
73
CompPlugin *plugin = CompPlugin::find (optionGetInitPlugin ().c_str ());
79
foreach (CompOption &opt, plugin->vTable->getOptions ())
81
if (opt.type () == CompOption::TypeAction ||
82
opt.type () == CompOption::TypeKey ||
83
opt.type () == CompOption::TypeButton ||
84
opt.type () == CompOption::TypeEdge ||
85
opt.type () == CompOption::TypeBell)
86
if (opt.name () == optionGetInitAction () &&
87
opt.value ().action ().terminate ())
89
rv = opt.value ().action ().terminate ()
90
(action, state, options);
99
VPSwitchScreen::gotovp (int x, int y)
103
xev.xclient.type = ClientMessage;
104
xev.xclient.display = screen->dpy ();
105
xev.xclient.format = 32;
107
xev.xclient.message_type = Atoms::desktopViewport;
108
xev.xclient.window = screen->root ();
110
xev.xclient.data.l[0] = x * screen->width ();
111
xev.xclient.data.l[1] = y * screen->height ();
112
xev.xclient.data.l[2] = 0;
113
xev.xclient.data.l[3] = 0;
114
xev.xclient.data.l[4] = 0;
116
XSendEvent (screen->dpy (), screen->root (), false,
117
SubstructureRedirectMask | SubstructureNotifyMask, &xev);
120
/* desktop mouse button initiated actions */
123
VPSwitchScreen::next (CompAction *action,
124
CompAction::State state,
125
CompOption::Vector &options)
127
int targetX, targetY;
128
CompPoint vp (screen->vp ());
129
CompSize vpsize (screen->vpSize ());
133
targetX = vp.x () + 1;
136
if (targetX >= vpsize.width ())
141
if (targetY >= vpsize.height ())
144
gotovp (targetX, targetY);
150
VPSwitchScreen::prev (CompAction *action,
151
CompAction::State state,
152
CompOption::Vector &options)
154
int targetX, targetY;
155
CompPoint vp (screen->vp ());
156
CompSize vpsize (screen->vpSize ());
160
targetX = vp.x () - 1;
165
targetX = vpsize.width () - 1;
169
targetY = vpsize.height () - 1;
171
gotovp (targetX, targetY);
177
VPSwitchScreen::movevp (CompAction *action,
178
CompAction::State state,
179
CompOption::Vector &options,
180
unsigned int dx, unsigned int dy)
182
CompPoint vp (screen->vp ());
183
CompSize vpsize (screen->vpSize ());
189
if (dx < 0 && vp.x () + dx < 0)
192
if (dx > 0 && vp.x () + dx > (unsigned int) vpsize.width ())
195
if (dy < 0 && vp.y () + dy < 0)
198
if (dy > 0 && vp.y () + dy > (unsigned int) vpsize.height ())
201
gotovp (vp.x () + dx, vp.y () + dy);
206
/* Handle viewport number switch key events */
208
VPSwitchScreen::handleEvent (XEvent *event)
213
KeySym pressedKeySym;
220
pressedKeySym = XLookupKeysym (&event->xkey, 0);
221
mods = modHandler->keycodeToModifiers (event->xkey.keycode);
222
if (mods & CompNumLockMask)
223
row = 1; /* use first row of lookup table */
227
for (i = 0; i < 10; i++)
229
/* first try to handle normal number keys */
230
if (numberKeySyms[0][i] == pressedKeySym)
238
if (numberKeySyms[row][i] == pressedKeySym)
248
screen->handleEvent (event);
253
VPSwitchScreen::initiateNumbered (CompAction *action,
254
CompAction::State state,
255
CompOption::Vector &options)
258
numberedActive = true;
260
if (state & CompAction::StateInitKey)
261
action->setState (action->state () | CompAction::StateTermKey);
267
VPSwitchScreen::terminateNumbered (CompAction *action,
268
CompAction::State state,
269
CompOption::Vector &options)
272
CompSize vpsize (screen->vpSize ());
277
numberedActive = false;
279
if (destination < 1 ||
280
destination > (int) (vpsize.width () * vpsize.height ()))
283
nx = (destination - 1 ) % vpsize.width ();
284
ny = (destination - 1 ) / vpsize.width ();
291
/* switch-to-specific viewport stuff */
294
VPSwitchScreen::switchto (CompAction *action,
295
CompAction::State state,
296
CompOption::Vector &options,
302
numberedActive = true;
303
return terminateNumbered (action, state, options);
306
VPSwitchScreen::VPSwitchScreen (CompScreen *screen):
307
PluginClassHandler <VPSwitchScreen, CompScreen> (screen),
309
numberedActive (false)
311
ScreenInterface::setHandler (screen);
313
#define directionBind(name, dx, dy) \
314
optionSet##name##ButtonInitiate (boost::bind (&VPSwitchScreen::movevp, \
315
this, _1, _2, _3, dx, dy))
317
directionBind (Left, -1, 0);
318
directionBind (Right, 1, 0);
319
directionBind (Up, 0, -1);
320
directionBind (Down, 0, 1);
324
#define numberedBind(num) \
325
optionSetSwitchTo##num##KeyInitiate (boost::bind (&VPSwitchScreen::switchto, \
326
this, _1, _2, _3, num))
328
/* Note: get actions in multi-lists, this is ugly */
343
optionSetBeginKeyInitiate (boost::bind(&VPSwitchScreen::initiateNumbered,
345
optionSetBeginKeyTerminate (boost::bind (&VPSwitchScreen::terminateNumbered,
348
optionSetNextButtonInitiate (boost::bind
349
(&VPSwitchScreen::next,
351
optionSetPrevButtonInitiate (boost::bind
352
(&VPSwitchScreen::prev,
354
optionSetInitiateButtonInitiate (boost::bind
355
(&VPSwitchScreen::initPluginAction,
357
optionSetInitiateButtonTerminate (boost::bind
358
(&VPSwitchScreen::termPluginAction,
363
VPSwitchPluginVTable::init ()
365
if (!CompPlugin::checkPluginABI ("core", CORE_ABIVERSION))