| @@ -111,11 +111,19 @@ pub fn manage(win: xlib.Window, window_attrs: *xlib.XWindowAttributes, wm: *Wind |
| 111 |
arrange(monitor, wm); |
111 |
arrange(monitor, wm); |
| 112 |
_ = xlib.XMapWindow(wm.display.handle, win); |
112 |
_ = xlib.XMapWindow(wm.display.handle, win); |
| 113 |
focus(null, wm); |
113 |
focus(null, wm); |
|
|
114 |
+ |
|
|
115 |
+ if (client.rule_fullscreen) { |
|
|
116 |
+ setFullscreen(client, true, wm); |
|
|
117 |
+ } |
| 114 |
} |
118 |
} |
| 115 |
|
119 |
|
| 116 |
-pub fn unmanage(client: *Client, wm: *WindowManager) void { |
120 |
+pub fn unmanage(client: *Client, destroyed: bool, wm: *WindowManager) void { |
| 117 |
const client_monitor = client.monitor; |
121 |
const client_monitor = client.monitor; |
| 118 |
|
122 |
|
|
|
123 |
+ if (!destroyed) { |
|
|
124 |
+ setClientState(client, window_manager.WithdrawnState, wm); |
|
|
125 |
+ } |
|
|
126 |
+ |
| 119 |
var next_focus: ?*Client = null; |
127 |
var next_focus: ?*Client = null; |
| 120 |
if (client_monitor) |monitor| { |
128 |
if (client_monitor) |monitor| { |
| 121 |
if (monitor.sel == client and isScrollingLayout(monitor)) { |
129 |
if (monitor.sel == client and isScrollingLayout(monitor)) { |
| @@ -336,25 +344,30 @@ pub fn grabbuttons(client: *Client, focused: bool, wm: *WindowManager) void { |
| 336 |
|
344 |
|
| 337 |
pub fn setClientState(client: *Client, state: c_long, wm: *WindowManager) void { |
345 |
pub fn setClientState(client: *Client, state: c_long, wm: *WindowManager) void { |
| 338 |
var data: [2]c_long = .{ state, xlib.None }; |
346 |
var data: [2]c_long = .{ state, xlib.None }; |
| 339 |
- _ = xlib.c.XChangeProperty(wm.display.handle, client.window, wm.atoms.wm_state, xlib.XA_ATOM, 32, xlib.PropModeReplace, @ptrCast(&data), 2); |
347 |
+ _ = xlib.c.XChangeProperty(wm.display.handle, client.window, wm.atoms.wm_state, wm.atoms.wm_state, 32, xlib.PropModeReplace, @ptrCast(&data), 2); |
|
|
348 |
+} |
|
|
349 |
+ |
|
|
350 |
+pub fn publishNetWmState(client: *Client, wm: *WindowManager) void { |
|
|
351 |
+ var fullscreen_atom = wm.atoms.net_wm_state_fullscreen; |
|
|
352 |
+ const count: c_int = if (client.is_fullscreen) 1 else 0; |
|
|
353 |
+ _ = xlib.XChangeProperty( |
|
|
354 |
+ wm.display.handle, |
|
|
355 |
+ client.window, |
|
|
356 |
+ wm.atoms.net_wm_state, |
|
|
357 |
+ xlib.XA_ATOM, |
|
|
358 |
+ 32, |
|
|
359 |
+ xlib.PropModeReplace, |
|
|
360 |
+ @ptrCast(&fullscreen_atom), |
|
|
361 |
+ count, |
|
|
362 |
+ ); |
| 340 |
} |
363 |
} |
| 341 |
|
364 |
|
| 342 |
pub fn setFullscreen(client: *Client, fullscreen: bool, wm: *WindowManager) void { |
365 |
pub fn setFullscreen(client: *Client, fullscreen: bool, wm: *WindowManager) void { |
| 343 |
const monitor = client.monitor orelse return; |
366 |
const monitor = client.monitor orelse return; |
| 344 |
|
367 |
|
| 345 |
if (fullscreen and !client.is_fullscreen) { |
368 |
if (fullscreen and !client.is_fullscreen) { |
| 346 |
- var fullscreen_atom = wm.atoms.net_wm_state_fullscreen; |
|
|
| 347 |
- _ = xlib.XChangeProperty( |
|
|
| 348 |
- wm.display.handle, |
|
|
| 349 |
- client.window, |
|
|
| 350 |
- wm.atoms.net_wm_state, |
|
|
| 351 |
- xlib.XA_ATOM, |
|
|
| 352 |
- 32, |
|
|
| 353 |
- xlib.PropModeReplace, |
|
|
| 354 |
- @ptrCast(&fullscreen_atom), |
|
|
| 355 |
- 1, |
|
|
| 356 |
- ); |
|
|
| 357 |
client.is_fullscreen = true; |
369 |
client.is_fullscreen = true; |
|
|
370 |
+ publishNetWmState(client, wm); |
| 358 |
client.old_state = client.is_floating; |
371 |
client.old_state = client.is_floating; |
| 359 |
client.old_border_width = client.border_width; |
372 |
client.old_border_width = client.border_width; |
| 360 |
client.border_width = 0; |
373 |
client.border_width = 0; |
| @@ -366,18 +379,8 @@ pub fn setFullscreen(client: *Client, fullscreen: bool, wm: *WindowManager) void |
| 366 |
|
379 |
|
| 367 |
std.debug.print("fullscreen enabled: window=0x{x}\n", .{client.window}); |
380 |
std.debug.print("fullscreen enabled: window=0x{x}\n", .{client.window}); |
| 368 |
} else if (!fullscreen and client.is_fullscreen) { |
381 |
} else if (!fullscreen and client.is_fullscreen) { |
| 369 |
- var no_atom: xlib.Atom = 0; |
|
|
| 370 |
- _ = xlib.XChangeProperty( |
|
|
| 371 |
- wm.display.handle, |
|
|
| 372 |
- client.window, |
|
|
| 373 |
- wm.atoms.net_wm_state, |
|
|
| 374 |
- xlib.XA_ATOM, |
|
|
| 375 |
- 32, |
|
|
| 376 |
- xlib.PropModeReplace, |
|
|
| 377 |
- @ptrCast(&no_atom), |
|
|
| 378 |
- 0, |
|
|
| 379 |
- ); |
|
|
| 380 |
client.is_fullscreen = false; |
382 |
client.is_fullscreen = false; |
|
|
383 |
+ publishNetWmState(client, wm); |
| 381 |
client.is_floating = client.old_state; |
384 |
client.is_floating = client.old_state; |
| 382 |
client.border_width = client.old_border_width; |
385 |
client.border_width = client.old_border_width; |
| 383 |
|
386 |
|
| @@ -570,24 +573,61 @@ fn positionFloating(client: *Client, monitor: *Monitor, pos: config_mod.Floating |
| 570 |
client.y = y; |
573 |
client.y = y; |
| 571 |
} |
574 |
} |
| 572 |
|
575 |
|
|
|
576 |
+fn ruleMatches(rule: config_mod.Rule, class_str: []const u8, instance_str: []const u8, title_str: []const u8) bool { |
|
|
577 |
+ const class_matches = if (rule.class) |rc| std.mem.indexOf(u8, class_str, rc) != null else true; |
|
|
578 |
+ const instance_matches = if (rule.instance) |ri| std.mem.indexOf(u8, instance_str, ri) != null else true; |
|
|
579 |
+ const title_matches = if (rule.title) |rt| std.mem.indexOf(u8, title_str, rt) != null else true; |
|
|
580 |
+ return class_matches and instance_matches and title_matches; |
|
|
581 |
+} |
|
|
582 |
+ |
|
|
583 |
+pub fn applyFullscreenRule(client: *Client, wm: *WindowManager) void { |
|
|
584 |
+ if (client.rule_fullscreen or client.is_fullscreen) return; |
|
|
585 |
+ |
|
|
586 |
+ var has_fullscreen_rule = false; |
|
|
587 |
+ for (wm.config.rules.items) |rule| { |
|
|
588 |
+ if (rule.is_fullscreen) has_fullscreen_rule = true; |
|
|
589 |
+ } |
|
|
590 |
+ if (!has_fullscreen_rule) return; |
|
|
591 |
+ |
|
|
592 |
+ var class_hint: xlib.XClassHint = .{ .res_name = null, .res_class = null }; |
|
|
593 |
+ _ = xlib.XGetClassHint(wm.display.handle, client.window, &class_hint); |
|
|
594 |
+ defer { |
|
|
595 |
+ if (class_hint.res_class) |ptr| _ = xlib.XFree(@ptrCast(ptr)); |
|
|
596 |
+ if (class_hint.res_name) |ptr| _ = xlib.XFree(@ptrCast(ptr)); |
|
|
597 |
+ } |
|
|
598 |
+ |
|
|
599 |
+ const class_str: []const u8 = if (class_hint.res_class) |ptr| std.mem.sliceTo(ptr, 0) else ""; |
|
|
600 |
+ const instance_str: []const u8 = if (class_hint.res_name) |ptr| std.mem.sliceTo(ptr, 0) else ""; |
|
|
601 |
+ const title_str = std.mem.sliceTo(&client.name, 0); |
|
|
602 |
+ |
|
|
603 |
+ for (wm.config.rules.items) |rule| { |
|
|
604 |
+ if (rule.is_fullscreen and ruleMatches(rule, class_str, instance_str, title_str)) { |
|
|
605 |
+ client.rule_fullscreen = true; |
|
|
606 |
+ setFullscreen(client, true, wm); |
|
|
607 |
+ return; |
|
|
608 |
+ } |
|
|
609 |
+ } |
|
|
610 |
+} |
|
|
611 |
+ |
| 573 |
pub fn applyRules(client: *Client, wm: *WindowManager) void { |
612 |
pub fn applyRules(client: *Client, wm: *WindowManager) void { |
| 574 |
var class_hint: xlib.XClassHint = .{ .res_name = null, .res_class = null }; |
613 |
var class_hint: xlib.XClassHint = .{ .res_name = null, .res_class = null }; |
| 575 |
_ = xlib.XGetClassHint(wm.display.handle, client.window, &class_hint); |
614 |
_ = xlib.XGetClassHint(wm.display.handle, client.window, &class_hint); |
| 576 |
|
615 |
|
| 577 |
const class_str: []const u8 = if (class_hint.res_class) |ptr| std.mem.sliceTo(ptr, 0) else ""; |
616 |
const class_str: []const u8 = if (class_hint.res_class) |ptr| std.mem.sliceTo(ptr, 0) else ""; |
| 578 |
const instance_str: []const u8 = if (class_hint.res_name) |ptr| std.mem.sliceTo(ptr, 0) else ""; |
617 |
const instance_str: []const u8 = if (class_hint.res_name) |ptr| std.mem.sliceTo(ptr, 0) else ""; |
|
|
618 |
+ const title_str = std.mem.sliceTo(&client.name, 0); |
| 579 |
|
619 |
|
| 580 |
client.is_floating = false; |
620 |
client.is_floating = false; |
| 581 |
client.tags = 0; |
621 |
client.tags = 0; |
|
|
622 |
+ client.rule_fullscreen = false; |
| 582 |
var rule_focus = false; |
623 |
var rule_focus = false; |
| 583 |
|
624 |
|
| 584 |
for (wm.config.rules.items) |rule| { |
625 |
for (wm.config.rules.items) |rule| { |
| 585 |
- const class_matches = if (rule.class) |rc| std.mem.indexOf(u8, class_str, rc) != null else true; |
626 |
+ if (ruleMatches(rule, class_str, instance_str, title_str)) { |
| 586 |
- const instance_matches = if (rule.instance) |ri| std.mem.indexOf(u8, instance_str, ri) != null else true; |
|
|
| 587 |
- const title_matches = if (rule.title) |rt| std.mem.indexOf(u8, std.mem.sliceTo(&client.name, 0), rt) != null else true; |
|
|
| 588 |
- |
|
|
| 589 |
- if (class_matches and instance_matches and title_matches) { |
|
|
| 590 |
client.is_floating = rule.is_floating; |
627 |
client.is_floating = rule.is_floating; |
|
|
628 |
+ if (rule.is_fullscreen) { |
|
|
629 |
+ client.rule_fullscreen = true; |
|
|
630 |
+ } |
| 591 |
client.tags |= rule.tags; |
631 |
client.tags |= rule.tags; |
| 592 |
if (rule.width > 0) client.scroll_width = rule.width; |
632 |
if (rule.width > 0) client.scroll_width = rule.width; |
| 593 |
if (rule.monitor >= 0) { |
633 |
if (rule.monitor >= 0) { |