summaryrefslogtreecommitdiff
path: root/gdk/gdktoplevelsize.c
blob: e5802782d4a46a6bc67e2d65efce96830b6d5ede (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
/* 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 "gdktoplevelsizeprivate.h"

/**
 * SECTION:gdktoplevelsize
 * @Title: GdkToplevelSize
 * @Short_description: Information for computing toplevel size
 *
 * The GdkToplevelSIze struct contains information that may be useful
 * for users of GdkToplevel to compute a surface size. It also carries
 * information back with the computational result.
 */

G_DEFINE_POINTER_TYPE (GdkToplevelSize, gdk_toplevel_size)

#define UNCONFIGURED_WIDTH 400
#define UNCONFIGURED_HEIGHT 300

void
gdk_toplevel_size_init (GdkToplevelSize *size,
                        int              bounds_width,
                        int              bounds_height)
{
  *size = (GdkToplevelSize) { 0 };

  size->bounds_width = bounds_width;
  size->bounds_height = bounds_height;

  size->width = UNCONFIGURED_WIDTH;
  size->height = UNCONFIGURED_HEIGHT;
}

/**
 * gdk_toplevel_size_get_bounds:
 * @size: a #GdkToplevelSize
 * @bounds_width: (out): return location for width
 * @bounds_height: (out): return location for height
 *
 * Retrieves the bounds the toplevel is placed within.
 *
 * The bounds represent the largest size a toplevel may have while still being
 * able to fit within some type of boundary. Depending on the backend, this may
 * be equivalent to the dimensions of the work area or the monitor on which the
 * window is being presented on, or something else that limits the way a
 * toplevel can be presented.
 */
void
gdk_toplevel_size_get_bounds (GdkToplevelSize *size,
                              int             *bounds_width,
                              int             *bounds_height)
{
  g_return_if_fail (bounds_width);
  g_return_if_fail (bounds_height);

  *bounds_width = size->bounds_width;
  *bounds_height = size->bounds_height;
}

/**
 * gdk_toplevel_size_set_size:
 * @size: a #GdkToplevelSize
 * @width: the width
 * @height: the height
 *
 * Sets the size the toplevel prefers to be resized to. The size should be
 * within the bounds (see gdk_toplevel_size_get_bounds()). The set size should
 * be considered as a hint, and should not be assumed to be respected by the
 * windowing system, or backend.
 */
void
gdk_toplevel_size_set_size (GdkToplevelSize *size,
                            int              width,
                            int              height)
{
  size->width = width;
  size->height = height;
}

/**
 * gdk_toplevel_size_set_min_size:
 * @size: a #GdkToplevelSize
 * @min_width: the minimum width
 * @min_height: the minimum height
 *
 * The minimum size corresponds to the limitations the toplevel can be shrunk
 * to, without resulting in incorrect painting. A user of a #GdkToplevel should
 * calculate these given both the existing size, and the bounds retrieved from
 * the #GdkToplevelSize object.
 *
 * The minimum size should be within the bounds (see
 * gdk_toplevel_size_get_bounds()).
 */
void
gdk_toplevel_size_set_min_size (GdkToplevelSize *size,
                                int              min_width,
                                int              min_height)
{
  size->min_width = min_width;
  size->min_height = min_height;
}

void
gdk_toplevel_size_validate (GdkToplevelSize *size)
{
  if (size->min_width > size->bounds_width ||
      size->min_height > size->bounds_height)
    g_warning ("GdkToplevelSize: min_size (%d, %d) exceeds bounds (%d, %d)",
               size->min_width, size->min_height,
               size->bounds_width, size->bounds_height);

  if (size->width > size->bounds_width ||
      size->height > size->bounds_height)
    g_warning ("GdkToplevelSize: size (%d, %d) exceeds bounds (%d, %d)",
               size->width, size->height,
               size->bounds_width, size->bounds_height);

  if (size->min_width > size->width ||
      size->min_height > size->height)
    g_warning ("GdkToplevelSize: min_size (%d, %d) exceeds size (%d, %d)",
               size->min_width, size->min_height,
               size->width, size->height);
}