2021-10-25 11:16:22 +00:00
|
|
|
#include "wayland/WaylandServer.h"
|
|
|
|
#include <AppKit/NSEvent.h>
|
|
|
|
#include <AppKit/NSApplication.h>
|
|
|
|
|
|
|
|
static void
|
|
|
|
xdg_surface_on_configure(void *data, struct xdg_surface *xdg_surface,
|
|
|
|
uint32_t serial)
|
|
|
|
{
|
|
|
|
struct window *window = data;
|
|
|
|
|
|
|
|
NSDebugLog(@"xdg_surface_on_configure: win=%d", window->window_id);
|
|
|
|
|
|
|
|
if(window->terminated == YES) {
|
|
|
|
NSDebugLog(@"deleting window win=%d", window->window_id);
|
|
|
|
free(window);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
WaylandConfig *wlconfig = window->wlconfig;
|
|
|
|
|
|
|
|
NSEvent *ev = nil;
|
|
|
|
NSWindow *nswindow = GSWindowWithNumber(window->window_id);
|
|
|
|
|
2021-10-28 06:35:31 +00:00
|
|
|
//NSDebugLog(@"Acknowledging surface configure %p %d (window_id=%d)", xdg_surface, serial, window->window_id);
|
2021-11-06 12:07:44 +00:00
|
|
|
|
2021-10-25 11:16:22 +00:00
|
|
|
xdg_surface_ack_configure(xdg_surface, serial);
|
|
|
|
window->configured = YES;
|
|
|
|
|
|
|
|
|
|
|
|
if(window->buffer_needs_attach) {
|
|
|
|
NSDebugLog(@"attach: win=%d toplevel", window->window_id);
|
|
|
|
wl_surface_attach(window->surface, window->buffer, 0, 0);
|
|
|
|
wl_surface_commit(window->surface);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (wlconfig->pointer.focus &&
|
|
|
|
wlconfig->pointer.focus->window_id == window->window_id) {
|
|
|
|
ev = [NSEvent otherEventWithType: NSAppKitDefined
|
|
|
|
location: NSZeroPoint
|
|
|
|
modifierFlags: 0
|
|
|
|
timestamp: 0
|
|
|
|
windowNumber: (int)window->window_id
|
|
|
|
context: GSCurrentContext()
|
|
|
|
subtype: GSAppKitWindowFocusIn
|
|
|
|
data1: 0
|
|
|
|
data2: 0];
|
|
|
|
|
|
|
|
[nswindow sendEvent: ev];
|
|
|
|
}
|
2021-11-06 12:07:44 +00:00
|
|
|
}
|
2021-10-25 11:16:22 +00:00
|
|
|
|
2021-11-06 12:07:44 +00:00
|
|
|
static void xdg_toplevel_configure(void *data, struct xdg_toplevel *xdg_toplevel,
|
|
|
|
int32_t width, int32_t height, struct wl_array *states) {
|
2021-10-25 11:16:22 +00:00
|
|
|
struct window *window = data;
|
2021-11-06 12:07:44 +00:00
|
|
|
WaylandConfig *wlconfig = window->wlconfig;
|
2021-10-25 11:16:22 +00:00
|
|
|
|
2021-11-06 12:07:44 +00:00
|
|
|
NSDebugLog(@"[%d] xdg_toplevel_configure %ldx%ld",
|
|
|
|
window->window_id, width, height);
|
2021-10-25 11:16:22 +00:00
|
|
|
|
2021-11-06 12:07:44 +00:00
|
|
|
// the compositor can send 0.0x0.0
|
|
|
|
if(width == 0 || height == 0) {
|
|
|
|
return;
|
2021-10-25 11:16:22 +00:00
|
|
|
}
|
2021-11-06 12:07:44 +00:00
|
|
|
if(window->width != width || window->height != height) {
|
|
|
|
window->width = width;
|
|
|
|
window->height = height;
|
|
|
|
|
|
|
|
xdg_surface_set_window_geometry(window->xdg_surface,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
window->width,
|
|
|
|
window->height);
|
|
|
|
|
|
|
|
NSEvent *ev = [NSEvent otherEventWithType: NSAppKitDefined
|
|
|
|
location: NSMakePoint(0.0, 0.0)
|
|
|
|
modifierFlags: 0
|
|
|
|
timestamp: 0
|
|
|
|
windowNumber: window->window_id
|
|
|
|
context: GSCurrentContext()
|
|
|
|
subtype: GSAppKitWindowResized
|
|
|
|
data1: window->width
|
|
|
|
data2: window->height];
|
|
|
|
[(GSWindowWithNumber(window->window_id)) sendEvent: ev];
|
|
|
|
}
|
|
|
|
NSDebugLog(@"[%d] notify resize from backend=%ldx%ld", window->window_id, width, height);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void xdg_toplevel_close_handler(void *data, struct zxdg_toplevel_v6 *xdg_toplevel) {
|
|
|
|
NSDebugLog(@"xdg_toplevel_close_handler");
|
2021-10-25 11:16:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void xdg_popup_configure(void *data, struct xdg_popup *xdg_popup,
|
|
|
|
int32_t x, int32_t y, int32_t width, int32_t height) {
|
|
|
|
struct window *window = data;
|
|
|
|
WaylandConfig *wlconfig = window->wlconfig;
|
|
|
|
|
2021-11-06 12:07:44 +00:00
|
|
|
NSDebugLog(@"xdg_popup_configure");
|
2021-10-25 11:16:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void xdg_popup_done(void *data, struct xdg_popup *xdg_popup) {
|
|
|
|
struct window *window = data;
|
|
|
|
WaylandConfig *wlconfig = window->wlconfig;
|
2021-11-06 12:07:44 +00:00
|
|
|
window->terminated = YES;
|
2021-10-25 11:16:22 +00:00
|
|
|
xdg_popup_destroy(xdg_popup);
|
|
|
|
wl_surface_destroy(window->surface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void wm_base_handle_ping(void *data, struct xdg_wm_base *xdg_wm_base,
|
|
|
|
uint32_t serial)
|
|
|
|
{
|
2021-11-06 12:07:44 +00:00
|
|
|
NSDebugLog(@"wm_base_handle_ping");
|
2021-10-25 11:16:22 +00:00
|
|
|
xdg_wm_base_pong(xdg_wm_base, serial);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const struct xdg_surface_listener xdg_surface_listener = {
|
|
|
|
xdg_surface_on_configure,
|
|
|
|
};
|
|
|
|
|
|
|
|
const struct xdg_wm_base_listener wm_base_listener = {
|
|
|
|
.ping = wm_base_handle_ping,
|
|
|
|
};
|
|
|
|
|
|
|
|
const struct xdg_popup_listener xdg_popup_listener = {
|
|
|
|
.configure = xdg_popup_configure,
|
|
|
|
.popup_done = xdg_popup_done,
|
|
|
|
};
|
2021-11-06 12:07:44 +00:00
|
|
|
|
|
|
|
const struct xdg_toplevel_listener xdg_toplevel_listener = {
|
|
|
|
.configure = xdg_toplevel_configure,
|
|
|
|
.close = xdg_toplevel_close_handler,
|
|
|
|
};
|
|
|
|
|