feat: popup positioning depending on panel anchor
This commit is contained in:
parent
ac0b555946
commit
59a112523d
7 changed files with 34 additions and 14 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
|
@ -421,6 +421,7 @@ name = "cosmic-applet-notifications"
|
|||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"cascade",
|
||||
"cosmic-panel-config",
|
||||
"futures",
|
||||
"gtk4",
|
||||
"libadwaita",
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
use crate::dock_list::DockList;
|
||||
use crate::dock_list::DockListType;
|
||||
use cascade::cascade;
|
||||
use cosmic_panel_config::{CosmicPanelConfig, PanelAnchor};
|
||||
use cosmic_panel_config::{PanelAnchor};
|
||||
use gtk4::prelude::*;
|
||||
use gtk4::subclass::prelude::*;
|
||||
use gtk4::Orientation;
|
||||
|
|
|
|||
|
|
@ -17,3 +17,4 @@ serde = "1"
|
|||
zbus = "2.0.1"
|
||||
zbus_names = "2"
|
||||
zvariant = "3"
|
||||
cosmic-panel-config = {git = "https://github.com/pop-os/cosmic-panel", features = ["gtk4"] }
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
use gtk4::{glib, prelude::*};
|
||||
use gtk4::{glib, prelude::*, PositionType};
|
||||
use relm4_macros::view;
|
||||
use cosmic_panel_config::PanelAnchor;
|
||||
|
||||
mod dbus_service;
|
||||
mod deref_cell;
|
||||
|
|
@ -31,7 +32,16 @@ fn main() {
|
|||
window.show();
|
||||
|
||||
// XXX show in correct place
|
||||
let notification_popover = NotificationPopover::new(¬ifications);
|
||||
let position = std::env::var("COSMIC_PANEL_ANCHOR")
|
||||
.ok()
|
||||
.and_then(|anchor| anchor.parse::<PanelAnchor>().ok())
|
||||
.map(|anchor| match anchor {
|
||||
PanelAnchor::Left => PositionType::Right,
|
||||
PanelAnchor::Right => PositionType::Left,
|
||||
PanelAnchor::Top => PositionType::Bottom,
|
||||
PanelAnchor::Bottom => PositionType::Top,
|
||||
});
|
||||
let notification_popover = NotificationPopover::new(¬ifications, position);
|
||||
notification_popover.set_parent(&applet_button);
|
||||
|
||||
let main_loop = glib::MainLoop::new(None, false);
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ use cascade::cascade;
|
|||
use gtk4::{
|
||||
glib::{self, clone},
|
||||
prelude::*,
|
||||
subclass::prelude::*,
|
||||
subclass::prelude::*, PositionType,
|
||||
};
|
||||
use std::cell::RefCell;
|
||||
|
||||
|
|
@ -75,9 +75,11 @@ glib::wrapper! {
|
|||
}
|
||||
|
||||
impl NotificationPopover {
|
||||
pub fn new(notifications: &Notifications) -> Self {
|
||||
pub fn new(notifications: &Notifications, position: Option<PositionType>) -> Self {
|
||||
let obj = glib::Object::new::<Self>(&[]).unwrap();
|
||||
|
||||
if let Some(position) = position {
|
||||
obj.set_position(position);
|
||||
}
|
||||
let notification_widget = cascade! {
|
||||
NotificationWidget::new(notifications);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use cosmic_panel_config::{CosmicPanelConfig, PanelSize};
|
||||
use gtk4::{glib, prelude::*, subclass::prelude::*};
|
||||
use cosmic_panel_config::{PanelSize, PanelAnchor};
|
||||
use gtk4::{glib, prelude::*, subclass::prelude::*, PositionType};
|
||||
use relm4_macros::view;
|
||||
|
||||
use crate::deref_cell::DerefCell;
|
||||
|
|
@ -18,7 +18,6 @@ button.cosmic_applet_button {
|
|||
#[derive(Default)]
|
||||
pub struct AppletButtonInner {
|
||||
menu_button: DerefCell<gtk4::MenuButton>,
|
||||
panel_config: DerefCell<CosmicPanelConfig>,
|
||||
popover: DerefCell<gtk4::Popover>,
|
||||
}
|
||||
|
||||
|
|
@ -31,6 +30,15 @@ impl ObjectSubclass for AppletButtonInner {
|
|||
|
||||
impl ObjectImpl for AppletButtonInner {
|
||||
fn constructed(&self, obj: &AppletButton) {
|
||||
let position = std::env::var("COSMIC_PANEL_ANCHOR")
|
||||
.ok()
|
||||
.and_then(|anchor| anchor.parse::<PanelAnchor>().ok())
|
||||
.map(|anchor| match anchor {
|
||||
PanelAnchor::Left => PositionType::Right,
|
||||
PanelAnchor::Right => PositionType::Left,
|
||||
PanelAnchor::Top => PositionType::Bottom,
|
||||
PanelAnchor::Bottom => PositionType::Top,
|
||||
});
|
||||
view! {
|
||||
menu_button = gtk4::MenuButton {
|
||||
set_parent: obj,
|
||||
|
|
@ -38,7 +46,6 @@ impl ObjectImpl for AppletButtonInner {
|
|||
set_has_frame: false,
|
||||
#[wrap(Some)]
|
||||
set_popover: popover = >k4::Popover {
|
||||
// TODO: change if it can be positioned correctly?
|
||||
set_has_arrow: false,
|
||||
}
|
||||
},
|
||||
|
|
@ -46,6 +53,9 @@ impl ObjectImpl for AppletButtonInner {
|
|||
load_from_data: STYLE.as_bytes(),
|
||||
}
|
||||
}
|
||||
if let Some(position) = position {
|
||||
popover.set_position(position);
|
||||
}
|
||||
obj.set_layout_manager(Some(>k4::BinLayout::new()));
|
||||
obj.style_context()
|
||||
.add_provider(&provider, gtk4::STYLE_PROVIDER_PRIORITY_APPLICATION);
|
||||
|
|
|
|||
|
|
@ -1,7 +1,3 @@
|
|||
use cosmic_panel_config::CosmicPanelConfig;
|
||||
use gtk4::{glib, prelude::*, subclass::prelude::*};
|
||||
use relm4_macros::view;
|
||||
|
||||
mod button;
|
||||
pub use button::AppletButton;
|
||||
mod deref_cell;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue