From b894fbd9ff0f3efa347ff807b91f94b7c0a53113 Mon Sep 17 00:00:00 2001 From: Olivier Fourdan Date: Wed, 14 Jun 2017 10:54:16 +0200 Subject: [PATCH] core: add MetaInhibitShortcutsDialog Add a new interface for allowing or denying shortcuts inhibit requests. https://bugzilla.gnome.org/show_bug.cgi?id=783342 --- src/Makefile.am | 3 + src/core/meta-inhibit-shortcuts-dialog.c | 103 +++++++++++++++++++++++ src/meta/meta-inhibit-shortcuts-dialog.h | 49 +++++++++++ 3 files changed, 155 insertions(+) create mode 100644 src/core/meta-inhibit-shortcuts-dialog.c create mode 100644 src/meta/meta-inhibit-shortcuts-dialog.h diff --git a/src/Makefile.am b/src/Makefile.am index 736fff16c..4d45a8ad7 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -235,6 +235,8 @@ libmutter_@LIBMUTTER_API_VERSION@_la_SOURCES = \ meta/meta-close-dialog.h \ core/meta-close-dialog-default.c \ core/meta-close-dialog-default-private.h \ + core/meta-inhibit-shortcuts-dialog.c \ + meta/meta-inhibit-shortcuts-dialog.h \ core/delete.c \ core/display.c \ core/display-private.h \ @@ -453,6 +455,7 @@ libmutterinclude_headers = \ meta/meta-background-image.h \ meta/meta-background-group.h \ meta/meta-close-dialog.h \ + meta/meta-inhibit-shortcuts-dialog.h \ meta/meta-cursor-tracker.h \ meta/meta-dnd.h \ meta/meta-idle-monitor.h \ diff --git a/src/core/meta-inhibit-shortcuts-dialog.c b/src/core/meta-inhibit-shortcuts-dialog.c new file mode 100644 index 000000000..d5b4e5a05 --- /dev/null +++ b/src/core/meta-inhibit-shortcuts-dialog.c @@ -0,0 +1,103 @@ +/* + * Copyright (C) 2017 Red Hat + * + * 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 2 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 . + * + */ + +#include "config.h" + +#include "core/window-private.h" +#include "meta/meta-inhibit-shortcuts-dialog.h" +#include "meta/meta-enum-types.h" + +enum +{ + RESPONSE, + LAST_SIGNAL +}; + +static guint inhibit_dialog_signals[LAST_SIGNAL] = { 0, }; + +G_DEFINE_INTERFACE (MetaInhibitShortcutsDialog, meta_inhibit_shortcuts_dialog, G_TYPE_OBJECT) + +static void +meta_inhibit_shortcuts_dialog_default_init (MetaInhibitShortcutsDialogInterface *iface) +{ + g_object_interface_install_property (iface, + g_param_spec_object ("window", + "Window", + "Window", + META_TYPE_WINDOW, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS)); + inhibit_dialog_signals[RESPONSE] = + g_signal_new ("response", + G_TYPE_FROM_INTERFACE (iface), + G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, + 0, + NULL, NULL, NULL, + G_TYPE_NONE, 1, META_TYPE_INHIBIT_SHORTCUTS_DIALOG_RESPONSE); +} + +/** + * meta_inhibit_shortcuts_dialog_show: + * @dialog: a #MetaInhibitShortcutsDialog + * + * Shows the inhibit shortcuts dialog. + **/ +void +meta_inhibit_shortcuts_dialog_show (MetaInhibitShortcutsDialog *dialog) +{ + MetaInhibitShortcutsDialogInterface *iface; + + g_return_if_fail (META_IS_INHIBIT_SHORTCUTS_DIALOG (dialog)); + + iface = META_INHIBIT_SHORTCUTS_DIALOG_GET_IFACE (dialog); + iface->show (dialog); +} + +/** + * meta_inhibit_shortcuts_dialog_hide: + * @dialog: a #MetaInhibitShortcutsDialog + * + * Hides the inhibit shortcuts dialog. + **/ +void +meta_inhibit_shortcuts_dialog_hide (MetaInhibitShortcutsDialog *dialog) +{ + MetaInhibitShortcutsDialogInterface *iface; + + g_return_if_fail (META_IS_INHIBIT_SHORTCUTS_DIALOG (dialog)); + + iface = META_INHIBIT_SHORTCUTS_DIALOG_GET_IFACE (dialog); + iface->hide (dialog); +} + +/** + * meta_inhibit_shortcuts_dialog_response: + * @dialog: a #MetaInhibitShortcutsDialog + * @response: a #MetaInhibitShortcutsDialogResponse + * + * Responds and closes the dialog. To be called by #MetaInhibitShortcutsDialog + * implementations. + **/ +void +meta_inhibit_shortcuts_dialog_response (MetaInhibitShortcutsDialog *dialog, + MetaInhibitShortcutsDialogResponse response) +{ + g_signal_emit (dialog, inhibit_dialog_signals[RESPONSE], 0, response); + meta_inhibit_shortcuts_dialog_hide (dialog); +} diff --git a/src/meta/meta-inhibit-shortcuts-dialog.h b/src/meta/meta-inhibit-shortcuts-dialog.h new file mode 100644 index 000000000..8ebeb398d --- /dev/null +++ b/src/meta/meta-inhibit-shortcuts-dialog.h @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2017 Red Hat + * + * 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 2 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 . + * + */ + +#ifndef META_INHIBIT_SHORTCUTS_DIALOG_H +#define META_INHIBIT_SHORTCUTS_DIALOG_H + +#include +#include + +#define META_TYPE_INHIBIT_SHORTCUTS_DIALOG (meta_inhibit_shortcuts_dialog_get_type ()) +G_DECLARE_INTERFACE (MetaInhibitShortcutsDialog, meta_inhibit_shortcuts_dialog, + META, INHIBIT_SHORTCUTS_DIALOG, GObject) + +typedef enum +{ + META_INHIBIT_SHORTCUTS_DIALOG_RESPONSE_ALLOW, + META_INHIBIT_SHORTCUTS_DIALOG_RESPONSE_DENY, +} MetaInhibitShortcutsDialogResponse; + +struct _MetaInhibitShortcutsDialogInterface +{ + GTypeInterface parent_iface; + + void (* show) (MetaInhibitShortcutsDialog *dialog); + void (* hide) (MetaInhibitShortcutsDialog *dialog); +}; + +void meta_inhibit_shortcuts_dialog_show (MetaInhibitShortcutsDialog *dialog); +void meta_inhibit_shortcuts_dialog_hide (MetaInhibitShortcutsDialog *dialog); + +void meta_inhibit_shortcuts_dialog_response (MetaInhibitShortcutsDialog *dialog, + MetaInhibitShortcutsDialogResponse response); + +#endif /* META_INHIBIT_SHORTCUTS_DIALOG_H */