-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wl: Add an XdpParent on file chooser dialog
The XdpParent needs to know the "parent_window" string to keep the dialog on top. On wayland this "parent_window" can be obtained using the xdg-foreign protocol. This protocol is used on this XdpParent implementation. First it must call export_toplevel method, and then register a callback to receive a handle which is the "parent_window". To store the required data for this XdpParent implementation it is used the private "data" pointer property as a xdp_parent_wl_data. XdpParent isn't responsible of freeing it, so that data is handled at cog-platform-wl.
- Loading branch information
Showing
4 changed files
with
109 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* cog-xdp-parent-wl.c | ||
* Copyright (C) 2023 SUSE Software Solutions Germany GmbH | ||
* | ||
* Distributed under terms of the MIT license. | ||
*/ | ||
|
||
#include "cog-xdp-parent-wl.h" | ||
|
||
#include "../common/xdp-parent-private.h" | ||
|
||
static void | ||
handle_exported(void *data, struct zxdg_exported_v2 *zxdg_exported_v2, const char *handle) | ||
{ | ||
XdpParent *parent = data; | ||
struct xdp_parent_wl_data *wl_data = (struct xdp_parent_wl_data *) parent->data; | ||
g_autofree char *handle_str = g_strdup_printf("wayland:%s", handle); | ||
|
||
parent->callback(parent, handle_str, wl_data->user_data); | ||
} | ||
|
||
static const struct zxdg_exported_v2_listener zxdg_exported_listener = { | ||
.handle = handle_exported, | ||
}; | ||
|
||
static gboolean | ||
xdp_parent_export_wl(XdpParent *parent, XdpParentExported callback, gpointer user_data) | ||
{ | ||
struct xdp_parent_wl_data *wl_data = (struct xdp_parent_wl_data *) parent->data; | ||
|
||
parent->callback = callback; | ||
wl_data->user_data = user_data; | ||
wl_data->zxdg_exported = zxdg_exporter_v2_export_toplevel(wl_data->zxdg_exporter, wl_data->wl_surface); | ||
|
||
return zxdg_exported_v2_add_listener(wl_data->zxdg_exported, &zxdg_exported_listener, parent); | ||
} | ||
|
||
static void | ||
xdp_parent_unexport_wl(XdpParent *parent) | ||
{ | ||
struct xdp_parent_wl_data *wl_data = (struct xdp_parent_wl_data *) parent->data; | ||
|
||
zxdg_exported_v2_destroy(wl_data->zxdg_exported); | ||
} | ||
|
||
XdpParent * | ||
xdp_parent_new_wl(struct xdp_parent_wl_data *wl_data) | ||
{ | ||
XdpParent *parent = g_new0(XdpParent, 1); | ||
parent->parent_export = xdp_parent_export_wl; | ||
parent->parent_unexport = xdp_parent_unexport_wl; | ||
parent->data = (gpointer) wl_data; | ||
return parent; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* cog-xdp-parent-wl.h | ||
* Copyright (C) 2023 SUSE Software Solutions Germany GmbH | ||
* | ||
* Distributed under terms of the MIT license. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <libportal/types.h> | ||
|
||
#include "xdg-foreign-unstable-v2-client.h" | ||
|
||
G_BEGIN_DECLS | ||
|
||
struct xdp_parent_wl_data { | ||
struct wl_surface *wl_surface; | ||
struct zxdg_exporter_v2 *zxdg_exporter; | ||
struct zxdg_exported_v2 *zxdg_exported; | ||
gpointer user_data; | ||
}; | ||
|
||
XdpParent *xdp_parent_new_wl(struct xdp_parent_wl_data *wl_data); | ||
|
||
G_END_DECLS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters