Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add thumbnail position #104

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -659,11 +659,13 @@ impl Application for App {
fn view_window(&self, id: iced::window::Id) -> cosmic::prelude::Element<Self::Message> {
use iced::widget::*;
if let Some(surface) = self.layer_surfaces.get(&id) {
return view::layer_surface(self, surface);
return view::layer_surface(self, surface, &self.conf.config);
}
if let Some((drag_id, drag_surface, size)) = &self.drag_surface {
if drag_id == &id {
if let Some(element) = view::drag_surface(self, drag_surface, *size) {
if let Some(element) =
view::drag_surface(self, drag_surface, *size, &self.conf.config)
{
return element;
}
}
Expand Down
76 changes: 51 additions & 25 deletions src/view/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,17 @@ use cosmic::{
widget,
};
use cosmic_bg_config::Source;
use cosmic_comp_config::workspace::WorkspaceLayout;
use cosmic_comp_config::workspace::{WorkspaceLayout, WorkspaceThumbnailPlacement};

use crate::{
backend::{self, CaptureImage},
App, DragSurface, LayerSurface, Msg, Toplevel, Workspace,
App, CosmicWorkspacesConfig, DragSurface, LayerSurface, Msg, Toplevel, Workspace,
};

pub(crate) fn layer_surface<'a>(
app: &'a App,
surface: &'a LayerSurface,
config: &CosmicWorkspacesConfig,
) -> cosmic::Element<'a, Msg> {
let mut drop_target = None;
if let Some((workspace, output)) = &app.drop_target {
Expand All @@ -37,13 +38,15 @@ pub(crate) fn layer_surface<'a>(
drag_toplevel = Some(handle);
}
let layout = app.conf.workspace_config.workspace_layout;
let placement = app.conf.workspace_config.workspace_thumbnail_placement;
let sidebar = workspaces_sidebar(
app.workspaces
.iter()
.filter(|i| i.outputs.contains(&surface.output)),
&surface.output,
layout,
drop_target,
config,
);
let toplevels = toplevel_previews(
app.toplevels.iter().filter(|i| {
Expand All @@ -60,19 +63,31 @@ pub(crate) fn layer_surface<'a>(
layout,
drag_toplevel,
);
let container = match layout {
WorkspaceLayout::Vertical => widget::layer_container(
let container = match placement {
WorkspaceThumbnailPlacement::Left => widget::layer_container(
row![sidebar, toplevels]
.spacing(12)
.height(iced::Length::Fill)
.width(iced::Length::Fill),
),
WorkspaceLayout::Horizontal => widget::layer_container(
WorkspaceThumbnailPlacement::Right => widget::layer_container(
row![toplevels, sidebar]
.spacing(12)
.height(iced::Length::Fill)
.width(iced::Length::Fill),
),
WorkspaceThumbnailPlacement::Top => widget::layer_container(
column![sidebar, toplevels]
.spacing(12)
.height(iced::Length::Fill)
.width(iced::Length::Fill),
),
WorkspaceThumbnailPlacement::Bottom => widget::layer_container(
column![toplevels, sidebar]
.spacing(12)
.height(iced::Length::Fill)
.width(iced::Length::Fill),
),
};
container.into()
}
Expand All @@ -81,11 +96,12 @@ pub(crate) fn drag_surface<'a>(
app: &'a App,
drag_surface: &DragSurface,
size: Size,
config: &CosmicWorkspacesConfig,
) -> Option<cosmic::Element<'a, Msg>> {
let item = match drag_surface {
DragSurface::Workspace { handle, output } => {
if let Some(workspace) = app.workspaces.iter().find(|x| &x.handle == handle) {
workspace_item(workspace, output, false)
workspace_item(workspace, output, false, config)
} else {
return None;
}
Expand Down Expand Up @@ -141,28 +157,36 @@ fn workspace_item<'a>(
workspace: &'a Workspace,
output: &wl_output::WlOutput,
is_drop_target: bool,
config: &CosmicWorkspacesConfig,
) -> cosmic::Element<'a, Msg> {
let image = capture_image(workspace.img_for_output.get(output), 1.0);
let is_active = workspace.is_active;
column![
// TODO editable name?
widget::button(column![image, widget::text(&workspace.name)])
.selected(workspace.is_active)
.style(cosmic::theme::Button::Custom {
active: Box::new(move |_focused, theme| workspace_item_appearance(
theme,
is_active,
is_drop_target
)),
disabled: Box::new(|_theme| { unreachable!() }),
hovered: Box::new(move |_focused, theme| workspace_item_appearance(
theme, is_active, true
)),
pressed: Box::new(move |_focused, theme| workspace_item_appearance(
theme, is_active, true
)),
})
.on_press(Msg::ActivateWorkspace(workspace.handle.clone())),
widget::button(
// FIXME currently, the namespace number is used as name, so display the workspace label if either is enabled
if config.show_workspace_name || config.show_workspace_number {
column![image, widget::text(&workspace.name)].into()
} else {
image
}
)
.selected(workspace.is_active)
.style(cosmic::theme::Button::Custom {
active: Box::new(move |_focused, theme| workspace_item_appearance(
theme,
is_active,
is_drop_target
)),
disabled: Box::new(|_theme| { unreachable!() }),
hovered: Box::new(move |_focused, theme| workspace_item_appearance(
theme, is_active, true
)),
pressed: Box::new(move |_focused, theme| workspace_item_appearance(
theme, is_active, true
)),
})
.on_press(Msg::ActivateWorkspace(workspace.handle.clone())),
]
.spacing(4)
//.height(iced::Length::Fill)
Expand All @@ -173,6 +197,7 @@ fn workspace_sidebar_entry<'a>(
workspace: &'a Workspace,
output: &'a wl_output::WlOutput,
is_drop_target: bool,
config: &CosmicWorkspacesConfig,
) -> cosmic::Element<'a, Msg> {
/* XXX
let mouse_interaction = if is_drop_target {
Expand All @@ -198,7 +223,7 @@ fn workspace_sidebar_entry<'a>(
*/
//crate::widgets::mouse_interaction_wrapper(
// mouse_interaction,
iced::widget::dnd_listener(workspace_item(workspace, output, is_drop_target))
iced::widget::dnd_listener(workspace_item(workspace, output, is_drop_target, config))
.on_enter(|actions, mime, pos| {
Msg::DndWorkspaceEnter(workspace.handle.clone(), output.clone(), actions, mime, pos)
})
Expand All @@ -217,9 +242,10 @@ fn workspaces_sidebar<'a>(
output: &'a wl_output::WlOutput,
layout: WorkspaceLayout,
drop_target: Option<&backend::ZcosmicWorkspaceHandleV1>,
config: &CosmicWorkspacesConfig,
) -> cosmic::Element<'a, Msg> {
let sidebar_entries = workspaces
.map(|w| workspace_sidebar_entry(w, output, drop_target == Some(&w.handle)))
.map(|w| workspace_sidebar_entry(w, output, drop_target == Some(&w.handle), config))
.collect();
let axis = match layout {
WorkspaceLayout::Vertical => Axis::Vertical,
Expand Down