Add setIconGeometry(), getShowingDesktop(), setShowingDesktop(), and getWMState(...
authorHong Jen Yee (PCMan) <pcman.tw@gmail.com>
Tue, 5 Nov 2013 11:19:56 +0000 (19:19 +0800)
committerHong Jen Yee (PCMan) <pcman.tw@gmail.com>
Tue, 5 Nov 2013 11:19:56 +0000 (19:19 +0800)
lxqtxfitman.cpp
lxqtxfitman.h

index d7e706a..11f271f 100644 (file)
@@ -634,7 +634,15 @@ int XfitMan::getWindowDesktop(Window _wid) const
 
 void XfitMan::moveWindowToDesktop(Window _wid, int _display) const
 {
-    clientMessage(_wid, atom("_NET_WM_DESKTOP"), (unsigned long) _display,0,0,0,0);
+    WMState state = getWMState(_wid);
+    if(state != WMStateWithdrawn)
+        clientMessage(_wid, atom("_NET_WM_DESKTOP"), (unsigned long) _display,0,0,0,0);
+    else
+    {
+        long desktop = _display;
+        XChangeProperty(QX11Info::display(), _wid, XfitMan::atom("_NET_WM_DESKTOP"), XA_CARDINAL, 32,
+                        PropModeReplace, (unsigned char*)&desktop, 1);
+    }
 }
 
 
@@ -976,4 +984,57 @@ bool XfitMan::isWindowManagerActive() const
     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(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);
+    else
+    {
+        long data[4];
+        data[0] = rect->x();
+        data[1] = rect->y();
+        data[2] = rect->width();
+        data[3] = rect->height();
+        XChangeProperty(QX11Info::display(), _wid, net_wm_icon_geometry,
+                        XA_CARDINAL, 32, PropModeReplace, (unsigned char*)data, 4);
+    }
+}
+
+XfitMan::WMState XfitMan::getWMState(Window _wid) const
+{
+  WMState state = WMStateWithdrawn;
+    Atom wm_state = atom("WM_STATE");
+    unsigned long resultLen;
+    unsigned char* result = NULL;
+    if(getWindowProperty(_wid, wm_state, wm_state, &resultLen, &result))
+    {
+        if(result)
+        {
+            state = WMState(*((long*)result));
+            XFree(result);
+        }
+    }
+    return state;
+}
+
 } // namespace LxQt
index 7c80ad7..264712b 100644 (file)
 #ifndef LXQTXFITMAN_H
 #define LXQTXFITMAN_H
 
-#include <QtCore/QList>
-#include <QtGui/QPixmap>
-#include <QtCore/QString>
-#include <QtCore/QMap>
+#include <QList>
+#include <QPixmap>
+#include <QString>
+#include <QMap>
+#include <QIcon>
 #include <X11/Xlib.h>
 
 //some net_wm state-operations we need here
@@ -112,6 +113,13 @@ public:
         MaximizeBoth
     };
 
+    enum WMState
+    {
+        WMStateWithdrawn = 0,
+        WMStateNormal = 1,
+        WMStateIconic = 3
+    };
+
     ~XfitMan();
     XfitMan();
     void moveWindow(Window _win, int _x, int _y) const;
@@ -150,6 +158,16 @@ public:
     Window getActiveWindow() const;
     int getNumDesktop() const;
 
+    bool getShowingDesktop() const;
+    void setShowingDesktop(bool show) const;
+
+    void setIconGeometry(Window _wid, QRect* rect = 0) const;
+
+    /*!
+     * Returns ICCCM WM_STATE
+    */
+    WMState getWMState(Window _wid) const;
+
     /*!
      * Returns the names of all virtual desktops. This is a list of UTF-8 encoding strings.
      *