File: mdk-window.c

package info (click to toggle)
mutter 49.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 51,732 kB
  • sloc: ansic: 397,916; xml: 3,384; python: 3,270; sh: 389; ruby: 167; makefile: 61; javascript: 26
file content (180 lines) | stat: -rw-r--r-- 5,145 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/*
 * Copyright (C) 2025 Red Hat Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
 */

#include "config.h"

#include "mdk-window.h"

#include "mdk-context.h"

enum
{
  PROP_0,

  PROP_CONTEXT,

  N_PROPS
};

static GParamSpec *obj_props[N_PROPS];

typedef struct _MdkWindowPrivate
{
  MdkContext *context;

  gboolean is_system_shortcuts_inhibited;
} MdkWindowPrivate;

G_DEFINE_TYPE_WITH_PRIVATE (MdkWindow, mdk_window, GTK_TYPE_APPLICATION_WINDOW)

static void
mdk_window_dispose (GObject *object)
{
  gtk_widget_dispose_template (GTK_WIDGET (object), MDK_TYPE_WINDOW);

  G_OBJECT_CLASS (mdk_window_parent_class)->dispose (object);
}

static void
mdk_window_set_property (GObject      *object,
                         guint         prop_id,
                         const GValue *value,
                         GParamSpec   *pspec)
{
  MdkWindow *window = MDK_WINDOW (object);
  MdkWindowPrivate *priv = mdk_window_get_instance_private (window);

  switch (prop_id)
    {
    case PROP_CONTEXT:
      priv->context = g_value_get_object (value);
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
    }
}

static void
mdk_window_get_property (GObject    *object,
                         guint       prop_id,
                         GValue     *value,
                         GParamSpec *pspec)
{
  MdkWindow *window = MDK_WINDOW (object);
  MdkWindowPrivate *priv = mdk_window_get_instance_private (window);

  switch (prop_id)
    {
    case PROP_CONTEXT:
      g_value_set_object (value, priv->context);
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
    }
}

static void
sync_system_shortcut_inhibitation (MdkWindow *window)
{
  MdkWindowPrivate *priv = mdk_window_get_instance_private (window);
  gboolean should_inhibit_system_shortcuts;
  GtkNative *native;
  GdkSurface *surface;

  should_inhibit_system_shortcuts =
    mdk_context_get_inhibit_system_shortcuts (priv->context) &&
    gtk_widget_is_visible (GTK_WIDGET (window));

  if (priv->is_system_shortcuts_inhibited == should_inhibit_system_shortcuts)
    return;

  priv->is_system_shortcuts_inhibited = should_inhibit_system_shortcuts;

  native = gtk_widget_get_native (GTK_WIDGET (window));
  surface = gtk_native_get_surface (native);

  if (should_inhibit_system_shortcuts)
    gdk_toplevel_inhibit_system_shortcuts (GDK_TOPLEVEL (surface), NULL);
  else
    gdk_toplevel_restore_system_shortcuts (GDK_TOPLEVEL (surface));
}

static void
on_inhibit_system_shortcuts_changed (MdkContext *context,
                                     GParamSpec *pspec,
                                     MdkWindow  *window)
{
  sync_system_shortcut_inhibitation (window);
}

static void
on_show (MdkWindow *window)
{
  sync_system_shortcut_inhibitation (window);
}

static void
mdk_window_constructed (GObject *object)
{
  MdkWindow *window = MDK_WINDOW (object);
  MdkWindowPrivate *priv = mdk_window_get_instance_private (window);

  g_signal_connect (window, "show", G_CALLBACK (on_show), NULL);
  g_signal_connect (priv->context, "notify::inhibit-system-shortcuts",
                    G_CALLBACK (on_inhibit_system_shortcuts_changed),
                    window);

  G_OBJECT_CLASS (mdk_window_parent_class)->constructed (object);
}

static void
mdk_window_class_init (MdkWindowClass *klass)
{
  GObjectClass *object_class = G_OBJECT_CLASS (klass);
  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);

  object_class->dispose = mdk_window_dispose;
  object_class->set_property = mdk_window_set_property;
  object_class->get_property = mdk_window_get_property;
  object_class->constructed = mdk_window_constructed;

  gtk_widget_class_set_template_from_resource (widget_class,
                                               "/ui/mdk-window.ui");

  obj_props[PROP_CONTEXT] = g_param_spec_object ("context", NULL, NULL,
                                                 MDK_TYPE_CONTEXT,
                                                 G_PARAM_CONSTRUCT_ONLY |
                                                 G_PARAM_READWRITE |
                                                 G_PARAM_STATIC_STRINGS);
  g_object_class_install_properties (object_class, N_PROPS, obj_props);
}

static void
mdk_window_init (MdkWindow *window)
{
  gtk_widget_init_template (GTK_WIDGET (window));
}

MdkContext *
mdk_window_get_context (MdkWindow *window)
{
  MdkWindowPrivate *priv = mdk_window_get_instance_private (window);

  return priv->context;
}