Skip to content

Commit 37133ed

Browse files
committed
prepare for adding top window bars (hard)
1 parent b1403ff commit 37133ed

File tree

3 files changed

+46
-6
lines changed

3 files changed

+46
-6
lines changed

gridwm.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ exec = []
44
[general]
55
update_ms = 5
66
scale_steps = 20
7+
window_bars = true
8+
window_bar_height = 20
79

810
[keyboard]
911
layout = "de"

src/gridwm/config.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,17 @@ pub struct Config {
2222
pub struct General {
2323
pub update_ms: u64,
2424
pub scale_steps: u32,
25+
pub window_bars: bool,
26+
pub window_bar_height: u32,
2527
}
2628

2729
impl Default for General {
2830
fn default() -> Self {
2931
Self {
3032
update_ms: 5,
3133
scale_steps: 20,
34+
window_bars: false,
35+
window_bar_height: 20,
3236
}
3337
}
3438
}

src/gridwm/mod.rs

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ use std::{
2424
use x11::{
2525
xinerama,
2626
xlib::{
27-
self, Atom, Cursor, GCForeground, XAllocColor, XButtonPressedEvent, XClearWindow, XColor, XCreateFontCursor, XDefaultColormap, XDefaultRootWindow, XDefaultScreen, XFlush, XGCValues, XGetWindowProperty, XInternAtom, XParseColor, XSetWindowBackground, XUnmapWindow, XWindowAttributes
27+
self, Atom, Cursor, GCForeground, XAllocColor, XButtonPressedEvent, XClearWindow, XColor,
28+
XCreateFontCursor, XDefaultColormap, XDefaultRootWindow, XDefaultScreen, XFlush, XGCValues,
29+
XGetWindowProperty, XInternAtom, XParseColor, XSetWindowBackground, XUnmapWindow,
30+
XWindowAttributes,
2831
},
2932
};
3033

@@ -516,8 +519,16 @@ impl GridWM {
516519

517520
// if above fails
518521
unsafe {
519-
let net_wm_name = XInternAtom(self.display, CString::new("_NET_WM_NAME").unwrap().as_ptr(), 0);
520-
let utf8 = XInternAtom(self.display, CString::new("UTF8_STRING").unwrap().as_ptr(), 0);
522+
let net_wm_name = XInternAtom(
523+
self.display,
524+
CString::new("_NET_WM_NAME").unwrap().as_ptr(),
525+
0,
526+
);
527+
let utf8 = XInternAtom(
528+
self.display,
529+
CString::new("UTF8_STRING").unwrap().as_ptr(),
530+
0,
531+
);
521532

522533
let mut actual_type: Atom = std::mem::zeroed();
523534
let mut actual_format: i32 = std::mem::zeroed();
@@ -538,7 +549,9 @@ impl GridWM {
538549
&mut nitems,
539550
&mut bytes_after,
540551
&mut data,
541-
) == 0 && !data.is_null() {
552+
) == 0
553+
&& !data.is_null()
554+
{
542555
let win_title = std::ffi::CStr::from_ptr(data as *const i8)
543556
.to_string_lossy()
544557
.into_owned();
@@ -547,7 +560,10 @@ impl GridWM {
547560
}
548561
}
549562

550-
Err(GridWMError::Other(format!("failed to get name for window {}", window)))
563+
Err(GridWMError::Other(format!(
564+
"failed to get name for window {}",
565+
window
566+
)))
551567
}
552568

553569
fn get_focused(&self) -> Option<Window> {
@@ -845,14 +861,32 @@ impl GridWM {
845861
(0..n)
846862
.map(|i| {
847863
let i = i as i32;
848-
if self.config.bar.enable {
864+
if self.config.bar.enable && !self.config.general.window_bars {
849865
WindowInfo {
850866
x: (i % cols) * w,
851867
y: ((i / cols) * h) + self.config.bar.height as i32,
852868
w,
853869
h,
854870
}
871+
} else if self.config.bar.enable && self.config.general.window_bars {
872+
WindowInfo {
873+
x: (i % cols) * w,
874+
y: ((i / cols) * h)
875+
+ self.config.bar.height as i32
876+
+ (((i / cols) + 1) * self.config.general.window_bar_height as i32),
877+
w,
878+
h,
879+
}
880+
} else if !self.config.bar.enable && self.config.general.window_bars {
881+
WindowInfo {
882+
x: (i % cols) * w,
883+
y: ((i / cols) * h)
884+
+ (((i / cols) + 1) * self.config.general.window_bar_height as i32),
885+
w,
886+
h,
887+
}
855888
} else {
889+
// bar disabled and window bars disabled
856890
WindowInfo {
857891
x: (i % cols) * w,
858892
y: (i / cols) * h,

0 commit comments

Comments
 (0)