feat: sticky graphics mode after selection
This commit is contained in:
parent
af1e16b1f5
commit
e55ce3e519
1 changed files with 32 additions and 13 deletions
|
|
@ -3,8 +3,6 @@ use crate::graphics::{get_current_graphics, set_graphics, Graphics};
|
||||||
use cosmic::applet::{get_popup_settings, icon_button, popup_container};
|
use cosmic::applet::{get_popup_settings, icon_button, popup_container};
|
||||||
use cosmic::iced_style::application::{self, Appearance};
|
use cosmic::iced_style::application::{self, Appearance};
|
||||||
use cosmic::separator;
|
use cosmic::separator;
|
||||||
use cosmic::theme::Container;
|
|
||||||
use cosmic::widget::widget::container;
|
|
||||||
use cosmic::{
|
use cosmic::{
|
||||||
iced::widget::{column, radio, text},
|
iced::widget::{column, radio, text},
|
||||||
iced::{self, Application, Command, Length},
|
iced::{self, Application, Command, Length},
|
||||||
|
|
@ -13,7 +11,7 @@ use cosmic::{
|
||||||
Element,
|
Element,
|
||||||
};
|
};
|
||||||
use cosmic_panel_config::{PanelAnchor, PanelSize};
|
use cosmic_panel_config::{PanelAnchor, PanelSize};
|
||||||
use iced_sctk::alignment::{Horizontal, Vertical};
|
use iced_sctk::alignment::Horizontal;
|
||||||
use iced_sctk::commands::popup::{destroy_popup, get_popup};
|
use iced_sctk::commands::popup::{destroy_popup, get_popup};
|
||||||
use iced_sctk::Color;
|
use iced_sctk::Color;
|
||||||
use zbus::Connection;
|
use zbus::Connection;
|
||||||
|
|
@ -24,6 +22,21 @@ enum State {
|
||||||
SettingGraphicsMode(Graphics),
|
SettingGraphicsMode(Graphics),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Copy)]
|
||||||
|
enum GraphicsMode {
|
||||||
|
SelectedGraphicsMode(Graphics),
|
||||||
|
CurrentGraphicsMode(Graphics),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl GraphicsMode {
|
||||||
|
fn inner(&self) -> Graphics {
|
||||||
|
match self {
|
||||||
|
GraphicsMode::SelectedGraphicsMode(g) => *g,
|
||||||
|
GraphicsMode::CurrentGraphicsMode(g) => *g,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Default for State {
|
impl Default for State {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self::SelectGraphicsMode(false)
|
Self::SelectGraphicsMode(false)
|
||||||
|
|
@ -33,7 +46,7 @@ impl Default for State {
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct Window {
|
pub struct Window {
|
||||||
popup: Option<window::Id>,
|
popup: Option<window::Id>,
|
||||||
graphics_mode: Option<Graphics>,
|
graphics_mode: Option<GraphicsMode>,
|
||||||
id_ctr: u32,
|
id_ctr: u32,
|
||||||
icon_size: u16,
|
icon_size: u16,
|
||||||
anchor: PanelAnchor,
|
anchor: PanelAnchor,
|
||||||
|
|
@ -46,7 +59,7 @@ pub struct Window {
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub enum Message {
|
pub enum Message {
|
||||||
CurrentGraphics(Option<Graphics>),
|
CurrentGraphics(Option<Graphics>),
|
||||||
AppliedGraphicsMode(Option<Graphics>),
|
SelectedGraphicsMode(Option<Graphics>),
|
||||||
DBusInit(Option<(Connection, PowerDaemonProxy<'static>)>),
|
DBusInit(Option<(Connection, PowerDaemonProxy<'static>)>),
|
||||||
SelectGraphicsMode(Graphics),
|
SelectGraphicsMode(Graphics),
|
||||||
TogglePopup,
|
TogglePopup,
|
||||||
|
|
@ -97,14 +110,15 @@ impl Application for Window {
|
||||||
return Command::perform(
|
return Command::perform(
|
||||||
set_graphics(proxy.clone(), new_graphics_mode),
|
set_graphics(proxy.clone(), new_graphics_mode),
|
||||||
move |success| {
|
move |success| {
|
||||||
Message::AppliedGraphicsMode(success.ok().map(|_| new_graphics_mode))
|
Message::SelectedGraphicsMode(success.ok().map(|_| new_graphics_mode))
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Message::AppliedGraphicsMode(g) => {
|
Message::SelectedGraphicsMode(g) => {
|
||||||
if let Some(g) = g {
|
if let Some(g) = g {
|
||||||
self.graphics_mode.replace(g);
|
self.graphics_mode
|
||||||
|
.replace(GraphicsMode::SelectedGraphicsMode(g));
|
||||||
self.state = State::SelectGraphicsMode(true);
|
self.state = State::SelectGraphicsMode(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -146,7 +160,12 @@ impl Application for Window {
|
||||||
}
|
}
|
||||||
Message::CurrentGraphics(g) => {
|
Message::CurrentGraphics(g) => {
|
||||||
if let Some(g) = g {
|
if let Some(g) = g {
|
||||||
self.graphics_mode.replace(g);
|
self.graphics_mode = Some(match self.graphics_mode.take() {
|
||||||
|
Some(GraphicsMode::CurrentGraphicsMode(_)) | None => {
|
||||||
|
GraphicsMode::CurrentGraphicsMode(g)
|
||||||
|
}
|
||||||
|
Some(g) => g,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -160,28 +179,28 @@ impl Application for Window {
|
||||||
radio(
|
radio(
|
||||||
"Integrated Graphics",
|
"Integrated Graphics",
|
||||||
Graphics::Integrated,
|
Graphics::Integrated,
|
||||||
self.graphics_mode,
|
self.graphics_mode.map(|g| g.inner()),
|
||||||
|g| Message::SelectGraphicsMode(g),
|
|g| Message::SelectGraphicsMode(g),
|
||||||
)
|
)
|
||||||
.into(),
|
.into(),
|
||||||
radio(
|
radio(
|
||||||
"Nvidia Graphics",
|
"Nvidia Graphics",
|
||||||
Graphics::Nvidia,
|
Graphics::Nvidia,
|
||||||
self.graphics_mode,
|
self.graphics_mode.map(|g| g.inner()),
|
||||||
|g| Message::SelectGraphicsMode(g),
|
|g| Message::SelectGraphicsMode(g),
|
||||||
)
|
)
|
||||||
.into(),
|
.into(),
|
||||||
radio(
|
radio(
|
||||||
"Hybrid Graphics",
|
"Hybrid Graphics",
|
||||||
Graphics::Hybrid,
|
Graphics::Hybrid,
|
||||||
self.graphics_mode,
|
self.graphics_mode.map(|g| g.inner()),
|
||||||
|g| Message::SelectGraphicsMode(g),
|
|g| Message::SelectGraphicsMode(g),
|
||||||
)
|
)
|
||||||
.into(),
|
.into(),
|
||||||
radio(
|
radio(
|
||||||
"Compute Graphics",
|
"Compute Graphics",
|
||||||
Graphics::Compute,
|
Graphics::Compute,
|
||||||
self.graphics_mode,
|
self.graphics_mode.map(|g| g.inner()),
|
||||||
|g| Message::SelectGraphicsMode(g),
|
|g| Message::SelectGraphicsMode(g),
|
||||||
)
|
)
|
||||||
.into(),
|
.into(),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue