2020-02-29 15:31:22 +00:00
|
|
|
/* 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"
|
|
|
|
|
|
|
|
/**
|
2021-02-21 05:13:57 +00:00
|
|
|
* GdkToplevelLayout:
|
|
|
|
*
|
|
|
|
* The `GdkToplevelLayout` struct contains information that
|
|
|
|
* is necessary to present a sovereign window on screen.
|
|
|
|
*
|
2021-02-22 00:11:52 +00:00
|
|
|
* The `GdkToplevelLayout` struct is necessary for using
|
|
|
|
* [method@Gdk.Toplevel.present].
|
2020-02-29 15:31:22 +00:00
|
|
|
*
|
|
|
|
* 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;
|
2020-12-16 10:53:19 +00:00
|
|
|
|
|
|
|
guint maximized_valid : 1;
|
2020-02-29 15:31:22 +00:00
|
|
|
guint maximized : 1;
|
2020-12-16 10:53:19 +00:00
|
|
|
guint fullscreen_valid : 1;
|
2020-02-29 15:31:22 +00:00
|
|
|
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.
|
|
|
|
*
|
2020-04-13 13:29:11 +00:00
|
|
|
* The size is in ”application pixels”, not
|
|
|
|
* ”device pixels” (see gdk_surface_get_scale_factor()).
|
|
|
|
*
|
2021-05-20 03:39:18 +00:00
|
|
|
* Returns: (transfer full): newly created instance of `GdkToplevelLayout`
|
2020-02-29 15:31:22 +00:00
|
|
|
*/
|
|
|
|
GdkToplevelLayout *
|
2020-07-30 21:06:59 +00:00
|
|
|
gdk_toplevel_layout_new (void)
|
2020-02-29 15:31:22 +00:00
|
|
|
{
|
|
|
|
GdkToplevelLayout *layout;
|
|
|
|
|
|
|
|
layout = g_new0 (GdkToplevelLayout, 1);
|
|
|
|
g_ref_count_init (&layout->ref_count);
|
|
|
|
layout->resizable = TRUE;
|
2020-12-16 10:53:19 +00:00
|
|
|
layout->maximized_valid = FALSE;
|
2020-02-29 15:31:22 +00:00
|
|
|
layout->maximized = FALSE;
|
2020-12-16 10:53:19 +00:00
|
|
|
layout->fullscreen_valid = FALSE;
|
2020-02-29 15:31:22 +00:00
|
|
|
layout->fullscreen = FALSE;
|
|
|
|
layout->fullscreen_monitor = NULL;
|
|
|
|
|
|
|
|
return layout;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gdk_toplevel_layout_ref:
|
2021-05-20 03:39:18 +00:00
|
|
|
* @layout: a `GdkToplevelLayout`
|
2020-02-29 15:31:22 +00:00
|
|
|
*
|
|
|
|
* 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:
|
2021-05-20 03:39:18 +00:00
|
|
|
* @layout: a `GdkToplevelLayout`
|
2020-02-29 15:31:22 +00:00
|
|
|
*
|
|
|
|
* 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:
|
2021-05-20 03:39:18 +00:00
|
|
|
* @layout: a `GdkToplevelLayout`
|
2020-02-29 15:31:22 +00:00
|
|
|
*
|
2021-05-20 03:39:18 +00:00
|
|
|
* Create a new `GdkToplevelLayout` and copy the contents of @layout into it.
|
2020-02-29 15:31:22 +00:00
|
|
|
*
|
|
|
|
* 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;
|
2020-12-16 10:53:19 +00:00
|
|
|
new_layout->maximized_valid = layout->maximized_valid;
|
2020-02-29 15:31:22 +00:00
|
|
|
new_layout->maximized = layout->maximized;
|
2020-12-16 10:53:19 +00:00
|
|
|
new_layout->fullscreen_valid = layout->fullscreen_valid;
|
2020-02-29 15:31:22 +00:00
|
|
|
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:
|
2021-05-20 03:39:18 +00:00
|
|
|
* @layout: a `GdkToplevelLayout`
|
|
|
|
* @other: another `GdkToplevelLayout`
|
2020-02-29 15:31:22 +00:00
|
|
|
*
|
|
|
|
* Check whether @layout and @other has identical layout properties.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if @layout and @other have identical layout properties,
|
2021-05-18 21:05:26 +00:00
|
|
|
* otherwise %FALSE.
|
2020-02-29 15:31:22 +00:00
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gdk_toplevel_layout_equal (GdkToplevelLayout *layout,
|
|
|
|
GdkToplevelLayout *other)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (layout, FALSE);
|
|
|
|
g_return_val_if_fail (other, FALSE);
|
|
|
|
|
2020-07-30 21:06:59 +00:00
|
|
|
return layout->resizable == other->resizable &&
|
2020-12-16 10:53:19 +00:00
|
|
|
layout->maximized_valid == other->maximized_valid &&
|
2020-02-29 15:31:22 +00:00
|
|
|
layout->maximized == other->maximized &&
|
2020-12-16 10:53:19 +00:00
|
|
|
layout->fullscreen_valid == other->fullscreen_valid &&
|
2020-02-29 15:31:22 +00:00
|
|
|
layout->fullscreen == other->fullscreen &&
|
|
|
|
layout->fullscreen_monitor == other->fullscreen_monitor;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gdk_toplevel_layout_set_resizable:
|
2021-05-20 03:39:18 +00:00
|
|
|
* @layout: a `GdkToplevelLayout`
|
2020-02-29 15:31:22 +00:00
|
|
|
* @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:
|
2021-05-20 03:39:18 +00:00
|
|
|
* @layout: a `GdkToplevelLayout`
|
2020-02-29 15:31:22 +00:00
|
|
|
*
|
|
|
|
* 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:
|
2021-05-20 03:39:18 +00:00
|
|
|
* @layout: a `GdkToplevelLayout`
|
2020-02-29 15:31:22 +00:00
|
|
|
* @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)
|
|
|
|
{
|
2020-12-16 10:53:19 +00:00
|
|
|
layout->maximized_valid = TRUE;
|
2020-02-29 15:31:22 +00:00
|
|
|
layout->maximized = maximized;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gdk_toplevel_layout_get_maximized:
|
2021-05-20 03:39:18 +00:00
|
|
|
* @layout: a `GdkToplevelLayout`
|
2020-12-16 10:53:19 +00:00
|
|
|
* @maximized: (out): set to %TRUE if the toplevel should be maximized
|
2020-02-29 15:31:22 +00:00
|
|
|
*
|
2020-12-16 10:53:19 +00:00
|
|
|
* 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.
|
2020-02-29 15:31:22 +00:00
|
|
|
*
|
2020-12-16 10:53:19 +00:00
|
|
|
* Returns: whether the @layout specifies the maximized state for the toplevel
|
2020-02-29 15:31:22 +00:00
|
|
|
*/
|
|
|
|
gboolean
|
2020-12-16 10:53:19 +00:00
|
|
|
gdk_toplevel_layout_get_maximized (GdkToplevelLayout *layout,
|
|
|
|
gboolean *maximized)
|
2020-02-29 15:31:22 +00:00
|
|
|
{
|
2020-12-16 10:53:19 +00:00
|
|
|
if (layout->maximized_valid)
|
|
|
|
{
|
|
|
|
*maximized = layout->maximized;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
2020-02-29 15:31:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gdk_toplevel_layout_set_fullscreen:
|
2021-05-20 03:39:18 +00:00
|
|
|
* @layout: a `GdkToplevelLayout`
|
2020-02-29 15:31:22 +00:00
|
|
|
* @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)
|
|
|
|
{
|
2020-12-16 10:53:19 +00:00
|
|
|
layout->fullscreen_valid = TRUE;
|
2020-02-29 15:31:22 +00:00
|
|
|
layout->fullscreen = fullscreen;
|
|
|
|
if (monitor)
|
|
|
|
layout->fullscreen_monitor = g_object_ref (monitor);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gdk_toplevel_layout_get_fullscreen:
|
2021-05-20 03:39:18 +00:00
|
|
|
* @layout: a ``GdkToplevelLayout`
|
2020-12-16 10:53:19 +00:00
|
|
|
* @fullscreen: (out): location to store whether the toplevel should be fullscreen
|
2020-02-29 15:31:22 +00:00
|
|
|
*
|
2020-12-16 10:53:19 +00:00
|
|
|
* 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.
|
2020-02-29 15:31:22 +00:00
|
|
|
*
|
2020-12-16 10:53:19 +00:00
|
|
|
* Returns: whether the @layout specifies the fullscreen state for the toplevel
|
2020-02-29 15:31:22 +00:00
|
|
|
*/
|
|
|
|
gboolean
|
2020-12-16 10:53:19 +00:00
|
|
|
gdk_toplevel_layout_get_fullscreen (GdkToplevelLayout *layout,
|
|
|
|
gboolean *fullscreen)
|
2020-02-29 15:31:22 +00:00
|
|
|
{
|
2020-12-16 10:53:19 +00:00
|
|
|
if (layout->fullscreen_valid)
|
|
|
|
{
|
|
|
|
*fullscreen = layout->fullscreen;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
2020-02-29 15:31:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gdk_toplevel_layout_get_fullscreen_monitor:
|
2021-05-20 03:39:18 +00:00
|
|
|
* @layout: a `GdkToplevelLayout`
|
2020-02-29 15:31:22 +00:00
|
|
|
*
|
|
|
|
* Returns the monitor that the layout is fullscreening
|
|
|
|
* the surface on.
|
|
|
|
*
|
2020-04-03 14:30:56 +00:00
|
|
|
* Returns: (nullable) (transfer none): the monitor on which @layout fullscreens
|
2020-02-29 15:31:22 +00:00
|
|
|
*/
|
|
|
|
GdkMonitor *
|
|
|
|
gdk_toplevel_layout_get_fullscreen_monitor (GdkToplevelLayout *layout)
|
|
|
|
{
|
|
|
|
return layout->fullscreen_monitor;
|
|
|
|
}
|