TransWikia.com

Help to grab Gnome Settings Media Keys focus by "force"

Ask Ubuntu Asked by Gabriel Martins on December 19, 2021

I’m trying to create an application that listens for events sent by Gnome’s gsd-media-keys,what I have already achieved, but other apps like VLC and Chrome are "stealing" my app’s focus when they launch.

What I realized is that these applications use a different method than the one I used in my application to ask gnome to send messages to it, and also I realized that the method I’m using is not able to do the same(steal the focus), I can only get my application to receive the messages when none of these other applications are open(which is very selfish, but anyway…).

I’m doing these tests using node.js, this is the code that has the behavior that it describes up here:

const DBus = require('dbus');

try {
  const dbus = new DBus();
  const session = dbus.getBus('session');

  session.getInterface('org.gnome.SettingsDaemon', '/org/gnome/SettingsDaemon/MediaKeys',
    'org.gnome.SettingsDaemon.MediaKeys', (err, iface) => {
      if (!err) {
        iface.on('MediaPlayerKeyPressed', (n, keyName) => {
          console.log(n, keyName);
        });
        iface.GrabMediaPlayerKeys('Custom-Player', 'org.gnome.SettingsDaemon.MediaKeys');
      } else {
        console.error(err);
      }
    });
}
catch (e) {
  console.log(e);
}

These are the logs generated in the JournalCtl when my application connects to the dbus:

gsd-media-keys[134383]: Calling method 'GrabMediaPlayerKeys' for media-keys
gsd-media-keys[134383]: Registering Custom-Player at 2102244559

And these are the ones generated by chrome and vlc when they launch:

# VLC
gsd-media-keys[134383]: Updating client: index=202 name='Native client (UNIX socket client)'
gsd-media-keys[134383]: Updating client: index=202 name='VLC media player (LibVLC 3.0.9.2)'
gsd-media-keys[134383]: Creating proxy for for org.mpris.MediaPlayer2.vlc

# Chrome
gsd-media-keys[134383]: Updating client: index=214 name='Native client (UNIX socket client)'
gsd-media-keys[134383]: Updating client: index=214 name='Chrome input'
gsd-media-keys[134383]: Creating proxy for for org.mpris.MediaPlayer2.chrome.instance139709

I’m trying to understand how Chrome and VLC communicate with gsd-media-keys and how I can achieve the same behavior in my application, and I’m under the impression that these two applications are not doing this through DBUS(and I’m hesitating for now to go there in their source code to find out rs).

Can someone help me understand what’s going on or point me to some material that clarifies things a little more?
Because I’m spending a lot of time researching but I don’t know where or exactly what to look for. ☹

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP