diff --git a/Cargo.lock b/Cargo.lock index 0e0a49e0..55b0ba95 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1462,7 +1462,7 @@ dependencies = [ [[package]] name = "cosmic-comp-config" version = "0.1.0" -source = "git+https://github.com/pop-os/cosmic-comp#90883c6ab12533da08a31da338881c38aa773634" +source = "git+https://github.com/pop-os/cosmic-comp#641bb75eb1a6449752d14b9776381a823999b85e" dependencies = [ "cosmic-config", "input", diff --git a/cosmic-settings/src/pages/desktop/workspaces.rs b/cosmic-settings/src/pages/desktop/workspaces.rs index 1ce5d835..e51c04d4 100644 --- a/cosmic-settings/src/pages/desktop/workspaces.rs +++ b/cosmic-settings/src/pages/desktop/workspaces.rs @@ -18,6 +18,8 @@ use slab::Slab; use slotmap::SlotMap; use tracing::error; +use crate::utils::system_has_touchpad; + #[derive(Clone, Debug)] pub enum Message { SetWorkspaceMode(WorkspaceMode), @@ -162,7 +164,8 @@ impl page::Page for Page { sections: &mut SlotMap>, ) -> Option { Some(vec![ - sections.insert(multi_behavior()), + // FIXME currently unsupported by cosmic-comp + // sections.insert(multi_behavior()), sections.insert(workspace_orientation()), sections.insert(workspace_overview()), ]) @@ -386,89 +389,61 @@ fn workspace_orientation() -> Section { ) .spacing(cosmic::theme::active().cosmic().space_m()) .align_x(Alignment::Center), - ) - .add(settings::item( - &descriptions[thumbnail_placement_label], - thumbnail_placement, - )) - .add( - cosmic::iced::widget::MouseArea::new(settings::item( - &descriptions[trackpad_gestures], - cosmic::iced::widget::container( - icon::from_name(if page.show_trackpad_gesture { - "go-up-symbolic" - } else { - "go-down-symbolic" - }) - .size(16), - ) - .width(Length::Shrink), - )) - .on_press(Message::ShowTrackpadGestureInfo( - !page.show_trackpad_gesture, - )), ); - if page.show_trackpad_gesture { - let (switch_ws, open_ws, open_app) = - match page.comp_workspace_config.workspace_layout { - WorkspaceLayout::Vertical => ( - asset_handle(Asset::TrackpadGestureSwipeVertical), - asset_handle(Asset::TrackpadGestureSwipeLeft), - asset_handle(Asset::TrackpadGestureSwipeRight), - ), - WorkspaceLayout::Horizontal => ( - asset_handle(Asset::TrackpadGestureSwipeHorizontal), - asset_handle(Asset::TrackpadGestureSwipeUp), - asset_handle(Asset::TrackpadGestureSwipeDown), - ), - }; - let (switch_ws_label, open_ws_label, open_app_label) = - match page.comp_workspace_config.workspace_layout { - WorkspaceLayout::Vertical => (swipe_vertical, swipe_left, swipe_right), - WorkspaceLayout::Horizontal => (swipe_horizontal, swipe_up, swipe_down), - }; - section = section.add( - cosmic::widget::list_column() - .padding([0, 32]) - .add( - cosmic::iced::widget::row!( - text(&descriptions[switch_workspace]), - cosmic::iced::widget::horizontal_space().width(2), - text(&descriptions[switch_ws_label]).font(cosmic::font::bold()), - cosmic::iced::widget::horizontal_space().width(Length::Fill), - cosmic::iced::widget::container(cosmic::iced::widget::svg( - switch_ws - )) - .width(115) - .height(92) - ) - .width(Length::Fill) - .align_y(Alignment::Center) - .padding([0, 16]), - ) - .add( - cosmic::iced::widget::row!( - text(&descriptions[open_workspaces]), - cosmic::iced::widget::horizontal_space().width(2), - text(&descriptions[open_ws_label]).font(cosmic::font::bold()), - cosmic::iced::widget::horizontal_space().width(Length::Fill), - cosmic::iced::widget::container(cosmic::iced::widget::svg(open_ws)) - .width(115) - .height(92) + // FIXME currently unsupported by cosmic-comp + // .add(settings::item( + // &descriptions[thumbnail_placement_label], + // thumbnail_placement, + // )); + if system_has_touchpad() { + section = section + .add( + cosmic::iced::widget::MouseArea::new(settings::item( + &descriptions[trackpad_gestures], + cosmic::iced::widget::container( + icon::from_name(if page.show_trackpad_gesture { + "go-up-symbolic" + } else { + "go-down-symbolic" + }) + .size(16), ) - .width(Length::Fill) - .align_y(Alignment::Center) - .padding([0, 16]), - ) - .add( - cosmic::widget::list_column().add( + .width(Length::Shrink), + )) + .on_press(Message::ShowTrackpadGestureInfo( + !page.show_trackpad_gesture, + )), + ); + if page.show_trackpad_gesture { + let (switch_ws, open_ws, open_app) = + match page.comp_workspace_config.workspace_layout { + WorkspaceLayout::Vertical => ( + asset_handle(Asset::TrackpadGestureSwipeVertical), + asset_handle(Asset::TrackpadGestureSwipeLeft), + asset_handle(Asset::TrackpadGestureSwipeRight), + ), + WorkspaceLayout::Horizontal => ( + asset_handle(Asset::TrackpadGestureSwipeHorizontal), + asset_handle(Asset::TrackpadGestureSwipeUp), + asset_handle(Asset::TrackpadGestureSwipeDown), + ), + }; + let (switch_ws_label, open_ws_label, open_app_label) = + match page.comp_workspace_config.workspace_layout { + WorkspaceLayout::Vertical => (swipe_vertical, swipe_left, swipe_right), + WorkspaceLayout::Horizontal => (swipe_horizontal, swipe_up, swipe_down), + }; + section = section.add( + cosmic::widget::list_column() + .padding([0, 32]) + .add( cosmic::iced::widget::row!( - text(&descriptions[open_applications]), + text(&descriptions[switch_workspace]), cosmic::iced::widget::horizontal_space().width(2), - text(&descriptions[open_app_label]).font(cosmic::font::bold()), + text(&descriptions[switch_ws_label]).font(cosmic::font::bold()), cosmic::iced::widget::horizontal_space().width(Length::Fill), cosmic::iced::widget::container(cosmic::iced::widget::svg( - open_app + switch_ws )) .width(115) .height(92) @@ -476,9 +451,41 @@ fn workspace_orientation() -> Section { .width(Length::Fill) .align_y(Alignment::Center) .padding([0, 16]), + ) + .add( + cosmic::iced::widget::row!( + text(&descriptions[open_workspaces]), + cosmic::iced::widget::horizontal_space().width(2), + text(&descriptions[open_ws_label]).font(cosmic::font::bold()), + cosmic::iced::widget::horizontal_space().width(Length::Fill), + cosmic::iced::widget::container(cosmic::iced::widget::svg(open_ws)) + .width(115) + .height(92) + ) + .width(Length::Fill) + .align_y(Alignment::Center) + .padding([0, 16]), + ) + .add( + cosmic::widget::list_column().add( + cosmic::iced::widget::row!( + text(&descriptions[open_applications]), + cosmic::iced::widget::horizontal_space().width(2), + text(&descriptions[open_app_label]).font(cosmic::font::bold()), + cosmic::iced::widget::horizontal_space().width(Length::Fill), + cosmic::iced::widget::container(cosmic::iced::widget::svg( + open_app + )) + .width(115) + .height(92) + ) + .width(Length::Fill) + .align_y(Alignment::Center) + .padding([0, 16]), + ), ), - ), - ); + ); + } } section diff --git a/cosmic-settings/src/pages/input/mod.rs b/cosmic-settings/src/pages/input/mod.rs index e1573907..a0663b30 100644 --- a/cosmic-settings/src/pages/input/mod.rs +++ b/cosmic-settings/src/pages/input/mod.rs @@ -1,4 +1,4 @@ -use crate::app; +use crate::{app, utils::system_has_touchpad}; use cosmic::{ cosmic_config::{self, ConfigGet, ConfigSet}, Task, @@ -200,22 +200,3 @@ impl page::AutoBind for Page { } } } - -/// Uses `udev` to check if a touchpad device exists on the system. -fn system_has_touchpad() -> bool { - let Ok(mut enumerator) = udev::Enumerator::new() else { - return false; - }; - - let _res = enumerator.match_subsystem("input"); - - let Ok(mut devices) = enumerator.scan_devices() else { - return false; - }; - - devices.any(|device| { - device - .property_value("ID_INPUT_TOUCHPAD") - .map_or(false, |value| value == "1") - }) -} diff --git a/cosmic-settings/src/utils.rs b/cosmic-settings/src/utils.rs index 7fe5c186..e917c58d 100644 --- a/cosmic-settings/src/utils.rs +++ b/cosmic-settings/src/utils.rs @@ -58,6 +58,25 @@ pub fn map_stderr_output(result: io::Result) -> Result<(), Stri }) } +/// Uses `udev` to check if a touchpad device exists on the system. +pub fn system_has_touchpad() -> bool { + let Ok(mut enumerator) = udev::Enumerator::new() else { + return false; + }; + + let _res = enumerator.match_subsystem("input"); + + let Ok(mut devices) = enumerator.scan_devices() else { + return false; + }; + + devices.any(|device| { + device + .property_value("ID_INPUT_TOUCHPAD") + .map_or(false, |value| value == "1") + }) +} + /// Creates a slab with predefined items #[macro_export] macro_rules! slab {