summaryrefslogtreecommitdiff
path: root/gdk/gdktoplevellayout.c
blob: 64f648c476e5f2ec9fdcba974acd8a38fdba9c13 (plain)
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
/* GDK - The GIMP Drawing Kit
 * Copyright (C) 2020 Red Hat
 *
 * 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 "gdktoplevellayout.h"

#include "gdkmonitor.h"

/**
 * GdkToplevelLayout:
 *
 * The `GdkToplevelLayout` struct contains information that
 * is necessary to present a sovereign window on screen.
 *
 * The `GdkToplevelLayout` struct is necessary for using
 * [method@Gdk.Toplevel.present].
 *
 * Toplevel surfaces are sovereign windows that can be presented
 * to the user in various states (maximized, on all workspaces,
 * etc).
 */
struct _GdkToplevelLayout
{
  /* < private >*/
  grefcount ref_count;

  guint resizable  : 1;

  guint maximized_valid : 1;
  guint maximized  : 1;
  guint fullscreen_valid : 1;
  guint fullscreen : 1;
  GdkMonitor *fullscreen_monitor;
};

G_DEFINE_BOXED_TYPE (GdkToplevelLayout, gdk_toplevel_layout,
                     gdk_toplevel_layout_ref,
                     gdk_toplevel_layout_unref)

/**
 * gdk_toplevel_layout_new: (constructor)
 *
 * Create a toplevel layout description.
 *
 * Used together with gdk_toplevel_present() to describe
 * how a toplevel surface should be placed and behave on-screen.
 *
 * The size is in ”application pixels”, not
 * ”device pixels” (see gdk_surface_get_scale_factor()).
 *
 * Returns: (transfer full): newly created instance of `GdkToplevelLayout`
 */
GdkToplevelLayout *
gdk_toplevel_layout_new (void)
{
  GdkToplevelLayout *layout;

  layout = g_new0 (GdkToplevelLayout, 1);
  g_ref_count_init (&layout->ref_count);
  layout->resizable = TRUE;
  layout->maximized_valid = FALSE;
  layout->maximized = FALSE;
  layout->fullscreen_valid = FALSE;
  layout->fullscreen = FALSE;
  layout->fullscreen_monitor = NULL;

  return layout;
}

/**
 * gdk_toplevel_layout_ref:
 * @layout: a `GdkToplevelLayout`
 *
 * Increases the reference count of @layout.
 *
 * Returns: the same @layout
 */
GdkToplevelLayout *
gdk_toplevel_layout_ref (GdkToplevelLayout *layout)
{
  g_ref_count_inc (&layout->ref_count);
  return layout;
}

/**
 * gdk_toplevel_layout_unref:
 * @layout: a `GdkToplevelLayout`
 *
 * Decreases the reference count of @layout.
 */
void
gdk_toplevel_layout_unref (GdkToplevelLayout *layout)
{
  if (g_ref_count_dec (&layout->ref_count))
    {
      g_clear_object (&layout->fullscreen_monitor);
      g_free (layout);
    }
}

/**
 * gdk_toplevel_layout_copy:
 * @layout: a `GdkToplevelLayout`
 *
 * Create a new `GdkToplevelLayout` and copy the contents of @layout into it.
 *
 * Returns: (transfer full): a copy of @layout.
 */
GdkToplevelLayout *
gdk_toplevel_layout_copy (GdkToplevelLayout *layout)
{
  GdkToplevelLayout *new_layout;

  new_layout = g_new0 (GdkToplevelLayout, 1);
  g_ref_count_init (&new_layout->ref_count);

  new_layout->resizable = layout->resizable;
  new_layout->maximized_valid = layout->maximized_valid;
  new_layout->maximized = layout->maximized;
  new_layout->fullscreen_valid = layout->fullscreen_valid;
  new_layout->fullscreen = layout->fullscreen;
  if (layout->fullscreen_monitor)
    new_layout->fullscreen_monitor = g_object_ref (layout->fullscreen_monitor);

  return new_layout;
}

/**
 * gdk_toplevel_layout_equal:
 * @layout: a `GdkToplevelLayout`
 * @other: another `GdkToplevelLayout`
 *
 * Check whether @layout and @other has identical layout properties.
 *
 * Returns: %TRUE if @layout and @other have identical layout properties,
 *   otherwise %FALSE.
 */
