mirror of
https://github.com/elementary/gala.git
synced 2024-09-11 15:15:39 +03:00
Forward the Media Keys to the Gnome Settings Daemon
This commit is contained in:
parent
72539e3b04
commit
043b89529d
10
configure.ac
10
configure.ac
@ -172,6 +172,16 @@ if test "x$enable_plank_0_11" = "xyes" ; then
|
||||
VALAFLAGS="$VALAFLAGS --define HAVE_PLANK_0_11"
|
||||
fi
|
||||
|
||||
# Check for Gnome Settings Daemon 3.10
|
||||
PKG_CHECK_MODULES(GSD310, [gnome-settings-daemon >= 3.9.5], [have_gsd310=yes], [have_gsd310=no])
|
||||
if test "x$have_gsd310" = "xyes" ; then
|
||||
VALAFLAGS="$VALAFLAGS --define HAS_GSD310"
|
||||
fi
|
||||
PKG_CHECK_MODULES(GSD316, [gnome-settings-daemon >= 3.15.2], [have_gsd316=yes], [have_gsd316=no])
|
||||
if test "x$have_gsd316" = "xyes" ; then
|
||||
VALAFLAGS="$VALAFLAGS --define HAS_GSD316"
|
||||
fi
|
||||
|
||||
# -----------------------------------------------------------
|
||||
# Dependencies for Notifications plugin
|
||||
# -----------------------------------------------------------
|
||||
|
122
src/DBusAccelerator.vala
Normal file
122
src/DBusAccelerator.vala
Normal file
@ -0,0 +1,122 @@
|
||||
//
|
||||
// Copyright (C) 2015 Nicolas Bruguier, Corentin Noël
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
namespace Gala
|
||||
{
|
||||
public struct Accelerator
|
||||
{
|
||||
public string name;
|
||||
public uint flags;
|
||||
}
|
||||
|
||||
[DBus (name="org.gnome.Shell")]
|
||||
public class DBusAccelerator
|
||||
{
|
||||
static DBusAccelerator? instance;
|
||||
static WindowManager wm;
|
||||
|
||||
[DBus (visible = false)]
|
||||
public static void init (WindowManager _wm)
|
||||
{
|
||||
wm = _wm;
|
||||
|
||||
Bus.own_name (BusType.SESSION, "org.gnome.Shell", BusNameOwnerFlags.NONE,
|
||||
(connection) => {
|
||||
if (instance == null)
|
||||
instance = new DBusAccelerator ();
|
||||
|
||||
try {
|
||||
connection.register_object ("/org/gnome/Shell", instance);
|
||||
} catch (Error e) { warning (e.message); }
|
||||
},
|
||||
() => {},
|
||||
() => critical ("Could not acquire name") );
|
||||
}
|
||||
|
||||
#if HAS_GSD316
|
||||
public signal void accelerator_activated (uint action, GLib.HashTable<string, Variant> parameters);
|
||||
#else
|
||||
public signal void accelerator_activated (uint action, uint device_id, uint timestamp);
|
||||
#endif
|
||||
|
||||
HashTable<string, uint?> grabbed_accelerators;
|
||||
|
||||
DBusAccelerator ()
|
||||
{
|
||||
grabbed_accelerators = new HashTable<string, uint> (str_hash, str_equal);
|
||||
|
||||
wm.get_screen ().get_display ().accelerator_activated.connect (on_accelerator_activated);
|
||||
}
|
||||
|
||||
void on_accelerator_activated (uint action, uint device_id, uint timestamp)
|
||||
{
|
||||
foreach (string accelerator in grabbed_accelerators.get_keys ()) {
|
||||
if (grabbed_accelerators[accelerator] == action) {
|
||||
#if HAS_GSD316
|
||||
var parameters = new GLib.HashTable<string, Variant> (null, null);
|
||||
parameters.set ("device-id", new Variant.uint32 (device_id));
|
||||
parameters.set ("timestamp", new Variant.uint32 (timestamp));
|
||||
|
||||
accelerator_activated (action, parameters);
|
||||
#else
|
||||
accelerator_activated (action, device_id, timestamp);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public uint grab_accelerator (string accelerator, uint flags)
|
||||
{
|
||||
uint? action = grabbed_accelerators[accelerator];
|
||||
|
||||
if (action == null) {
|
||||
action = wm.get_screen ().get_display ().grab_accelerator (accelerator);
|
||||
if (action > 0) {
|
||||
grabbed_accelerators[accelerator] = action;
|
||||
}
|
||||
}
|
||||
|
||||
return action;
|
||||
}
|
||||
|
||||
public uint[] grab_accelerators (Accelerator[] accelerators)
|
||||
{
|
||||
uint[] actions = {};
|
||||
|
||||
foreach (unowned Accelerator? accelerator in accelerators) {
|
||||
actions += grab_accelerator (accelerator.name, accelerator.flags);
|
||||
}
|
||||
|
||||
return actions;
|
||||
}
|
||||
|
||||
public bool ungrab_accelerator (uint action)
|
||||
{
|
||||
bool ret = false;
|
||||
|
||||
foreach (unowned string accelerator in grabbed_accelerators.get_keys ()) {
|
||||
if (grabbed_accelerators[accelerator] == action) {
|
||||
ret = wm.get_screen ().get_display ().ungrab_accelerator (action);
|
||||
grabbed_accelerators.remove (accelerator);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
@ -32,6 +32,7 @@ gala_LDADD = \
|
||||
|
||||
gala_VALASOURCES = \
|
||||
DBus.vala \
|
||||
DBusAccelerator.vala \
|
||||
DockThemeManager.vala \
|
||||
DragDropAction.vala \
|
||||
InternalUtils.vala \
|
||||
|
@ -91,6 +91,9 @@ namespace Gala
|
||||
var display = screen.get_display ();
|
||||
|
||||
DBus.init (this);
|
||||
#if HAS_GSD310
|
||||
DBusAccelerator.init (this);
|
||||
#endif
|
||||
WindowListener.init (screen);
|
||||
|
||||
// Due to a bug which enables access to the stage when using multiple monitors
|
||||
|
Loading…
Reference in New Issue
Block a user