Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a window hint for setting app_id on wayland #2122

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Expand Up @@ -157,6 +157,7 @@ video tutorials.
- Peoro
- Braden Pellett
- Christopher Pelloux
- Michael Pennington
- Arturo J. Pérez
- Vladimir Perminov
- Anthony Pesch
Expand Down
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -121,6 +121,8 @@ information on what to include when reporting a bug.

## Changelog

- Added `GLFW_WAYLAND_APP_ID` window hint string for wayland app_id selection
(#2121)
- Added `GLFW_PLATFORM` init hint for runtime platform selection (#1958)
- Added `GLFW_ANY_PLATFORM`, `GLFW_PLATFORM_WIN32`, `GLFW_PLATFORM_COCOA`,
`GLFW_PLATFORM_WAYLAND`, `GLFW_PLATFORM_X11` and `GLFW_PLATFORM_NULL` symbols to
Expand Down
5 changes: 5 additions & 0 deletions docs/news.dox
Expand Up @@ -9,6 +9,11 @@

@subsection features_34 New features in version 3.4

@subsubsection wayland_app_id_32 Wayland app_id specification

GLFW now supports specifying the app_id for a wayland window using the
@ref GLFW_WAYLAND_APP_ID window hint string.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably link to GLFW_WAYLAND_APP_ID_hint, like in the header file documentation snippet.


@subsubsection runtime_platform_34 Runtime platform selection

GLFW now supports being compiled for multiple backends and selecting between
Expand Down
8 changes: 8 additions & 0 deletions docs/window.dox
Expand Up @@ -492,6 +492,13 @@ __GLFW_X11_CLASS_NAME__ and __GLFW_X11_INSTANCE_NAME__ specifies the desired
ASCII encoded class and instance parts of the ICCCM `WM_CLASS` window property.
These are set with @ref glfwWindowHintString.

@subsubsection window_hints_wayland Wayland specific window hints

@anchor GLFW_WAYLAND_APP_ID_hint
__GLFW_WAYLAND_APP_ID__ specifies the wayland app_id for a wayland window, used
by window managers to identify types of windows. This is set with
@ref glfwWindowHintString.


@subsubsection window_hints_values Supported and default values

Expand Down Expand Up @@ -540,6 +547,7 @@ GLFW_COCOA_FRAME_NAME | `""` | A UTF-8 encoded fr
GLFW_COCOA_GRAPHICS_SWITCHING | `GLFW_FALSE` | `GLFW_TRUE` or `GLFW_FALSE`
GLFW_X11_CLASS_NAME | `""` | An ASCII encoded `WM_CLASS` class name
GLFW_X11_INSTANCE_NAME | `""` | An ASCII encoded `WM_CLASS` instance name
GLFW_WAYLAND_APP_ID | `""` | An ASCII encoded wayland `app_id` name


@section window_events Window event processing
Expand Down
6 changes: 6 additions & 0 deletions include/GLFW/glfw3.h
Expand Up @@ -1104,6 +1104,12 @@ extern "C" {
* [window hint](@ref GLFW_X11_CLASS_NAME_hint).
*/
#define GLFW_X11_INSTANCE_NAME 0x00024002
/*! @brief Wayland specific
* [window hint](@ref GLFW_WAYLAND_APP_ID_hint).
*
* Allows specification of the wayland app_id.
*/
#define GLFW_WAYLAND_APP_ID 0x00026001
#define GLFW_WIN32_KEYBOARD_MENU 0x00025001
/*! @} */

Expand Down
3 changes: 3 additions & 0 deletions src/internal.h
Expand Up @@ -421,6 +421,9 @@ struct _GLFWwndconfig
struct {
GLFWbool keymenu;
} win32;
struct {
char appId[256];
} wl;
};

// Context configuration
Expand Down
4 changes: 4 additions & 0 deletions src/window.c
Expand Up @@ -417,6 +417,10 @@ GLFWAPI void glfwWindowHintString(int hint, const char* value)
strncpy(_glfw.hints.window.x11.instanceName, value,
sizeof(_glfw.hints.window.x11.instanceName) - 1);
return;
case GLFW_WAYLAND_APP_ID:
strncpy(_glfw.hints.window.wl.appId, value,
sizeof(_glfw.hints.window.wl.appId) - 1);
return;
}

_glfwInputError(GLFW_INVALID_ENUM, "Invalid window hint string 0x%08X", hint);
Expand Down
1 change: 1 addition & 0 deletions src/wl_platform.h
Expand Up @@ -249,6 +249,7 @@ typedef struct _GLFWwindowWayland
double cursorPosX, cursorPosY;

char* title;
char* appId;

// We need to track the monitors the window spans on to calculate the
// optimal scaling factor.
Expand Down
5 changes: 5 additions & 0 deletions src/wl_window.c
Expand Up @@ -579,6 +579,9 @@ static GLFWbool createXdgSurface(_GLFWwindow* window)
&xdgToplevelListener,
window);

if (strlen(window->wl.appId))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the struct member is only set if the hint is a non-empty string, not setting the hint causes a segfault here.

xdg_toplevel_set_app_id(window->wl.xdg.toplevel, window->wl.appId);

if (window->wl.title)
xdg_toplevel_set_title(window->wl.xdg.toplevel, window->wl.title);

Expand Down Expand Up @@ -637,6 +640,8 @@ static GLFWbool createSurface(_GLFWwindow* window,
window->wl.height = wndconfig->height;
window->wl.scale = 1;
window->wl.title = _glfw_strdup(wndconfig->title);
if (strlen(wndconfig->wl.appId))
window->wl.appId = _glfw_strdup(wndconfig->wl.appId);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This allocation needs to be freed at window destruction. Alternatively, since the maximum length of the string is known, the struct member can be made a char array.


window->wl.transparent = fbconfig->transparent;
if (!window->wl.transparent)
Expand Down