Browse Source

x11 maximized and coords x,y

Eduardo Bart 10 years ago
parent
commit
e1b5d52b07
2 changed files with 77 additions and 10 deletions
  1. 74
    7
      src/framework/x11platform.cpp
  2. 3
    3
      src/main.cpp

+ 74
- 7
src/framework/x11platform.cpp View File

@@ -51,10 +51,16 @@ struct X11PlatformPrivate {
51 51
     Atom atomText;
52 52
     Atom atomCompoundText;
53 53
     Atom atomUTF8String;
54
+    Atom atomWindowState;
55
+    Atom atomWindowMaximizedVert;
56
+    Atom atomWindowMaximizedHorz;
54 57
     bool visible;
55 58
     bool focused;
59
+    bool maximizeOnFirstShow;
56 60
     int width;
57 61
     int height;
62
+    int x;
63
+    int y;
58 64
     std::string clipboardText;
59 65
     std::map<int, unsigned char> keyMap;
60 66
 } x11;
@@ -73,6 +79,7 @@ void Platform::init()
73 79
     x11.focused = false;
74 80
     x11.width = 0;
75 81
     x11.height = 0;
82
+    x11.maximizeOnFirstShow = false;
76 83
 
77 84
     // setup keymap
78 85
     x11.keyMap[XK_1] = KC_1;
@@ -243,6 +250,9 @@ void Platform::init()
243 250
     x11.atomUTF8String = XInternAtom(x11.display, "UTF8_STRING", False);
244 251
     x11.atomText = XInternAtom(x11.display, "TEXT", False);
245 252
     x11.atomCompoundText = XInternAtom(x11.display, "COMPOUND_TEXT", False);
253
+    x11.atomWindowState = XInternAtom(x11.display, "_NET_WM_STATE", False);
254
+    x11.atomWindowMaximizedVert = XInternAtom(x11.display, "_NET_WM_STATE_MAXIMIZED_VERT", False);
255
+    x11.atomWindowMaximizedHorz = XInternAtom(x11.display, "_NET_WM_STATE_MAXIMIZED_HORZ", False);
246 256
 }
247 257
 
248 258
 void Platform::terminate()
@@ -287,6 +297,15 @@ void Platform::poll()
287 297
                     x11.height = event.xconfigure.height;
288 298
                     g_engine.onResize(x11.width, x11.height);
289 299
                 }
300
+
301
+                // hack to fix x11 windows move gaps
302
+                static int gap_x = -1, gap_y = -1;
303
+                if(gap_x == -1 && gap_y == -1) {
304
+                    gap_x = event.xconfigure.x;
305
+                    gap_y = event.xconfigure.y;
306
+                }
307
+                x11.x = event.xconfigure.x - gap_x;
308
+                x11.y = event.xconfigure.y - gap_y;
290 309
                 break;
291 310
 
292 311
             case KeyPress:
