feat: use libcosmic::init

This commit is contained in:
Ashley Wulber 2022-08-16 14:36:31 -04:00
parent a96decd24b
commit 98813824d4
No known key found for this signature in database
GPG key ID: 5216D4F46A90A820
37 changed files with 396 additions and 295 deletions

View file

@ -54,7 +54,10 @@ impl AppsContainer {
imp.active_list.set(active_app_list_view).unwrap();
// Setup
self_.setup_callbacks();
let anchor = std::env::var("COSMIC_PANEL_ANCHOR").ok().and_then(|anchor| anchor.parse::<PanelAnchor>().ok()).unwrap_or_default();
let anchor = std::env::var("COSMIC_PANEL_ANCHOR")
.ok()
.and_then(|anchor| anchor.parse::<PanelAnchor>().ok())
.unwrap_or_default();
self_.set_position(anchor);
Self::setup_callbacks(&self_);

View file

@ -500,15 +500,18 @@ impl DockList {
let factory = SignalListItemFactory::new();
let model = imp.model.get().expect("Failed to get saved app model.");
let icon_size = std::env::var("COSMIC_PANEL_SIZE").ok().and_then(|size| match size.parse::<PanelSize>() {
Ok(PanelSize::XL) => Some(64),
Ok(PanelSize::L) => Some(48),
Ok(PanelSize::M) => Some(36),
Ok(PanelSize::S) => Some(24),
Ok(PanelSize::XS) => Some(18),
Err(_) => Some(36),
}).unwrap_or(36);
let icon_size = std::env::var("COSMIC_PANEL_SIZE")
.ok()
.and_then(|size| match size.parse::<PanelSize>() {
Ok(PanelSize::XL) => Some(64),
Ok(PanelSize::L) => Some(48),
Ok(PanelSize::M) => Some(36),
Ok(PanelSize::S) => Some(24),
Ok(PanelSize::XS) => Some(18),
Err(_) => Some(36),
})
.unwrap_or(36);
factory.connect_setup(
glib::clone!(@weak popover_menu_index, @weak model => move |_, list_item| {
let dock_item = DockItem::new(icon_size);

View file

@ -49,9 +49,8 @@ fn load_css() {
}
fn main() {
let _ = gtk4::init();
adw::init();
let _ = libcosmic::init();
// Initialize logger
pretty_env_logger::init();
glib::set_application_name("Cosmic Dock App List");
@ -243,7 +242,7 @@ fn main() {
dock_obj.set_property("active", BoxedWindowList::default().to_value());
saved_app_model.items_changed(saved_i, 0, 0);
}
if let Some(cur_app_info) =
dock_obj.property::<Option<DesktopAppInfo>>("appinfo")
{

View file

@ -1,7 +1,7 @@
use crate::config::AppListConfig;
use crate::{config::TopLevelFilter, utils::AppListEvent, wayland_source::WaylandSource, TX};
use calloop::channel::*;
use cosmic_panel_config::{CosmicPanelOuput};
use cosmic_panel_config::CosmicPanelOuput;
use cosmic_protocols::{
toplevel_info::v1::client::{
zcosmic_toplevel_handle_v1::{self, ZcosmicToplevelHandleV1},
@ -52,10 +52,12 @@ pub fn spawn_toplevels() -> SyncSender<ToplevelEvent> {
.and_then(|s| s.map(|s| Connection::from_socket(s).map_err(anyhow::Error::msg)))
{
std::thread::spawn(move || {
let output = std::env::var("COSMIC_PANEL_OUTPUT").ok().and_then(|size| match size.parse::<CosmicPanelOuput>() {
Ok(CosmicPanelOuput::Name(n)) => Some(n),
// TODO handle Active & panic if the space is still configured for All instead of being assigned a named output
_ => None,
let output = std::env::var("COSMIC_PANEL_OUTPUT").ok().and_then(|size| {
match size.parse::<CosmicPanelOuput>() {
Ok(CosmicPanelOuput::Name(n)) => Some(n),
// TODO handle Active & panic if the space is still configured for All instead of being assigned a named output
_ => None,
}
});
let mut event_loop = calloop::EventLoop::<State>::try_new().unwrap();
@ -305,26 +307,25 @@ impl Dispatch<ZcosmicToplevelHandleV1, ()> for State {
if let Some(i) = state.toplevels.iter().position(|t| &t.toplevel_handle == p) {
let removed_toplevel = state.toplevels.remove(i);
if match state.config.filter_top_levels {
Some(TopLevelFilter::ActiveWorkspace) => {
state
.workspace_groups
.iter()
.find(|g| {
g.workspaces
.iter()
.find(|w| {
w.states.contains(
&zcosmic_workspace_handle_v1::State::Active,
) && Some(&w.workspace_handle) == removed_toplevel.workspace.as_ref()
})
.is_some()
})
.is_some()
},
Some(TopLevelFilter::ActiveWorkspace) => state
.workspace_groups
.iter()
.find(|g| {
g.workspaces
.iter()
.find(|w| {
w.states
.contains(&zcosmic_workspace_handle_v1::State::Active)
&& Some(&w.workspace_handle)
== removed_toplevel.workspace.as_ref()
})
.is_some()
})
.is_some(),
Some(TopLevelFilter::ConfiguredOutput) => {
state.expected_output == removed_toplevel.output
}
_ => true
_ => true,
} {
let tx = TX.get().unwrap().clone();
let _ = tx.send(AppListEvent::Remove(removed_toplevel));