aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--freedowm.py71
1 files changed, 46 insertions, 25 deletions
diff --git a/freedowm.py b/freedowm.py
index 5c3736e..ed76a92 100644
--- a/freedowm.py
+++ b/freedowm.py
@@ -8,9 +8,14 @@ from Xlib.display import Display
display = Display()
root = display.screen().root
colormap = display.screen().default_colormap
+currently_focused = None
+
+NET_WM_NAME = display.intern_atom('_NET_WM_NAME')
+NET_ACTIVE_WINDOW = display.intern_atom('_NET_ACTIVE_WINDOW')
# Listen for window changes
-root.change_attributes(event_mask=X.PropertyChangeMask | X.FocusChangeMask)
+root.change_attributes(event_mask=
+ X.PropertyChangeMask | X.FocusChangeMask | X.SubstructureNotifyMask | X.PointerMotionMask)
# Keyboard listener
root.grab_key(X.AnyKey, X.Mod4Mask, 1, X.GrabModeAsync, X.GrabModeAsync)
@@ -28,34 +33,56 @@ def is_key(key_name):
def window_focused():
- return hasattr(event, "child") and event.child != X.NONE
+ return hasattr(event, "child") and event.child != X.NONE or root.query_pointer().child != 0
+
+
+def set_border(child, color):
+ if child is not None and child is not X.NONE:
+ border_color = colormap.alloc_named_color(color).pixel
+ child.configure(border_width=1)
+ child.change_attributes(None, border_pixel=border_color)
def update_windows():
# Only update if the event has relevance (focus/title change)
# if event.type != X.PropertyNotify:
# return
-
- # Update borders
- if event.type == X.FocusOut or event.type == X.FocusIn:
- if hasattr(event, "window"):
- for child in root.query_tree().children:
- print("NO FOCUS")
- border_color = colormap.alloc_named_color("#000").pixel
- child.configure(border_width=1)
- child.change_attributes(None, border_pixel=border_color)
- if window_focused():
- print("FOCUS")
+ global currently_focused # TODO: Convert to class-scheme
+ new_focus = False
+
+ # Set focused window "in focus"
+ if window_focused():
+ if hasattr(event, "child") and event.child != currently_focused:
+ new_focus = True
+ currently_focused = event.child
event.child.configure(stack_mode=X.Above)
- border_color = colormap.alloc_named_color("#fff").pixel
- event.child.configure(border_width=1)
- event.child.change_attributes(None, border_pixel=border_color)
- display.sync()
+ elif root.query_pointer().child != currently_focused:
+ new_focus = True
+ currently_focused = root.query_pointer().child
+ root.query_pointer().child.configure(stack_mode=X.Above)
+
+ # Set all windows to un-focused borders
+ if event.type == X.FocusOut or new_focus:
+ for child in root.query_tree().children:
+ print("RESET FOCUS")
+ set_border(child, "#000")
+
+ # Set focused window border
+ if event.type == X.FocusIn or new_focus:
+ child = root.query_pointer().child
+ currently_focused = child
+ if child != 0:
+ print("FOCUS")
+ child.configure(stack_mode=X.Above)
+ set_border(child, "#fff")
+
+ display.sync()
# Check for actions until exit
while 1:
event = display.next_event()
+ update_windows()
# Resize window (MOD + right click)
if event.type == X.ButtonPress and event.child != X.NONE:
@@ -73,14 +100,10 @@ while 1:
height=max(1, attribute.height + (start.detail == 3 and yDiff or 0))
)
- # Raise window under cursor (MOD + J)
- if is_key("j") and window_focused():
+ # Switch between windows (MOD + Tab)
+ if is_key("tab") and window_focused():
event.child.configure(stack_mode=X.Below)
- # Raise window under cursor (MOD + K)
- if is_key("k") and window_focused():
- event.child.configure(stack_mode=X.Above)
-
# Close window (MOD + Q)
elif is_key("q") and window_focused():
event.child.destroy()
@@ -99,5 +122,3 @@ while 1:
elif event.type == X.ButtonRelease:
start = None
-
- update_windows()