Skip to content

Commit

Permalink
DRYer
Browse files Browse the repository at this point in the history
  • Loading branch information
kovidgoyal committed Dec 24, 2023
1 parent 91cdf4a commit 7d8c017
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
29 changes: 15 additions & 14 deletions glfw/wl_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -622,28 +622,29 @@ static void registryHandleGlobal(void* data UNUSED,
const char* interface,
uint32_t version)
{
if (strcmp(interface, "wl_compositor") == 0)
#define is(x) strcmp(interface, #x) == 0
if (is(wl_compositor))
{
_glfw.wl.compositorVersion = min(3, version);
_glfw.wl.compositor =
wl_registry_bind(registry, name, &wl_compositor_interface,
_glfw.wl.compositorVersion);
}
else if (strcmp(interface, "wl_subcompositor") == 0)
else if (is(wl_subcompositor))
{
_glfw.wl.subcompositor =
wl_registry_bind(registry, name, &wl_subcompositor_interface, 1);
}
else if (strcmp(interface, "wl_shm") == 0)
else if (is(wl_shm))
{
_glfw.wl.shm =
wl_registry_bind(registry, name, &wl_shm_interface, 1);
}
else if (strcmp(interface, "wl_output") == 0)
else if (is(wl_output))
{
_glfwAddOutputWayland(name, version);
}
else if (strcmp(interface, "wl_seat") == 0)
else if (is(wl_seat))
{
if (!_glfw.wl.seat)
{
Expand All @@ -661,38 +662,38 @@ static void registryHandleGlobal(void* data UNUSED,
_glfwWaylandInitTextInput();
}
}
else if (strcmp(interface, "xdg_wm_base") == 0)
else if (is(xdg_wm_base))
{
_glfw.wl.wmBase =
wl_registry_bind(registry, name, &xdg_wm_base_interface, 1);
xdg_wm_base_add_listener(_glfw.wl.wmBase, &wmBaseListener, NULL);
}
else if (strcmp(interface, "zxdg_decoration_manager_v1") == 0)
else if (is(zxdg_decoration_manager_v1))
{
_glfw.wl.decorationManager =
wl_registry_bind(registry, name,
&zxdg_decoration_manager_v1_interface, 1);
}
else if (strcmp(interface, "zwp_relative_pointer_manager_v1") == 0)
else if (is(zwp_relative_pointer_manager_v1))
{
_glfw.wl.relativePointerManager =
wl_registry_bind(registry, name,
&zwp_relative_pointer_manager_v1_interface,
1);
}
else if (strcmp(interface, "zwp_pointer_constraints_v1") == 0)
else if (is(zwp_pointer_constraints_v1))
{
_glfw.wl.pointerConstraints =
wl_registry_bind(registry, name,
&zwp_pointer_constraints_v1_interface,
1);
}
else if (strcmp(interface, GLFW_WAYLAND_TEXT_INPUT_INTERFACE_NAME) == 0)
else if (is(zwp_text_input_manager_v3))
{
_glfwWaylandBindTextInput(registry, name);
_glfwWaylandInitTextInput();
}
else if (strcmp(interface, "wl_data_device_manager") == 0)
else if (is(wl_data_device_manager))
{
_glfw.wl.dataDeviceManager =
wl_registry_bind(registry, name,
Expand All @@ -702,7 +703,7 @@ static void registryHandleGlobal(void* data UNUSED,
_glfwSetupWaylandDataDevice();
}
}
else if (strcmp(interface, "zwp_primary_selection_device_manager_v1") == 0)
else if (is(zwp_primary_selection_device_manager_v1))
{
_glfw.wl.primarySelectionDeviceManager =
wl_registry_bind(registry, name,
Expand All @@ -712,10 +713,10 @@ static void registryHandleGlobal(void* data UNUSED,
_glfwSetupWaylandPrimarySelectionDevice();
}
}
else if (strstr(interface, "xdg_activation_v1") != 0) {
else if (is(xdg_activation_v1)) {
_glfw.wl.xdg_activation_v1 = wl_registry_bind(registry, name, &xdg_activation_v1_interface, 1);
}

#undef is
}

static void registryHandleGlobalRemove(void *data UNUSED,
Expand Down
2 changes: 0 additions & 2 deletions glfw/wl_text_input.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
#pragma once
#include <wayland-client.h>

#define GLFW_WAYLAND_TEXT_INPUT_INTERFACE_NAME "zwp_text_input_manager_v3"

void _glfwWaylandBindTextInput(struct wl_registry* registry, uint32_t name);
void _glfwWaylandInitTextInput(void);
void _glfwWaylandDestroyTextInput(void);

0 comments on commit 7d8c017

Please sign in to comment.