~ubuntu-branches/ubuntu/precise/compiz/precise

« back to all changes in this revision

Viewing changes to .pc/fix_931927.patch/src/event.cpp

  • Committer: Package Import Robot
  • Author(s): Didier Roche, Łukasz 'sil2100' Zemczak, Didier Roche
  • Date: 2012-03-12 10:22:10 UTC
  • mfrom: (0.168.15)
  • Revision ID: package-import@ubuntu.com-20120312102210-e248pzbccr7r2tdq
Tags: 1:0.9.7.0+bzr3035-0ubuntu1
[ Łukasz 'sil2100' Zemczak ]
* New upstream snapshot:
  - Fix gtk-window-decorator crash upon demaximizing a window (LP: #930071)
  - Fix core keybindings (LP: #930412)
  - Fixes compiz crash with SIGSEGV on shutdown (LP: #931283)
  - Plugins can't tell the difference between a key-tap and modifier
    key-release (LP: #925293)
  - compiz-core r3001 (and 3002) ftbfs (LP: #933226)
  - Semi-maximized windows have no shadow or frame (LP: #924736)
  - Untranslated strings in gtk-window-decorator (LP: #780505)
  - Initialize the _NET_WM_STATE_FOCUSED (LP: #932087)
  - [regression] Customized shortcuts don't work (LP: #931927)
  - Window stacking problem (LP: #936675)
  - Quickly demaximized windows can receive maximized window decorations if 
    they were initially maximized (LP: #936778)
  - Maximized windows do not get shadows at all (LP: #936774)
  - [regression] Launcher, top panel and keyboard un-responsive after using 
    any Super-x shortcut (LP: #934058)
  - No draggable border if mutter isn't installed (LP: #936781)
  - Fix compiz crash with SIGSEGV in XDefineCursor() (LP: #936487)
  - Fixes memory leak at DecorWindow::updateSwitcher() (LP: #940115)
  - Unresolved symbols in plugins cause compiz to exit (LP: #938478)
  - Fix compiz spending about 51% of its CPU time in CompRegion 
    construction/destruction (LP: #940139)
  - Fix Conditional jump or move depends on uninitialised value(s) in 
    decor_match_pixmap (LP: #940066)
  - Fix 'show desktop' behaviour (LP: #871801)
  - Tweak algorithm used to cast shadows on maximized windows (LP: #936784)
  - "Svg" and "Png" should be "SVG and "PNG" (LP: #942890)
  - Fix invalid memory usage after free() in DecorWindow (LP: #943116)
  - Fix alt + F10 (LP: #943223)
* Removed cherry-picked patches
* debian/patches/fix_944631.patch:
  - Always replay the keyboard if something was grabbed and didn't trigger 
    an action and don't trigger actions which aren't added accidentally 
    (LP: #943612) (LP: #944631)
* debian/patches/fix_923683.patch:
  - Backports a patch which prevents the shift race condition

[ Didier Roche ]
* debian/patches/fix_alt_pressing.patch:
  - Patch from ddv to fix all the regressions with the alt key fix and other
    (LP: #943851, #945373)
  - Fix Quicklist are not showing if right-clicking a launcher icon in Expo
    mode if triggered by Super + S (LP: #944979)
* debian/patches/fix_806255.patch:
  - Unity/compiz intercepts keystrokes from grabbed windows (LP: #806255)
* debian/patches/fix_943194.patch:
  - second part for the alt key fix (LP: #943194)
* debian/patches/additional_alt_tapping_fix.patch:
  - again another alt tapping related fix for some regressions from the
    previous branch. Taken from "tapping-panacea" upstream branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright © 2005 Novell, Inc.
3
 
 *
4
 
 * Permission to use, copy, modify, distribute, and sell this software
5
 
 * and its documentation for any purpose is hereby granted without
6
 
 * fee, provided that the above copyright notice appear in all copies
7
 
 * and that both that copyright notice and this permission notice
8
 
 * appear in supporting documentation, and that the name of
9
 
 * Novell, Inc. not be used in advertising or publicity pertaining to
10
 
 * distribution of the software without specific, written prior permission.
11
 
 * Novell, Inc. makes no representations about the suitability of this
12
 
 * software for any purpose. It is provided "as is" without express or
13
 
 * implied warranty.
14
 
 *
15
 
 * NOVELL, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
16
 
 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
17
 
 * NO EVENT SHALL NOVELL, INC. BE LIABLE FOR ANY SPECIAL, INDIRECT OR
18
 
 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
19
 
 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
20
 
 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
21
 
 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22
 
 *
23
 
 * Author: David Reveman <davidr@novell.com>
24
 
 */
25
 
 
26
 
#include <stdlib.h>
27
 
#include <string.h>
28
 
 
29
 
#include <boost/bind.hpp>
30
 
#include <boost/foreach.hpp>
31
 
#define foreach BOOST_FOREACH
32
 
 
33
 
#include <X11/Xlib.h>
34
 
#include <X11/Xatom.h>
35
 
#include <X11/extensions/shape.h>
36
 
#include <X11/extensions/Xrandr.h>
37
 
#include <X11/extensions/Xfixes.h>
38
 
 
39
 
#include <core/atoms.h>
40
 
#include "privatescreen.h"
41
 
#include "privatewindow.h"
42
 
#include "privatestackdebugger.h"
43
 
 
44
 
bool
45
 
PrivateWindow::handleSyncAlarm ()
46
 
{
47
 
    if (priv->syncWait)
48
 
    {
49
 
        priv->syncWait = false;
50
 
 
51
 
        if (window->resize (priv->syncGeometry))
52
 
        {
53
 
            window->windowNotify (CompWindowNotifySyncAlarm);
54
 
        }
55
 
        else
56
 
        {
57
 
            /* resizeWindow failing means that there is another pending
58
 
               resize and we must send a new sync request to the client */
59
 
            window->sendSyncRequest ();
60
 
        }
61
 
    }
62
 
 
63
 
    return false;
64
 
}
65
 
 
66
 
 
67
 
static bool
68
 
autoRaiseTimeout (CompScreen *screen)
69
 
{
70
 
    CompWindow  *w = screen->findWindow (screen->activeWindow ());
71
 
 
72
 
    if (screen->autoRaiseWindow () == screen->activeWindow () ||
73
 
        (w && (screen->autoRaiseWindow () == w->transientFor ())))
74
 
    {
75
 
        w = screen->findWindow (screen->autoRaiseWindow ());
76
 
        if (w)
77
 
            w->updateAttributes (CompStackingUpdateModeNormal);
78
 
    }
79
 
 
80
 
    return false;
81
 
}
82
 
 
83
 
#define REAL_MOD_MASK (ShiftMask | ControlMask | Mod1Mask | Mod2Mask | \
84
 
                       Mod3Mask | Mod4Mask | Mod5Mask | CompNoMask)
85
 
 
86
 
static bool
87
 
isCallBackBinding (CompOption              &option,
88
 
                   CompAction::BindingType type,
89
 
                   CompAction::State       state)
90
 
{
91
 
    if (!option.isAction ())
92
 
        return false;
93
 
 
94
 
    if (!(option.value ().action ().type () & type))
95
 
        return false;
96
 
 
97
 
    if (!(option.value ().action ().state () & state))
98
 
        return false;
99
 
 
100
 
    return true;
101
 
}
102
 
 
103
 
static bool
104
 
isInitiateBinding (CompOption              &option,
105
 
                   CompAction::BindingType type,
106
 
                   CompAction::State       state,
107
 
                   CompAction              **action)
108
 
{
109
 
    if (!isCallBackBinding (option, type, state))
110
 
        return false;
111
 
 
112
 
    if (option.value ().action ().initiate ().empty ())
113
 
        return false;
114
 
 
115
 
    *action = &option.value ().action ();
116
 
 
117
 
    return true;
118
 
}
119
 
 
120
 
static bool
121
 
isTerminateBinding (CompOption              &option,
122
 
                    CompAction::BindingType type,
123
 
                    CompAction::State       state,
124
 
                    CompAction              **action)
125
 
{
126
 
    if (!isCallBackBinding (option, type, state))
127
 
        return false;
128
 
 
129
 
    if (option.value ().action ().terminate ().empty ())
130
 
        return false;
131
 
 
132
 
    *action = &option.value ().action ();
133
 
 
134
 
    return true;
135
 
}
136
 
 
137
 
bool
138
 
PrivateScreen::triggerButtonPressBindings (CompOption::Vector &options,
139
 
                                           XButtonEvent       *event,
140
 
                                           CompOption::Vector &arguments)
141
 
{
142
 
    CompAction::State state = CompAction::StateInitButton;
143
 
    CompAction        *action;
144
 
    unsigned int      ignored = modHandler->ignoredModMask ();
145
 
    unsigned int      modMask = REAL_MOD_MASK & ~ignored;
146
 
    unsigned int      bindMods;
147
 
    unsigned int      edge = 0;
148
 
 
149
 
    if (edgeWindow)
150
 
    {
151
 
        unsigned int i;
152
 
 
153
 
        if (event->root != root)
154
 
            return false;
155
 
 
156
 
        if (event->window != edgeWindow)
157
 
        {
158
 
            if (grabs.empty () || event->window != root)
159
 
                return false;
160
 
        }
161
 
 
162
 
        for (i = 0; i < SCREEN_EDGE_NUM; i++)
163
 
        {
164
 
            if (edgeWindow == screenEdge[i].id)
165
 
            {
166
 
                edge = 1 << i;
167
 
                arguments[1].value ().set ((int) activeWindow);
168
 
                break;
169
 
            }
170
 
        }
171
 
    }
172
 
 
173
 
    foreach (CompOption &option, options)
174
 
    {
175
 
        if (isInitiateBinding (option, CompAction::BindingTypeButton, state,
176
 
                               &action))
177
 
        {
178
 
            if (action->button ().button () == (int) event->button)
179
 
            {
180
 
                bindMods = modHandler->virtualToRealModMask (
181
 
                    action->button ().modifiers ());
182
 
 
183
 
                if ((bindMods & modMask) == (event->state & modMask))
184
 
                {
185
 
                    if (action->initiate () (action, state, arguments))
186
 
                        return true;
187
 
                }
188
 
            }
189
 
        }
190
 
 
191
 
        if (edge)
192
 
        {
193
 
            if (isInitiateBinding (option, CompAction::BindingTypeEdgeButton,
194
 
                                   state | CompAction::StateInitEdge, &action))
195
 
            {
196
 
                if ((action->button ().button () == (int) event->button) &&
197
 
                    (action->edgeMask () & edge))
198
 
                {
199
 
                    bindMods = modHandler->virtualToRealModMask (
200
 
                        action->button ().modifiers ());
201
 
 
202
 
                    if ((bindMods & modMask) == (event->state & modMask))
203
 
                        if (action->initiate () (action, state |
204
 
                                                 CompAction::StateInitEdge,
205
 
                                                 arguments))
206
 
                            return true;
207
 
                }
208
 
            }
209
 
        }
210
 
    }
211
 
 
212
 
    return false;
213
 
}
214
 
 
215
 
bool
216
 
PrivateScreen::triggerButtonReleaseBindings (CompOption::Vector &options,
217
 
                                             XButtonEvent       *event,
218
 
                                             CompOption::Vector &arguments)
219
 
{
220
 
    CompAction::State       state = CompAction::StateTermButton;
221
 
    CompAction::BindingType type  = CompAction::BindingTypeButton |
222
 
                                    CompAction::BindingTypeEdgeButton;
223
 
    CompAction              *action;
224
 
 
225
 
    foreach (CompOption &option, options)
226
 
    {
227
 
        if (isTerminateBinding (option, type, state, &action))
228
 
        {
229
 
            if (action->button ().button () == (int) event->button)
230
 
            {
231
 
                if (action->terminate () (action, state, arguments))
232
 
                    return true;
233
 
            }
234
 
        }
235
 
    }
236
 
 
237
 
    return false;
238
 
}
239
 
 
240
 
bool
241
 
PrivateScreen::triggerKeyPressBindings (CompOption::Vector &options,
242
 
                                        XKeyEvent          *event,
243
 
                                        CompOption::Vector &arguments)
244
 
{
245
 
    CompAction::State state = 0;
246
 
    CompAction        *action;
247
 
    unsigned int      modMask = REAL_MOD_MASK & ~modHandler->ignoredModMask ();
248
 
    unsigned int      bindMods;
249
 
 
250
 
    if (event->keycode == escapeKeyCode)
251
 
        state = CompAction::StateCancel;
252
 
    else if (event->keycode == returnKeyCode)
253
 
        state = CompAction::StateCommit;
254
 
 
255
 
    if (state)
256
 
    {
257
 
        foreach (CompOption &o, options)
258
 
        {
259
 
            if (o.isAction ())
260
 
            {
261
 
                if (!o.value ().action ().terminate ().empty ())
262
 
                    o.value ().action ().terminate () (&o.value ().action (),
263
 
                                                       state, noOptions);
264
 
            }
265
 
        }
266
 
 
267
 
        if (state == CompAction::StateCancel)
268
 
            return false;
269
 
    }
270
 
 
271
 
    state = CompAction::StateInitKey;
272
 
    foreach (CompOption &option, options)
273
 
    {
274
 
        if (isInitiateBinding (option, CompAction::BindingTypeKey,
275
 
                               state, &action))
276
 
        {
277
 
            bindMods = modHandler->virtualToRealModMask (
278
 
                action->key ().modifiers ());
279
 
 
280
 
            if (action->key ().keycode () == (int) event->keycode)
281
 
            {
282
 
                if ((bindMods & modMask) == (event->state & modMask))
283
 
                    if (action->initiate () (action, state, arguments))
284
 
                        return true;
285
 
            }
286
 
            else if (!xkbEvent && action->key ().keycode () == 0)
287
 
            {
288
 
                if (bindMods == (event->state & modMask))
289
 
                    if (action->initiate () (action, state, arguments))
290
 
                        return true;
291
 
            }
292
 
        }
293
 
    }
294
 
 
295
 
    return false;
296
 
}
297
 
 
298
 
bool
299
 
PrivateScreen::triggerKeyReleaseBindings (CompOption::Vector &options,
300
 
                                          XKeyEvent          *event,
301
 
                                          CompOption::Vector &arguments)
302
 
{
303
 
    CompAction::State state = CompAction::StateTermKey;
304
 
    CompAction        *action;
305
 
    unsigned int      ignored = modHandler->ignoredModMask ();
306
 
    unsigned int      modMask = REAL_MOD_MASK & ~ignored;
307
 
    unsigned int      bindMods;
308
 
    unsigned int      mods;
309
 
 
310
 
    mods = modHandler->keycodeToModifiers (event->keycode);
311
 
    if (!xkbEvent && !mods)
312
 
        return false;
313
 
 
314
 
    foreach (CompOption &option, options)
315
 
    {
316
 
        if (isTerminateBinding (option, CompAction::BindingTypeKey,
317
 
                                state, &action))
318
 
        {
319
 
            bindMods = modHandler->virtualToRealModMask (action->key ().modifiers ());
320
 
 
321
 
            if ((bindMods & modMask) == 0)
322
 
            {
323
 
                if ((unsigned int) action->key ().keycode () ==
324
 
                                                  (unsigned int) event->keycode)
325
 
                {
326
 
                    if (action->terminate () (action, state, arguments))
327
 
                        return true;
328
 
                }
329
 
            }
330
 
            else if (!xkbEvent && ((mods & modMask & bindMods) != bindMods))
331
 
            {
332
 
                if (action->terminate () (action, state, arguments))
333
 
                    return true;
334
 
            }
335
 
        }
336
 
    }
337
 
 
338
 
    return false;
339
 
}
340
 
 
341
 
bool
342
 
PrivateScreen::triggerStateNotifyBindings (CompOption::Vector  &options,
343
 
                                           XkbStateNotifyEvent *event,
344
 
                                           CompOption::Vector  &arguments)
345
 
{
346
 
    CompAction::State state;
347
 
    CompAction        *action;
348
 
    unsigned int      ignored = modHandler->ignoredModMask ();
349
 
    unsigned int      modMask = REAL_MOD_MASK & ~ignored;
350
 
    unsigned int      bindMods;
351
 
 
352
 
    if (event->event_type == KeyPress)
353
 
    {
354
 
        state = CompAction::StateInitKey;
355
 
 
356
 
        foreach (CompOption &option, options)
357
 
        {
358
 
            if (isInitiateBinding (option, CompAction::BindingTypeKey,
359
 
                                   state, &action))
360
 
            {
361
 
                if (action->key ().keycode () == 0)
362
 
                {
363
 
                    bindMods =
364
 
                        modHandler->virtualToRealModMask (action->key ().modifiers ());
365
 
 
366
 
                    if ((event->mods & modMask & bindMods) == bindMods)
367
 
                    {
368
 
                        if (action->initiate () (action, state, arguments))
369
 
                            return true;
370
 
                    }
371
 
                }
372
 
            }
373
 
        }
374
 
    }
375
 
    else
376
 
    {
377
 
        state = CompAction::StateTermKey;
378
 
 
379
 
        foreach (CompOption &option, options)
380
 
        {
381
 
            if (isTerminateBinding (option, CompAction::BindingTypeKey,
382
 
                                    state, &action))
383
 
            {
384
 
                bindMods = modHandler->virtualToRealModMask (action->key ().modifiers ());
385
 
 
386
 
                if ((event->mods & modMask & bindMods) != bindMods)
387
 
                {
388
 
                    if (action->terminate () (action, state, arguments))
389
 
                        return true;
390
 
                }
391
 
            }
392
 
        }
393
 
    }
394
 
 
395
 
    return false;
396
 
}
397
 
 
398
 
static bool
399
 
isBellAction (CompOption        &option,
400
 
              CompAction::State state,
401
 
              CompAction        **action)
402
 
{
403
 
    if (option.type () != CompOption::TypeAction &&
404
 
        option.type () != CompOption::TypeBell)
405
 
        return false;
406
 
 
407
 
    if (!option.value ().action ().bell ())
408
 
        return false;
409
 
 
410
 
    if (!(option.value ().action ().state () & state))
411
 
        return false;
412
 
 
413
 
    if (option.value ().action ().initiate ().empty ())
414
 
        return false;
415
 
 
416
 
    *action = &option.value ().action ();
417
 
 
418
 
    return true;
419
 
}
420
 
 
421
 
static bool
422
 
triggerBellNotifyBindings (CompOption::Vector &options,
423
 
                           CompOption::Vector &arguments)
424
 
{
425
 
    CompAction::State state = CompAction::StateInitBell;
426
 
    CompAction        *action;
427
 
 
428
 
    foreach (CompOption &option, options)
429
 
    {
430
 
        if (isBellAction (option, state, &action))
431
 
        {
432
 
            if (action->initiate () (action, state, arguments))
433
 
                return true;
434
 
        }
435
 
    }
436
 
 
437
 
    return false;
438
 
}
439
 
 
440
 
static bool
441
 
isEdgeAction (CompOption        &option,
442
 
              CompAction::State state,
443
 
              unsigned int      edge)
444
 
{
445
 
    if (option.type () != CompOption::TypeAction &&
446
 
        option.type () != CompOption::TypeButton &&
447
 
        option.type () != CompOption::TypeEdge)
448
 
        return false;
449
 
 
450
 
    if (!(option.value ().action ().edgeMask () & edge))
451
 
        return false;
452
 
 
453
 
    if (!(option.value ().action ().state () & state))
454
 
        return false;
455
 
 
456
 
    return true;
457
 
}
458
 
 
459
 
static bool
460
 
isEdgeEnterAction (CompOption        &option,
461
 
                   CompAction::State state,
462
 
                   CompAction::State delayState,
463
 
                   unsigned int      edge,
464
 
                   CompAction        **action)
465
 
{
466
 
    if (!isEdgeAction (option, state, edge))
467
 
        return false;
468
 
 
469
 
    if (option.value ().action ().type () & CompAction::BindingTypeEdgeButton)
470
 
        return false;
471
 
 
472
 
    if (option.value ().action ().initiate ().empty ())
473
 
        return false;
474
 
 
475
 
    if (delayState)
476
 
    {
477
 
        if ((option.value ().action ().state () &
478
 
             CompAction::StateNoEdgeDelay) !=
479
 
            (delayState & CompAction::StateNoEdgeDelay))
480
 
        {
481
 
            /* ignore edge actions which shouldn't be delayed when invoking
482
 
               undelayed edges (or vice versa) */
483
 
            return false;
484
 
        }
485
 
    }
486
 
 
487
 
 
488
 
    *action = &option.value ().action ();
489
 
 
490
 
    return true;
491
 
}
492
 
 
493
 
static bool
494
 
isEdgeLeaveAction (CompOption        &option,
495
 
                   CompAction::State state,
496
 
                   unsigned int      edge,
497
 
                   CompAction        **action)
498
 
{
499
 
    if (!isEdgeAction (option, state, edge))
500
 
        return false;
501
 
 
502
 
    if (option.value ().action ().terminate ().empty ())
503
 
        return false;
504
 
 
505
 
    *action = &option.value ().action ();
506
 
 
507
 
    return true;
508
 
}
509
 
 
510
 
static bool
511
 
triggerEdgeEnterBindings (CompOption::Vector &options,
512
 
                          CompAction::State  state,
513
 
                          CompAction::State  delayState,
514
 
                          unsigned int       edge,
515
 
                          CompOption::Vector &arguments)
516
 
{
517
 
    CompAction *action;
518
 
 
519
 
    foreach (CompOption &option, options)
520
 
    {
521
 
        if (isEdgeEnterAction (option, state, delayState, edge, &action))
522
 
        {
523
 
            if (action->initiate () (action, state, arguments))
524
 
                return true;
525
 
        }
526
 
    }
527
 
 
528
 
    return false;
529
 
}
530
 
 
531
 
static bool
532
 
triggerEdgeLeaveBindings (CompOption::Vector &options,
533
 
                          CompAction::State  state,
534
 
                          unsigned int       edge,
535
 
                          CompOption::Vector &arguments)
536
 
{
537
 
    CompAction *action;
538
 
 
539
 
    foreach (CompOption &option, options)
540
 
    {
541
 
        if (isEdgeLeaveAction (option, state, edge, &action))
542
 
        {
543
 
            if (action->terminate () (action, state, arguments))
544
 
                return true;
545
 
        }
546
 
    }
547
 
 
548
 
    return false;
549
 
}
550
 
 
551
 
static bool
552
 
triggerAllEdgeEnterBindings (CompAction::State  state,
553
 
                             CompAction::State  delayState,
554
 
                             unsigned int       edge,
555
 
                             CompOption::Vector &arguments)
556
 
{
557
 
    foreach (CompPlugin *p, CompPlugin::getPlugins ())
558
 
    {
559
 
        CompOption::Vector &options = p->vTable->getOptions ();
560
 
        if (triggerEdgeEnterBindings (options, state, delayState, edge,
561
 
                                      arguments))
562
 
        {
563
 
            return true;
564
 
        }
565
 
    }
566
 
    return false;
567
 
}
568
 
 
569
 
static bool
570
 
delayedEdgeTimeout (CompDelayedEdgeSettings *settings)
571
 
{
572
 
    triggerAllEdgeEnterBindings (settings->state,
573
 
                                 ~CompAction::StateNoEdgeDelay,
574
 
                                 settings->edge,
575
 
                                 settings->options);
576
 
 
577
 
    return false;
578
 
}
579
 
 
580
 
bool
581
 
PrivateScreen::triggerEdgeEnter (unsigned int       edge,
582
 
                                 CompAction::State  state,
583
 
                                 CompOption::Vector &arguments)
584
 
{
585
 
    int                     delay;
586
 
 
587
 
    delay = optionGetEdgeDelay ();
588
 
 
589
 
    if (delay > 0)
590
 
    {
591
 
        CompAction::State delayState;
592
 
        edgeDelaySettings.edge    = edge;
593
 
        edgeDelaySettings.state   = state;
594
 
        edgeDelaySettings.options = arguments;
595
 
 
596
 
        edgeDelayTimer.start  (
597
 
            boost::bind (delayedEdgeTimeout, &edgeDelaySettings),
598
 
                         delay, (unsigned int) ((float) delay * 1.2));
599
 
 
600
 
        delayState = CompAction::StateNoEdgeDelay;
601
 
        if (triggerAllEdgeEnterBindings (state, delayState, edge, arguments))
602
 
            return true;
603
 
    }
604
 
    else
605
 
    {
606
 
        if (triggerAllEdgeEnterBindings (state, 0, edge, arguments))
607
 
            return true;
608
 
    }
609
 
 
610
 
    return false;
611
 
}
612
 
 
613
 
bool
614
 
PrivateScreen::handleActionEvent (XEvent *event)
615
 
{
616
 
    static CompOption::Vector o (8);
617
 
    Window xid;
618
 
 
619
 
    o[0].setName ("event_window", CompOption::TypeInt);
620
 
    o[1].setName ("window", CompOption::TypeInt);
621
 
    o[2].setName ("modifiers", CompOption::TypeInt);
622
 
    o[3].setName ("x", CompOption::TypeInt);
623
 
    o[4].setName ("y", CompOption::TypeInt);
624
 
    o[5].setName ("root", CompOption::TypeInt);
625
 
    o[6].reset ();
626
 
    o[7].reset ();
627
 
 
628
 
    switch (event->type) {
629
 
    case ButtonPress:
630
 
        /* We need to determine if we clicked on a parent frame
631
 
         * window, if so, pass the appropriate child window as
632
 
         * "window" and the frame as "event_window"
633
 
         */
634
 
 
635
 
        xid = event->xbutton.window;
636
 
 
637
 
        foreach (CompWindow *w, screen->windows ())
638
 
        {
639
 
            if (w->priv->frame == xid)
640
 
                xid = w->id ();
641
 
        }
642
 
 
643
 
        o[0].value ().set ((int) event->xbutton.window);
644
 
        o[1].value ().set ((int) xid);
645
 
        o[2].value ().set ((int) event->xbutton.state);
646
 
        o[3].value ().set ((int) event->xbutton.x_root);
647
 
        o[4].value ().set ((int) event->xbutton.y_root);
648
 
        o[5].value ().set ((int) event->xbutton.root);
649
 
 
650
 
        o[6].setName ("button", CompOption::TypeInt);
651
 
        o[7].setName ("time", CompOption::TypeInt);
652
 
 
653
 
        o[6].value ().set ((int) event->xbutton.button);
654
 
        o[7].value ().set ((int) event->xbutton.time);
655
 
 
656
 
        foreach (CompPlugin *p, CompPlugin::getPlugins ())
657
 
        {
658
 
            CompOption::Vector &options = p->vTable->getOptions ();
659
 
            if (triggerButtonPressBindings (options, &event->xbutton, o))
660
 
                return true;
661
 
        }
662
 
        break;
663
 
    case ButtonRelease:
664
 
        o[0].value ().set ((int) event->xbutton.window);
665
 
        o[1].value ().set ((int) event->xbutton.window);
666
 
        o[2].value ().set ((int) event->xbutton.state);
667
 
        o[3].value ().set ((int) event->xbutton.x_root);
668
 
        o[4].value ().set ((int) event->xbutton.y_root);
669
 
        o[5].value ().set ((int) event->xbutton.root);
670
 
 
671
 
        o[6].setName ("button", CompOption::TypeInt);
672
 
        o[7].setName ("time", CompOption::TypeInt);
673
 
 
674
 
        o[6].value ().set ((int) event->xbutton.button);
675
 
        o[7].value ().set ((int) event->xbutton.time);
676
 
 
677
 
        foreach (CompPlugin *p, CompPlugin::getPlugins ())
678
 
        {
679
 
            CompOption::Vector &options = p->vTable->getOptions ();
680
 
            if (triggerButtonReleaseBindings (options, &event->xbutton, o))
681
 
                return true;
682
 
        }
683
 
        break;
684
 
    case KeyPress:
685
 
        o[0].value ().set ((int) event->xkey.window);
686
 
        o[1].value ().set ((int) activeWindow);
687
 
        o[2].value ().set ((int) event->xkey.state);
688
 
        o[3].value ().set ((int) event->xkey.x_root);
689
 
        o[4].value ().set ((int) event->xkey.y_root);
690
 
        o[5].value ().set ((int) event->xkey.root);
691
 
 
692
 
        o[6].setName ("keycode", CompOption::TypeInt);
693
 
        o[7].setName ("time", CompOption::TypeInt);
694
 
 
695
 
        o[6].value ().set ((int) event->xkey.keycode);
696
 
        o[7].value ().set ((int) event->xkey.time);
697
 
 
698
 
        foreach (CompPlugin *p, CompPlugin::getPlugins ())
699
 
        {
700
 
            CompOption::Vector &options = p->vTable->getOptions ();
701
 
            if (triggerKeyPressBindings (options, &event->xkey, o))
702
 
                return true;
703
 
        }
704
 
        break;
705
 
    case KeyRelease:
706
 
        o[0].value ().set ((int) event->xkey.window);
707
 
        o[1].value ().set ((int) activeWindow);
708
 
        o[2].value ().set ((int) event->xkey.state);
709
 
        o[3].value ().set ((int) event->xkey.x_root);
710
 
        o[4].value ().set ((int) event->xkey.y_root);
711
 
        o[5].value ().set ((int) event->xkey.root);
712
 
 
713
 
        o[6].setName ("keycode", CompOption::TypeInt);
714
 
        o[7].setName ("time", CompOption::TypeInt);
715
 
 
716
 
        o[6].value ().set ((int) event->xkey.keycode);
717
 
        o[7].value ().set ((int) event->xkey.time);
718
 
 
719
 
        foreach (CompPlugin *p, CompPlugin::getPlugins ())
720
 
        {
721
 
            CompOption::Vector &options = p->vTable->getOptions ();
722
 
            if (triggerKeyReleaseBindings (options, &event->xkey, o))
723
 
                return true;
724
 
        }
725
 
        break;
726
 
    case EnterNotify:
727
 
        if (event->xcrossing.mode   != NotifyGrab   &&
728
 
            event->xcrossing.mode   != NotifyUngrab &&
729
 
            event->xcrossing.detail != NotifyInferior)
730
 
        {
731
 
            unsigned int      edge, i;
732
 
            CompAction::State state;
733
 
 
734
 
            if (event->xcrossing.root != root)
735
 
                return false;
736
 
 
737
 
            if (edgeDelayTimer.active ())
738
 
                edgeDelayTimer.stop ();
739
 
 
740
 
            if (edgeWindow && edgeWindow != event->xcrossing.window)
741
 
            {
742
 
                state = CompAction::StateTermEdge;
743
 
                edge  = 0;
744
 
 
745
 
                for (i = 0; i < SCREEN_EDGE_NUM; i++)
746
 
                {
747
 
                    if (edgeWindow == screenEdge[i].id)
748
 
                    {
749
 
                        edge = 1 << i;
750
 
                        break;
751
 
                    }
752
 
                }
753
 
 
754
 
                edgeWindow = None;
755
 
 
756
 
                o[0].value ().set ((int) event->xcrossing.window);
757
 
                o[1].value ().set ((int) activeWindow);
758
 
                o[2].value ().set ((int) event->xcrossing.state);
759
 
                o[3].value ().set ((int) event->xcrossing.x_root);
760
 
                o[4].value ().set ((int) event->xcrossing.y_root);
761
 
                o[5].value ().set ((int) event->xcrossing.root);
762
 
 
763
 
                o[6].setName ("time", CompOption::TypeInt);
764
 
                o[6].value ().set ((int) event->xcrossing.time);
765
 
 
766
 
                foreach (CompPlugin *p, CompPlugin::getPlugins ())
767
 
                {
768
 
                    CompOption::Vector &options = p->vTable->getOptions ();
769
 
                    if (triggerEdgeLeaveBindings (options, state, edge, o))
770
 
                        return true;
771
 
                }
772
 
            }
773
 
 
774
 
            edge = 0;
775
 
 
776
 
            for (i = 0; i < SCREEN_EDGE_NUM; i++)
777
 
            {
778
 
                if (event->xcrossing.window == screenEdge[i].id)
779
 
                {
780
 
                    edge = 1 << i;
781
 
                    break;
782
 
                }
783
 
            }
784
 
 
785
 
            if (edge)
786
 
            {
787
 
                state = CompAction::StateInitEdge;
788
 
 
789
 
                edgeWindow = event->xcrossing.window;
790
 
 
791
 
                o[0].value ().set ((int) event->xcrossing.window);
792
 
                o[1].value ().set ((int) activeWindow);
793
 
                o[2].value ().set ((int) event->xcrossing.state);
794
 
                o[3].value ().set ((int) event->xcrossing.x_root);
795
 
                o[4].value ().set ((int) event->xcrossing.y_root);
796
 
                o[5].value ().set ((int) event->xcrossing.root);
797
 
 
798
 
                o[6].setName ("time", CompOption::TypeInt);
799
 
                o[6].value ().set ((int) event->xcrossing.time);
800
 
 
801
 
                if (triggerEdgeEnter (edge, state, o))
802
 
                    return true;
803
 
            }
804
 
        }
805
 
        break;
806
 
    case ClientMessage:
807
 
        if (event->xclient.message_type == Atoms::xdndEnter)
808
 
        {
809
 
            xdndWindow = event->xclient.window;
810
 
        }
811
 
        else if (event->xclient.message_type == Atoms::xdndLeave)
812
 
        {
813
 
            unsigned int      edge = 0;
814
 
            CompAction::State state;
815
 
 
816
 
            if (!xdndWindow)
817
 
            {
818
 
                CompWindow *w;
819
 
 
820
 
                w = screen->findWindow (event->xclient.window);
821
 
                if (w)
822
 
                {
823
 
                    unsigned int i;
824
 
 
825
 
                    for (i = 0; i < SCREEN_EDGE_NUM; i++)
826
 
                    {
827
 
                        if (event->xclient.window == screenEdge[i].id)
828
 
                        {
829
 
                            edge = 1 << i;
830
 
                            break;
831
 
                        }
832
 
                    }
833
 
                }
834
 
            }
835
 
 
836
 
            if (edge)
837
 
            {
838
 
                state = CompAction::StateTermEdgeDnd;
839
 
 
840
 
                o[0].value ().set ((int) event->xclient.window);
841
 
                o[1].value ().set ((int) activeWindow);
842
 
                o[2].value ().set ((int) 0); /* fixme */
843
 
                o[3].value ().set ((int) 0); /* fixme */
844
 
                o[4].value ().set ((int) 0); /* fixme */
845
 
                o[5].value ().set ((int) root);
846
 
 
847
 
                foreach (CompPlugin *p, CompPlugin::getPlugins ())
848
 
                {
849
 
                    CompOption::Vector &options = p->vTable->getOptions ();
850
 
                    if (triggerEdgeLeaveBindings (options, state, edge, o))
851
 
                        return true;
852
 
                }
853
 
            }
854
 
        }
855
 
        else if (event->xclient.message_type == Atoms::xdndPosition)
856
 
        {
857
 
            unsigned int      edge = 0;
858
 
            CompAction::State state;
859
 
 
860
 
            if (xdndWindow == event->xclient.window)
861
 
            {
862
 
                CompWindow *w;
863
 
 
864
 
                w = screen->findWindow (event->xclient.window);
865
 
                if (w)
866
 
                {
867
 
                    unsigned int i;
868
 
 
869
 
                    for (i = 0; i < SCREEN_EDGE_NUM; i++)
870
 
                    {
871
 
                        if (xdndWindow == screenEdge[i].id)
872
 
                        {
873
 
                            edge = 1 << i;
874
 
                            break;
875
 
                        }
876
 
                    }
877
 
                }
878
 
            }
879
 
 
880
 
            if (edge)
881
 
            {
882
 
                state = CompAction::StateInitEdgeDnd;
883
 
 
884
 
                o[0].value ().set ((int) event->xclient.window);
885
 
                o[1].value ().set ((int) activeWindow);
886
 
                o[2].value ().set ((int) 0); /* fixme */
887
 
                o[3].value ().set ((int) event->xclient.data.l[2] >> 16);
888
 
                o[4].value ().set ((int) event->xclient.data.l[2] & 0xffff);
889
 
                o[5].value ().set ((int) root);
890
 
 
891
 
                if (triggerEdgeEnter (edge, state, o))
892
 
                    return true;
893
 
            }
894
 
 
895
 
            xdndWindow = None;
896
 
        }
897
 
        break;
898
 
    default:
899
 
        if (event->type == xkbEvent)
900
 
        {
901
 
            XkbAnyEvent *xkbEvent = (XkbAnyEvent *) event;
902
 
 
903
 
            if (xkbEvent->xkb_type == XkbStateNotify)
904
 
            {
905
 
                XkbStateNotifyEvent *stateEvent = (XkbStateNotifyEvent *) event;
906
 
 
907
 
                o[0].value ().set ((int) activeWindow);
908
 
                o[1].value ().set ((int) activeWindow);
909
 
                o[2].value ().set ((int) stateEvent->mods);
910
 
 
911
 
                o[3].setName ("time", CompOption::TypeInt);
912
 
                o[3].value ().set ((int) xkbEvent->time);
913
 
                o[4].reset ();
914
 
                o[5].reset ();
915
 
 
916
 
                foreach (CompPlugin *p, CompPlugin::getPlugins ())
917
 
                {
918
 
                    CompOption::Vector &options = p->vTable->getOptions ();
919
 
                    if (triggerStateNotifyBindings (options, stateEvent, o))
920
 
                        return true;
921
 
                }
922
 
            }
923
 
            else if (xkbEvent->xkb_type == XkbBellNotify)
924
 
            {
925
 
                o[0].value ().set ((int) activeWindow);
926
 
                o[1].value ().set ((int) activeWindow);
927
 
 
928
 
                o[2].setName ("time", CompOption::TypeInt);
929
 
                o[2].value ().set ((int) xkbEvent->time);
930
 
                o[3].reset ();
931
 
                o[4].reset ();
932
 
                o[5].reset ();
933
 
 
934
 
 
935
 
                foreach (CompPlugin *p, CompPlugin::getPlugins ())
936
 
                {
937
 
                    CompOption::Vector &options = p->vTable->getOptions ();
938
 
                    if (triggerBellNotifyBindings (options, o))
939
 
                        return true;
940
 
                }
941
 
            }
942
 
        }
943
 
        break;
944
 
    }
945
 
 
946
 
    return false;
947
 
}
948
 
 
949
 
void
950
 
PrivateScreen::setDefaultWindowAttributes (XWindowAttributes *wa)
951
 
{
952
 
    wa->x                     = 0;
953
 
    wa->y                     = 0;
954
 
    wa->width                 = 1;
955
 
    wa->height                = 1;
956
 
    wa->border_width          = 0;
957
 
    wa->depth                 = 0;
958
 
    wa->visual                = NULL;
959
 
    wa->root                  = root;
960
 
    wa->c_class               = InputOnly;
961
 
    wa->bit_gravity           = NorthWestGravity;
962
 
    wa->win_gravity           = NorthWestGravity;
963
 
    wa->backing_store         = NotUseful;
964
 
    wa->backing_planes        = 0;
965
 
    wa->backing_pixel         = 0;
966
 
    wa->save_under            = false;
967
 
    wa->colormap              = None;
968
 
    wa->map_installed         = false;
969
 
    wa->map_state             = IsUnviewable;
970
 
    wa->all_event_masks       = 0;
971
 
    wa->your_event_mask       = 0;
972
 
    wa->do_not_propagate_mask = 0;
973
 
    wa->override_redirect     = true;
974
 
    wa->screen                = ScreenOfDisplay (dpy, screenNum);
975
 
}
976
 
 
977
 
void
978
 
CompScreen::handleCompizEvent (const char         *plugin,
979
 
                               const char         *event,
980
 
                               CompOption::Vector &options)
981
 
{
982
 
    WRAPABLE_HND_FUNCTN (handleCompizEvent, plugin, event, options);
983
 
    _handleCompizEvent (plugin, event, options);
984
 
}
985
 
 
986
 
void
987
 
CompScreenImpl::_handleCompizEvent (const char         *plugin,
988
 
                               const char         *event,
989
 
                               CompOption::Vector &options)
990
 
{
991
 
}
992
 
 
993
 
void
994
 
CompScreen::handleEvent (XEvent *event)
995
 
{
996
 
    WRAPABLE_HND_FUNCTN (handleEvent, event)
997
 
    _handleEvent (event);
998
 
}
999
 
 
1000
 
void
1001
 
CompScreenImpl::_handleEvent (XEvent *event)
1002
 
{
1003
 
    CompWindow *w = NULL;
1004
 
    XWindowAttributes wa;
1005
 
    bool              actionEventHandled = false;
1006
 
 
1007
 
    switch (event->type) {
1008
 
    case ButtonPress:
1009
 
        if (event->xbutton.root == priv->root)
1010
 
            priv->setCurrentOutput (
1011
 
                outputDeviceForPoint (event->xbutton.x_root,
1012
 
                                                 event->xbutton.y_root));
1013
 
        break;
1014
 
    case MotionNotify:
1015
 
        if (event->xmotion.root == priv->root)
1016
 
            priv->setCurrentOutput (
1017
 
                outputDeviceForPoint (event->xmotion.x_root,
1018
 
                                      event->xmotion.y_root));
1019
 
        break;
1020
 
    case KeyPress:
1021
 
        w = findWindow (priv->activeWindow);
1022
 
        if (w)
1023
 
            priv->setCurrentOutput (w->outputDevice ());
1024
 
        break;
1025
 
    default:
1026
 
        break;
1027
 
    }
1028
 
 
1029
 
    if (priv->handleActionEvent (event))
1030
 
    {
1031
 
        if (priv->grabs.empty ())
1032
 
            XAllowEvents (priv->dpy, AsyncPointer, event->xbutton.time);
1033
 
 
1034
 
        actionEventHandled = true;
1035
 
    }
1036
 
 
1037
 
    if (priv->grabs.empty ())
1038
 
    {
1039
 
        switch (event->type)
1040
 
        {
1041
 
            case KeyPress:
1042
 
                XUngrabKeyboard (priv->dpy, event->xkey.time);
1043
 
                break;
1044
 
            default:
1045
 
                break;
1046
 
        }
1047
 
    }
1048
 
 
1049
 
    if (actionEventHandled)
1050
 
        return;
1051
 
 
1052
 
    switch (event->type) {
1053
 
    case SelectionRequest:
1054
 
        priv->handleSelectionRequest (event);
1055
 
        break;
1056
 
    case SelectionClear:
1057
 
        priv->handleSelectionClear (event);
1058
 
        break;
1059
 
    case ConfigureNotify:
1060
 
        w = findWindow (event->xconfigure.window);
1061
 
 
1062
 
        if (w && !w->priv->frame)
1063
 
        {
1064
 
            w->priv->configure (&event->xconfigure);
1065
 
        }
1066
 
        else
1067
 
        {
1068
 
            w = findTopLevelWindow (event->xconfigure.window);
1069
 
 
1070
 
            if (w && w->priv->frame == event->xconfigure.window)
1071
 
                w->priv->configureFrame (&event->xconfigure);
1072
 
            else
1073
 
            {
1074
 
                if (event->xconfigure.window == priv->root)
1075
 
                    priv->configure (&event->xconfigure);
1076
 
            }
1077
 
        }
1078
 
        break;
1079
 
    case CreateNotify:
1080
 
    {
1081
 
        bool create = true;
1082
 
 
1083
 
        /* Failure means that window has been destroyed. We still have to add 
1084
 
         * the window to the window list as we might get configure requests
1085
 
         * which require us to stack other windows relative to it. Setting
1086
 
         * some default values if this is the case. */
1087
 
        if (!XGetWindowAttributes (priv->dpy, event->xcreatewindow.window, &wa))
1088
 
            priv->setDefaultWindowAttributes (&wa);
1089
 
 
1090
 
        foreach (CompWindow *w, screen->windows ())
1091
 
        {
1092
 
            if (w->priv->serverFrame == event->xcreatewindow.window)
1093
 
            {
1094
 
                w->priv->frame = event->xcreatewindow.window;
1095
 
                w->priv->updatePassiveButtonGrabs ();
1096
 
                create = false;
1097
 
            }
1098
 
        }
1099
 
 
1100
 
        foreach (CompWindow *w, priv->destroyedWindows)
1101
 
        {
1102
 
            if (w->priv->serverId == event->xcreatewindow.window)
1103
 
            {
1104
 
                /* Previously destroyed window
1105
 
                 * plugins were keeping around
1106
 
                 * in order to avoid an xid conflict,
1107
 
                 * destroy it right away and manage
1108
 
                 * the new window */
1109
 
 
1110
 
                StackDebugger *dbg = StackDebugger::Default ();
1111
 
 
1112
 
                while (w->priv->destroyRefCnt)
1113
 
                    w->destroy ();
1114
 
 
1115
 
                if (dbg)
1116
 
                    dbg->removeDestroyedFrame (event->xcreatewindow.window);
1117
 
            }
1118
 
 
1119
 
        }
1120
 
 
1121
 
        if (wa.root != event->xcreatewindow.parent)
1122
 
            create = false;
1123
 
 
1124
 
        if (create)
1125
 
        {
1126
 
            /* Track the window if it was created on this
1127
 
             * screen, otherwise we still need to register
1128
 
             * for FocusChangeMask. Also, we don't want to
1129
 
             * manage it straight away - in reality we want
1130
 
             * that to wait until the map request */
1131
 
            if ((wa.root == priv->root))
1132
 
            {
1133
 
                CoreWindow *cw = new CoreWindow (event->xcreatewindow.window);
1134
 
                cw->manage (priv->getTopWindow (), wa);
1135
 
 
1136
 
                removeFromCreatedWindows (cw);
1137
 
                delete cw;
1138
 
            }
1139
 
            else
1140
 
                XSelectInput (priv->dpy, event->xcreatewindow.window,
1141
 
                              FocusChangeMask);
1142
 
        }
1143
 
        else
1144
 
            compLogMessage ("core", CompLogLevelDebug, "refusing to manage window 0x%x", (unsigned int) event->xcreatewindow.window);
1145
 
 
1146
 
        break;
1147
 
    }
1148
 
    case DestroyNotify:
1149
 
        w = findWindow (event->xdestroywindow.window);
1150
 
 
1151
 
        /* It is possible that some plugin might call
1152
 
         * w->destroy () before the window actually receives
1153
 
         * its first DestroyNotify event which would mean
1154
 
         * that it is already in the list of destroyed
1155
 
         * windows, so check that list too */
1156
 
 
1157
 
        if (!w)
1158
 
        {
1159
 
            foreach (CompWindow *dw, priv->destroyedWindows)
1160
 
            {
1161
 
                if (dw->priv->serverId == event->xdestroywindow.window)
1162
 
                {
1163
 
                    w = dw;
1164
 
                    break;
1165
 
                }
1166
 
            }
1167
 
        }
1168
 
 
1169
 
        if (w)
1170
 
        {
1171
 
            w->moveInputFocusToOtherWindow ();
1172
 
            w->destroy ();
1173
 
        }
1174
 
        break;
1175
 
    case MapNotify:
1176
 
 
1177
 
        /* Search in already-created windows for this window */
1178
 
        if (!w)
1179
 
            w = findWindow (event->xmap.window);
1180
 
 
1181
 
        if (w)
1182
 
        {
1183
 
            if (w->priv->pendingMaps)
1184
 
            {
1185
 
                /* The only case where this happens
1186
 
                 * is where the window unmaps itself
1187
 
                 * but doesn't get destroyed so when
1188
 
                 * it re-maps we need to reparent it */
1189
 
 
1190
 
                if (!w->priv->serverFrame)
1191
 
                    w->priv->reparent ();
1192
 
 
1193
 
                w->priv->managed = true;
1194
 
            }
1195
 
 
1196
 
            /* been shaded */
1197
 
            if (w->priv->height == 0)
1198
 
            {
1199
 
                if (w->id () == priv->activeWindow)
1200
 
                    w->moveInputFocusTo ();
1201
 
            }
1202
 
 
1203
 
            w->map ();
1204
 
        }
1205
 
 
1206
 
        break;
1207
 
    case UnmapNotify:
1208
 
        w = findWindow (event->xunmap.window);
1209
 
        if (w)
1210
 
        {
1211
 
            /* Normal -> Iconic */
1212
 
            if (w->pendingUnmaps ())
1213
 
            {
1214
 
                priv->setWmState (IconicState, w->id ());
1215
 
                w->priv->pendingUnmaps--;
1216
 
            }
1217
 
            else /* X -> Withdrawn */
1218
 
            {
1219
 
                /* Iconic -> Withdrawn:
1220
 
                 *
1221
 
                 * The window is already unmapped so we need to check the
1222
 
                 * synthetic UnmapNotify that comes and withdraw the window here */
1223
 
                if (w->state () & CompWindowStateHiddenMask)
1224
 
                {
1225
 
                    w->priv->minimized = false;
1226
 
                    w->changeState (w->state () & ~CompWindowStateHiddenMask);
1227
 
 
1228
 
                    priv->updateClientList ();
1229
 
                    w->priv->withdraw ();
1230
 
                }
1231
 
                /* Closing:
1232
 
                 *
1233
 
                 * ICCCM Section 4.1.4 says that clients need to send
1234
 
                 * a synthetic UnmapNotify for every real unmap
1235
 
                 * in order to reflect the change in state, but
1236
 
                 * since we already withdraw the window on the real
1237
 
                 * UnmapNotify, no need to do it again on the synthetic
1238
 
                 * one. */
1239
 
                else if (!event->xunmap.send_event)
1240
 
                {
1241
 
                    w->windowNotify (CompWindowNotifyClose);
1242
 
                    w->priv->withdraw ();
1243
 
                }
1244
 
            }
1245
 
 
1246
 
            if (!event->xunmap.send_event)
1247
 
            {
1248
 
                w->unmap ();
1249
 
 
1250
 
                if (!w->shaded () && !w->priv->pendingMaps)
1251
 
                    w->moveInputFocusToOtherWindow ();
1252
 
            }
1253
 
        }
1254
 
        break;
1255
 
    case ReparentNotify:
1256
 
 
1257
 
        w = findWindow (event->xreparent.window);
1258
 
 
1259
 
        /* If this window isn't part of our tracked window
1260
 
         * list and was reparented into the root window then
1261
 
         * we need to track it */
1262
 
        if (!w)
1263
 
        {
1264
 
            if (event->xreparent.parent == priv->root)
1265
 
            {
1266
 
                /* Failure means that window has been destroyed. We still have to add 
1267
 
                 * the window to the window list as we might get configure requests
1268
 
                 * which require us to stack other windows relative to it. Setting
1269
 
                 * some default values if this is the case. */
1270
 
                if (!XGetWindowAttributes (priv->dpy, event->xcreatewindow.window, &wa))
1271
 
                    priv->setDefaultWindowAttributes (&wa);
1272
 
 
1273
 
                CoreWindow *cw = new CoreWindow (event->xcreatewindow.window);
1274
 
                cw->manage (priv->getTopWindow (), wa);
1275
 
 
1276
 
                removeFromCreatedWindows (cw);
1277
 
                delete cw;
1278
 
                break;
1279
 
            }
1280
 
            else
1281
 
            {
1282
 
                /* It is possible that some plugin might call
1283
 
                 * w->destroy () before the window actually receives
1284
 
                 * its first ReparentNotify event which would mean
1285
 
                 * that it is already in the list of destroyed
1286
 
                 * windows, so check that list too */
1287
 
 
1288
 
                foreach (CompWindow *dw, priv->destroyedWindows)
1289
 
                {
1290
 
                    if (dw->priv->serverId == event->xreparent.window)
1291
 
                    {
1292
 
                        w = dw;
1293
 
                        break;
1294
 
                    }
1295
 
                }
1296
 
            }
1297
 
        }
1298
 
 
1299
 
        /* This is the only case where a window is removed but not
1300
 
           destroyed. We must remove our event mask and all passive
1301
 
           grabs. */
1302
 
 
1303
 
        if (w)
1304
 
        {
1305
 
            if (event->xreparent.parent != w->priv->wrapper)
1306
 
            {
1307
 
                w->moveInputFocusToOtherWindow ();
1308
 
                w->destroy ();
1309
 
 
1310
 
                XSelectInput (priv->dpy, w->id (), NoEventMask);
1311
 
                XShapeSelectInput (priv->dpy, w->id (), NoEventMask);
1312
 
                XUngrabButton (priv->dpy, AnyButton, AnyModifier, w->id ());
1313
 
            }
1314
 
        }
1315
 
 
1316
 
        break;
1317
 
    case CirculateNotify:
1318
 
        w = findWindow (event->xcirculate.window);
1319
 
        if (w)
1320
 
            w->priv->circulate (&event->xcirculate);
1321
 
        break;
1322
 
    case ButtonPress:
1323
 
        if (event->xbutton.button == Button1 ||
1324
 
            event->xbutton.button == Button2 ||
1325
 
            event->xbutton.button == Button3)
1326
 
        {
1327
 
            w = findTopLevelWindow (event->xbutton.window);
1328
 
            if (w)
1329
 
            {
1330
 
                if (priv->optionGetRaiseOnClick ())
1331
 
                {
1332
 
                    w->updateAttributes (CompStackingUpdateModeAboveFullscreen);
1333
 
                }
1334
 
 
1335
 
                if (w->id () != priv->activeWindow)
1336
 
                    if (!(w->type () & CompWindowTypeDockMask))
1337
 
                        if (w->focus ())
1338
 
                            w->moveInputFocusTo ();
1339
 
            }
1340
 
        }
1341
 
 
1342
 
        if (priv->grabs.empty ())
1343
 
            XAllowEvents (priv->dpy, ReplayPointer, event->xbutton.time);
1344
 
 
1345
 
        break;
1346
 
    case PropertyNotify:
1347
 
        if (event->xproperty.atom == Atoms::winType)
1348
 
        {
1349
 
            w = findWindow (event->xproperty.window);
1350
 
            if (w)
1351
 
            {
1352
 
                unsigned int type;
1353
 
 
1354
 
                type = priv->getWindowType (w->id ());
1355
 
 
1356
 
                if (type != w->wmType ())
1357
 
                {
1358
 
                    if (w->isViewable ())
1359
 
                    {
1360
 
                        if (w->type () == CompWindowTypeDesktopMask)
1361
 
                            priv->desktopWindowCount--;
1362
 
                        else if (type == CompWindowTypeDesktopMask)
1363
 
                            priv->desktopWindowCount++;
1364
 
                    }
1365
 
 
1366
 
                    w->wmType () = type;
1367
 
 
1368
 
                    w->recalcType ();
1369
 
                    w->recalcActions ();
1370
 
 
1371
 
                    if (type & (CompWindowTypeDockMask |
1372
 
                                CompWindowTypeDesktopMask))
1373
 
                        w->setDesktop (0xffffffff);
1374
 
 
1375
 
                    priv->updateClientList ();
1376
 
 
1377
 
                    matchPropertyChanged (w);
1378
 
                }
1379
 
            }
1380
 
        }
1381
 
        else if (event->xproperty.atom == Atoms::winState)
1382
 
        {
1383
 
            w = findWindow (event->xproperty.window);
1384
 
            if (w && !w->managed ())
1385
 
            {
1386
 
                unsigned int state;
1387
 
 
1388
 
                state = priv->getWindowState (w->id ());
1389
 
                state = CompWindow::constrainWindowState (state, w->actions ());
1390
 
 
1391
 
                /* EWMH suggests that we ignore changes
1392
 
                   to _NET_WM_STATE_HIDDEN */
1393
 
                if (w->state () & CompWindowStateHiddenMask)
1394
 
                    state |= CompWindowStateHiddenMask;
1395
 
                else
1396
 
                    state &= ~CompWindowStateHiddenMask;
1397
 
 
1398
 
                w->changeState (state);
1399
 
            }
1400
 
        }
1401
 
        else if (event->xproperty.atom == XA_WM_NORMAL_HINTS)
1402
 
        {
1403
 
            w = findWindow (event->xproperty.window);
1404
 
            if (w)
1405
 
            {
1406
 
                w->priv->updateNormalHints ();
1407
 
                w->recalcActions ();
1408
 
            }
1409
 
        }
1410
 
        else if (event->xproperty.atom == XA_WM_HINTS)
1411
 
        {
1412
 
            w = findWindow (event->xproperty.window);
1413
 
            if (w)
1414
 
                w->priv->updateWmHints ();
1415
 
        }
1416
 
        else if (event->xproperty.atom == XA_WM_TRANSIENT_FOR)
1417
 
        {
1418
 
            w = findWindow (event->xproperty.window);
1419
 
            if (w)
1420
 
            {
1421
 
                w->priv->updateTransientHint ();
1422
 
                w->recalcActions ();
1423
 
            }
1424
 
        }
1425
 
        else if (event->xproperty.atom == Atoms::wmClientLeader)
1426
 
        {
1427
 
            w = findWindow (event->xproperty.window);
1428
 
            if (w)
1429
 
                w->priv->clientLeader = w->priv->getClientLeader ();
1430
 
        }
1431
 
        else if (event->xproperty.atom == Atoms::wmIconGeometry)
1432
 
        {
1433
 
            w = findWindow (event->xproperty.window);
1434
 
            if (w)
1435
 
                w->priv->updateIconGeometry ();
1436
 
        }
1437
 
        else if (event->xproperty.atom == Atoms::wmStrut ||
1438
 
                 event->xproperty.atom == Atoms::wmStrutPartial)
1439
 
        {
1440
 
            w = findWindow (event->xproperty.window);
1441
 
            if (w)
1442
 
            {
1443
 
                if (w->updateStruts ())
1444
 
                    updateWorkarea ();
1445
 
            }
1446
 
        }
1447
 
        else if (event->xproperty.atom == Atoms::mwmHints)
1448
 
        {
1449
 
            w = findWindow (event->xproperty.window);
1450
 
            if (w)
1451
 
                w->priv->updateMwmHints ();
1452
 
        }
1453
 
        else if (event->xproperty.atom == Atoms::wmProtocols)
1454
 
        {
1455
 
            w = findWindow (event->xproperty.window);
1456
 
            if (w)
1457
 
                w->priv->protocols = priv->getProtocols (w->id ());
1458
 
        }
1459
 
        else if (event->xproperty.atom == Atoms::wmIcon)
1460
 
        {
1461
 
            w = findWindow (event->xproperty.window);
1462
 
            if (w)
1463
 
                w->priv->freeIcons ();
1464
 
        }
1465
 
        else if (event->xproperty.atom == Atoms::startupId)
1466
 
        {
1467
 
            w = findWindow (event->xproperty.window);
1468
 
            if (w)
1469
 
                w->priv->updateStartupId ();
1470
 
        }
1471
 
        else if (event->xproperty.atom == XA_WM_CLASS)
1472
 
        {
1473
 
            w = findWindow (event->xproperty.window);
1474
 
            if (w)
1475
 
                w->priv->updateClassHints ();
1476
 
        }
1477
 
        break;
1478
 
    case MotionNotify:
1479
 
        break;
1480
 
    case ClientMessage:
1481
 
        if (event->xclient.message_type == Atoms::winActive)
1482
 
        {
1483
 
            w = findTopLevelWindow (event->xclient.window);
1484
 
            if (w)
1485
 
            {
1486
 
                /* use focus stealing prevention if request came
1487
 
                   from an application  */
1488
 
                if (event->xclient.data.l[0] != ClientTypeApplication ||
1489
 
                    w->priv->allowWindowFocus (0, event->xclient.data.l[1]))
1490
 
                {
1491
 
                    w->activate ();
1492
 
                }
1493
 
            }
1494
 
        }
1495
 
        else if (event->xclient.message_type == Atoms::winState)
1496
 
        {
1497
 
            w = findWindow (event->xclient.window);
1498
 
            if (w)
1499
 
            {
1500
 
                unsigned long wState, state;
1501
 
                int           i;
1502
 
 
1503
 
                wState = w->state ();
1504
 
 
1505
 
                for (i = 1; i < 3; i++)
1506
 
                {
1507
 
                    state = priv->windowStateMask (event->xclient.data.l[i]);
1508
 
                    if (state & ~CompWindowStateHiddenMask)
1509
 
                    {
1510
 
 
1511
 
#define _NET_WM_STATE_REMOVE 0
1512
 
#define _NET_WM_STATE_ADD    1
1513
 
#define _NET_WM_STATE_TOGGLE 2
1514
 
 
1515
 
                        switch (event->xclient.data.l[0]) {
1516
 
                        case _NET_WM_STATE_REMOVE:
1517
 
                            wState &= ~state;
1518
 
                            break;
1519
 
                        case _NET_WM_STATE_ADD:
1520
 
                            wState |= state;
1521
 
                            break;
1522
 
                        case _NET_WM_STATE_TOGGLE:
1523
 
                            wState ^= state;
1524
 
                            break;
1525
 
                        }
1526
 
                    }
1527
 
                }
1528
 
 
1529
 
                wState = CompWindow::constrainWindowState (wState,
1530
 
                                                           w->actions ());
1531
 
                if (w->id () == priv->activeWindow)
1532
 
                    wState &= ~CompWindowStateDemandsAttentionMask;
1533
 
 
1534
 
                if (wState != w->state ())
1535
 
                {
1536
 
                    CompStackingUpdateMode stackingUpdateMode;
1537
 
                    unsigned long          dState = wState ^ w->state ();
1538
 
 
1539
 
                    stackingUpdateMode = CompStackingUpdateModeNone;
1540
 
 
1541
 
                    /* raise the window whenever its fullscreen state,
1542
 
                       above/below state or maximization state changed */
1543
 
                    if (dState & (CompWindowStateFullscreenMask |
1544
 
                                  CompWindowStateAboveMask |
1545
 
                                  CompWindowStateBelowMask |
1546
 
                                  CompWindowStateMaximizedHorzMask |
1547
 
                                  CompWindowStateMaximizedVertMask))
1548
 
                        stackingUpdateMode = CompStackingUpdateModeNormal;
1549
 
 
1550
 
                    w->changeState (wState);
1551
 
 
1552
 
                    w->updateAttributes (stackingUpdateMode);
1553
 
                }
1554
 
            }
1555
 
        }
1556
 
        else if (event->xclient.message_type == Atoms::wmProtocols)
1557
 
        {
1558
 
            if ((unsigned long) event->xclient.data.l[0] == Atoms::wmPing)
1559
 
            {
1560
 
                w = findWindow (event->xclient.data.l[2]);
1561
 
                if (w)
1562
 
                    w->priv->handlePing (priv->lastPing);
1563
 
            }
1564
 
        }
1565
 
        else if (event->xclient.message_type == Atoms::closeWindow)
1566
 
        {
1567
 
            w = findWindow (event->xclient.window);
1568
 
            if (w)
1569
 
                w->close (event->xclient.data.l[0]);
1570
 
        }
1571
 
        else if (event->xclient.message_type == Atoms::desktopGeometry)
1572
 
        {
1573
 
            if (event->xclient.window == priv->root)
1574
 
            {
1575
 
                CompOption::Value value;
1576
 
 
1577
 
                value.set ((int) (event->xclient.data.l[0] /
1578
 
                           width ()));
1579
 
 
1580
 
                setOptionForPlugin ("core", "hsize", value);
1581
 
 
1582
 
                value.set ((int) (event->xclient.data.l[1] /
1583
 
                           height ()));
1584
 
 
1585
 
                setOptionForPlugin ("core", "vsize", value);
1586
 
            }
1587
 
        }
1588
 
        else if (event->xclient.message_type == Atoms::moveResizeWindow)
1589
 
        {
1590
 
            w = findWindow (event->xclient.window);
1591
 
            if (w)
1592
 
            {
1593
 
                unsigned int   xwcm = 0;
1594
 
                XWindowChanges xwc;
1595
 
                int            gravity;
1596
 
                int            value_mask;
1597
 
                unsigned int   source;
1598
 
 
1599
 
                gravity = (event->xclient.data.l[0] & 0xFF);            
1600
 
                value_mask = (event->xclient.data.l[0] & 0xF00) >> 8;
1601
 
                source = (event->xclient.data.l[0] & 0xF000) >> 12;
1602
 
 
1603
 
                memset (&xwc, 0, sizeof (xwc));
1604
 
 
1605
 
                if (value_mask & CWX)
1606
 
                {
1607
 
                    xwcm |= CWX;
1608
 
                    xwc.x = event->xclient.data.l[1];
1609
 
                }
1610
 
 
1611
 
                if (value_mask & CWY)
1612
 
                {
1613
 
                    xwcm |= CWY;
1614
 
                    xwc.y = event->xclient.data.l[2];
1615
 
                }
1616
 
 
1617
 
                if (value_mask & CWWidth)
1618
 
                {
1619
 
                    xwcm |= CWWidth;
1620
 
                    xwc.width = event->xclient.data.l[3];
1621
 
                }
1622
 
 
1623
 
                if (value_mask & CWHeight)
1624
 
                {
1625
 
                    xwcm |= CWHeight;
1626
 
                    xwc.height = event->xclient.data.l[4];
1627
 
                }
1628
 
 
1629
 
                w->moveResize (&xwc, xwcm, gravity, source);
1630
 
            }
1631
 
        }
1632
 
        else if (event->xclient.message_type == Atoms::restackWindow)
1633
 
        {
1634
 
            w = findWindow (event->xclient.window);
1635
 
            if (w)
1636
 
            {
1637
 
                /* TODO: other stack modes than Above and Below */
1638
 
                if (event->xclient.data.l[1])
1639
 
                {
1640
 
                    CompWindow *sibling;
1641
 
 
1642
 
                    sibling = findWindow (event->xclient.data.l[1]);
1643
 
                    if (sibling)
1644
 
                    {
1645
 
                        if (event->xclient.data.l[2] == Above)
1646
 
                            w->restackAbove (sibling);
1647
 
                        else if (event->xclient.data.l[2] == Below)
1648
 
                            w->restackBelow (sibling);
1649
 
                    }
1650
 
                }
1651
 
                else
1652
 
                {
1653
 
                    if (event->xclient.data.l[2] == Above)
1654
 
                        w->raise ();
1655
 
                    else if (event->xclient.data.l[2] == Below)
1656
 
                        w->lower ();
1657
 
                }
1658
 
            }
1659
 
        }
1660
 
        else if (event->xclient.message_type == Atoms::wmChangeState)
1661
 
        {
1662
 
            w = findWindow (event->xclient.window);
1663
 
            if (w)
1664
 
            {
1665
 
                if (event->xclient.data.l[0] == IconicState)
1666
 
                {
1667
 
                    if (w->actions () & CompWindowActionMinimizeMask)
1668
 
                        w->minimize ();
1669
 
                }
1670
 
                else if (event->xclient.data.l[0] == NormalState)
1671
 
                {
1672
 
                    w->unminimize ();
1673
 
                }
1674
 
            }
1675
 
        }
1676
 
        else if (event->xclient.message_type == Atoms::showingDesktop)
1677
 
        {
1678
 
            if (event->xclient.window == priv->root ||
1679
 
                event->xclient.window == None)
1680
 
            {
1681
 
                if (event->xclient.data.l[0])
1682
 
                    enterShowDesktopMode ();
1683
 
                else
1684
 
                    leaveShowDesktopMode (NULL);
1685
 
            }
1686
 
        }
1687
 
        else if (event->xclient.message_type == Atoms::numberOfDesktops)
1688
 
        {
1689
 
            if (event->xclient.window == priv->root)
1690
 
            {
1691
 
                CompOption::Value value;
1692
 
 
1693
 
                value.set ((int) event->xclient.data.l[0]);
1694
 
 
1695
 
                setOptionForPlugin ("core", "number_of_desktops", value);
1696
 
            }
1697
 
        }
1698
 
        else if (event->xclient.message_type == Atoms::currentDesktop)
1699
 
        {
1700
 
            if (event->xclient.window == priv->root)
1701
 
                priv->setCurrentDesktop (event->xclient.data.l[0]);
1702
 
        }
1703
 
        else if (event->xclient.message_type == Atoms::winDesktop)
1704
 
        {
1705
 
            w = findWindow (event->xclient.window);
1706
 
            if (w)
1707
 
                w->setDesktop (event->xclient.data.l[0]);
1708
 
        }
1709
 
        else if (event->xclient.message_type == Atoms::wmFullscreenMonitors)
1710
 
        {
1711
 
            w = findWindow (event->xclient.window);
1712
 
            if (w)
1713
 
            {
1714
 
                CompFullscreenMonitorSet monitors;
1715
 
 
1716
 
                monitors.top    = event->xclient.data.l[0];
1717
 
                monitors.bottom = event->xclient.data.l[1];
1718
 
                monitors.left   = event->xclient.data.l[2];
1719
 
                monitors.right  = event->xclient.data.l[3];
1720
 
 
1721
 
                w->priv->setFullscreenMonitors (&monitors);
1722
 
            }
1723
 
        }
1724
 
        break;
1725
 
    case MappingNotify:
1726
 
        modHandler->updateModifierMappings ();
1727
 
        break;
1728
 
    case MapRequest:
1729
 
        w = screen->findWindow (event->xmaprequest.window);
1730
 
 
1731
 
        if (w)
1732
 
        {
1733
 
            XWindowAttributes attr;
1734
 
            bool              doMapProcessing = true;
1735
 
 
1736
 
            /* We should check the override_redirect flag here, because the
1737
 
               client might have changed it while being unmapped. */
1738
 
            if (XGetWindowAttributes (priv->dpy, w->id (), &attr))
1739
 
                w->priv->setOverrideRedirect (attr.override_redirect != 0);
1740
 
 
1741
 
            if (w->state () & CompWindowStateHiddenMask)
1742
 
                if (!w->minimized () && !w->inShowDesktopMode ())
1743
 
                    doMapProcessing = false;
1744
 
 
1745
 
            if (doMapProcessing)
1746
 
                w->priv->processMap ();
1747
 
 
1748
 
            w->priv->managed = true;
1749
 
 
1750
 
            setWindowProp (w->id (), Atoms::winDesktop, w->desktop ());
1751
 
        }
1752
 
        else
1753
 
        {
1754
 
            XMapWindow (priv->dpy, event->xmaprequest.window);
1755
 
        }
1756
 
        break;
1757
 
    case ConfigureRequest:
1758
 
        w = findWindow (event->xconfigurerequest.window);
1759
 
        if (w && w->managed ())
1760
 
        {
1761
 
            XWindowChanges xwc;
1762
 
 
1763
 
            memset (&xwc, 0, sizeof (xwc));
1764
 
 
1765
 
            xwc.x            = event->xconfigurerequest.x;
1766
 
            xwc.y            = event->xconfigurerequest.y;
1767
 
            xwc.width        = event->xconfigurerequest.width;
1768
 
            xwc.height       = event->xconfigurerequest.height;
1769
 
            xwc.border_width = event->xconfigurerequest.border_width;
1770
 
 
1771
 
            w->moveResize (&xwc, event->xconfigurerequest.value_mask,
1772
 
                           0, ClientTypeUnknown);
1773
 
 
1774
 
            if (event->xconfigurerequest.value_mask & CWStackMode)
1775
 
            {
1776
 
                Window     above    = None;
1777
 
                CompWindow *sibling = NULL;
1778
 
 
1779
 
                if (event->xconfigurerequest.value_mask & CWSibling)
1780
 
                {
1781
 
                    above   = event->xconfigurerequest.above;
1782
 
                    sibling = findTopLevelWindow (above);
1783
 
                }
1784
 
 
1785
 
                switch (event->xconfigurerequest.detail) {
1786
 
                case Above:
1787
 
                    if (w->priv->allowWindowFocus (NO_FOCUS_MASK, 0))
1788
 
                    {
1789
 
                        if (above)
1790
 
                        {
1791
 
                            if (sibling)
1792
 
                                w->restackAbove (sibling);
1793
 
                        }
1794
 
                        else
1795
 
                            w->raise ();
1796
 
                    }
1797
 
                    break;
1798
 
                case Below:
1799
 
                    if (above)
1800
 
                    {
1801
 
                        if (sibling)
1802
 
                            w->restackBelow (sibling);
1803
 
                    }
1804
 
                    else
1805
 
                        w->lower ();
1806
 
                    break;
1807
 
                default:
1808
 
                    /* no handling of the TopIf, BottomIf, Opposite cases -
1809
 
                       there will hardly be any client using that */
1810
 
                    break;
1811
 
                }
1812
 
            }
1813
 
        }
1814
 
        else
1815
 
        {
1816
 
            XWindowChanges xwc;
1817
 
            unsigned int   xwcm;
1818
 
 
1819
 
            xwcm = event->xconfigurerequest.value_mask &
1820
 
                (CWX | CWY | CWWidth | CWHeight | CWBorderWidth);
1821
 
 
1822
 
            xwc.x            = event->xconfigurerequest.x;
1823
 
            xwc.y            = event->xconfigurerequest.y;
1824
 
            xwc.width        = event->xconfigurerequest.width;
1825
 
            xwc.height       = event->xconfigurerequest.height;
1826
 
            xwc.border_width = event->xconfigurerequest.border_width;
1827
 
 
1828
 
            if (w)
1829
 
            {
1830
 
                /* Any window that receives a ConfigureRequest
1831
 
                 * is not override redirect, and may have changed
1832
 
                 * to being not override redirect */
1833
 
                w->priv->setOverrideRedirect (false);
1834
 
                w->configureXWindow (xwcm, &xwc);
1835
 
            }
1836
 
            else
1837
 
                XConfigureWindow (priv->dpy, event->xconfigurerequest.window,
1838
 
                                  xwcm, &xwc);
1839
 
        }
1840
 
        break;
1841
 
    case CirculateRequest:
1842
 
        break;
1843
 
    case FocusIn:
1844
 
    {
1845
 
        if (!XGetWindowAttributes (priv->dpy, event->xfocus.window, &wa))
1846
 
            priv->setDefaultWindowAttributes (&wa);
1847
 
 
1848
 
        /* If the call to XGetWindowAttributes failed it means
1849
 
         * the window was destroyed, so track the focus change
1850
 
         * anyways since we need to increment activeNum
1851
 
         * and the passive button grabs and then we will
1852
 
         * get the DestroyNotify later and change the focus
1853
 
         * there
1854
 
         */
1855
 
 
1856
 
        if (wa.root == priv->root)
1857
 
        {
1858
 
            if (event->xfocus.mode == NotifyGrab)
1859
 
                priv->grabbed = true;
1860
 
            else if (event->xfocus.mode == NotifyUngrab)
1861
 
                priv->grabbed = false;
1862
 
            else
1863
 
            {
1864
 
                CompWindowList dockWindows;
1865
 
                XWindowChanges xwc;
1866
 
                unsigned int   mask;
1867
 
 
1868
 
                w = findTopLevelWindow (event->xfocus.window);
1869
 
                if (w && w->managed ())
1870
 
                {
1871
 
                    unsigned int state = w->state ();
1872
 
 
1873
 
                    if (priv->nextActiveWindow == event->xfocus.window)
1874
 
                        priv->nextActiveWindow = None;
1875
 
 
1876
 
                    if (w->id () != priv->activeWindow)
1877
 
                    {
1878
 
                        CompWindow     *active = screen->findWindow (priv->activeWindow);
1879
 
 
1880
 
                        priv->activeWindow = w->id ();
1881
 
                        w->priv->activeNum = priv->activeNum++;
1882
 
 
1883
 
                        if (active)
1884
 
                        {
1885
 
                            CompWindowList windowsLostFocus;
1886
 
                            /* If this window lost focus and was above a fullscreen window
1887
 
                             * and is no longer capable of being focused (eg, it is
1888
 
                             * not visible on this viewport) then we need to check if
1889
 
                             * any other windows below it are also now no longer capable
1890
 
                             * of being focused and restack them in the highest position
1891
 
                             * below docks that they are allowed to take */
1892
 
                            if (!active->focus ())
1893
 
                            {
1894
 
                                windowsLostFocus.push_back (active);
1895
 
                                for (CompWindow *fsw = active->prev; fsw; fsw = fsw->prev)
1896
 
                                {
1897
 
                                    if (!fsw->focus () &&
1898
 
                                        fsw->managed () &&
1899
 
                                        !(fsw->type () & (CompWindowTypeDockMask |
1900
 
                                                          CompWindowTypeFullscreenMask)) &&
1901
 
                                        !fsw->overrideRedirect ())
1902
 
                                        windowsLostFocus.push_back (fsw);
1903
 
 
1904
 
                                    if (fsw->type () & CompWindowTypeFullscreenMask)
1905
 
                                    {
1906
 
                                        /* This will be the window that we must lower relative to */
1907
 
                                        CompWindow *sibling = PrivateWindow::findValidStackSiblingBelow (active, fsw);
1908
 
 
1909
 
                                        if (sibling)
1910
 
                                        {
1911
 
                                            for (CompWindowList::reverse_iterator rit = windowsLostFocus.rbegin ();
1912
 
                                                 rit != windowsLostFocus.rend (); rit++)
1913
 
                                            {
1914
 
                                                (*rit)->restackAbove (sibling);
1915
 
                                            }
1916
 
                                        }
1917
 
 
1918
 
                                        break;
1919
 
                                    }
1920
 
                                }
1921
 
                            }
1922
 
 
1923
 
                            active->changeState (active->focused () ?
1924
 
                                                 active->state () | CompWindowStateFocusedMask :
1925
 
                                                 active->state () & ~CompWindowStateFocusedMask);
1926
 
 
1927
 
                            active->priv->updatePassiveButtonGrabs ();
1928
 
                        }
1929
 
 
1930
 
                        if (w->focused ())
1931
 
                            state |= w->state () | CompWindowStateFocusedMask;
1932
 
                        else
1933
 
                            state &= w->state () & ~CompWindowStateFocusedMask;
1934
 
 
1935
 
                        w->priv->updatePassiveButtonGrabs ();
1936
 
 
1937
 
                        priv->addToCurrentActiveWindowHistory (w->id ());
1938
 
 
1939
 
                        XChangeProperty (priv->dpy , priv->root,
1940
 
                                         Atoms::winActive,
1941
 
                                         XA_WINDOW, 32, PropModeReplace,
1942
 
                                         (unsigned char *) &priv->activeWindow, 1);
1943
 
 
1944
 
                        w->windowNotify (CompWindowNotifyFocusChange);
1945
 
                    }
1946
 
 
1947
 
                    state &= ~CompWindowStateDemandsAttentionMask;
1948
 
                    w->changeState (state);
1949
 
                }
1950
 
                else if (event->xfocus.window == priv->root)
1951
 
                {
1952
 
                    /* Don't ever let the focus go to the root
1953
 
                     * window except in grab cases
1954
 
                     *
1955
 
                     * FIXME: There might be a case where we have to
1956
 
                     * handle root windows of other screens here, but
1957
 
                     * the other window managers should handle that
1958
 
                     */
1959
 
 
1960
 
                    if (event->xfocus.detail == NotifyDetailNone ||
1961
 
                        (event->xfocus.mode == NotifyNormal &&
1962
 
                         event->xfocus.detail == NotifyInferior))
1963
 
                    {
1964
 
                        priv->activeWindow = None;
1965
 
 
1966
 
                        if (event->xfocus.detail == NotifyDetailNone ||
1967
 
                            (event->xfocus.mode == NotifyNormal &&
1968
 
                             event->xfocus.detail == NotifyInferior))
1969
 
                        {
1970
 
                            screen->focusDefaultWindow ();
1971
 
                        }
1972
 
                    }
1973
 
                }
1974
 
 
1975
 
                /* Ensure that docks are stacked in the right place
1976
 
                 *
1977
 
                 * When a normal window gets the focus and is above a
1978
 
                 * fullscreen window, restack the docks to be above
1979
 
                 * the highest level mapped and visible normal window,
1980
 
                 * otherwise put them above the highest fullscreen window
1981
 
                 */
1982
 
                if (w)
1983
 
                {
1984
 
                    if (PrivateWindow::stackDocks (w, dockWindows, &xwc, &mask))
1985
 
                    {
1986
 
                        Window sibling = xwc.sibling;
1987
 
                        xwc.stack_mode = Above;
1988
 
 
1989
 
                        /* Then update the dock windows */
1990
 
                        foreach (CompWindow *dw, dockWindows)
1991
 
                        {
1992
 
                            xwc.sibling = sibling;
1993
 
                            dw->configureXWindow (mask, &xwc);
1994
 
                        }
1995
 
                    }
1996
 
                }
1997
 
 
1998
 
            }
1999
 
        }
2000
 
        else
2001
 
        {
2002
 
            CompWindow *w;
2003
 
 
2004
 
            w = screen->findWindow (priv->activeWindow);
2005
 
 
2006
 
            priv->nextActiveWindow = None;
2007
 
            priv->activeWindow = None;
2008
 
 
2009
 
            if (w)
2010
 
                w->priv->updatePassiveButtonGrabs ();
2011
 
        }
2012
 
    }
2013
 
    break;
2014
 
    case FocusOut:
2015
 
        if (event->xfocus.mode == NotifyUngrab)
2016
 
            priv->grabbed = false;
2017
 
        break;
2018
 
    case EnterNotify:
2019
 
        if (event->xcrossing.root == priv->root)
2020
 
            w = findTopLevelWindow (event->xcrossing.window);
2021
 
        else
2022
 
            w = NULL;
2023
 
 
2024
 
        if (w && w->id () != priv->below)
2025
 
        {
2026
 
            priv->below = w->id ();
2027
 
 
2028
 
            if (!priv->optionGetClickToFocus () &&
2029
 
                priv->grabs.empty ()                                 &&
2030
 
                event->xcrossing.mode   != NotifyGrab                &&
2031
 
                event->xcrossing.detail != NotifyInferior)
2032
 
            {
2033
 
                bool raise;
2034
 
                int  delay;
2035
 
 
2036
 
                raise = priv->optionGetAutoraise ();
2037
 
                delay = priv->optionGetAutoraiseDelay ();
2038
 
 
2039
 
                if (priv->autoRaiseTimer.active () &&
2040
 
                    priv->autoRaiseWindow != w->id ())
2041
 
                {
2042
 
                    priv->autoRaiseTimer.stop ();
2043
 
                }
2044
 
 
2045
 
                if (w->type () & ~(CompWindowTypeDockMask |
2046
 
                                   CompWindowTypeDesktopMask))
2047
 
                {
2048
 
                    w->moveInputFocusTo ();
2049
 
 
2050
 
                    if (raise)
2051
 
                    {
2052
 
                        if (delay > 0)
2053
 
                        {
2054
 
                            priv->autoRaiseWindow = w->id ();
2055
 
                            priv->autoRaiseTimer.start (
2056
 
                                boost::bind (autoRaiseTimeout, this),
2057
 
                                delay, (unsigned int) ((float) delay * 1.2));
2058
 
                        }
2059
 
                        else
2060
 
                        {
2061
 
                            CompStackingUpdateMode mode =
2062
 
                                CompStackingUpdateModeNormal;
2063
 
 
2064
 
                            w->updateAttributes (mode);
2065
 
                        }
2066
 
                    }
2067
 
                }
2068
 
            }
2069
 
        }
2070
 
        break;
2071
 
    case LeaveNotify:
2072
 
        if (event->xcrossing.detail != NotifyInferior)
2073
 
        {
2074
 
            if (event->xcrossing.window == priv->below)
2075
 
                priv->below = None;
2076
 
        }
2077
 
        break;
2078
 
    default:
2079
 
        if (priv->shapeExtension &&
2080
 
                 event->type == priv->shapeEvent + ShapeNotify)
2081
 
        {
2082
 
            w = findWindow (((XShapeEvent *) event)->window);
2083
 
            if (w)
2084
 
            {
2085
 
                if (w->mapNum ())
2086
 
                    w->priv->updateRegion ();
2087
 
            }
2088
 
        }
2089
 
        else if (event->type == priv->syncEvent + XSyncAlarmNotify)
2090
 
        {
2091
 
            XSyncAlarmNotifyEvent *sa;
2092
 
 
2093
 
            sa = (XSyncAlarmNotifyEvent *) event;
2094
 
 
2095
 
 
2096
 
            foreach (w, priv->windows)
2097
 
            {
2098
 
                if (w->priv->syncAlarm == sa->alarm)
2099
 
                {
2100
 
                    w->priv->handleSyncAlarm ();
2101
 
                    break;
2102
 
                }
2103
 
            }
2104
 
        }
2105
 
        break;
2106
 
    }
2107
 
}