Skip to content

Commit

Permalink
chore(Workspace): hide features unsupported by comp
Browse files Browse the repository at this point in the history
  • Loading branch information
acolombier committed Nov 8, 2024
1 parent 05e38a1 commit 6062fa2
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 101 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

167 changes: 87 additions & 80 deletions cosmic-settings/src/pages/desktop/workspaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -162,7 +164,8 @@ impl page::Page<crate::pages::Message> for Page {
sections: &mut SlotMap<section::Entity, Section<crate::pages::Message>>,
) -> Option<page::Content> {
Some(vec![
sections.insert(multi_behavior()),
// FIXME currently unsupported by cosmic-comp
// sections.insert(multi_behavior()),
sections.insert(workspace_orientation()),
sections.insert(workspace_overview()),
])
Expand Down Expand Up @@ -386,99 +389,103 @@ fn workspace_orientation() -> Section<crate::pages::Message> {
)
.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)
)
.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
Expand Down
21 changes: 1 addition & 20 deletions cosmic-settings/src/pages/input/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::app;
use crate::{app, utils::system_has_touchpad};
use cosmic::{
cosmic_config::{self, ConfigGet, ConfigSet},
Task,
Expand Down Expand Up @@ -200,22 +200,3 @@ impl page::AutoBind<crate::pages::Message> 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")
})
}
19 changes: 19 additions & 0 deletions cosmic-settings/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,25 @@ pub fn map_stderr_output(result: io::Result<process::Output>) -> 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 {
Expand Down

0 comments on commit 6062fa2

Please sign in to comment.