@@ -482,14 +501,13 @@ bool Platform::createWindow(int x, int y, int width, int height, int minWidth, i
482 501
                          ExposureMask | VisibilityChangeMask |
483 502
                          StructureNotifyMask | FocusChangeMask;
484 503
 
485
-    // calculate center position
486
-    //x = (XDisplayWidth(x11.display, DefaultScreen(x11.display)) - width) / 2;
487
-    //y = (XDisplayHeight(x11.display, DefaultScreen(x11.display)) - height) / 2;
504
+    x11.x = x;
505
+    x11.y = y;
488 506
 
489 507
     // create the window
490 508
     x11.window = XCreateWindow(x11.display,
491 509
                              RootWindow(x11.display, x11.visual->screen),
492
-                             x, y,
510
+                             0, 0,
493 511
                              width, height,
494 512
                              0,
495 513
                              x11.visual->depth,
@@ -537,6 +555,7 @@ bool Platform::createWindow(int x, int y, int width, int height, int minWidth, i
537 555
 
538 556
     x11.width = width;
539 557
     x11.height = height;
558
+    x11.maximizeOnFirstShow = maximized;
540 559
     return true;
541 560
 }
542 561
 
@@ -578,6 +597,30 @@ void Platform::destroyWindow()
578 597
 void Platform::showWindow()
579 598
 {
580 599
     XMapWindow(x11.display, x11.window);
600
+
601
+    static bool firstShow = true;
602
+    if(firstShow) {
603
+        // move window
604
+        XMoveWindow(x11.display, x11.window, x11.x, x11.y);
605
+
606
+        // set window maximized if needed
607
+        if(x11.maximizeOnFirstShow) {
608
+            XEvent e;
609
+            bzero(&e, sizeof(XEvent));
610
+            e.xany.type = ClientMessage;
611
+            e.xclient.message_type = x11.atomWindowState;
612
+            e.xclient.format = 32;
613
+            e.xclient.window = x11.window;
614
+            e.xclient.data.l[0] = 1l;
615
+            e.xclient.data.l[1] = x11.atomWindowMaximizedVert;
616
+            e.xclient.data.l[2] = x11.atomWindowMaximizedHorz;
617
+            e.xclient.data.l[3] = 0l;
618
+
619
+            XSendEvent(x11.display, RootWindow(x11.display, x11.visual->screen), 0,
620
+                    SubstructureNotifyMask | SubstructureRedirectMask, &e);
621
+        }
622
+        firstShow = false;
623
+    }
581 624
 }
582 625
 
583 626
 void Platform::setWindowTitle(const char *title)
@@ -709,12 +752,12 @@ bool Platform::isWindowVisible()
709 752
 
710 753
 int Platform::getWindowX()
711 754
 {
712
-    return 0;
755
+    return x11.x;
713 756
 }
714 757
 
715 758
 int Platform::getWindowY()
716 759
 {
717
-    return 0;
760
+    return x11.y;
718 761
 }
719 762
 
720 763
 int Platform::getWindowWidth()
@@ -729,7 +772,31 @@ int Platform::getWindowHeight()
729 772
 
730 773
 bool Platform::isWindowMaximized()
731 774
 {
732
-    return false;
775
+    bool ret = false;
776
+    Atom actualType;
777
+    int actualFormat;
778
+    unsigned long i, numItems, bytesAfter;
779
+    unsigned char *propertyValue = NULL;
780
+    long maxLength = 1024;
781
+
782
+    if(XGetWindowProperty(x11.display, x11.window, x11.atomWindowState,
783
+                            0l, maxLength, False, XA_ATOM, &actualType,
784
+                            &actualFormat, &numItems, &bytesAfter,
785
+                            &propertyValue) == Success) {
786
+        Atom *atoms = (Atom *)propertyValue;
787
+        int maximized = 0;
788
+
789
+        for(i=0; i<numItems; ++i) {
790
+            if(atoms[i] == x11.atomWindowMaximizedVert)
791
+                maximized |= 1;
792
+            else if(atoms[i] == x11.atomWindowMaximizedHorz)
793
+                maximized |= 2;
794
+        }
795
+        if(maximized == 3)
796
+            ret = true;
797
+        XFree(propertyValue);
798
+    }
799
+    return ret;
733 800
 }
734 801
 
735 802
 const char *Platform::getAppUserDir(const char *appName)

+ 3
- 3
src/main.cpp View File

@@ -111,12 +111,12 @@ int main(int argc, const char *argv[])
111 111
     // terminate stuff
112 112
     g_engine.terminate();
113 113
 
114
-    //Platform::showMouseCursor();
115
-    Platform::terminate();
116
-
117 114
     // save configurations before exiting
118 115
     saveConfigs();
119 116
 
117
+    //Platform::showMouseCursor();
118
+    Platform::terminate();
119
+
120 120
     // unload resources
121 121
     g_resources.terminate();
122 122
     return 0;

Loading…
Cancel
Save