feat: misc overflow

This commit is contained in:
Ashley Wulber 2024-07-12 16:30:50 -04:00 committed by Ashley Wulber
parent f46f50e8e2
commit 6661598839
17 changed files with 64 additions and 29 deletions

View file

@ -13,3 +13,4 @@ NoDisplay=true
X-CosmicApplet=true
# Indicates that the auto-hover click should go to the "end" of the hover popup
X-CosmicHoverPopup=End
X-OverflowPriority=10

View file

@ -6,26 +6,6 @@ mod mouse_area;
use crate::{localize::localize, pulse::DeviceInfo};
use config::AudioAppletConfig;
use cosmic::cctk::sctk::reexports::calloop;
use cosmic::cctk::sctk::reexports::protocols::xdg::shell::client::xdg_positioner::Anchor;
use cosmic::cosmic_config::CosmicConfigEntry;
use cosmic::iced::widget;
use cosmic::iced::Limits;
use cosmic::iced::Point;
use cosmic::iced::Rectangle;
use cosmic::iced::{
self,
widget::{column, row, slider, text},
window, Alignment, Length, Size, Subscription,
};
use cosmic::iced_runtime::core::alignment::Horizontal;
use cosmic::iced_style::application;
use cosmic::widget::button;
use cosmic::widget::horizontal_space;
use cosmic::widget::Column;
use cosmic::widget::Row;
use cosmic::widget::{divider, icon};
use cosmic::Renderer;
use cosmic::{
app::Command,
applet::{
@ -33,19 +13,18 @@ use cosmic::{
menu_button, menu_control_padding, padded_control,
token::subscription::{activation_token_subscription, TokenRequest, TokenUpdate},
},
cctk::sctk::reexports::calloop,
cctk::sctk::reexports::{calloop, protocols::xdg::shell::client::xdg_positioner::Anchor},
cosmic_config::CosmicConfigEntry,
iced::{
self, widget,
widget::{column, row, slider, text},
window, Alignment, Length, Limits, Subscription,
self,
widget::{self, column, row, slider, text},
window, Alignment, Length, Limits, Rectangle, Subscription,
},
iced_runtime::core::alignment::Horizontal,
iced_style::application,
widget::{button, divider, horizontal_space, icon, Column, Row},
Element, Renderer, Theme,
};
use cosmic::{Element, Theme};
use cosmic_settings_subscriptions::pulse as sub_pulse;
use cosmic_time::{anim, chain, id, once_cell::sync::Lazy, Instant, Timeline};
use iced::{
@ -708,7 +687,13 @@ impl cosmic::Application for Audio {
.clamp(0.0, 100.0);
Message::SetOutputVolume(new_volume)
});
if let Some(playback_buttons) = self.playback_buttons() {
let playback_buttons = (!self.core.applet.configure.as_ref().is_some_and(|c| {
// if we have a configure for width and height, we're in a overflow popup
c.new_size.0.is_some() && c.new_size.1.is_some()
}))
.then(|| self.playback_buttons());
if let Some(Some(playback_buttons)) = playback_buttons {
match self.core.applet.anchor {
PanelAnchor::Left | PanelAnchor::Right => {
Column::with_children(vec![playback_buttons, btn.into()])

View file

@ -12,3 +12,4 @@ StartupNotify=true
NoDisplay=true
X-CosmicApplet=true
X-CosmicHoverPopup=Start
X-OverflowPriority=10

View file

@ -658,7 +658,12 @@ impl cosmic::Application for CosmicBatteryApplet {
.into(),
);
if gpu.toggled {
if gpu.toggled
&& !self.core.applet.configure.as_ref().is_some_and(|c| {
// if we have a configure for width and height, we're in a overflow popup
c.new_size.0.is_some() && c.new_size.1.is_some()
})
{
let app_list = gpu.app_list.as_ref().unwrap();
let mut list_apps = Vec::with_capacity(app_list.len());
for app in app_list {

View file

@ -11,3 +11,4 @@ StartupNotify=true
NoDisplay=true
X-CosmicApplet=true
X-CosmicHoverPopup=Auto
X-OverflowPriority=10

View file

@ -11,3 +11,4 @@ StartupNotify=true
NoDisplay=true
X-CosmicApplet=true
X-CosmicHoverPopup=Auto
X-OverflowPriority=10

View file

@ -12,3 +12,4 @@ NoDisplay=true
X-CosmicApplet=true
X-MinimizeApplet=10
X-HostWaylandDisplay=true
X-OverflowPriority=50

View file

@ -11,3 +11,4 @@ StartupNotify=true
NoDisplay=true
X-CosmicApplet=true
X-CosmicHoverPopup=Auto
X-OverflowPriority=10

View file

@ -11,3 +11,4 @@ NoDisplay=true
X-CosmicApplet=true
X-NotificationsApplet=true
X-CosmicHoverPopup=Auto
X-OverflowPriority=10

View file

@ -11,3 +11,4 @@ StartupNotify=true
NoDisplay=true
X-CosmicApplet=true
X-CosmicHoverPopup=Auto
X-OverflowPriority=10

View file

@ -12,3 +12,4 @@ StartupNotify=true
NoDisplay=true
X-CosmicApplet=true
X-CosmicHoverPopup=Auto
X-OverflowPriority=10

View file

@ -11,4 +11,4 @@ NoDisplay=true
X-CosmicApplet=true
X-HostWaylandDisplay=true
X-CosmicHoverPopup=Auto
# No shrink priority, as this applet is always visible when configured

View file

@ -10,3 +10,5 @@ StartupNotify=true
NoDisplay=true
X-CosmicApplet=true
X-HostWaylandDisplay=true
X-OverflowPriority=5
X-OverflowMinSize=4

View file

@ -47,6 +47,33 @@ struct IcedWorkspacesApplet {
layout: Layout,
}
impl IcedWorkspacesApplet {
/// returns the index of the workspace button after which which must be moved to a popup
/// if it exists.
fn popup_index(&self) -> Option<usize> {
let mut index = None;
let Some(max_major_axis_len) = self.core.applet.configure.as_ref().and_then(|c| {
// if we have a configure for width and height, we're in a overflow popup
match self.core.applet.anchor {
PanelAnchor::Top | PanelAnchor::Bottom => c.new_size.0,
PanelAnchor::Left | PanelAnchor::Right => c.new_size.1,
}
}) else {
return index;
};
let button_total_size = self.core.applet.suggested_size(true).0
+ self.core.applet.suggested_padding(true) * 2
+ 4;
let btn_count = max_major_axis_len.get() / button_total_size as u32;
if btn_count >= self.workspaces.len() as u32 {
index = None;
} else {
index = Some((btn_count as usize).min(self.workspaces.len()));
}
index
}
}
#[derive(Debug, Clone)]
enum Message {
WorkspaceUpdate(WorkspacesUpdate),
@ -146,7 +173,9 @@ impl cosmic::Application for IcedWorkspacesApplet {
let suggested_total =
self.core.applet.suggested_size(true).0 + self.core.applet.suggested_padding(true) * 2;
let suggested_window_size = self.core.applet.suggested_window_size();
let buttons = self.workspaces.iter().filter_map(|w| {
let popup_index = self.popup_index().unwrap_or(self.workspaces.len());
let buttons = self.workspaces[..popup_index].iter().filter_map(|w| {
let content = self.core.applet.text(w.0.clone()).font(FONT_BOLD);
let (width, height) = if self.core.applet.is_horizontal() {
@ -245,6 +274,8 @@ impl cosmic::Application for IcedWorkspacesApplet {
.into(),
)
});
// TODO if there is a popup_index, create a button with a popup for the remaining workspaces
// Should it appear on hover or on click?
let layout_section: Element<_> = match self.layout {
Layout::Row => row(buttons).spacing(4).into(),
Layout::Column => column(buttons).spacing(4).into(),

View file

@ -15,3 +15,4 @@ Icon=com.system76.CosmicPanelAppButton
StartupNotify=true
NoDisplay=true
X-CosmicApplet=true
X-OverflowPriority=10

View file

@ -10,3 +10,4 @@ Icon=com.system76.CosmicPanelLauncherButton
StartupNotify=true
NoDisplay=true
X-CosmicApplet=true
X-OverflowPriority=10

View file

@ -11,3 +11,4 @@ Icon=com.system76.CosmicPanelWorkspacesButton
StartupNotify=true
NoDisplay=true
X-CosmicApplet=true
X-OverflowPriority=10