2017-06-14 05:27:14 -04:00
|
|
|
/*
|
|
|
|
* 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 <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2018-07-10 04:36:24 -04:00
|
|
|
#include "config.h"
|
2017-06-14 05:27:14 -04:00
|
|
|
|
|
|
|
#include "compositor/compositor-private.h"
|
2018-07-10 04:36:24 -04:00
|
|
|
#include "core/window-private.h"
|
|
|
|
#include "wayland/meta-wayland-inhibit-shortcuts-dialog.h"
|
|
|
|
#include "wayland/meta-wayland.h"
|
|
|
|
#include "wayland/meta-window-wayland.h"
|
2017-06-14 05:27:14 -04:00
|
|
|
|
|
|
|
static GQuark quark_surface_inhibit_shortcuts_data = 0;
|
|
|
|
|
|
|
|
typedef struct _InhibitShortcutsData
|
|
|
|
{
|
|
|
|
MetaWaylandSurface *surface;
|
|
|
|
MetaWaylandSeat *seat;
|
|
|
|
MetaInhibitShortcutsDialog *dialog;
|
2017-08-18 12:22:08 -04:00
|
|
|
gulong response_handler_id;
|
2017-08-18 12:06:22 -04:00
|
|
|
gboolean has_last_response;
|
wayland: Keep the inhibit shortcut dialog
On Wayland, the grab()/ungrab() in gtk+/gdk are wired to the shortcut
inhibitor mechanism, which in turn shows the dialog, which can take
focus away from the client window when the dialog is shown.
If the client issues an ungrab() when the keyboard focus is lost, we
would hide the dialog, causing the keyboard focus to be returned to the
client surface, which in turn would issue a new grab(), so forth and so
on, causing a continuous show/hide of the shortcut inhibitor dialog.
To avoid this issue, keep the dialog around even if the shortcut inhibit
is canceled by the client, so that the user is forced to make a choice
that we can reuse on the next request without showing the dialog again.
Instead of hiding the dialog when the shortcut inhibitor is destroyed by
the client, we simply mark the request as canceled and do not apply the
user's choice.
https://bugzilla.gnome.org/show_bug.cgi?id=787568
2017-09-12 03:39:24 -04:00
|
|
|
gboolean request_canceled;
|
2017-06-14 05:27:14 -04:00
|
|
|
MetaInhibitShortcutsDialogResponse last_response;
|
|
|
|
} InhibitShortcutsData;
|
|
|
|
|
|
|
|
static InhibitShortcutsData *
|
|
|
|
surface_inhibit_shortcuts_data_get (MetaWaylandSurface *surface)
|
|
|
|
{
|
|
|
|
return g_object_get_qdata (G_OBJECT (surface),
|
|
|
|
quark_surface_inhibit_shortcuts_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
surface_inhibit_shortcuts_data_set (MetaWaylandSurface *surface,
|
|
|
|
InhibitShortcutsData *data)
|
|
|
|
{
|
|
|
|
g_object_set_qdata (G_OBJECT (surface),
|
|
|
|
quark_surface_inhibit_shortcuts_data,
|
|
|
|
data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-08-18 12:22:08 -04:00
|
|
|
surface_inhibit_shortcuts_data_destroy_dialog (InhibitShortcutsData *data)
|
2017-06-14 05:27:14 -04:00
|
|
|
{
|
2019-11-15 19:25:52 -05:00
|
|
|
g_clear_signal_handler (&data->response_handler_id, data->dialog);
|
2017-06-14 05:27:14 -04:00
|
|
|
meta_inhibit_shortcuts_dialog_hide (data->dialog);
|
2017-08-18 12:22:08 -04:00
|
|
|
g_clear_object (&data->dialog);
|
|
|
|
}
|
2017-06-14 05:27:14 -04:00
|
|
|
|
2017-08-18 12:22:08 -04:00
|
|
|
static void
|
|
|
|
surface_inhibit_shortcuts_data_free (InhibitShortcutsData *data)
|
|
|
|
{
|
|
|
|
if (data->dialog)
|
|
|
|
surface_inhibit_shortcuts_data_destroy_dialog (data);
|
2017-06-14 05:27:14 -04:00
|
|
|
g_free (data);
|
|
|
|
}
|
|
|
|
|
2017-08-18 12:17:48 -04:00
|
|
|
static void
|
|
|
|
on_surface_destroyed (MetaWaylandSurface *surface,
|
|
|
|
InhibitShortcutsData *data)
|
|
|
|
{
|
|
|
|
surface_inhibit_shortcuts_data_free (data);
|
|
|
|
g_object_set_qdata (G_OBJECT (surface),
|
|
|
|
quark_surface_inhibit_shortcuts_data,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
2017-06-14 05:27:14 -04:00
|
|
|
static void
|
|
|
|
inhibit_shortcuts_dialog_response_apply (InhibitShortcutsData *data)
|
|
|
|
{
|
|
|
|
if (data->last_response == META_INHIBIT_SHORTCUTS_DIALOG_RESPONSE_ALLOW)
|
|
|
|
meta_wayland_surface_inhibit_shortcuts (data->surface, data->seat);
|
|
|
|
else if (meta_wayland_surface_is_shortcuts_inhibited (data->surface, data->seat))
|
|
|
|
meta_wayland_surface_restore_shortcuts (data->surface, data->seat);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
inhibit_shortcuts_dialog_response_cb (MetaInhibitShortcutsDialog *dialog,
|
|
|
|
MetaInhibitShortcutsDialogResponse response,
|
|
|
|
InhibitShortcutsData *data)
|
|
|
|
{
|
|
|
|
data->last_response = response;
|
2017-08-18 12:06:22 -04:00
|
|
|
data->has_last_response = TRUE;
|
wayland: Keep the inhibit shortcut dialog
On Wayland, the grab()/ungrab() in gtk+/gdk are wired to the shortcut
inhibitor mechanism, which in turn shows the dialog, which can take
focus away from the client window when the dialog is shown.
If the client issues an ungrab() when the keyboard focus is lost, we
would hide the dialog, causing the keyboard focus to be returned to the
client surface, which in turn would issue a new grab(), so forth and so
on, causing a continuous show/hide of the shortcut inhibitor dialog.
To avoid this issue, keep the dialog around even if the shortcut inhibit
is canceled by the client, so that the user is forced to make a choice
that we can reuse on the next request without showing the dialog again.
Instead of hiding the dialog when the shortcut inhibitor is destroyed by
the client, we simply mark the request as canceled and do not apply the
user's choice.
https://bugzilla.gnome.org/show_bug.cgi?id=787568
2017-09-12 03:39:24 -04:00
|
|
|
|
|
|
|
/* If the request was canceled, we don't need to apply the choice made */
|
|
|
|
if (!data->request_canceled)
|
|
|
|
inhibit_shortcuts_dialog_response_apply (data);
|
2017-08-18 12:28:00 -04:00
|
|
|
|
|
|
|
meta_inhibit_shortcuts_dialog_hide (data->dialog);
|
|
|
|
surface_inhibit_shortcuts_data_destroy_dialog (data);
|
2017-06-14 05:27:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static InhibitShortcutsData *
|
|
|
|
meta_wayland_surface_ensure_inhibit_shortcuts_dialog (MetaWaylandSurface *surface,
|
|
|
|
MetaWaylandSeat *seat)
|
|
|
|
{
|
|
|
|
InhibitShortcutsData *data;
|
|
|
|
MetaWindow *window;
|
|
|
|
MetaDisplay *display;
|
|
|
|
MetaInhibitShortcutsDialog *dialog;
|
|
|
|
|
|
|
|
data = surface_inhibit_shortcuts_data_get (surface);
|
2017-08-18 12:17:48 -04:00
|
|
|
if (data)
|
2017-06-14 05:27:14 -04:00
|
|
|
return data;
|
|
|
|
|
2017-09-12 00:20:31 -04:00
|
|
|
data = g_new0 (InhibitShortcutsData, 1);
|
2017-08-18 12:17:48 -04:00
|
|
|
surface_inhibit_shortcuts_data_set (surface, data);
|
|
|
|
g_signal_connect (surface, "destroy",
|
|
|
|
G_CALLBACK (on_surface_destroyed),
|
|
|
|
data);
|
|
|
|
|
2017-06-14 05:27:14 -04:00
|
|
|
window = meta_wayland_surface_get_toplevel_window (surface);
|
|
|
|
display = window->display;
|
|
|
|
dialog =
|
|
|
|
meta_compositor_create_inhibit_shortcuts_dialog (display->compositor,
|
|
|
|
window);
|
|
|
|
|
|
|
|
data->surface = surface;
|
|
|
|
data->seat = seat;
|
|
|
|
data->dialog = dialog;
|
2017-08-18 12:22:08 -04:00
|
|
|
data->response_handler_id =
|
|
|
|
g_signal_connect (dialog, "response",
|
|
|
|
G_CALLBACK (inhibit_shortcuts_dialog_response_cb),
|
|
|
|
data);
|
2017-06-14 05:27:14 -04:00
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
meta_wayland_surface_show_inhibit_shortcuts_dialog (MetaWaylandSurface *surface,
|
|
|
|
MetaWaylandSeat *seat)
|
|
|
|
{
|
|
|
|
InhibitShortcutsData *data;
|
|
|
|
|
|
|
|
g_return_if_fail (META_IS_WAYLAND_SURFACE (surface));
|
|
|
|
|
|
|
|
data = surface_inhibit_shortcuts_data_get (surface);
|
2017-08-18 12:06:22 -04:00
|
|
|
if (data && data->has_last_response)
|
2017-06-14 05:27:14 -04:00
|
|
|
{
|
|
|
|
/* The dialog was shown before for this surface but is not showing
|
|
|
|
* anymore, reuse the last user response.
|
|
|
|
*/
|
|
|
|
inhibit_shortcuts_dialog_response_apply (data);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
data = meta_wayland_surface_ensure_inhibit_shortcuts_dialog (surface, seat);
|
wayland: Keep the inhibit shortcut dialog
On Wayland, the grab()/ungrab() in gtk+/gdk are wired to the shortcut
inhibitor mechanism, which in turn shows the dialog, which can take
focus away from the client window when the dialog is shown.
If the client issues an ungrab() when the keyboard focus is lost, we
would hide the dialog, causing the keyboard focus to be returned to the
client surface, which in turn would issue a new grab(), so forth and so
on, causing a continuous show/hide of the shortcut inhibitor dialog.
To avoid this issue, keep the dialog around even if the shortcut inhibit
is canceled by the client, so that the user is forced to make a choice
that we can reuse on the next request without showing the dialog again.
Instead of hiding the dialog when the shortcut inhibitor is destroyed by
the client, we simply mark the request as canceled and do not apply the
user's choice.
https://bugzilla.gnome.org/show_bug.cgi?id=787568
2017-09-12 03:39:24 -04:00
|
|
|
/* This is a new request */
|
|
|
|
data->request_canceled = FALSE;
|
|
|
|
|
2017-06-14 05:27:14 -04:00
|
|
|
meta_inhibit_shortcuts_dialog_show (data->dialog);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
wayland: Keep the inhibit shortcut dialog
On Wayland, the grab()/ungrab() in gtk+/gdk are wired to the shortcut
inhibitor mechanism, which in turn shows the dialog, which can take
focus away from the client window when the dialog is shown.
If the client issues an ungrab() when the keyboard focus is lost, we
would hide the dialog, causing the keyboard focus to be returned to the
client surface, which in turn would issue a new grab(), so forth and so
on, causing a continuous show/hide of the shortcut inhibitor dialog.
To avoid this issue, keep the dialog around even if the shortcut inhibit
is canceled by the client, so that the user is forced to make a choice
that we can reuse on the next request without showing the dialog again.
Instead of hiding the dialog when the shortcut inhibitor is destroyed by
the client, we simply mark the request as canceled and do not apply the
user's choice.
https://bugzilla.gnome.org/show_bug.cgi?id=787568
2017-09-12 03:39:24 -04:00
|
|
|
meta_wayland_surface_cancel_inhibit_shortcuts_dialog (MetaWaylandSurface *surface)
|
2017-06-14 05:27:14 -04:00
|
|
|
{
|
|
|
|
InhibitShortcutsData *data;
|
|
|
|
|
|
|
|
g_return_if_fail (META_IS_WAYLAND_SURFACE (surface));
|
|
|
|
|
|
|
|
/* The closure notify will take care of actually hiding the dialog */
|
|
|
|
data = surface_inhibit_shortcuts_data_get (surface);
|
2017-08-18 12:24:23 -04:00
|
|
|
g_return_if_fail (data);
|
|
|
|
|
wayland: Keep the inhibit shortcut dialog
On Wayland, the grab()/ungrab() in gtk+/gdk are wired to the shortcut
inhibitor mechanism, which in turn shows the dialog, which can take
focus away from the client window when the dialog is shown.
If the client issues an ungrab() when the keyboard focus is lost, we
would hide the dialog, causing the keyboard focus to be returned to the
client surface, which in turn would issue a new grab(), so forth and so
on, causing a continuous show/hide of the shortcut inhibitor dialog.
To avoid this issue, keep the dialog around even if the shortcut inhibit
is canceled by the client, so that the user is forced to make a choice
that we can reuse on the next request without showing the dialog again.
Instead of hiding the dialog when the shortcut inhibitor is destroyed by
the client, we simply mark the request as canceled and do not apply the
user's choice.
https://bugzilla.gnome.org/show_bug.cgi?id=787568
2017-09-12 03:39:24 -04:00
|
|
|
/* Keep the dialog on screen, but mark the request as canceled */
|
|
|
|
data->request_canceled = TRUE;
|
2017-06-14 05:27:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
meta_wayland_surface_inhibit_shortcuts_dialog_init (void)
|
|
|
|
{
|
|
|
|
quark_surface_inhibit_shortcuts_data =
|
|
|
|
g_quark_from_static_string ("-meta-wayland-surface-inhibit-shortcuts-data");
|
|
|
|
}
|