diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c36d37b..531c877 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -21,12 +21,12 @@ jobs: toolchain: nightly override: true components: rustfmt - - uses: actions/checkout@v2 + - uses: Swatinem/rust-cache@v1 - name: Build x11 - run: cargo --no-default-features --features=x11 check + run: cargo check --no-default-features --features=x11 - name: Build wayland - run: cargo --no-default-features --features=wayland check + run: cargo check --no-default-features --features=wayland - name: Build no-x11-wayland - run: cargo --no-default-features --features=no-x11-wayland check + run: cargo check --no-default-features --features=no-x11-wayland diff --git a/gen-docs.ts b/gen-docs.ts index 17cf195..f274c09 100644 --- a/gen-docs.ts +++ b/gen-docs.ts @@ -15,9 +15,9 @@ interface Widget { function parseVars(code: string): Record { const VAR_PATTERN = /^.*\/\/+ *@var +(.*?) +- +(.*)$/; const vars: Record = {}; - + for (const line of code.split("\n")) { - + const match = line.match(VAR_PATTERN); if (match && match.length == 3) { const name = match[1]; @@ -50,12 +50,12 @@ function parseDocs(code: string) { const ARG_TYPE_PATTERN = /(\w+):\s+as_(\w+)/g; const widgets: Record = {}; - const lines = code.split("\n") - + const lines = code.split("\n") + let currentWidget = ""; - + for (let lineIndex = 0; lineIndex < lines.length; lineIndex++) { - + const line = lines[lineIndex] const newWidgetMatch = NEW_WIDGET_PATTERN.exec(line); @@ -85,13 +85,13 @@ function parseDocs(code: string) { const propMatch = line.match(PROP_PATTERN); if (propMatch && propMatch.length == 3) { let no = lineIndex + 1 - + while (/\s*\/\//.test(lines[no])) { no += 1 } // continue till you find the line with actual code - + const matches = [...lines[no].matchAll(ARG_TYPE_PATTERN)].map(z => { z.shift(); return z }).flat() // try to use the iterator directly - + const possibleMatch = matches.findIndex(x => x == propMatch[1].replaceAll("-", "_")) if (possibleMatch == -1) { console.log(`Failed to find a match for "${propMatch[1].replace("-", "_")}" ~ ${JSON.stringify(matches, null, 2)} ~ ${lines[no]}`) diff --git a/src/config/window_definition.rs b/src/config/window_definition.rs index 2dccd1e..934efcb 100644 --- a/src/config/window_definition.rs +++ b/src/config/window_definition.rs @@ -9,7 +9,6 @@ use super::*; /// Full window-definition containing the fully expanded widget tree. /// **Use this** rather than `[RawEwwWindowDefinition]`. -#[cfg(feature = "x11")] #[derive(Debug, Clone)] pub struct EwwWindowDefinition { pub name: WindowName, @@ -17,20 +16,13 @@ pub struct EwwWindowDefinition { pub stacking: WindowStacking, pub screen_number: Option, pub widget: Box, - pub struts: StrutDefinition, pub focusable: bool, -} -#[cfg(feature = "wayland")] -#[derive(Debug, Clone)] -pub struct EwwWindowDefinition { - pub name: WindowName, - pub geometry: EwwWindowGeometry, - pub stacking: WindowStacking, - pub screen_number: Option, - pub widget: Box, + #[cfg(feature = "x11")] + pub struts: StrutDefinition, + + #[cfg(feature = "wayland")] pub exclusive: bool, - pub focusable: bool, } impl EwwWindowDefinition { @@ -51,7 +43,6 @@ impl EwwWindowDefinition { } /// Window-definition storing the raw WidgetUse, as received directly from parsing. -#[cfg(feature = "x11")] #[derive(Debug, Clone, PartialEq)] pub struct RawEwwWindowDefinition { pub name: WindowName, @@ -59,20 +50,13 @@ pub struct RawEwwWindowDefinition { pub stacking: WindowStacking, pub screen_number: Option, pub widget: WidgetUse, - pub struts: StrutDefinition, pub focusable: bool, -} -#[cfg(feature = "wayland")] -#[derive(Debug, Clone, PartialEq)] -pub struct RawEwwWindowDefinition { - pub name: WindowName, + #[cfg(feature = "x11")] + pub struts: StrutDefinition, + + #[cfg(feature = "wayland")] pub exclusive: bool, - pub geometry: EwwWindowGeometry, - pub stacking: WindowStacking, - pub screen_number: Option, - pub widget: WidgetUse, - pub focusable: bool, } impl RawEwwWindowDefinition { @@ -118,7 +102,6 @@ pub enum Side { impl std::str::FromStr for Side { type Err = anyhow::Error; - #[cfg(feature = "x11")] fn from_str(s: &str) -> Result { match s { "l" | "left" => Ok(Side::Left), @@ -131,14 +114,12 @@ impl std::str::FromStr for Side { } // Surface definition if the backend for X11 is enable -#[cfg(feature = "x11")] #[derive(Debug, Clone, Copy, Eq, PartialEq, Default)] pub struct StrutDefinition { pub side: Side, pub dist: NumWithUnit, } -#[cfg(feature = "x11")] impl StrutDefinition { pub fn from_xml_element(xml: XmlElement) -> Result { Ok(StrutDefinition { side: xml.attr("side")?.parse()?, dist: xml.attr("distance")?.parse()? }) @@ -157,7 +138,7 @@ pub enum WindowStacking { impl std::str::FromStr for WindowStacking { type Err = anyhow::Error; - #[cfg(feature = "x11")] + #[cfg(not(feature = "wayland"))] fn from_str(s: &str) -> Result { let s = s.to_lowercase(); match s.as_str() { diff --git a/src/display_backend.rs b/src/display_backend.rs index 35a11e7..ba1ee7b 100644 --- a/src/display_backend.rs +++ b/src/display_backend.rs @@ -2,20 +2,38 @@ pub use platform::*; #[cfg(feature = "no-x11-wayland")] mod platform { - use crate::config::{Side, StrutDefinition}; + use crate::config::{EwwWindowDefinition, StrutDefinition, WindowStacking}; use anyhow::*; - pub fn reserve_space_for(window: >k::Window, monitor: gdk::Rectangle, strut_def: StrutDefinition) -> Result<()> { + use gtk::{self, prelude::*}; + + pub fn initialize_window(window_def: &mut EwwWindowDefinition, _monitor: gdk::Rectangle) -> gtk::Window { + let window = if window_def.focusable { + gtk::Window::new(gtk::WindowType::Toplevel) + } else { + gtk::Window::new(gtk::WindowType::Popup) + }; + window.set_resizable(true); + if !window_def.focusable { + window.set_type_hint(gdk::WindowTypeHint::Dock); + } + if window_def.stacking == WindowStacking::Foreground { + window.set_keep_above(true); + } else { + window.set_keep_below(true); + } + window + } + + pub fn reserve_space_for(_window: >k::Window, _monitor: gdk::Rectangle, _strut_def: StrutDefinition) -> Result<()> { Err(anyhow!("Cannot reserve space on non X11 or and wayland backends")) } } #[cfg(feature = "wayland")] mod platform { - use gdk; - use crate::{ - config::{EwwWindowDefinition, AnchorAlignment, Side, WindowStacking}, - }; + use crate::config::{AnchorAlignment, EwwWindowDefinition, Side, WindowStacking}; use anyhow::*; + use gdk; use gtk::prelude::*; pub fn initialize_window(window_def: &mut EwwWindowDefinition, monitor: gdk::Rectangle) -> gtk::Window { @@ -25,9 +43,7 @@ mod platform { // Sets the monitor where the surface is shown match window_def.screen_number { Some(index) => { - if let Some(monitor) = gdk::Display::get_default() - .expect("could not get default display") - .get_monitor(index) { + if let Some(monitor) = gdk::Display::get_default().expect("could not get default display").get_monitor(index) { gtk_layer_shell::set_monitor(&window, &monitor); }; }