about summary refs log tree commit diff
path: root/exwm-manage.el
diff options
context:
space:
mode:
authorChris Feng <chris.w.feng@gmail.com>2015-09-19T08·46+0800
committerChris Feng <chris.w.feng@gmail.com>2015-09-19T08·53+0800
commitb35430429e96ce6b2bb46a4d155d86acdba8d768 (patch)
tree22752f9ca9600ea0bbdaf0d140fadfc9af16cb3a /exwm-manage.el
parent921e6e5be989b94b3b62d6db72d31fb16c24ee30 (diff)
Check _MOTIF_WM_HINTS when attempting to manage an X window
* exwm-core.el: New buffer-local variable exwm--mwm-hints.
* exwm-manage.el: New variable exwm--atom-_MOTIF_WM_HINTS for holding the
  value of _MOTIF_WM_HINTS atom; new function exwm--update-mwm-hints for
  updating the _MOTIF_WM_HINTS property of an X window.
* exwm-manage.el (exwm-manage--init): Intern the _MOTIF_WM_HINTS atom.
* exwm-manage.el (exwm-manage--manage-window): Avoid managing windows
  without decoration (implied by _MOTIF_WM_HINTS).
Diffstat (limited to 'exwm-manage.el')
-rw-r--r--exwm-manage.el38
1 files changed, 33 insertions, 5 deletions
diff --git a/exwm-manage.el b/exwm-manage.el
index 3e3c848a56ee..b2eda4b8fc6f 100644
--- a/exwm-manage.el
+++ b/exwm-manage.el
@@ -42,6 +42,23 @@ corresponding buffer.")
         (when reply                     ;nil when destroyed
           (setq exwm--geometry reply))))))
 
+;; The _MOTIF_WM_HINTS atom (see <Xm/MwmUtil.h> for more details)
+;; It's currently only used in 'exwm-manage' module
+(defvar exwm-manage--_MOTIF_WM_HINTS nil "_MOTIF_WM_HINTS atom.")
+
+(defun exwm-manage--update-mwm-hints (id &optional force)
+  "Update _MOTIF_WM_HINTS."
+  (with-current-buffer (exwm--id->buffer id)
+    (unless (and exwm--mwm-hints (not force))
+      (let ((reply (xcb:+request-unchecked+reply exwm--connection
+                       (make-instance 'xcb:icccm:-GetProperty
+                                      :window id
+                                      :property exwm-manage--_MOTIF_WM_HINTS
+                                      :type exwm-manage--_MOTIF_WM_HINTS
+                                      :long-length 5))))
+        (when reply
+          (setq exwm--mwm-hints (append (slot-value reply 'value) nil)))))))
+
 (defun exwm-manage--manage-window (id)
   "Manage window ID."
   (exwm--log "Try to manage #x%x" id)
@@ -63,6 +80,7 @@ corresponding buffer.")
       (exwm--update-window-type id)
       (exwm--update-class id)
       (exwm-manage--update-geometry id)
+      (exwm-manage--update-mwm-hints id)
       ;; No need to manage (please check OverrideRedirect outside)
       (when (or
              (not
@@ -70,11 +88,12 @@ corresponding buffer.")
                   (memq xcb:Atom:_NET_WM_WINDOW_TYPE_UTILITY exwm-window-type)
                   (memq xcb:Atom:_NET_WM_WINDOW_TYPE_DIALOG exwm-window-type)
                   (memq xcb:Atom:_NET_WM_WINDOW_TYPE_NORMAL exwm-window-type)))
-             ;; For Java applications
-             (and (memq xcb:Atom:_NET_WM_WINDOW_TYPE_NORMAL exwm-window-type)
-                  exwm-instance-name
-                  (string-prefix-p "sun-awt-X11-" exwm-instance-name)
-                  (not (string-suffix-p "XFramePeer" exwm-instance-name))))
+             ;; Check _MOTIF_WM_HINTS (mainly for Java applications)
+             ;; See <Xm/MwmUtil.h> for the definitions of these fields
+             (and exwm--mwm-hints
+                  (/= 0 (logand (elt exwm--mwm-hints 0) ;MotifWmHints.flags
+                                2))     ;MWM_HINTS_DECORATIONS
+                  (= 0 (elt exwm--mwm-hints 2)))) ;MotifWmHints.decorations
         (exwm--log "No need to manage #x%x" id)
         ;; Remove all events
         (xcb:+request-checked+request-check exwm--connection
@@ -356,6 +375,15 @@ corresponding buffer.")
 
 (defun exwm-manage--init ()
   "Initialize manage module."
+  ;; Intern _MOTIF_WM_HINTS
+  (let ((atom-name "_MOTIF_WM_HINTS"))
+    (setq exwm-manage--_MOTIF_WM_HINTS
+          (slot-value (xcb:+request-unchecked+reply exwm--connection
+                          (make-instance 'xcb:InternAtom
+                                         :only-if-exists 0
+                                         :name-len (length atom-name)
+                                         :name atom-name))
+                      'atom)))
   (xcb:+event exwm--connection 'xcb:ConfigureRequest
               #'exwm-manage--on-ConfigureRequest)
   (xcb:+event exwm--connection 'xcb:MapRequest #'exwm-manage--on-MapRequest)