Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add globalshortcuts demo #214

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

dcz-self
Copy link

@dcz-self
Copy link
Author

dcz-self commented Jun 19, 2024

I have a video, but github doesn't seem to accept it.

It's here instead: https://gitlab.gnome.org/GNOME/xdg-desktop-portal-gnome/-/issues/47#note_2144834

@bilelmoussaoui bilelmoussaoui linked an issue Jun 19, 2024 that may be closed by this pull request
<child>
<object class="AdwPreferencesGroup">
<property name="title" translatable="yes">Global Shortcuts</property>
<property name="description" translatable="yes">Comma-separated list of shortcuts to request, in the form: "name:description:optional trigger"</property>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a fan of putting this in a single entry, instead I would do something like notifications buttons

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do I do that? Is there an example I could use as a guide?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are examples in both emails attachments and notifications buttons

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried and I failed. Those examples don't show how to modify a property of a widget inside the list. Finding the inside widgets in the obvious way (by treating the widget as a list of widgets) fails in incomprehensible ways.

}

impl GlobalShortcutsPage {
async fn start_session(&self) -> ashpd::Result<()> {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am sorry but this function is too huge, please split it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what hugeness standard we're aiming for, so I split it once.

Comment on lines 200 to 201
imp.session_state_label.set_text("Shortcut list invalid");
imp.response_group.set_visible(true);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, please use the notifications bits that are part of PortalPage already and drop the session_state_label.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

}

let Ok(activated_stream) = global_shortcuts.receive_activated().await
else {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weirdly broken formatting but why not just write global_shortcuts.receive_activated().await?;

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cannot use the ?operator in an async block that returns()``.

let (abort_handle, abort_registration) = AbortHandle::new_pair();
let future = Abortable::new(
async {
enum Event {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Define this enum outside of this function please

let triggers = self.imp().triggers.lock().await.clone();
let text: Vec<String> = triggers.into_iter()
.map(|RegisteredShortcut { id, activation }| {
let escape = |s: &str| s.replace("<", "&lt;").replace(">", "&gt;");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am sure glib has a proper function for this :)

<object class="AdwActionRow">
<property name="title" translatable="yes">Shortcuts Status</property>
<child>
<object class="GtkLabel" id="shortcuts_status_label">
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems to be unused?

</object>
</child>
<child>
<object class="AdwPreferencesGroup" id="response_group">
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The respnose group seems to be completely unused, I would suggest moving the binding_changes_count there and maybe adding a row that displays the shortcut that was triggered or something like that

let triggers: Vec<_>
= resp.shortcuts().iter()
.map(|s: &Shortcut| RegisteredShortcut {
id: s.id().into(),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as elsewhere, use to_owned please

Comment on lines 114 to 121
imp.session_state_label.set_text(
&match &response {
Ok(_) => "OK".into(),
Err(ashpd::Error::Response(ResponseError::Cancelled)) => "Cancelled".into(),
Err(ashpd::Error::Response(ResponseError::Other)) => "Other response error".into(),
Err(e) => format!("{}", e),
}
);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, use the notifications infrastructure

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to make the notifications stay? By the time I get back from the debugger, the message is already gone and I don't know what went wrong.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that is a good point, but there isn't actually. I can change the notification widget implementation separately later :)

@@ -7,7 +7,7 @@ version = "0.4.1"
[dependencies]
adw = {version = "0.6", package = "libadwaita", features = ["v1_4"]}
anyhow = "1.0"
ashpd = {version = "^0.8", features = ["gtk4", "tracing", "pipewire"]}
ashpd = {path="..", features = ["gtk4", "tracing", "pipewire"]}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will not work for flatpak, you will have to point it to your github branch until the PR is approved and then merged.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ugh.

@dcz-self
Copy link
Author

I don't really know what's happening with the pipeline failure. It's not in globalshortcuts.

@Covkie
Copy link

Covkie commented Aug 28, 2024

I don't really know what's happening with the pipeline failure. It's not in globalshortcuts.

@dcz-self Pull in latest git & fix errors, it builds fine.
in global_shortcuts.rs:

-      pub session: Arc<Mutex<Option<Session<'static>>>>,
+      pub session: Arc<Mutex<Option<Session<'static, GlobalShortcuts<'static>>>>>,

This seems to work other than it creating a new session instead of hooking into the existing one & missing metadata about the name and icon. (KDE)
image

#231 related?

@dcz-self
Copy link
Author

dcz-self commented Sep 4, 2024

Thanks for the interest. Sadly, meanwhile my funding ran out and I no longer have the time to continue this work. Feel free to take over.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a global shortcuts demo
3 participants