Skip to content

Commit

Permalink
feat: add EventLoopBuilderExtUnix::with_app_id on Linux (#912)
Browse files Browse the repository at this point in the history
closes #910
  • Loading branch information
amrbashir committed Apr 30, 2024
1 parent bc0a719 commit cd38f23
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changes/app_id_gtk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tao": "patch"
---

Add `EventLoopBuilderExtUnix::with_app_id` on Linux to allow setting a unique app id for the underlying gtk application.
10 changes: 10 additions & 0 deletions src/platform/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ pub trait EventLoopBuilderExtUnix {
/// terminates. Attempting to use a `Window` after its parent thread terminates has
/// unspecified, although explicitly not undefined, behavior.
fn with_any_thread(&mut self, any_thread: bool) -> &mut Self;

/// Set the gtk application id.
///
/// If no application ID is given then some features (most notably application uniqueness) will be disabled.
fn with_app_id<S: Into<String>>(&mut self, id: S) -> &mut Self;
}

impl<T> EventLoopBuilderExtUnix for EventLoopBuilder<T> {
Expand All @@ -46,6 +51,11 @@ impl<T> EventLoopBuilderExtUnix for EventLoopBuilder<T> {
self.platform_specific.any_thread = any_thread;
self
}

fn with_app_id<S: Into<String>>(&mut self, id: S) -> &mut Self {
self.platform_specific.app_id = Some(id.into());
self
}
}

/// Additional methods on `Window` that are specific to Unix.
Expand Down
11 changes: 7 additions & 4 deletions src/platform_impl/linux/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,10 @@ pub struct EventLoop<T: 'static> {
run_device_thread: Option<Rc<AtomicBool>>,
}

#[derive(Default, Debug, Copy, Clone, PartialEq, Eq, Hash)]
#[derive(Default, Debug, Clone, PartialEq, Eq, Hash)]
pub(crate) struct PlatformSpecificEventLoopAttributes {
pub(crate) any_thread: bool,
pub(crate) app_id: Option<String>,
}

impl<T: 'static> EventLoop<T> {
Expand All @@ -184,13 +185,15 @@ impl<T: 'static> EventLoop<T> {

let context = MainContext::default();
context
.with_thread_default(|| EventLoop::new_gtk().expect("Failed to initialize gtk backend!"))
.with_thread_default(|| {
EventLoop::new_gtk(attrs.app_id.as_deref()).expect("Failed to initialize gtk backend!")
})
.expect("Failed to initialize gtk backend!")
}

fn new_gtk() -> Result<EventLoop<T>, Box<dyn Error>> {
fn new_gtk(app_id: Option<&str>) -> Result<EventLoop<T>, Box<dyn Error>> {
let context = MainContext::default();
let app = gtk::Application::new(None, gio::ApplicationFlags::empty());
let app = gtk::Application::new(app_id, gio::ApplicationFlags::empty());
let app_ = app.clone();
let cancellable: Option<&Cancellable> = None;
app.register(cancellable)?;
Expand Down
2 changes: 0 additions & 2 deletions src/platform_impl/linux/icon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// Copyright 2021-2023 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0

use std::{fs::File, io::BufWriter, path::Path};

use gtk::gdk_pixbuf::{Colorspace, Pixbuf};

use crate::window::BadIcon;
Expand Down

0 comments on commit cd38f23

Please sign in to comment.