fix(graphics): only make the button pressable if the graphics can be switched
This commit is contained in:
parent
78f8a3f722
commit
5a0b6e03e9
1 changed files with 18 additions and 7 deletions
|
|
@ -43,6 +43,7 @@ pub struct Window {
|
||||||
popup: Option<window::Id>,
|
popup: Option<window::Id>,
|
||||||
graphics_mode: Option<GraphicsMode>,
|
graphics_mode: Option<GraphicsMode>,
|
||||||
dbus: Option<(Connection, PowerDaemonProxy<'static>)>,
|
dbus: Option<(Connection, PowerDaemonProxy<'static>)>,
|
||||||
|
switchable: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
|
|
@ -50,7 +51,7 @@ pub struct Window {
|
||||||
pub enum Message {
|
pub enum Message {
|
||||||
CurrentGraphics(Option<Graphics>),
|
CurrentGraphics(Option<Graphics>),
|
||||||
AppliedGraphics(Option<Graphics>),
|
AppliedGraphics(Option<Graphics>),
|
||||||
DBusInit(Option<(Connection, PowerDaemonProxy<'static>)>),
|
DBusInit(Option<(Connection, PowerDaemonProxy<'static>)>, bool),
|
||||||
SelectGraphicsMode(Graphics),
|
SelectGraphicsMode(Graphics),
|
||||||
TogglePopup,
|
TogglePopup,
|
||||||
PopupClosed(window::Id),
|
PopupClosed(window::Id),
|
||||||
|
|
@ -72,9 +73,18 @@ impl cosmic::Application for Window {
|
||||||
};
|
};
|
||||||
(
|
(
|
||||||
window,
|
window,
|
||||||
iced::Command::perform(dbus::init(), |x| {
|
iced::Command::perform(
|
||||||
cosmic::app::message::app(Message::DBusInit(x))
|
async {
|
||||||
}),
|
let dbus = dbus::init().await;
|
||||||
|
let switchable = if let Some((_, proxy)) = dbus.as_ref() {
|
||||||
|
proxy.get_switchable().await.ok().unwrap_or(false)
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
};
|
||||||
|
(dbus, switchable)
|
||||||
|
},
|
||||||
|
|(dbus, switchable)| cosmic::app::message::app(Message::DBusInit(dbus, switchable)),
|
||||||
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -132,7 +142,8 @@ impl cosmic::Application for Window {
|
||||||
return iced::Command::batch(commands).map(cosmic::app::message::app);
|
return iced::Command::batch(commands).map(cosmic::app::message::app);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Message::DBusInit(dbus) => {
|
Message::DBusInit(dbus, switchable) => {
|
||||||
|
self.switchable = switchable;
|
||||||
if dbus.is_none() {
|
if dbus.is_none() {
|
||||||
eprintln!("Could not connect to com.system76.PowerDaemon. Exiting.");
|
eprintln!("Could not connect to com.system76.PowerDaemon. Exiting.");
|
||||||
std::process::exit(0);
|
std::process::exit(0);
|
||||||
|
|
@ -214,7 +225,7 @@ impl cosmic::Application for Window {
|
||||||
.core
|
.core
|
||||||
.applet
|
.applet
|
||||||
.icon_button(ID)
|
.icon_button(ID)
|
||||||
.on_press(Message::TogglePopup)
|
.on_press_maybe(self.switchable.then(|| Message::TogglePopup))
|
||||||
.into(),
|
.into(),
|
||||||
PanelAnchor::Top | PanelAnchor::Bottom => button(
|
PanelAnchor::Top | PanelAnchor::Bottom => button(
|
||||||
row![
|
row![
|
||||||
|
|
@ -243,7 +254,7 @@ impl cosmic::Application for Window {
|
||||||
.padding([0, self.core.applet.suggested_size().0 / 2])
|
.padding([0, self.core.applet.suggested_size().0 / 2])
|
||||||
.align_items(Alignment::Center),
|
.align_items(Alignment::Center),
|
||||||
)
|
)
|
||||||
.on_press(Message::TogglePopup)
|
.on_press_maybe(self.switchable.then(|| Message::TogglePopup))
|
||||||
.padding(8)
|
.padding(8)
|
||||||
.width(Length::Shrink)
|
.width(Length::Shrink)
|
||||||
.height(Length::Shrink)
|
.height(Length::Shrink)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue