Merge pull request #10 from xsoder/master
Browse files
Implementation of Full screen mode
+8 −7 src/config.rs
| @@ -14,12 +14,12 @@ pub const FONT: &str = "JetBrainsMono Nerd Font:style=Bold:size=12"; | |||
| 14 | // ======================================== | 14 | // ======================================== |
| 15 | // GAPS (Vanity Gaps) | 15 | // GAPS (Vanity Gaps) |
| 16 | // ======================================== | 16 | // ======================================== |
| 17 | -pub const GAPS_ENABLED: bool = true; | 17 | +pub const GAPS_ENABLED: bool = false; |
| 18 | -pub const GAP_INNER_HORIZONTAL: u32 = 6; | 18 | +pub const GAP_INNER_HORIZONTAL: u32 = 3; |
| 19 | -pub const GAP_INNER_VERTICAL: u32 = 6; | 19 | +pub const GAP_INNER_VERTICAL: u32 = 3; |
| 20 | -pub const GAP_OUTER_HORIZONTAL: u32 = 6; | 20 | +pub const GAP_OUTER_HORIZONTAL: u32 = 3; |
| 21 | -pub const GAP_OUTER_VERTICAL: u32 = 6; | 21 | +pub const GAP_OUTER_VERTICAL: u32 = 3; |
| 22 | - | 22 | +// |
| 23 | // ======================================== | 23 | // ======================================== |
| 24 | // DEFAULTS | 24 | // DEFAULTS |
| 25 | // ======================================== | 25 | // ======================================== |
| @@ -83,7 +83,7 @@ const DMENU_CMD: &[&str] = &["sh", "-c", "dmenu_run -l 10"]; | |||
| 83 | // ======================================== | 83 | // ======================================== |
| 84 | pub const TAG_COUNT: usize = 9; | 84 | pub const TAG_COUNT: usize = 9; |
| 85 | pub const TAGS: [&str; TAG_COUNT] = ["1", "2", "3", "4", "5", "6", "7", "8", "9"]; | 85 | pub const TAGS: [&str; TAG_COUNT] = ["1", "2", "3", "4", "5", "6", "7", "8", "9"]; |
| 86 | -// pub const TAGS: [&str; TAG_COUNT] = ["", "", "", "", "", "", "", "", ""]; | 86 | +//pub const TAGS: [&str; TAG_COUNT] = ["", "", "", "", "", "", "", "", ""]; |
| 87 | // pub const TAGS: [&str; TAG_COUNT] = [ | 87 | // pub const TAGS: [&str; TAG_COUNT] = [ |
| 88 | // "DEV", "WWW", "SYS", "DOC", "VBOX", "CHAT", "MUS", "VID", "MISC", | 88 | // "DEV", "WWW", "SYS", "DOC", "VBOX", "CHAT", "MUS", "VID", "MISC", |
| 89 | // ]; | 89 | // ]; |
| @@ -99,6 +99,7 @@ pub const KEYBINDINGS: &[Key] = &[ | |||
| 99 | Key::new(&[MODKEY], keycodes::S, KeyAction::Spawn, Arg::Array(SCREENSHOT_CMD)), | 99 | Key::new(&[MODKEY], keycodes::S, KeyAction::Spawn, Arg::Array(SCREENSHOT_CMD)), |
| 100 | Key::new(&[MODKEY], keycodes::D, KeyAction::Spawn, Arg::Array(DMENU_CMD)), | 100 | Key::new(&[MODKEY], keycodes::D, KeyAction::Spawn, Arg::Array(DMENU_CMD)), |
| 101 | Key::new(&[MODKEY], keycodes::Q, KeyAction::KillClient, Arg::None), | 101 | Key::new(&[MODKEY], keycodes::Q, KeyAction::KillClient, Arg::None), |
| 102 | + Key::new(&[MODKEY, SHIFT], keycodes::F, KeyAction::ToggleFullScreen, Arg::None), | ||
| 102 | Key::new(&[MODKEY], keycodes::A, KeyAction::ToggleGaps, Arg::None), | 103 | Key::new(&[MODKEY], keycodes::A, KeyAction::ToggleGaps, Arg::None), |
| 103 | Key::new(&[MODKEY, SHIFT], keycodes::Q, KeyAction::Quit, Arg::None), | 104 | Key::new(&[MODKEY, SHIFT], keycodes::Q, KeyAction::Quit, Arg::None), |
| 104 | Key::new(&[MODKEY, SHIFT], keycodes::R, KeyAction::Restart, Arg::None), | 105 | Key::new(&[MODKEY, SHIFT], keycodes::R, KeyAction::Restart, Arg::None), |
+1 −0 src/keyboard/handlers.rs
| @@ -12,6 +12,7 @@ pub enum KeyAction { | |||
| 12 | Restart, | 12 | Restart, |
| 13 | ViewTag, | 13 | ViewTag, |
| 14 | ToggleGaps, | 14 | ToggleGaps, |
| 15 | + ToggleFullScreen, | ||
| 15 | MoveToTag, | 16 | MoveToTag, |
| 16 | None, | 17 | None, |
| 17 | } | 18 | } |
+54 −2 src/keyboard/keycodes.rs
| @@ -1,6 +1,5 @@ | |||
| 1 | #![allow(dead_code)] | 1 | #![allow(dead_code)] |
| 2 | // Allowing dead code here because its just a file for potential keybinds | 2 | // Allowing dead code here because its just a file for potential keybinds |
| 3 | - | ||
| 4 | pub const RETURN: u8 = 36; | 3 | pub const RETURN: u8 = 36; |
| 5 | pub const Q: u8 = 24; | 4 | pub const Q: u8 = 24; |
| 6 | pub const ESCAPE: u8 = 9; | 5 | pub const ESCAPE: u8 = 9; |
| @@ -9,20 +8,49 @@ pub const TAB: u8 = 23; | |||
| 9 | pub const BACKSPACE: u8 = 22; | 8 | pub const BACKSPACE: u8 = 22; |
| 10 | pub const DELETE: u8 = 119; | 9 | pub const DELETE: u8 = 119; |
| 11 | 10 | ||
| 11 | +// Function Keys | ||
| 12 | pub const F1: u8 = 67; | 12 | pub const F1: u8 = 67; |
| 13 | pub const F2: u8 = 68; | 13 | pub const F2: u8 = 68; |
| 14 | pub const F3: u8 = 69; | 14 | pub const F3: u8 = 69; |
| 15 | pub const F4: u8 = 70; | 15 | pub const F4: u8 = 70; |
| 16 | +pub const F5: u8 = 71; | ||
| 17 | +pub const F6: u8 = 72; | ||
| 18 | +pub const F7: u8 = 73; | ||
| 19 | +pub const F8: u8 = 74; | ||
| 20 | +pub const F9: u8 = 75; | ||
| 21 | +pub const F10: u8 = 76; | ||
| 22 | +pub const F11: u8 = 95; | ||
| 23 | +pub const F12: u8 = 96; | ||
| 16 | 24 | ||
| 25 | +// Letters | ||
| 17 | pub const A: u8 = 38; | 26 | pub const A: u8 = 38; |
| 18 | -pub const S: u8 = 39; | 27 | +pub const B: u8 = 56; |
| 28 | +pub const C: u8 = 54; | ||
| 19 | pub const D: u8 = 40; | 29 | pub const D: u8 = 40; |
| 30 | +pub const E: u8 = 26; | ||
| 20 | pub const F: u8 = 41; | 31 | pub const F: u8 = 41; |
| 32 | +pub const G: u8 = 42; | ||
| 33 | +pub const H: u8 = 43; | ||
| 34 | +pub const I: u8 = 31; | ||
| 21 | pub const J: u8 = 44; | 35 | pub const J: u8 = 44; |
| 22 | pub const K: u8 = 45; | 36 | pub const K: u8 = 45; |
| 23 | pub const L: u8 = 46; | 37 | pub const L: u8 = 46; |
| 38 | +pub const M: u8 = 58; | ||
| 39 | +pub const N: u8 = 57; | ||
| 40 | +pub const O: u8 = 32; | ||
| 41 | +pub const P: u8 = 33; | ||
| 24 | pub const R: u8 = 27; | 42 | pub const R: u8 = 27; |
| 43 | +pub const S: u8 = 39; | ||
| 44 | +pub const T: u8 = 28; | ||
| 45 | +pub const U: u8 = 30; | ||
| 46 | +pub const V: u8 = 55; | ||
| 47 | +pub const W: u8 = 25; | ||
| 48 | +pub const X: u8 = 53; | ||
| 49 | +pub const Y: u8 = 29; | ||
| 50 | +pub const Z: u8 = 52; | ||
| 25 | 51 | ||
| 52 | +// Numbers | ||
| 53 | +pub const KEY_0: u8 = 19; | ||
| 26 | pub const KEY_1: u8 = 10; | 54 | pub const KEY_1: u8 = 10; |
| 27 | pub const KEY_2: u8 = 11; | 55 | pub const KEY_2: u8 = 11; |
| 28 | pub const KEY_3: u8 = 12; | 56 | pub const KEY_3: u8 = 12; |
| @@ -32,3 +60,27 @@ pub const KEY_6: u8 = 15; | |||
| 32 | pub const KEY_7: u8 = 16; | 60 | pub const KEY_7: u8 = 16; |
| 33 | pub const KEY_8: u8 = 17; | 61 | pub const KEY_8: u8 = 17; |
| 34 | pub const KEY_9: u8 = 18; | 62 | pub const KEY_9: u8 = 18; |
| 63 | + | ||
| 64 | +// Arrows | ||
| 65 | +pub const LEFT: u8 = 113; | ||
| 66 | +pub const RIGHT: u8 = 114; | ||
| 67 | +pub const UP: u8 = 111; | ||
| 68 | +pub const DOWN: u8 = 116; | ||
| 69 | +pub const HOME: u8 = 110; | ||
| 70 | +pub const END: u8 = 115; | ||
| 71 | +pub const PAGE_UP: u8 = 112; | ||
| 72 | +pub const PAGE_DOWN: u8 = 117; | ||
| 73 | +pub const INSERT: u8 = 118; | ||
| 74 | + | ||
| 75 | +// Symbols | ||
| 76 | +pub const MINUS: u8 = 20; | ||
| 77 | +pub const EQUAL: u8 = 21; | ||
| 78 | +pub const LEFT_BRACKET: u8 = 34; | ||
| 79 | +pub const RIGHT_BRACKET: u8 = 35; | ||
| 80 | +pub const SEMICOLON: u8 = 47; | ||
| 81 | +pub const APOSTROPHE: u8 = 48; | ||
| 82 | +pub const GRAVE: u8 = 49; | ||
| 83 | +pub const BACKSLASH: u8 = 51; | ||
| 84 | +pub const COMMA: u8 = 59; | ||
| 85 | +pub const PERIOD: u8 = 60; | ||
| 86 | +pub const SLASH: u8 = 61; | ||
+52 −0 src/window_manager.rs
| @@ -30,6 +30,7 @@ pub struct WindowManager { | |||
| 30 | window_tags: std::collections::HashMap<Window, TagMask>, | 30 | window_tags: std::collections::HashMap<Window, TagMask>, |
| 31 | selected_tags: TagMask, | 31 | selected_tags: TagMask, |
| 32 | gaps_enabled: bool, | 32 | gaps_enabled: bool, |
| 33 | + fullscreen_window: Option<Window>, | ||
| 33 | bar: Bar, | 34 | bar: Bar, |
| 34 | } | 35 | } |
| 35 | 36 | ||
| @@ -67,6 +68,7 @@ impl WindowManager { | |||
| 67 | window_tags: std::collections::HashMap::new(), | 68 | window_tags: std::collections::HashMap::new(), |
| 68 | selected_tags, | 69 | selected_tags, |
| 69 | gaps_enabled, | 70 | gaps_enabled, |
| 71 | + fullscreen_window: None, | ||
| 70 | bar, | 72 | bar, |
| 71 | }; | 73 | }; |
| 72 | 74 | ||
| @@ -278,6 +280,40 @@ impl WindowManager { | |||
| 278 | } | 280 | } |
| 279 | } | 281 | } |
| 280 | 282 | ||
| 283 | + fn toggle_fullscreen(&mut self) -> Result<()> { | ||
| 284 | + if let Some(focused) = self.focused_window { | ||
| 285 | + if self.fullscreen_window == Some(focused) { | ||
| 286 | + self.fullscreen_window = None; | ||
| 287 | + | ||
| 288 | + self.connection.map_window(self.bar.window())?; | ||
| 289 | + | ||
| 290 | + self.apply_layout()?; | ||
| 291 | + self.update_focus_visuals()?; | ||
| 292 | + } else { | ||
| 293 | + self.fullscreen_window = Some(focused); | ||
| 294 | + | ||
| 295 | + self.connection.unmap_window(self.bar.window())?; | ||
| 296 | + | ||
| 297 | + let screen_width = self.screen.width_in_pixels as u32; | ||
| 298 | + let screen_height = self.screen.height_in_pixels as u32; | ||
| 299 | + | ||
| 300 | + self.connection.configure_window( | ||
| 301 | + focused, | ||
| 302 | + &ConfigureWindowAux::new() | ||
| 303 | + .x(0) | ||
| 304 | + .y(0) | ||
| 305 | + .width(screen_width) | ||
| 306 | + .height(screen_height) | ||
| 307 | + .border_width(0) | ||
| 308 | + .stack_mode(StackMode::ABOVE), | ||
| 309 | + )?; | ||
| 310 | + | ||
| 311 | + self.connection.flush()?; | ||
| 312 | + } | ||
| 313 | + } | ||
| 314 | + Ok(()) | ||
| 315 | + } | ||
| 316 | + | ||
| 281 | fn update_bar(&mut self) -> Result<()> { | 317 | fn update_bar(&mut self) -> Result<()> { |
| 282 | let mut occupied_tags: TagMask = 0; | 318 | let mut occupied_tags: TagMask = 0; |
| 283 | for &tags in self.window_tags.values() { | 319 | for &tags in self.window_tags.values() { |
| @@ -315,6 +351,9 @@ impl WindowManager { | |||
| 315 | } | 351 | } |
| 316 | } | 352 | } |
| 317 | } | 353 | } |
| 354 | + KeyAction::ToggleFullScreen => { | ||
| 355 | + self.toggle_fullscreen()?; | ||
| 356 | + } | ||
| 318 | KeyAction::FocusStack => { | 357 | KeyAction::FocusStack => { |
| 319 | if let Arg::Int(direction) = arg { | 358 | if let Arg::Int(direction) = arg { |
| 320 | self.cycle_focus(*direction)?; | 359 | self.cycle_focus(*direction)?; |
| @@ -377,6 +416,11 @@ impl WindowManager { | |||
| 377 | return Ok(()); | 416 | return Ok(()); |
| 378 | } | 417 | } |
| 379 | 418 | ||
| 419 | + if self.fullscreen_window.is_some() { | ||
| 420 | + self.fullscreen_window = None; | ||
| 421 | + self.connection.map_window(self.bar.window())?; | ||
| 422 | + } | ||
| 423 | + | ||
| 380 | self.selected_tags = tag_mask(tag_index); | 424 | self.selected_tags = tag_mask(tag_index); |
| 381 | 425 | ||
| 382 | self.save_selected_tags()?; | 426 | self.save_selected_tags()?; |
| @@ -571,6 +615,9 @@ impl WindowManager { | |||
| 571 | } | 615 | } |
| 572 | 616 | ||
| 573 | fn apply_layout(&self) -> Result<()> { | 617 | fn apply_layout(&self) -> Result<()> { |
| 618 | + if self.fullscreen_window.is_some() { | ||
| 619 | + return Ok(()); | ||
| 620 | + } | ||
| 574 | let screen_width = self.screen.width_in_pixels as u32; | 621 | let screen_width = self.screen.width_in_pixels as u32; |
| 575 | let screen_height = self.screen.height_in_pixels as u32; | 622 | let screen_height = self.screen.height_in_pixels as u32; |
| 576 | let border_width = BORDER_WIDTH; | 623 | let border_width = BORDER_WIDTH; |
| @@ -623,6 +670,11 @@ impl WindowManager { | |||
| 623 | self.windows.retain(|&w| w != window); | 670 | self.windows.retain(|&w| w != window); |
| 624 | self.window_tags.remove(&window); | 671 | self.window_tags.remove(&window); |
| 625 | 672 | ||
| 673 | + if self.fullscreen_window == Some(window) { | ||
| 674 | + self.fullscreen_window = None; | ||
| 675 | + self.connection.map_window(self.bar.window())?; | ||
| 676 | + } | ||
| 677 | + | ||
| 626 | if self.windows.len() < initial_count { | 678 | if self.windows.len() < initial_count { |
| 627 | if self.focused_window == Some(window) { | 679 | if self.focused_window == Some(window) { |
| 628 | let new_focus = if self.windows.is_empty() { | 680 | let new_focus = if self.windows.is_empty() { |