gboolean
gdk_toplevel_layout_equal (GdkToplevelLayout *layout,
                           GdkToplevelLayout *other)
{
  g_return_val_if_fail (layout, FALSE);
  g_return_val_if_fail (other, FALSE);

  return layout->resizable == other->resizable &&
         layout->maximized_valid == other->maximized_valid &&
         layout->maximized == other->maximized &&
         layout->fullscreen_valid == other->fullscreen_valid &&
         layout->fullscreen == other->fullscreen &&
         layout->fullscreen_monitor == other->fullscreen_monitor;
}

/**
 * gdk_toplevel_layout_set_resizable:
 * @layout: a `GdkToplevelLayout`
 * @resizable: %TRUE to allow resizing
 *
 * Sets whether the layout should allow the user
 * to resize the surface after it has been presented.
 */
void
gdk_toplevel_layout_set_resizable (GdkToplevelLayout *layout,
                                   gboolean           resizable)
{
  layout->resizable = resizable;
}

/**
 * gdk_toplevel_layout_get_resizable:
 * @layout: a `GdkToplevelLayout`
 *
 * Returns whether the layout should allow the user
 * to resize the surface.
 *
 * Returns: %TRUE if the layout is resizable
 */
gboolean
gdk_toplevel_layout_get_resizable (GdkToplevelLayout *layout)
{
  return layout->resizable;
}

/**
 * gdk_toplevel_layout_set_maximized:
 * @layout: a `GdkToplevelLayout`
 * @maximized: %TRUE to maximize
 *
 * Sets whether the layout should cause the surface
 * to be maximized when presented.
 */
void
gdk_toplevel_layout_set_maximized (GdkToplevelLayout *layout,
                                   gboolean           maximized)
{
  layout->maximized_valid = TRUE;
  layout->maximized = maximized;
}

/**
 * gdk_toplevel_layout_get_maximized:
 * @layout: a `GdkToplevelLayout`
 * @maximized: (out): set to %TRUE if the toplevel should be maximized
 *
 * If the layout specifies whether to the toplevel should go maximized,
 * the value pointed to by @maximized is set to %TRUE if it should go
 * fullscreen, or %FALSE, if it should go unmaximized.
 *
 * Returns: whether the @layout specifies the maximized state for the toplevel
 */
gboolean
gdk_toplevel_layout_get_maximized (GdkToplevelLayout *layout,
                                   gboolean          *maximized)
{
  if (layout->maximized_valid)
    {
      *maximized = layout->maximized;
      return TRUE;
    }

  return FALSE;
}

/**
 * gdk_toplevel_layout_set_fullscreen:
 * @layout: a `GdkToplevelLayout`
 * @fullscreen: %TRUE to fullscreen the surface
 * @monitor: (nullable): the monitor to fullscreen on
 *
 * Sets whether the layout should cause the surface
 * to be fullscreen when presented.
 */
void
gdk_toplevel_layout_set_fullscreen (GdkToplevelLayout *layout,
                                    gboolean           fullscreen,
                                    GdkMonitor        *monitor)
{
  layout->fullscreen_valid = TRUE;
  layout->fullscreen = fullscreen;
  if (monitor)
    layout->fullscreen_monitor = g_object_ref (monitor);
}

/**
 * gdk_toplevel_layout_get_fullscreen:
 * @layout: a ``GdkToplevelLayout`
 * @fullscreen: (out): location to store whether the toplevel should be fullscreen
 *
 * If the layout specifies whether to the toplevel should go fullscreen,
 * the value pointed to by @fullscreen is set to %TRUE if it should go
 * fullscreen, or %FALSE, if it should go unfullscreen.
 *
 * Returns: whether the @layout specifies the fullscreen state for the toplevel
 */
gboolean
gdk_toplevel_layout_get_fullscreen (GdkToplevelLayout *layout,
                                    gboolean          *fullscreen)
{
  if (layout->fullscreen_valid)
    {
      *fullscreen = layout->fullscreen;
      return TRUE;
    }

  return FALSE;
}

/**
 * gdk_toplevel_layout_get_fullscreen_monitor:
 * @layout: a `GdkToplevelLayout`
 *
 * Returns the monitor that the layout is fullscreening
 * the surface on.
 *
 * Returns: (nullable) (transfer none): the monitor on which @layout fullscreens
 */
GdkMonitor *
gdk_toplevel_layout_get_fullscreen_monitor (GdkToplevelLayout *layout)
{
  return layout->fullscreen_monitor;
}