~sircmpwn/gdwlroots

0ae5c279dd9dae4dc5b000cced36cdd8e44913c9 — Drew DeVault 1 year, 2 months ago fc84cee
gdwlroots: add surface_enter and output scale
4 files changed, 43 insertions(+), 0 deletions(-)

M wlr_output.cpp
M wlr_output.h
M wlr_surface.cpp
M wlr_surface.h
M wlr_output.cpp => wlr_output.cpp +27 -0
@@ 44,8 44,29 @@ void WlrOutput::_size_changed() {
	wlr_output_set_custom_mode(wlr_output, 1280, 720, 0);
}

int WlrOutput::get_scale() const {
	if (wlr_output == NULL) {
		return scale;
	}
	return (int)wlr_output->scale;
}

void WlrOutput::set_scale(int scale) {
	this->scale = scale;
	if (wlr_output != NULL) {
		wlr_output_set_scale(wlr_output, scale);
	}
}

void WlrOutput::_bind_methods() {
	ClassDB::bind_method(D_METHOD("_size_changed"), &WlrOutput::_size_changed);
	ClassDB::bind_method(D_METHOD("get_scale"), &WlrOutput::get_scale);
	ClassDB::bind_method(D_METHOD("set_scale", "scale"), &WlrOutput::set_scale);

	ADD_PROPERTY(PropertyInfo(Variant::INT, "scale",
				PROPERTY_HINT_PLACEHOLDER_TEXT, "scale factor for this display",
				PROPERTY_USAGE_DEFAULT_INTL),
			"set_scale", "get_scale");
}

WlrBackend *WlrOutput::get_wlr_backend() {


@@ 58,6 79,10 @@ WlrBackend *WlrOutput::get_wlr_backend() {
	return backend;
}

struct wlr_output *WlrOutput::get_wlr_output() const {
	return wlr_output;
}

void WlrOutput::ensure_wl_global(WaylandDisplay *display) {
	if (wlr_output) {
		return;


@@ 72,6 97,7 @@ void WlrOutput::ensure_wl_global(WaylandDisplay *display) {
	strncpy(wlr_output->name, "GD-1", sizeof(wlr_output->name));
	_size_changed();
	wlr_output_create_global(wlr_output);
	wlr_output_set_scale(wlr_output, scale);
}

void WlrOutput::destroy_wl_global(WaylandDisplay *display) {


@@ 94,6 120,7 @@ void WlrOutput::_notification(int p_what) {

WlrOutput::WlrOutput() {
	wlr_output = NULL;
	scale = 1;
}

WlrOutput::~WlrOutput() {

M wlr_output.h => wlr_output.h +7 -0
@@ 15,6 15,8 @@ class WlrOutput : public WaylandGlobal {
	Viewport *viewport;
	struct wlr_output *wlr_output;

	int scale;

	void _size_changed();
	void ensure_wl_global(WaylandDisplay *display);
	void destroy_wl_global(WaylandDisplay *display);


@@ 25,6 27,11 @@ protected:
	virtual void _notification(int p_what);

public:
	int get_scale() const;
	void set_scale(int scale);

	struct wlr_output *get_wlr_output() const;

	WlrOutput();
	~WlrOutput();
};

M wlr_surface.cpp => wlr_surface.cpp +7 -0
@@ 80,6 80,11 @@ void WlrSurface::send_frame_done() {
	wlr_surface_send_frame_done(wlr_surface, &now);
}

void WlrSurface::send_enter(Variant _output) {
	auto output = dynamic_cast<WlrOutput *>((Object *)_output);
	wlr_surface_send_enter(wlr_surface, output->get_wlr_output());
}

void WlrSurface::_bind_methods() {
	ClassDB::bind_method(D_METHOD("get_sx"), &WlrSurface::get_sx);
	ClassDB::bind_method(D_METHOD("get_sy"), &WlrSurface::get_sy);


@@ 93,6 98,8 @@ void WlrSurface::_bind_methods() {
			&WlrSurface::get_texture);
	ClassDB::bind_method(D_METHOD("send_frame_done"),
			&WlrSurface::send_frame_done);
	ClassDB::bind_method(D_METHOD("send_enter", "output"),
			&WlrSurface::send_enter);
}

WlrSurface::WlrSurface() {

M wlr_surface.h => wlr_surface.h +2 -0
@@ 2,6 2,7 @@
#define GDWLR_WLR_SURFACE_H
#include "core/object.h"
#include "scene/resources/texture.h"
#include "wlr_output.h"
extern "C" {
#include <wlr/types/wlr_surface.h>
}


@@ 50,6 51,7 @@ public:
	WlrSurfaceState *get_previous_state() const;
	Ref<Texture> get_texture() const;
	void send_frame_done();
	void send_enter(Variant _output);
};

class WlrSurfaceAtResult : public Reference {