-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlxqtxfitman.cpp
1045 lines (859 loc) · 29.6 KB
/
lxqtxfitman.cpp
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
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* BEGIN_COMMON_COPYRIGHT_HEADER
* (c)LGPL2+
*
* LXQt - a lightweight, Qt based, desktop toolset
* http://razor-qt.org
*
* Copyright: 2010-2011 Razor team
* Authors:
* Christopher "VdoP" Regali
* Alexander Sokoloff <[email protected]>
*
* This program or library is free software; you can redistribute it
* and/or modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA
*
* END_COMMON_COPYRIGHT_HEADER */
#include <QList>
#include <QDebug>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <QX11Info>
#include <QApplication>
#include <QDesktopWidget>
#include <QWidget>
#include <QIcon>
#include "lxqtxfitman.h"
#include <X11/Xatom.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
/**
* @file xfitman.cpp
* @brief implements class Xfitman
* @author Christopher "VdoP" Regali
*/
/*
Some requests from Clients include type of the Client, for example the _NET_ACTIVE_WINDOW
message. Currently the types can be 1 for normal applications, and 2 for pagers.
See http://standards.freedesktop.org/wm-spec/latest/ar01s09.html#sourceindication
*/
#define SOURCE_NORMAL 1
#define SOURCE_PAGER 2
/*
_NET_WM_STATE actions
*/
#define _NET_WM_STATE_REMOVE 0 // remove/unset property
#define _NET_WM_STATE_ADD 1 // add/set property
#define _NET_WM_STATE_TOGGLE 2 // toggle property
namespace LxQt {
const XfitMan& xfitMan()
{
static XfitMan instance;
return instance;
}
/**
* @brief constructor: gets Display vars and registers us
*/
XfitMan::XfitMan()
{
root = (Window)QX11Info::appRootWindow();
}
/**
* @brief moves a window to a new position
*/
void XfitMan::moveWindow(Window _win, int _x, int _y) const
{
XMoveWindow(QX11Info::display(), _win, _x, _y);
}
/************************************************
************************************************/
bool XfitMan::getWindowProperty(Window window,
Atom atom, // property
Atom reqType, // req_type
unsigned long* resultLen,// nitems_return
unsigned char** result // prop_return
) const
{
int format;
unsigned long type, rest;
return XGetWindowProperty(QX11Info::display(), window, atom, 0, 4096, false,
reqType, &type, &format, resultLen, &rest,
result) == Success;
}
/************************************************
************************************************/
bool XfitMan::getRootWindowProperty(Atom atom, // property
Atom reqType, // req_type
unsigned long* resultLen,// nitems_return
unsigned char** result // prop_return
) const
{
return getWindowProperty(root, atom, reqType, resultLen, result);
}
/**
* @brief this one gets the active application window.
*/
Window XfitMan::getActiveAppWindow() const
{
Window window = getActiveWindow();
if (window == 0)
return 0;
if (acceptWindow(window))
return window;
Window transFor = None;
if (XGetTransientForHint(QX11Info::display(), window, &transFor))
return transFor;
return 0;
}
/**
* @brief returns the window that currently has inputfocus
*/
Window XfitMan::getActiveWindow() const
{
unsigned long len;
unsigned long *data;
if (!getWindowProperty(root, atom("_NET_ACTIVE_WINDOW"), XA_WINDOW,
&len, (unsigned char**) &data)
)
return 0;
Window result = 0;
if (len)
result = data[0];
XFree(data);
return result;
}
/**
* @brief Get the number of desktops
*/
int XfitMan::getNumDesktop() const
{
unsigned long length, *data;
getRootWindowProperty(atom("_NET_NUMBER_OF_DESKTOPS"), XA_CARDINAL, &length, (unsigned char**) &data);
if (data)
{
int res = data[0];
XFree(data);
return res;
}
return 0;
}
QStringList XfitMan::getDesktopNames() const
{
QStringList ret;
unsigned long length;
unsigned char *data = 0;
if (getRootWindowProperty(atom("_NET_DESKTOP_NAMES"), atom("UTF8_STRING"), &length, &data))
{
if (data)
{
char* c = (char*)data;
char* end = (char*)data + length;
while (c < end)
{
ret << QString::fromUtf8(c);
c += strlen(c) + 1; // for trailing \0
}
XFree(data);
}
}
return ret;
}
QString XfitMan::getDesktopName(int desktopNum, const QString &defaultName) const
{
QStringList names = getDesktopNames();
if (desktopNum<0 || desktopNum>names.count()-1)
return defaultName;
return names.at(desktopNum);
}
/**
* @brief resizes a window to the given dimensions
*/
void XfitMan::resizeWindow(Window _wid, int _width, int _height) const
{
XResizeWindow(QX11Info::display(), _wid, _width, _height);
}
/**
* @brief gets a windowpixmap from a window
*/
bool XfitMan::getClientIcon(Window _wid, QPixmap& _pixreturn) const
{
int format;
ulong type, nitems, extra;
ulong* data = 0;
XGetWindowProperty(QX11Info::display(), _wid, atom("_NET_WM_ICON"),
0, LONG_MAX, False, AnyPropertyType,
&type, &format, &nitems, &extra,
(uchar**)&data);
if (!data)
{
return false;
}
QImage img (data[0], data[1], QImage::Format_ARGB32);
for (int i=0; i<img.byteCount()/4; ++i)
((uint*)img.bits())[i] = data[i+2];
_pixreturn = QPixmap::fromImage(img);
XFree(data);
return true;
}
bool XfitMan::getClientIcon(Window _wid, QIcon *icon) const
{
int format;
ulong type, nitems, extra;
ulong* data = 0;
XGetWindowProperty(QX11Info::display(), _wid, atom("_NET_WM_ICON"),
0, LONG_MAX, False, AnyPropertyType,
&type, &format, &nitems, &extra,
(uchar**)&data);
if (!data)
{
return false;
}
ulong* d = data;
while (d < data + nitems)
{
QImage img (d[0], d[1], QImage::Format_ARGB32);
d+=2;
for (int i=0; i<img.byteCount()/4; ++i, ++d)
((uint*)img.bits())[i] = *d;
icon->addPixmap(QPixmap::fromImage(img));
}
XFree(data);
return true;
}
/**
* @brief destructor
*/
XfitMan::~XfitMan()
{
}
/**
* @brief returns a windowname and sets _nameSource to the finally used Atom
*/
//i got the idea for this from taskbar-plugin of LXPanel - so credits fly out :)
QString XfitMan::getWindowTitle(Window _wid) const
{
QString name = "";
//first try the modern net-wm ones
unsigned long length;
unsigned char *data = NULL;
Atom utf8Atom = atom("UTF8_STRING");
if (getWindowProperty(_wid, atom("_NET_WM_VISIBLE_NAME"), utf8Atom, &length, &data))
{
name = QString::fromUtf8((char*) data);
XFree(data);
}
if (name.isEmpty())
{
if (getWindowProperty(_wid, atom("_NET_WM_NAME"), utf8Atom, &length, &data))
{
name = QString::fromUtf8((char*) data);
XFree(data);
}
}
if (name.isEmpty())
{
if (getWindowProperty(_wid, atom("XA_WM_NAME"), XA_STRING, &length, &data))
{
name = (char*) data;
XFree(data);
}
}
if (name.isEmpty())
{
Status ok = XFetchName(QX11Info::display(), _wid, (char**) &data);
name = QString((char*) data);
if (0 != ok) XFree(data);
}
if (name.isEmpty())
{
XTextProperty prop;
if (XGetWMName(QX11Info::display(), _wid, &prop))
{
name = QString::fromUtf8((char*) prop.value);
XFree(prop.value);
}
}
return name;
}
QString XfitMan::getApplicationName(Window _wid) const
{
XClassHint hint;
QString ret;
if (XGetClassHint(QX11Info::display(), _wid, &hint))
{
if (hint.res_name)
{
ret = hint.res_name;
XFree(hint.res_name);
}
if (hint.res_class)
{
XFree(hint.res_class);
}
}
return ret;
}
/**
* @brief sends a clientmessage to a window
*/
int XfitMan::clientMessage(Window _wid, Atom _msg,
unsigned long data0,
unsigned long data1,
unsigned long data2,
unsigned long data3,
unsigned long data4) const
{
XClientMessageEvent msg;
msg.window = _wid;
msg.type = ClientMessage;
msg.message_type = _msg;
msg.send_event = true;
msg.display = QX11Info::display();
msg.format = 32;
msg.data.l[0] = data0;
msg.data.l[1] = data1;
msg.data.l[2] = data2;
msg.data.l[3] = data3;
msg.data.l[4] = data4;
if (XSendEvent(QX11Info::display(), root, false, (SubstructureRedirectMask | SubstructureNotifyMask) , (XEvent *) &msg) == Success)
return EXIT_SUCCESS;
else
return EXIT_FAILURE;
}
/***********************************************
***********************************************/
WindowAllowedActions XfitMan::getAllowedActions(Window window) const
{
WindowAllowedActions actions = { };
unsigned long len;
unsigned long *data;
if (getWindowProperty(window, atom("_NET_WM_ALLOWED_ACTIONS"), XA_ATOM, &len, (unsigned char**) &data))
{
for (unsigned long i=0; i<len; ++i)
{
if (data[i] == atom("_NET_WM_ACTION_MOVE")) actions.Move = true; else
if (data[i] == atom("_NET_WM_ACTION_RESIZE")) actions.Resize = true; else
if (data[i] == atom("_NET_WM_ACTION_MINIMIZE")) actions.Minimize = true; else
if (data[i] == atom("_NET_WM_ACTION_SHADE")) actions.Shade = true; else
if (data[i] == atom("_NET_WM_ACTION_STICK")) actions.Stick = true; else
if (data[i] == atom("_NET_WM_ACTION_MAXIMIZE_HORZ")) actions.MaximizeHoriz = true; else
if (data[i] == atom("_NET_WM_ACTION_MAXIMIZE_VERT")) actions.MaximizeVert = true; else
if (data[i] == atom("_NET_WM_ACTION_FULLSCREEN")) actions.FullScreen = true; else
if (data[i] == atom("_NET_WM_ACTION_CHANGE_DESKTOP")) actions.ChangeDesktop = true; else
if (data[i] == atom("_NET_WM_ACTION_CLOSE")) actions.Close = true; else
if (data[i] == atom("_NET_WM_ACTION_ABOVE")) actions.AboveLayer = true; else
if (data[i] == atom("_NET_WM_ACTION_BELOW")) actions.BelowLayer = true;
}
XFree(data);
}
return actions;
}
WindowState XfitMan::getWindowState(Window window) const
{
WindowState state = { };
unsigned long len;
unsigned long *data;
if (getWindowProperty(window, atom("_NET_WM_STATE"), XA_ATOM, &len, (unsigned char**) &data))
{
for (unsigned long i=0; i<len; ++i)
{
if (data[i] == atom("_NET_WM_STATE_MODAL")) state.Modal = true; else
if (data[i] == atom("_NET_WM_STATE_STICKY")) state.Sticky = true; else
if (data[i] == atom("_NET_WM_STATE_MAXIMIZED_VERT")) state.MaximizedVert = true; else
if (data[i] == atom("_NET_WM_STATE_MAXIMIZED_HORZ")) state.MaximizedHoriz = true; else
if (data[i] == atom("_NET_WM_STATE_SHADED")) state.Shaded = true; else
if (data[i] == atom("_NET_WM_STATE_SKIP_TASKBAR")) state.SkipTaskBar = true; else
if (data[i] == atom("_NET_WM_STATE_SKIP_PAGER")) state.SkipPager = true; else
if (data[i] == atom("_NET_WM_STATE_HIDDEN")) state.Hidden = true; else
if (data[i] == atom("_NET_WM_STATE_FULLSCREEN")) state.FullScreen = true; else
if (data[i] == atom("_NET_WM_STATE_ABOVE")) state.AboveLayer = true; else
if (data[i] == atom("_NET_WM_STATE_BELOW")) state.BelowLayer = true; else
if (data[i] == atom("_NET_WM_STATE_DEMANDS_ATTENTION")) state.Attention = true;
}
XFree(data);
}
return state;
}
/**
* @brief returns true if a window has its hidden_flag set
*/
bool XfitMan::isHidden(Window _wid) const
{
return getWindowState(_wid).Hidden;
}
Atom XfitMan::atom(const char* atomName)
{
static QHash<QString, Atom> hash;
if (hash.contains(atomName))
return hash.value(atomName);
Atom atom = XInternAtom(QX11Info::display(), atomName, false);
hash[atomName] = atom;
return atom;
}
AtomList XfitMan::getWindowType(Window window) const
{
AtomList result;
unsigned long length, *data;
length=0;
if (!getWindowProperty(window, atom("_NET_WM_WINDOW_TYPE"), (Atom)AnyPropertyType, &length, (unsigned char**) &data))
return result;
for (unsigned int i = 0; i < length; i++)
result.append(data[i]);
XFree(data);
return result;
}
/**
* @brief rejects a window from beeing listed
*/
bool XfitMan::acceptWindow(Window window) const
{
{
AtomList types = getWindowType(window);
AtomList ignoreList;
ignoreList << atom("_NET_WM_WINDOW_TYPE_DESKTOP")
<< atom("_NET_WM_WINDOW_TYPE_DOCK")
<< atom("_NET_WM_WINDOW_TYPE_SPLASH")
<< atom("_NET_WM_WINDOW_TYPE_TOOLBAR")
<< atom("_NET_WM_WINDOW_TYPE_MENU")
// for qlipper - using qpopup as a main window
<< atom("_NET_WM_WINDOW_TYPE_POPUP_MENU");
// issue #284: qmmp its not registered in window list panel
// qmmp has _KDE_NET_WM_WINDOW_TYPE_OVERRIDE in its
// _NET_WM_WINDOW_TYPE(ATOM) = _KDE_NET_WM_WINDOW_TYPE_OVERRIDE, _NET_WM_WINDOW_TYPE_NORMAL
// Let's expect that _KDE_NET_WM_WINDOW_TYPE_OVERRIDE can be set for
// regular windows too. If it should be hidden we should expect
// one of atoms listed above.
// << atom("_KDE_NET_WM_WINDOW_TYPE_OVERRIDE");
foreach (Atom i, ignoreList)
{
if (types.contains(i))
return false;
}
WindowState state = getWindowState(window);
if (state.SkipTaskBar) return false;
}
Window transFor = None;
// WM_TRANSIENT_FOR hint not set - normal window
if (!XGetTransientForHint(QX11Info::display(), window, &transFor))
return true;
if (transFor == 0) return true;
if (transFor == window) return true;
if (transFor == root) return true;
AtomList transForTypes = getWindowType(transFor);
return !transForTypes.contains(atom("_NET_WM_WINDOW_TYPE_NORMAL"));
}
/**
* @brief gets a client list
*/
WindowList XfitMan::getClientList() const
{
//initialize the parameters for the XGetWindowProperty call
unsigned long length, *data;
length=0;
/**
* @todo maybe support multiple desktops here!
*/
QList<Window> output;
if (getRootWindowProperty(atom("_NET_CLIENT_LIST"), (Atom)AnyPropertyType, &length, (unsigned char**) &data))
{
for (unsigned int i = 0; i < length; i ++)
output.append(data[i]);
XFree(data);
}
return output;
}
/**
* @brief returns the current desktop
*/
int XfitMan::getActiveDesktop() const
{
int res = -2;
unsigned long length, *data;
if (getRootWindowProperty(atom("_NET_CURRENT_DESKTOP"), XA_CARDINAL, &length, (unsigned char**) &data))
{
if (data)
{
res = data[0];
XFree(data);
}
}
return res;
}
/**
* @brief gets the desktop of the windows _wid
*/
int XfitMan::getWindowDesktop(Window _wid) const
{
int res = -1;
unsigned long length, *data;
// so we try to use net_wm_desktop first, but if the
// system does not use net_wm standard we use win_workspace!
if (getWindowProperty(_wid, atom("_NET_WM_DESKTOP"), XA_CARDINAL, &length, (unsigned char**) &data))
{
if (!data)
return res;
res = data[0];
XFree(data);
}
else
{
if (getWindowProperty(_wid, atom("_WIN_WORKSPACE"), XA_CARDINAL, &length, (unsigned char**) &data))
{
if (!data)
return res;
res = data[0];
XFree(data);
}
}
return res;
}
/**
* @brief moves a window to a specified desktop
*/
void XfitMan::moveWindowToDesktop(Window _wid, int _display) const
{
clientMessage(_wid, atom("_NET_WM_DESKTOP"), (unsigned long) _display,0,0,0,0);
}
/**
* @brief raises windows _wid
*/
void XfitMan::raiseWindow(Window _wid) const
{
clientMessage(_wid, atom("_NET_ACTIVE_WINDOW"),
SOURCE_PAGER);
}
/************************************************
************************************************/
void XfitMan::minimizeWindow(Window _wid) const
{
clientMessage(_wid, atom("WM_CHANGE_STATE"),
IconicState);
}
/************************************************
************************************************/
void XfitMan::maximizeWindow(Window _wid, MaximizeDirection direction) const
{
Atom atom1 = 0, atom2= 0;
switch (direction)
{
case MaximizeHoriz:
atom1 = atom("_NET_WM_STATE_MAXIMIZED_HORZ");
break;
case MaximizeVert:
atom1 = atom("_NET_WM_STATE_MAXIMIZED_VERT");
break;
case MaximizeBoth:
atom1 = atom("_NET_WM_STATE_MAXIMIZED_VERT");
atom2 = atom("_NET_WM_STATE_MAXIMIZED_HORZ");
break;
}
clientMessage(_wid, atom("_NET_WM_STATE"),
_NET_WM_STATE_ADD,
atom1, atom2,
SOURCE_PAGER);
raiseWindow(_wid);
}
/************************************************
************************************************/
void XfitMan::deMaximizeWindow(Window _wid) const
{
clientMessage(_wid, atom("_NET_WM_STATE"),
_NET_WM_STATE_REMOVE,
atom("_NET_WM_STATE_MAXIMIZED_VERT"),
atom("_NET_WM_STATE_MAXIMIZED_HORZ"),
SOURCE_PAGER);
}
/************************************************
************************************************/
void XfitMan::shadeWindow(Window _wid, bool shade) const
{
clientMessage(_wid, atom("_NET_WM_STATE"),
shade ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE,
atom("_NET_WM_STATE_SHADED"),
0,
SOURCE_PAGER);
}
/************************************************
************************************************/
void XfitMan::closeWindow(Window _wid) const
{
clientMessage(_wid, atom("_NET_CLOSE_WINDOW"),
0, // Timestamp
SOURCE_PAGER);
}
/************************************************
************************************************/
void XfitMan::setWindowLayer(Window _wid, XfitMan::Layer layer) const
{
ulong aboveAction = (layer == LayerAbove) ?
_NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE;
ulong belowAction = (layer == LayerBelow) ?
_NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE;
clientMessage(_wid, atom("_NET_WM_STATE"),
aboveAction,
atom("_NET_WM_STATE_ABOVE"),
0,
SOURCE_PAGER);
clientMessage(_wid, atom("_NET_WM_STATE"),
belowAction,
atom("_NET_WM_STATE_BELOW"),
0,
SOURCE_PAGER);
}
/**
* @brief changes active desktop to _desktop
*/
void XfitMan::setActiveDesktop(int _desktop) const
{
clientMessage(root, atom("_NET_CURRENT_DESKTOP"), (unsigned long) _desktop,0,0,0,0);
}
/**
* @brief sets net_wm_strut_partial = our reserved panelspace for the mainbar!
*/
void XfitMan::setStrut(Window _wid,
int left, int right,
int top, int bottom,
int leftStartY, int leftEndY,
int rightStartY, int rightEndY,
int topStartX, int topEndX,
int bottomStartX, int bottomEndX
) const
{
//qDebug() << "XfitMan: Trying to set STRUT_PARTIAL for panel!";
unsigned long desstrut[12];
memset(desstrut,0,sizeof(desstrut));
//prepare the array
//it has format:
/*
* left, right, top, bottom, left_start_y, left_end_y,
* right_start_y, right_end_y, top_start_x, top_end_x, bottom_start_x,
* bottom_end_x
*
*/
//so we take our panelsize from the bottom up
desstrut[0] = left; desstrut[1] = right;
desstrut[2] = top; desstrut[3] = bottom;
desstrut[4] = leftStartY; desstrut[5] = leftEndY;
desstrut[6] = rightStartY; desstrut[7] = rightEndY;
desstrut[8] = topStartX; desstrut[9] = topEndX;
desstrut[10] = bottomStartX; desstrut[11] = bottomEndX;
//now we can change that property right
XChangeProperty(QX11Info::display(), _wid , atom("_NET_WM_STRUT_PARTIAL"),
XA_CARDINAL, 32, PropModeReplace, (unsigned char *) desstrut, 12 );
//now some wm do not support net_wm_strut_partial but only net_wm_strut, so we also
// send that one too xdg-std says: if you get a strut_partial ignore all following
// struts! so if this msg is recognized its ok if not, we dont care either
XChangeProperty(QX11Info::display(), _wid, atom("_NET_WM_STRUT"),
XA_CARDINAL, 32, PropModeReplace, (unsigned char*) desstrut, 4);
}
#ifdef DEBUG
/************************************************
************************************************/
QString XfitMan::debugWindow(Window wnd)
{
if (!wnd)
return QString("[%1]").arg(wnd,8, 16);
QString typeStr;
int format;
unsigned long type, length, rest, *data;
length=0;
if (XGetWindowProperty(QX11Info::display(), wnd, XInternAtom(QX11Info::display(), "_NET_WM_WINDOW_TYPE", False),
0, 4096, FALSE, AnyPropertyType, &type, &format,
&length, &rest,(unsigned char**) &data) == Success)
{
for (unsigned int i = 0; i < length; i++)
{
char* aname = XGetAtomName(QX11Info::display(), data[i]);
typeStr = typeStr + " " + aname;
XFree(aname);
}
}
else
typeStr ="ERROR";
return QString("[%1] %2 %3").arg(wnd,8, 16).arg(xfitMan().getWindowTitle(wnd)).arg(typeStr);
}
#endif
/************************************************
************************************************/
const QRect XfitMan::availableGeometry(int screen) const
{
QDesktopWidget *d = QApplication::desktop();
if (screen < 0 || screen >= d->screenCount())
screen = d->primaryScreen();
QRect available = d->screenGeometry(screen);
// Iterate over all the client windows and subtract from the available
// area the space they reserved on the edges (struts).
// Note: _NET_WORKAREA is not reliable as it exposes only one
// rectangular area spanning all screens.
Display *display = QX11Info::display();
int x11Screen = d->isVirtualDesktop() ? DefaultScreen(display) : screen;
Atom ret;
int format, status;
uchar* data = 0;
ulong nitems, after;
status = XGetWindowProperty(display, (Window)QX11Info::appRootWindow(x11Screen),
atom("_NET_CLIENT_LIST"), 0L, ~0L, False, XA_WINDOW,
&ret, &format, &nitems, &after, &data);
if (status == Success && ret == XA_WINDOW && format == 32 && nitems)
{
const QRect desktopGeometry = d->rect();
Window* xids = (Window*) data;
for (quint32 i = 0; i < nitems; ++i)
{
ulong nitems2;
uchar* data2 = 0;
status = XGetWindowProperty(display, xids[i],
atom("_NET_WM_STRUT_PARTIAL"), 0, 12, False, XA_CARDINAL,
&ret, &format, &nitems2, &after, &data2);
if (status == Success && ret == XA_CARDINAL && format == 32 && nitems2 == 12)
{
ulong* struts = (ulong*) data2;
QRect left(desktopGeometry.x(),
desktopGeometry.y() + struts[4],
struts[0],
struts[5] - struts[4]);
if (available.intersects(left))
available.setX(left.width());
QRect right(desktopGeometry.x() + desktopGeometry.width() - struts[1],
desktopGeometry.y() + struts[6],
struts[1],
struts[7] - struts[6]);
if (available.intersects(right))
available.setWidth(right.x() - available.x());
QRect top(desktopGeometry.x() + struts[8],
desktopGeometry.y(),
struts[9] - struts[8],
struts[2]);
if (available.intersects(top))
available.setY(top.height());
QRect bottom(desktopGeometry.x() + struts[10],
desktopGeometry.y() + desktopGeometry.height() - struts[3],
struts[11] - struts[10],
struts[3]);
if (available.intersects(bottom))
available.setHeight(bottom.y() - available.y());
}
if (data2)
XFree(data2);
}
}
if (data)
XFree(data);
return available;
}
/************************************************
************************************************/
const QRect XfitMan::availableGeometry(const QWidget *widget) const
{
if (!widget)
{
qWarning("XfitMan::availableGeometry(): Attempt "
"to get the available geometry of a null widget");
return QRect();
}
return availableGeometry(QApplication::desktop()->screenNumber(widget));
}
/************************************************
************************************************/
const QRect XfitMan::availableGeometry(const QPoint &point) const
{
return availableGeometry(QApplication::desktop()->screenNumber(point));
}
/************************************************
The Window Manager MUST set this property on the root window to be the ID of a child
window created by himself, to indicate that a compliant window manager is active.
http://standards.freedesktop.org/wm-spec/wm-spec-latest.html#id2550836
************************************************/
bool XfitMan::isWindowManagerActive() const
{
//Window *wins;
//getRootWindowProperty(atom("_NET_SUPPORTING_WM_CHECK"), XA_WINDOW, &length, (unsigned char**) &wins);
Atom type;
unsigned long length;
Window *wins;
int format;
unsigned long after;
XGetWindowProperty(QX11Info::display(), root, atom("_NET_SUPPORTING_WM_CHECK"),
0, LONG_MAX,
false, XA_WINDOW, &type, &format, &length,
&after, (unsigned char **)&wins);
if ( type == XA_WINDOW && length > 0 && wins[0] != None )
{
XFree(wins);
return true;
}
return false;
}
bool XfitMan::getShowingDesktop() const
{
bool show = false;
unsigned long resultLen;
unsigned char* result = NULL;
if(getRootWindowProperty(atom("_NET_SHOWING_DESKTOP"), XA_CARDINAL, &resultLen, &result))
{
show = *reinterpret_cast<long*>(result) ? true : false;
if(result)
XFree(result);
}
return show;
}
void XfitMan::setShowingDesktop(bool show) const
{
clientMessage((Window)QX11Info::appRootWindow(), atom("_NET_SHOWING_DESKTOP"), show ? 1 : 0);
}
void XfitMan::setIconGeometry(Window _wid, QRect* rect) const
{
Atom net_wm_icon_geometry = atom("_NET_WM_ICON_GEOMETRY");
if(!rect)
XDeleteProperty(QX11Info::display(), _wid, net_wm_icon_geometry);