2021-06-06 01:26:18 +00:00
|
|
|
/**
|
|
|
|
* Looking Glass
|
2023-10-20 04:36:34 +00:00
|
|
|
* Copyright © 2017-2023 The Looking Glass Authors
|
2021-06-06 01:26:18 +00:00
|
|
|
* https://looking-glass.io
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the Free
|
|
|
|
* Software Foundation; either version 2 of the License, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This program 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 General Public License for
|
|
|
|
* more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc., 59
|
|
|
|
* Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
2021-03-06 12:09:44 +00:00
|
|
|
|
|
|
|
#include "wayland.h"
|
|
|
|
|
2021-07-21 22:48:10 +00:00
|
|
|
#include <errno.h>
|
2021-03-06 12:09:44 +00:00
|
|
|
#include <stdbool.h>
|
|
|
|
#include <string.h>
|
2021-07-21 22:48:10 +00:00
|
|
|
#include <sys/epoll.h>
|
2021-03-06 12:09:44 +00:00
|
|
|
|
|
|
|
#include <libdecor.h>
|
|
|
|
#include <wayland-client.h>
|
|
|
|
|
|
|
|
#include "app.h"
|
|
|
|
#include "common/debug.h"
|
|
|
|
|
|
|
|
struct libdecor_configuration {
|
|
|
|
uint32_t serial;
|
|
|
|
|
|
|
|
bool has_window_state;
|
|
|
|
enum libdecor_window_state window_state;
|
|
|
|
|
|
|
|
bool has_size;
|
|
|
|
int window_width;
|
|
|
|
int window_height;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void libdecorHandleError(struct libdecor * context, enum libdecor_error error,
|
|
|
|
const char *message)
|
|
|
|
{
|
|
|
|
DEBUG_ERROR("Got libdecor error (%d): %s", error, message);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void libdecorFrameConfigure(struct libdecor_frame * frame,
|
|
|
|
struct libdecor_configuration * configuration, void * opaque)
|
|
|
|
{
|
2021-10-04 17:55:18 +00:00
|
|
|
if (!wlWm.configured)
|
|
|
|
{
|
|
|
|
xdg_surface_ack_configure(libdecor_frame_get_xdg_surface(frame), configuration->serial);
|
|
|
|
wlWm.configured = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-03-06 12:09:44 +00:00
|
|
|
int width, height;
|
2021-10-04 17:55:18 +00:00
|
|
|
if (libdecor_configuration_get_content_size(configuration, frame, &width, &height))
|
|
|
|
{
|
2021-03-06 12:09:44 +00:00
|
|
|
wlWm.width = width;
|
|
|
|
wlWm.height = height;
|
2021-10-04 17:55:18 +00:00
|
|
|
|
|
|
|
struct libdecor_state * state = libdecor_state_new(wlWm.width, wlWm.height);
|
|
|
|
libdecor_frame_commit(wlWm.libdecorFrame, state, NULL);
|
|
|
|
libdecor_state_free(state);
|
2021-03-06 12:09:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
enum libdecor_window_state windowState;
|
|
|
|
if (libdecor_configuration_get_window_state(configuration, &windowState))
|
|
|
|
wlWm.fullscreen = windowState & LIBDECOR_WINDOW_STATE_FULLSCREEN;
|
|
|
|
|
2021-10-04 17:55:18 +00:00
|
|
|
wlWm.needsResize = true;
|
|
|
|
wlWm.resizeSerial = configuration->serial;
|
|
|
|
app_invalidateWindow(true);
|
|
|
|
waylandStopWaitFrame();
|
2021-03-06 12:09:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void libdecorFrameClose(struct libdecor_frame * frame, void * opaque)
|
|
|
|
{
|
|
|
|
app_handleCloseEvent();
|
|
|
|
}
|
|
|
|
|
2021-04-01 08:23:13 +00:00
|
|
|
static void libdecorFrameCommit(struct libdecor_frame * frame, void * opaque)
|
2021-03-06 12:09:44 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-04-01 08:23:13 +00:00
|
|
|
#pragma GCC diagnostic push
|
|
|
|
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
|
|
|
|
static struct libdecor_interface libdecorListener = {
|
|
|
|
libdecorHandleError,
|
|
|
|
};
|
|
|
|
|
2021-03-06 12:09:44 +00:00
|
|
|
static struct libdecor_frame_interface libdecorFrameListener = {
|
|
|
|
libdecorFrameConfigure,
|
|
|
|
libdecorFrameClose,
|
|
|
|
libdecorFrameCommit,
|
|
|
|
};
|
2021-04-01 08:23:13 +00:00
|
|
|
#pragma GCC diagnostic pop
|
2021-03-06 12:09:44 +00:00
|
|
|
|
2021-07-21 22:48:10 +00:00
|
|
|
static void libdecorCallback(uint32_t events, void * opaque)
|
|
|
|
{
|
|
|
|
libdecor_dispatch(wlWm.libdecor, 0);
|
|
|
|
}
|
|
|
|
|
2021-10-04 17:55:18 +00:00
|
|
|
bool waylandShellInit(const char * title, bool fullscreen, bool maximize, bool borderless, bool resizable)
|
2021-03-06 12:09:44 +00:00
|
|
|
{
|
|
|
|
wlWm.libdecor = libdecor_new(wlWm.display, &libdecorListener);
|
|
|
|
wlWm.libdecorFrame = libdecor_decorate(wlWm.libdecor, wlWm.surface, &libdecorFrameListener, NULL);
|
|
|
|
|
|
|
|
libdecor_frame_set_app_id(wlWm.libdecorFrame, "looking-glass-client");
|
|
|
|
libdecor_frame_set_title(wlWm.libdecorFrame, title);
|
|
|
|
libdecor_frame_map(wlWm.libdecorFrame);
|
|
|
|
|
2021-10-04 17:55:18 +00:00
|
|
|
if (resizable)
|
|
|
|
libdecor_frame_set_capabilities(wlWm.libdecorFrame, LIBDECOR_ACTION_RESIZE);
|
|
|
|
else
|
|
|
|
libdecor_frame_unset_capabilities(wlWm.libdecorFrame, LIBDECOR_ACTION_RESIZE);
|
|
|
|
|
2021-03-06 12:09:44 +00:00
|
|
|
while (!wlWm.configured)
|
2021-07-21 22:48:10 +00:00
|
|
|
libdecor_dispatch(wlWm.libdecor, 0);
|
2021-03-06 12:09:44 +00:00
|
|
|
|
2021-07-21 22:48:10 +00:00
|
|
|
if (!waylandPollRegister(libdecor_get_fd(wlWm.libdecor), libdecorCallback, NULL, EPOLLIN))
|
|
|
|
{
|
|
|
|
DEBUG_ERROR("Failed register display to epoll: %s", strerror(errno));
|
|
|
|
return false;
|
|
|
|
}
|
2021-03-06 12:09:44 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void waylandShellAckConfigureIfNeeded(void)
|
|
|
|
{
|
|
|
|
if (wlWm.resizeSerial)
|
|
|
|
{
|
|
|
|
xdg_surface_ack_configure(libdecor_frame_get_xdg_surface(wlWm.libdecorFrame), wlWm.resizeSerial);
|
|
|
|
wlWm.resizeSerial = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void waylandSetFullscreen(bool fs)
|
|
|
|
{
|
|
|
|
if (fs)
|
|
|
|
libdecor_frame_set_fullscreen(wlWm.libdecorFrame, NULL);
|
|
|
|
else
|
|
|
|
libdecor_frame_unset_fullscreen(wlWm.libdecorFrame);
|
2021-10-04 17:55:18 +00:00
|
|
|
|
|
|
|
libdecor_frame_set_visibility(wlWm.libdecorFrame, !fs);
|
2021-03-06 12:09:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool waylandGetFullscreen(void)
|
|
|
|
{
|
|
|
|
return wlWm.fullscreen;
|
|
|
|
}
|
2021-05-07 21:47:37 +00:00
|
|
|
|
|
|
|
void waylandMinimize(void)
|
|
|
|
{
|
|
|
|
libdecor_frame_set_minimized(wlWm.libdecorFrame);
|
|
|
|
}
|
2021-10-04 17:55:18 +00:00
|
|
|
|
|
|
|
void waylandShellResize(int w, int h)
|
|
|
|
{
|
|
|
|
if (!libdecor_frame_is_floating(wlWm.libdecorFrame))
|
|
|
|
return;
|
|
|
|
|
|
|
|
wlWm.width = w;
|
|
|
|
wlWm.height = h;
|
|
|
|
|
|
|
|
struct libdecor_state * state = libdecor_state_new(w, h);
|
|
|
|
libdecor_frame_commit(wlWm.libdecorFrame, state, NULL);
|
|
|
|
libdecor_state_free(state);
|
|
|
|
|
|
|
|
wlWm.needsResize = true;
|
|
|
|
app_invalidateWindow(true);
|
|
|
|
waylandStopWaitFrame();
|
|
|
|
}
|