Fix build on wayland and no display backend
This commit is contained in:
parent
cff2f6beb8
commit
186c284a1a
4 changed files with 118 additions and 98 deletions
|
@ -348,6 +348,7 @@ fn initialize_window(
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Apply the provided window-positioning rules to the window.
|
/// Apply the provided window-positioning rules to the window.
|
||||||
|
#[cfg(feature = "x11")]
|
||||||
fn apply_window_position(
|
fn apply_window_position(
|
||||||
mut window_geometry: WindowGeometry,
|
mut window_geometry: WindowGeometry,
|
||||||
monitor_geometry: gdk::Rectangle,
|
monitor_geometry: gdk::Rectangle,
|
||||||
|
|
|
@ -2,27 +2,27 @@ pub use platform::*;
|
||||||
|
|
||||||
#[cfg(feature = "no-x11-wayland")]
|
#[cfg(feature = "no-x11-wayland")]
|
||||||
mod platform {
|
mod platform {
|
||||||
use crate::config::{EwwWindowDefinition, StrutDefinition, WindowStacking};
|
use crate::config::EwwWindowDefinition;
|
||||||
use anyhow::*;
|
|
||||||
use gtk::{self, prelude::*};
|
|
||||||
|
|
||||||
pub fn initialize_window(window_def: &EwwWindowDefinition, _monitor: gdk::Rectangle) -> Option<gtk::Window> {
|
pub fn initialize_window(_window_def: &EwwWindowDefinition, _monitor: gdk::Rectangle) -> Option<gtk::Window> {
|
||||||
Some(gtk::Window::new(gtk::WindowType::Toplevel))
|
Some(gtk::Window::new(gtk::WindowType::Toplevel))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "wayland")]
|
#[cfg(feature = "wayland")]
|
||||||
mod platform {
|
mod platform {
|
||||||
use crate::config::{AnchorAlignment, EwwWindowDefinition, WindowStacking};
|
|
||||||
use gdk;
|
use gdk;
|
||||||
use gtk::prelude::*;
|
use gtk::prelude::*;
|
||||||
|
use yuck::config::{window_definition::WindowStacking, window_geometry::AnchorAlignment};
|
||||||
|
|
||||||
|
use crate::config::EwwWindowDefinition;
|
||||||
|
|
||||||
pub fn initialize_window(window_def: &EwwWindowDefinition, monitor: gdk::Rectangle) -> Option<gtk::Window> {
|
pub fn initialize_window(window_def: &EwwWindowDefinition, monitor: gdk::Rectangle) -> Option<gtk::Window> {
|
||||||
let window = gtk::Window::new(gtk::WindowType::Toplevel);
|
let window = gtk::Window::new(gtk::WindowType::Toplevel);
|
||||||
// Initialising a layer shell surface
|
// Initialising a layer shell surface
|
||||||
gtk_layer_shell::init_for_window(&window);
|
gtk_layer_shell::init_for_window(&window);
|
||||||
// Sets the monitor where the surface is shown
|
// Sets the monitor where the surface is shown
|
||||||
match window_def.screen_number {
|
match window_def.monitor_number {
|
||||||
Some(index) => {
|
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);
|
gtk_layer_shell::set_monitor(&window, &monitor);
|
||||||
|
|
|
@ -6,6 +6,12 @@ edition = "2018"
|
||||||
|
|
||||||
build = "build.rs"
|
build = "build.rs"
|
||||||
|
|
||||||
|
[features]
|
||||||
|
default = ["x11"]
|
||||||
|
x11 = []
|
||||||
|
wayland = []
|
||||||
|
no-x11-wayland = []
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
lalrpop-util = "0.19.5"
|
lalrpop-util = "0.19.5"
|
||||||
regex = "1"
|
regex = "1"
|
||||||
|
|
|
@ -12,39 +12,43 @@ use eww_shared_util::Span;
|
||||||
|
|
||||||
use super::{attributes::Attributes, window_definition::EnumParseError};
|
use super::{attributes::Attributes, window_definition::EnumParseError};
|
||||||
|
|
||||||
pub type BackendWindowOptions = X11WindowOptions;
|
pub use backend::*;
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize)]
|
#[cfg(feature = "x11")]
|
||||||
pub struct X11WindowOptions {
|
mod backend {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize)]
|
||||||
|
pub struct BackendWindowOptions {
|
||||||
pub wm_ignore: bool,
|
pub wm_ignore: bool,
|
||||||
pub sticky: bool,
|
pub sticky: bool,
|
||||||
pub window_type: WindowType,
|
pub window_type: WindowType,
|
||||||
pub struts: StrutDefinition,
|
pub struts: StrutDefinition,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl X11WindowOptions {
|
impl BackendWindowOptions {
|
||||||
pub fn from_attrs(attrs: &mut Attributes) -> AstResult<Self> {
|
pub fn from_attrs(attrs: &mut Attributes) -> AstResult<Self> {
|
||||||
let struts = attrs.ast_optional("reserve")?;
|
let struts = attrs.ast_optional("reserve")?;
|
||||||
let window_type = attrs.primitive_optional("windowtype")?;
|
let window_type = attrs.primitive_optional("windowtype")?;
|
||||||
Ok(X11WindowOptions {
|
Ok(Self {
|
||||||
wm_ignore: attrs.primitive_optional("wm-ignore")?.unwrap_or(window_type.is_none() && struts.is_none()),
|
wm_ignore: attrs.primitive_optional("wm-ignore")?.unwrap_or(window_type.is_none() && struts.is_none()),
|
||||||
window_type: window_type.unwrap_or_default(),
|
window_type: window_type.unwrap_or_default(),
|
||||||
sticky: attrs.primitive_optional("sticky")?.unwrap_or(true),
|
sticky: attrs.primitive_optional("sticky")?.unwrap_or(true),
|
||||||
struts: struts.unwrap_or_default(),
|
struts: struts.unwrap_or_default(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, smart_default::SmartDefault, serde::Serialize)]
|
#[derive(Debug, Clone, PartialEq, Eq, smart_default::SmartDefault, serde::Serialize)]
|
||||||
pub enum WindowType {
|
pub enum WindowType {
|
||||||
#[default]
|
#[default]
|
||||||
Dock,
|
Dock,
|
||||||
Dialog,
|
Dialog,
|
||||||
Toolbar,
|
Toolbar,
|
||||||
Normal,
|
Normal,
|
||||||
Utility,
|
Utility,
|
||||||
}
|
}
|
||||||
impl FromStr for WindowType {
|
impl FromStr for WindowType {
|
||||||
type Err = EnumParseError;
|
type Err = EnumParseError;
|
||||||
|
|
||||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||||
|
@ -56,18 +60,18 @@ impl FromStr for WindowType {
|
||||||
"utility" => Self::Utility,
|
"utility" => Self::Utility,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, Eq, PartialEq, smart_default::SmartDefault, serde::Serialize)]
|
#[derive(Debug, Clone, Copy, Eq, PartialEq, smart_default::SmartDefault, serde::Serialize)]
|
||||||
pub enum Side {
|
pub enum Side {
|
||||||
#[default]
|
#[default]
|
||||||
Top,
|
Top,
|
||||||
Left,
|
Left,
|
||||||
Right,
|
Right,
|
||||||
Bottom,
|
Bottom,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::str::FromStr for Side {
|
impl std::str::FromStr for Side {
|
||||||
type Err = EnumParseError;
|
type Err = EnumParseError;
|
||||||
|
|
||||||
fn from_str(s: &str) -> Result<Side, Self::Err> {
|
fn from_str(s: &str) -> Result<Side, Self::Err> {
|
||||||
|
@ -78,16 +82,16 @@ impl std::str::FromStr for Side {
|
||||||
"b" | "bottom" => Side::Bottom,
|
"b" | "bottom" => Side::Bottom,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Surface definition if the backend for X11 is enable
|
// Surface definition if the backend for X11 is enable
|
||||||
#[derive(Debug, Clone, Copy, Eq, PartialEq, Default, serde::Serialize)]
|
#[derive(Debug, Clone, Copy, Eq, PartialEq, Default, serde::Serialize)]
|
||||||
pub struct StrutDefinition {
|
pub struct StrutDefinition {
|
||||||
pub side: Side,
|
pub side: Side,
|
||||||
pub dist: NumWithUnit,
|
pub dist: NumWithUnit,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromAstElementContent for StrutDefinition {
|
impl FromAstElementContent for StrutDefinition {
|
||||||
fn get_element_name() -> &'static str {
|
fn get_element_name() -> &'static str {
|
||||||
"struts"
|
"struts"
|
||||||
}
|
}
|
||||||
|
@ -96,26 +100,35 @@ impl FromAstElementContent for StrutDefinition {
|
||||||
let mut attrs = iter.expect_key_values()?;
|
let mut attrs = iter.expect_key_values()?;
|
||||||
Ok(StrutDefinition { side: attrs.primitive_required("side")?, dist: attrs.primitive_required("distance")? })
|
Ok(StrutDefinition { side: attrs.primitive_required("side")?, dist: attrs.primitive_required("distance")? })
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize)]
|
#[cfg(feature = "wayland")]
|
||||||
pub struct WaylandWindowOptions {
|
mod backend {
|
||||||
|
use super::*;
|
||||||
|
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize)]
|
||||||
|
pub struct BackendWindowOptions {
|
||||||
pub exclusive: bool,
|
pub exclusive: bool,
|
||||||
pub focusable: bool,
|
pub focusable: bool,
|
||||||
}
|
}
|
||||||
impl WaylandWindowOptions {
|
impl BackendWindowOptions {
|
||||||
pub fn from_attrs(attrs: &mut Attributes) -> AstResult<Self> {
|
pub fn from_attrs(attrs: &mut Attributes) -> AstResult<Self> {
|
||||||
Ok(WaylandWindowOptions {
|
Ok(Self {
|
||||||
exclusive: attrs.primitive_optional("exclusive")?.unwrap_or(false),
|
exclusive: attrs.primitive_optional("exclusive")?.unwrap_or(false),
|
||||||
focusable: attrs.primitive_optional("focusable")?.unwrap_or(false),
|
focusable: attrs.primitive_optional("focusable")?.unwrap_or(false),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize)]
|
|
||||||
pub struct NoBackendWindowOptions;
|
#[cfg(feature = "no-x11-wayland")]
|
||||||
impl NoBackendWindowOptions {
|
mod backend {
|
||||||
pub fn from_attrs(attrs: &mut Attributes) -> Result<Self> {
|
use super::*;
|
||||||
Ok(NoBackendWindowOptions)
|
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize)]
|
||||||
|
pub struct BackendWindowOptions;
|
||||||
|
impl BackendWindowOptions {
|
||||||
|
pub fn from_attrs(attrs: &mut Attributes) -> AstResult<Self> {
|
||||||
|
Ok(Self)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue