1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
|
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the QtOpenVG module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "qtestlitewindow.h"
#include "qtestliteintegration.h"
#include "qtestlitescreen.h"
#include <QtGui/QWindowSystemInterface>
#include <QSocketNotifier>
#include <QApplication>
#include <QDebug>
#include <QtGui/private/qwindowsurface_p.h>
#include <QtGui/private/qapplication_p.h>
#ifndef QT_NO_OPENGL
#include "qglxintegration.h"
#endif
//#define MYX11_DEBUG
QT_BEGIN_NAMESPACE
QTestLiteWindow::QTestLiteWindow(QWidget *window)
: QPlatformWindow(window)
, mGLContext(0)
, mScreen(QTestLiteScreen::testLiteScreenForWidget(window))
{
int x = window->x();
int y = window->y();
int w = window->width();
int h = window->height();
if(window->platformWindowFormat().windowApi() == QPlatformWindowFormat::OpenGL
&& QApplicationPrivate::platformIntegration()->hasOpenGL() ) {
#ifndef QT_NO_OPENGL
XVisualInfo *visualInfo = QGLXContext::findVisualInfo(mScreen,window->platformWindowFormat());
Colormap cmap = XCreateColormap(mScreen->display(),mScreen->rootWindow(),visualInfo->visual,AllocNone);
XSetWindowAttributes a;
a.colormap = cmap;
x_window = XCreateWindow(mScreen->display(), mScreen->rootWindow(),x, y, w, h,
0, visualInfo->depth, InputOutput, visualInfo->visual,
CWColormap, &a);
#endif //QT_NO_OPENGL
} else {
x_window = XCreateSimpleWindow(mScreen->display(), mScreen->rootWindow(),
x, y, w, h, 0 /*border_width*/,
mScreen->blackPixel(), mScreen->whitePixel());
}
#ifdef MYX11_DEBUG
qDebug() << "QTestLiteWindow::QTestLiteWindow creating" << hex << x_window << window;
#endif
// }
// width = -1;
// height = -1;
// xpos = -1;
// ypos = -1;
XSetWindowBackgroundPixmap(mScreen->display(), x_window, XNone);
XSelectInput(mScreen->display(), x_window, ExposureMask | KeyPressMask | KeyReleaseMask |
EnterWindowMask | LeaveWindowMask | FocusChangeMask |
PointerMotionMask | ButtonPressMask | ButtonReleaseMask | ButtonMotionMask |
StructureNotifyMask);
gc = createGC();
Atom wmDeleteWindowAtom = mScreen->wmDeleteWindowAtom();
XChangeProperty (mScreen->display(), x_window,
mScreen->wmProtocolsAtom(),
XA_ATOM, 32, PropModeAppend,
(unsigned char *) &wmDeleteWindowAtom, 1);
mScreen->setWmDeleteWindowAtom(wmDeleteWindowAtom);
}
QTestLiteWindow::~QTestLiteWindow()
{
#ifdef MYX11_DEBUG
qDebug() << "~QTestLiteWindow" << hex << x_window;
#endif
delete mGLContext;
XFreeGC(mScreen->display(), gc);
XDestroyWindow(mScreen->display(), x_window);
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Mouse event stuff
static Qt::MouseButtons translateMouseButtons(int s)
{
Qt::MouseButtons ret = 0;
if (s & Button1Mask)
ret |= Qt::LeftButton;
if (s & Button2Mask)
ret |= Qt::MidButton;
if (s & Button3Mask)
ret |= Qt::RightButton;
return ret;
}
static Qt::KeyboardModifiers translateModifiers(int s)
{
const uchar qt_alt_mask = Mod1Mask;
const uchar qt_meta_mask = Mod4Mask;
Qt::KeyboardModifiers ret = 0;
if (s & ShiftMask)
ret |= Qt::ShiftModifier;
if (s & ControlMask)
ret |= Qt::ControlModifier;
if (s & qt_alt_mask)
ret |= Qt::AltModifier;
if (s & qt_meta_mask)
ret |= Qt::MetaModifier;
#if 0
if (s & qt_mode_switch_mask)
ret |= Qt::GroupSwitchModifier;
#endif
return ret;
}
void QTestLiteWindow::handleMouseEvent(QEvent::Type type, XButtonEvent *e)
{
static QPoint mousePoint;
Qt::MouseButton button = Qt::NoButton;
Qt::MouseButtons buttons = translateMouseButtons(e->state);
Qt::KeyboardModifiers modifiers = translateModifiers(e->state);
if (type != QEvent::MouseMove) {
switch (e->button) {
case Button1: button = Qt::LeftButton; break;
case Button2: button = Qt::MidButton; break;
case Button3: button = Qt::RightButton; break;
case Button4:
case Button5:
case 6:
case 7: {
//mouse wheel
if (type == QEvent::MouseButtonPress) {
//logic borrowed from qapplication_x11.cpp
int delta = 120 * ((e->button == Button4 || e->button == 6) ? 1 : -1);
bool hor = (((e->button == Button4 || e->button == Button5)
&& (modifiers & Qt::AltModifier))
|| (e->button == 6 || e->button == 7));
QWindowSystemInterface::handleWheelEvent(widget(), e->time,
QPoint(e->x, e->y),
QPoint(e->x_root, e->y_root),
delta, hor ? Qt::Horizontal : Qt::Vertical);
}
return;
}
default: break;
}
}
buttons ^= button; // X event uses state *before*, Qt uses state *after*
QWindowSystemInterface::handleMouseEvent(widget(), e->time, QPoint(e->x, e->y),
QPoint(e->x_root, e->y_root),
buttons);
mousePoint = QPoint(e->x_root, e->y_root);
}
void QTestLiteWindow::handleCloseEvent()
{
QWindowSystemInterface::handleCloseEvent(widget());
}
void QTestLiteWindow::handleEnterEvent()
{
QWindowSystemInterface::handleEnterEvent(widget());
}
void QTestLiteWindow::handleLeaveEvent()
{
QWindowSystemInterface::handleLeaveEvent(widget());
}
void QTestLiteWindow::handleFocusInEvent()
{
QWindowSystemInterface::handleWindowActivated(widget());
}
void QTestLiteWindow::handleFocusOutEvent()
{
QWindowSystemInterface::handleWindowActivated(0);
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Key event stuff -- not pretty either
//
// What we want to do is to port Robert's keytable code properly
// keyboard mapping table
static const unsigned int keyTbl[] = {
// misc keys
XK_Escape, Qt::Key_Escape,
XK_Tab, Qt::Key_Tab,
XK_ISO_Left_Tab, Qt::Key_Backtab,
XK_BackSpace, Qt::Key_Backspace,
XK_Return, Qt::Key_Return,
XK_Insert, Qt::Key_Insert,
XK_Delete, Qt::Key_Delete,
XK_Clear, Qt::Key_Delete,
XK_Pause, Qt::Key_Pause,
XK_Print, Qt::Key_Print,
0x1005FF60, Qt::Key_SysReq, // hardcoded Sun SysReq
0x1007ff00, Qt::Key_SysReq, // hardcoded X386 SysReq
// cursor movement
XK_Home, Qt::Key_Home,
XK_End, Qt::Key_End,
XK_Left, Qt::Key_Left,
XK_Up, Qt::Key_Up,
XK_Right, Qt::Key_Right,
XK_Down, Qt::Key_Down,
XK_Prior, Qt::Key_PageUp,
XK_Next, Qt::Key_PageDown,
// modifiers
XK_Shift_L, Qt::Key_Shift,
XK_Shift_R, Qt::Key_Shift,
XK_Shift_Lock, Qt::Key_Shift,
XK_Control_L, Qt::Key_Control,
XK_Control_R, Qt::Key_Control,
XK_Meta_L, Qt::Key_Meta,
XK_Meta_R, Qt::Key_Meta,
XK_Alt_L, Qt::Key_Alt,
XK_Alt_R, Qt::Key_Alt,
XK_Caps_Lock, Qt::Key_CapsLock,
XK_Num_Lock, Qt::Key_NumLock,
XK_Scroll_Lock, Qt::Key_ScrollLock,
XK_Super_L, Qt::Key_Super_L,
XK_Super_R, Qt::Key_Super_R,
XK_Menu, Qt::Key_Menu,
XK_Hyper_L, Qt::Key_Hyper_L,
XK_Hyper_R, Qt::Key_Hyper_R,
XK_Help, Qt::Key_Help,
0x1000FF74, Qt::Key_Backtab, // hardcoded HP backtab
0x1005FF10, Qt::Key_F11, // hardcoded Sun F36 (labeled F11)
0x1005FF11, Qt::Key_F12, // hardcoded Sun F37 (labeled F12)
// numeric and function keypad keys
XK_KP_Space, Qt::Key_Space,
XK_KP_Tab, Qt::Key_Tab,
XK_KP_Enter, Qt::Key_Enter,
//XK_KP_F1, Qt::Key_F1,
//XK_KP_F2, Qt::Key_F2,
//XK_KP_F3, Qt::Key_F3,
//XK_KP_F4, Qt::Key_F4,
XK_KP_Home, Qt::Key_Home,
XK_KP_Left, Qt::Key_Left,
XK_KP_Up, Qt::Key_Up,
XK_KP_Right, Qt::Key_Right,
XK_KP_Down, Qt::Key_Down,
XK_KP_Prior, Qt::Key_PageUp,
XK_KP_Next, Qt::Key_PageDown,
XK_KP_End, Qt::Key_End,
XK_KP_Begin, Qt::Key_Clear,
XK_KP_Insert, Qt::Key_Insert,
XK_KP_Delete, Qt::Key_Delete,
XK_KP_Equal, Qt::Key_Equal,
XK_KP_Multiply, Qt::Key_Asterisk,
XK_KP_Add, Qt::Key_Plus,
XK_KP_Separator, Qt::Key_Comma,
XK_KP_Subtract, Qt::Key_Minus,
XK_KP_Decimal, Qt::Key_Period,
XK_KP_Divide, Qt::Key_Slash,
// International input method support keys
// International & multi-key character composition
XK_ISO_Level3_Shift, Qt::Key_AltGr,
XK_Multi_key, Qt::Key_Multi_key,
XK_Codeinput, Qt::Key_Codeinput,
XK_SingleCandidate, Qt::Key_SingleCandidate,
XK_MultipleCandidate, Qt::Key_MultipleCandidate,
XK_PreviousCandidate, Qt::Key_PreviousCandidate,
// Misc Functions
XK_Mode_switch, Qt::Key_Mode_switch,
XK_script_switch, Qt::Key_Mode_switch,
// Japanese keyboard support
XK_Kanji, Qt::Key_Kanji,
XK_Muhenkan, Qt::Key_Muhenkan,
//XK_Henkan_Mode, Qt::Key_Henkan_Mode,
XK_Henkan_Mode, Qt::Key_Henkan,
XK_Henkan, Qt::Key_Henkan,
XK_Romaji, Qt::Key_Romaji,
XK_Hiragana, Qt::Key_Hiragana,
XK_Katakana, Qt::Key_Katakana,
XK_Hiragana_Katakana, Qt::Key_Hiragana_Katakana,
XK_Zenkaku, Qt::Key_Zenkaku,
XK_Hankaku, Qt::Key_Hankaku,
XK_Zenkaku_Hankaku, Qt::Key_Zenkaku_Hankaku,
XK_Touroku, Qt::Key_Touroku,
XK_Massyo, Qt::Key_Massyo,
XK_Kana_Lock, Qt::Key_Kana_Lock,
XK_Kana_Shift, Qt::Key_Kana_Shift,
XK_Eisu_Shift, Qt::Key_Eisu_Shift,
XK_Eisu_toggle, Qt::Key_Eisu_toggle,
//XK_Kanji_Bangou, Qt::Key_Kanji_Bangou,
//XK_Zen_Koho, Qt::Key_Zen_Koho,
//XK_Mae_Koho, Qt::Key_Mae_Koho,
XK_Kanji_Bangou, Qt::Key_Codeinput,
XK_Zen_Koho, Qt::Key_MultipleCandidate,
XK_Mae_Koho, Qt::Key_PreviousCandidate,
#ifdef XK_KOREAN
// Korean keyboard support
XK_Hangul, Qt::Key_Hangul,
XK_Hangul_Start, Qt::Key_Hangul_Start,
XK_Hangul_End, Qt::Key_Hangul_End,
XK_Hangul_Hanja, Qt::Key_Hangul_Hanja,
XK_Hangul_Jamo, Qt::Key_Hangul_Jamo,
XK_Hangul_Romaja, Qt::Key_Hangul_Romaja,
//XK_Hangul_Codeinput, Qt::Key_Hangul_Codeinput,
XK_Hangul_Codeinput, Qt::Key_Codeinput,
XK_Hangul_Jeonja, Qt::Key_Hangul_Jeonja,
XK_Hangul_Banja, Qt::Key_Hangul_Banja,
XK_Hangul_PreHanja, Qt::Key_Hangul_PreHanja,
XK_Hangul_PostHanja, Qt::Key_Hangul_PostHanja,
//XK_Hangul_SingleCandidate,Qt::Key_Hangul_SingleCandidate,
//XK_Hangul_MultipleCandidate,Qt::Key_Hangul_MultipleCandidate,
//XK_Hangul_PreviousCandidate,Qt::Key_Hangul_PreviousCandidate,
XK_Hangul_SingleCandidate, Qt::Key_SingleCandidate,
XK_Hangul_MultipleCandidate,Qt::Key_MultipleCandidate,
XK_Hangul_PreviousCandidate,Qt::Key_PreviousCandidate,
XK_Hangul_Special, Qt::Key_Hangul_Special,
//XK_Hangul_switch, Qt::Key_Hangul_switch,
XK_Hangul_switch, Qt::Key_Mode_switch,
#endif // XK_KOREAN
// dead keys
XK_dead_grave, Qt::Key_Dead_Grave,
XK_dead_acute, Qt::Key_Dead_Acute,
XK_dead_circumflex, Qt::Key_Dead_Circumflex,
XK_dead_tilde, Qt::Key_Dead_Tilde,
XK_dead_macron, Qt::Key_Dead_Macron,
XK_dead_breve, Qt::Key_Dead_Breve,
XK_dead_abovedot, Qt::Key_Dead_Abovedot,
XK_dead_diaeresis, Qt::Key_Dead_Diaeresis,
XK_dead_abovering, Qt::Key_Dead_Abovering,
XK_dead_doubleacute, Qt::Key_Dead_Doubleacute,
XK_dead_caron, Qt::Key_Dead_Caron,
XK_dead_cedilla, Qt::Key_Dead_Cedilla,
XK_dead_ogonek, Qt::Key_Dead_Ogonek,
XK_dead_iota, Qt::Key_Dead_Iota,
XK_dead_voiced_sound, Qt::Key_Dead_Voiced_Sound,
XK_dead_semivoiced_sound, Qt::Key_Dead_Semivoiced_Sound,
XK_dead_belowdot, Qt::Key_Dead_Belowdot,
XK_dead_hook, Qt::Key_Dead_Hook,
XK_dead_horn, Qt::Key_Dead_Horn,
#if 0
// Special multimedia keys
// currently only tested with MS internet keyboard
// browsing keys
XF86XK_Back, Qt::Key_Back,
XF86XK_Forward, Qt::Key_Forward,
XF86XK_Stop, Qt::Key_Stop,
XF86XK_Refresh, Qt::Key_Refresh,
XF86XK_Favorites, Qt::Key_Favorites,
XF86XK_AudioMedia, Qt::Key_LaunchMedia,
XF86XK_OpenURL, Qt::Key_OpenUrl,
XF86XK_HomePage, Qt::Key_HomePage,
XF86XK_Search, Qt::Key_Search,
// media keys
XF86XK_AudioLowerVolume, Qt::Key_VolumeDown,
XF86XK_AudioMute, Qt::Key_VolumeMute,
XF86XK_AudioRaiseVolume, Qt::Key_VolumeUp,
XF86XK_AudioPlay, Qt::Key_MediaPlay,
XF86XK_AudioStop, Qt::Key_MediaStop,
XF86XK_AudioPrev, Qt::Key_MediaPrevious,
XF86XK_AudioNext, Qt::Key_MediaNext,
XF86XK_AudioRecord, Qt::Key_MediaRecord,
// launch keys
XF86XK_Mail, Qt::Key_LaunchMail,
XF86XK_MyComputer, Qt::Key_Launch0,
XF86XK_Calculator, Qt::Key_Launch1,
XF86XK_Standby, Qt::Key_Standby,
XF86XK_Launch0, Qt::Key_Launch2,
XF86XK_Launch1, Qt::Key_Launch3,
XF86XK_Launch2, Qt::Key_Launch4,
XF86XK_Launch3, Qt::Key_Launch5,
XF86XK_Launch4, Qt::Key_Launch6,
XF86XK_Launch5, Qt::Key_Launch7,
XF86XK_Launch6, Qt::Key_Launch8,
XF86XK_Launch7, Qt::Key_Launch9,
XF86XK_Launch8, Qt::Key_LaunchA,
XF86XK_Launch9, Qt::Key_LaunchB,
XF86XK_LaunchA, Qt::Key_LaunchC,
XF86XK_LaunchB, Qt::Key_LaunchD,
XF86XK_LaunchC, Qt::Key_LaunchE,
XF86XK_LaunchD, Qt::Key_LaunchF,
#endif
#if 0
// Qtopia keys
QTOPIAXK_Select, Qt::Key_Select,
QTOPIAXK_Yes, Qt::Key_Yes,
QTOPIAXK_No, Qt::Key_No,
QTOPIAXK_Cancel, Qt::Key_Cancel,
QTOPIAXK_Printer, Qt::Key_Printer,
QTOPIAXK_Execute, Qt::Key_Execute,
QTOPIAXK_Sleep, Qt::Key_Sleep,
QTOPIAXK_Play, Qt::Key_Play,
QTOPIAXK_Zoom, Qt::Key_Zoom,
QTOPIAXK_Context1, Qt::Key_Context1,
QTOPIAXK_Context2, Qt::Key_Context2,
QTOPIAXK_Context3, Qt::Key_Context3,
QTOPIAXK_Context4, Qt::Key_Context4,
QTOPIAXK_Call, Qt::Key_Call,
QTOPIAXK_Hangup, Qt::Key_Hangup,
QTOPIAXK_Flip, Qt::Key_Flip,
#endif
0, 0
};
static int lookupCode(unsigned int xkeycode)
{
if (xkeycode >= XK_F1 && xkeycode <= XK_F35)
return Qt::Key_F1 + (int(xkeycode) - XK_F1);
const unsigned int *p = keyTbl;
while (*p) {
if (*p == xkeycode)
return *++p;
p += 2;
}
return 0;
}
static Qt::KeyboardModifiers modifierFromKeyCode(int qtcode)
{
switch (qtcode) {
case Qt::Key_Control:
return Qt::ControlModifier;
case Qt::Key_Alt:
return Qt::AltModifier;
case Qt::Key_Shift:
return Qt::ShiftModifier;
case Qt::Key_Meta:
return Qt::MetaModifier;
default:
return Qt::NoModifier;
}
}
void QTestLiteWindow::handleKeyEvent(QEvent::Type type, void *ev)
{
XKeyEvent *e = static_cast<XKeyEvent*>(ev);
KeySym keySym;
QByteArray chars;
chars.resize(513);
int count = XLookupString(e, chars.data(), chars.size(), &keySym, 0);
Q_UNUSED(count);
// qDebug() << "QTLWS::handleKeyEvent" << count << hex << "XKeysym:" << keySym;
// if (count)
// qDebug() << hex << int(chars[0]) << "String:" << chars;
Qt::KeyboardModifiers modifiers = translateModifiers(e->state);
int qtcode = lookupCode(keySym);
// qDebug() << "lookup: " << hex << keySym << qtcode << "mod" << modifiers;
//X11 specifies state *before*, Qt expects state *after* the event
modifiers ^= modifierFromKeyCode(qtcode);
if (qtcode) {
QWindowSystemInterface::handleKeyEvent(widget(), e->time, type, qtcode, modifiers);
} else if (chars[0]) {
int qtcode = chars.toUpper()[0]; //Not exactly right...
if (modifiers & Qt::ControlModifier && qtcode < ' ')
qtcode = chars[0] + '@';
QWindowSystemInterface::handleKeyEvent(0, e->time, type, qtcode, modifiers, QString::fromLatin1(chars));
} else {
qWarning() << "unknown X keycode" << hex << e->keycode << keySym;
}
}
void QTestLiteWindow::setGeometry(const QRect &rect)
{
XMoveResizeWindow(mScreen->display(), x_window, rect.x(), rect.y(), rect.width(), rect.height());
QPlatformWindow::setGeometry(rect);
}
Qt::WindowFlags QTestLiteWindow::windowFlags() const
{
return window_flags;
}
WId QTestLiteWindow::winId() const
{
return x_window;
}
void QTestLiteWindow::setParent(const QPlatformWindow *window)
{
QPoint topLeft = geometry().topLeft();
XReparentWindow(mScreen->display(),x_window,window->winId(),topLeft.x(),topLeft.y());
}
void QTestLiteWindow::raise()
{
XRaiseWindow(mScreen->display(), x_window);
}
void QTestLiteWindow::lower()
{
XLowerWindow(mScreen->display(), x_window);
}
void QTestLiteWindow::setWindowTitle(const QString &title)
{
QByteArray ba = title.toLatin1(); //We're not making a general solution here...
XTextProperty windowName;
windowName.value = (unsigned char *)ba.constData();
windowName.encoding = XA_STRING;
windowName.format = 8;
windowName.nitems = ba.length();
XSetWMName(mScreen->display(), x_window, &windowName);
}
GC QTestLiteWindow::createGC()
{
GC gc;
gc = XCreateGC(mScreen->display(), x_window, 0, 0);
if (gc < 0) {
qWarning("QTestLiteWindow::createGC() could not create GC");
}
return gc;
}
void QTestLiteWindow::paintEvent()
{
#ifdef MYX11_DEBUG
// qDebug() << "QTestLiteWindow::paintEvent" << shm_img.size() << painted;
#endif
if (QWindowSurface *surface = widget()->windowSurface())
surface->flush(widget(), widget()->geometry(), QPoint());
}
void QTestLiteWindow::requestActivateWindow()
{
XSetInputFocus(mScreen->display(), x_window, XRevertToParent, CurrentTime);
}
void QTestLiteWindow::resizeEvent(XConfigureEvent *e)
{
int xpos = geometry().x();
int ypos = geometry().y();
if ((e->width != geometry().width() || e->height != geometry().height()) && e->x == 0 && e->y == 0) {
//qDebug() << "resize with bogus pos" << e->x << e->y << e->width << e->height << "window"<< hex << window;
} else {
//qDebug() << "geometry change" << e->x << e->y << e->width << e->height << "window"<< hex << window;
xpos = e->x;
ypos = e->y;
}
#ifdef MYX11_DEBUG
qDebug() << hex << x_window << dec << "ConfigureNotify" << e->x << e->y << e->width << e->height << "geometry" << xpos << ypos << width << height;
#endif
QRect newRect(xpos, ypos, e->width, e->height);
QWindowSystemInterface::handleGeometryChange(widget(), newRect);
}
void QTestLiteWindow::mousePressEvent(XButtonEvent *e)
{
static long prevTime = 0;
static Window prevWindow;
static int prevX = -999;
static int prevY = -999;
QEvent::Type type = QEvent::MouseButtonPress;
if (e->window == prevWindow && long(e->time) - prevTime < QApplication::doubleClickInterval()
&& qAbs(e->x - prevX) < 5 && qAbs(e->y - prevY) < 5) {
type = QEvent::MouseButtonDblClick;
prevTime = e->time - QApplication::doubleClickInterval(); //no double click next time
} else {
prevTime = e->time;
}
prevWindow = e->window;
prevX = e->x;
prevY = e->y;
handleMouseEvent(type, e);
}
QtMWMHints QTestLiteWindow::getMWMHints() const
{
QtMWMHints mwmhints;
Atom type;
int format;
ulong nitems, bytesLeft;
uchar *data = 0;
if ((XGetWindowProperty(mScreen->display(), x_window, mScreen->atomForMotifWmHints(), 0, 5, false,
mScreen->atomForMotifWmHints(), &type, &format, &nitems, &bytesLeft,
&data) == Success)
&& (type == mScreen->atomForMotifWmHints()
&& format == 32
&& nitems >= 5)) {
mwmhints = *(reinterpret_cast<QtMWMHints *>(data));
} else {
mwmhints.flags = 0L;
mwmhints.functions = MWM_FUNC_ALL;
mwmhints.decorations = MWM_DECOR_ALL;
mwmhints.input_mode = 0L;
mwmhints.status = 0L;
}
if (data)
XFree(data);
return mwmhints;
}
void QTestLiteWindow::setMWMHints(const QtMWMHints &mwmhints)
{
if (mwmhints.flags != 0l) {
XChangeProperty(mScreen->display(), x_window,
mScreen->atomForMotifWmHints(), mScreen->atomForMotifWmHints(), 32,
PropModeReplace, (unsigned char *) &mwmhints, 5);
} else {
XDeleteProperty(mScreen->display(), x_window, mScreen->atomForMotifWmHints());
}
}
// Returns true if we should set WM_TRANSIENT_FOR on \a w
static inline bool isTransient(const QWidget *w)
{
return ((w->windowType() == Qt::Dialog
|| w->windowType() == Qt::Sheet
|| w->windowType() == Qt::Tool
|| w->windowType() == Qt::SplashScreen
|| w->windowType() == Qt::ToolTip
|| w->windowType() == Qt::Drawer
|| w->windowType() == Qt::Popup)
&& !w->testAttribute(Qt::WA_X11BypassTransientForHint));
}
Qt::WindowFlags QTestLiteWindow::setWindowFlags(Qt::WindowFlags flags)
{
// Q_ASSERT(flags & Qt::Window);
window_flags = flags;
#ifdef MYX11_DEBUG
qDebug() << "QTestLiteWindow::setWindowFlags" << hex << x_window << "flags" << flags;
#endif
Qt::WindowType type = static_cast<Qt::WindowType>(int(flags & Qt::WindowType_Mask));
if (type == Qt::ToolTip)
flags |= Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint;
if (type == Qt::Popup)
flags |= Qt::X11BypassWindowManagerHint;
bool topLevel = (flags & Qt::Window);
bool popup = (type == Qt::Popup);
bool dialog = (type == Qt::Dialog
|| type == Qt::Sheet);
bool desktop = (type == Qt::Desktop);
bool tool = (type == Qt::Tool || type == Qt::SplashScreen
|| type == Qt::ToolTip || type == Qt::Drawer);
Q_UNUSED(topLevel);
Q_UNUSED(dialog);
Q_UNUSED(desktop);
bool tooltip = (type == Qt::ToolTip);
XSetWindowAttributes wsa;
QtMWMHints mwmhints;
mwmhints.flags = 0L;
mwmhints.functions = 0L;
mwmhints.decorations = 0;
mwmhints.input_mode = 0L;
mwmhints.status = 0L;
ulong wsa_mask = 0;
if (type != Qt::SplashScreen) { // && customize) {
mwmhints.flags |= MWM_HINTS_DECORATIONS;
bool customize = flags & Qt::CustomizeWindowHint;
if (!(flags & Qt::FramelessWindowHint) && !(customize && !(flags & Qt::WindowTitleHint))) {
mwmhints.decorations |= MWM_DECOR_BORDER;
mwmhints.decorations |= MWM_DECOR_RESIZEH;
if (flags & Qt::WindowTitleHint)
mwmhints.decorations |= MWM_DECOR_TITLE;
if (flags & Qt::WindowSystemMenuHint)
mwmhints.decorations |= MWM_DECOR_MENU;
if (flags & Qt::WindowMinimizeButtonHint) {
mwmhints.decorations |= MWM_DECOR_MINIMIZE;
mwmhints.functions |= MWM_FUNC_MINIMIZE;
}
if (flags & Qt::WindowMaximizeButtonHint) {
mwmhints.decorations |= MWM_DECOR_MAXIMIZE;
mwmhints.functions |= MWM_FUNC_MAXIMIZE;
}
if (flags & Qt::WindowCloseButtonHint)
mwmhints.functions |= MWM_FUNC_CLOSE;
}
} else {
// if type == Qt::SplashScreen
mwmhints.decorations = MWM_DECOR_ALL;
}
if (tool) {
wsa.save_under = True;
wsa_mask |= CWSaveUnder;
}
if (flags & Qt::X11BypassWindowManagerHint) {
wsa.override_redirect = True;
wsa_mask |= CWOverrideRedirect;
}
#if 0
if (wsa_mask && initializeWindow) {
Q_ASSERT(id);
XChangeWindowAttributes(dpy, id, wsa_mask, &wsa);
}
#endif
if (mwmhints.functions != 0) {
mwmhints.flags |= MWM_HINTS_FUNCTIONS;
mwmhints.functions |= MWM_FUNC_MOVE | MWM_FUNC_RESIZE;
} else {
mwmhints.functions = MWM_FUNC_ALL;
}
if (!(flags & Qt::FramelessWindowHint)
&& flags & Qt::CustomizeWindowHint
&& flags & Qt::WindowTitleHint
&& !(flags &
(Qt::WindowMinimizeButtonHint
| Qt::WindowMaximizeButtonHint
| Qt::WindowCloseButtonHint))) {
// a special case - only the titlebar without any button
mwmhints.flags = MWM_HINTS_FUNCTIONS;
mwmhints.functions = MWM_FUNC_MOVE | MWM_FUNC_RESIZE;
mwmhints.decorations = 0;
}
setMWMHints(mwmhints);
//##### only if initializeWindow???
if (popup || tooltip) { // popup widget
#ifdef MYX11_DEBUG
qDebug() << "Doing XChangeWindowAttributes for popup" << wsa.override_redirect;
#endif
// set EWMH window types
// setNetWmWindowTypes();
wsa.override_redirect = True;
wsa.save_under = True;
XChangeWindowAttributes(mScreen->display(), x_window, CWOverrideRedirect | CWSaveUnder,
&wsa);
} else {
#ifdef MYX11_DEBUG
qDebug() << "Doing XChangeWindowAttributes for non-popup";
#endif
}
return flags;
}
void QTestLiteWindow::setVisible(bool visible)
{
#ifdef MYX11_DEBUG
qDebug() << "QTestLiteWindow::setVisible" << visible << hex << x_window;
#endif
if (visible)
XMapWindow(mScreen->display(), x_window);
else
XUnmapWindow(mScreen->display(), x_window);
}
void QTestLiteWindow::setCursor(const Cursor &cursor)
{
XDefineCursor(mScreen->display(), x_window, cursor);
XFlush(mScreen->display());
}
QPlatformGLContext *QTestLiteWindow::glContext() const
{
if (!QApplicationPrivate::platformIntegration()->hasOpenGL())
return 0;
if (!mGLContext) {
QTestLiteWindow *that = const_cast<QTestLiteWindow *>(this);
#ifndef QT_NO_OPENGL
that->mGLContext = new QGLXContext(x_window, mScreen,widget()->platformWindowFormat());
#endif
}
return mGLContext;
}
Window QTestLiteWindow::xWindow() const
{
return x_window;
}
GC QTestLiteWindow::graphicsContext() const
{
return gc;
}
QT_END_NAMESPACE
|