Skip to content
This repository has been archived by the owner on Sep 27, 2024. It is now read-only.

Commit

Permalink
feat: make wayland events sync better
Browse files Browse the repository at this point in the history
  • Loading branch information
RossComputerGuy committed May 16, 2024
1 parent 38747d5 commit 9889610
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 73 deletions.
1 change: 1 addition & 0 deletions lib/logic/wm.dart
Original file line number Diff line number Diff line change
Expand Up @@ -122,5 +122,6 @@ class Window extends ChangeNotifier {

await surface.setMaximized(true);
await surface.setSize(desktopSize.width.toInt(), desktopSize.height.toInt());
print(desktopSize);
}
}
20 changes: 17 additions & 3 deletions lib/widgets/output_layout.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ class OutputLayout extends StatelessWidget {
);
}

final toplevelSize = MediaQuery.of(context).size;
return Stack(
children: mngr.outputs.asMap().entries.map(
(entry) =>
Transform.translate(
(entry) {
Widget widget = Transform.translate(
offset: Offset(
(entry.value.geometry.x * entry.value.scale).toDouble(),
(entry.value.geometry.y * entry.value.scale).toDouble(),
Expand All @@ -46,7 +47,20 @@ class OutputLayout extends StatelessWidget {
builder(context, entry.value, entry.key),
),
),
)
);

final size = Size(entry.value.geometry.width.toDouble(), entry.value.geometry.height.toDouble());

if (toplevelSize >= size) {
widget = MediaQuery(
data: MediaQuery.of(context).copyWith(
size: size,
),
child: widget,
);
}
return widget;
}
).toList(),
);
},
Expand Down
37 changes: 16 additions & 21 deletions lib/widgets/system_layout.dart
Original file line number Diff line number Diff line change
Expand Up @@ -190,27 +190,22 @@ class SystemLayout extends StatelessWidget {
builder: (context, output, outputIndex) =>
Provider<Output>.value(
value: output,
child: MediaQuery(
data: MediaQuery.of(context).copyWith(
size: Size(output.geometry.width.toDouble(), output.geometry.height.toDouble()),
),
child: AdaptiveLayout(
body: SlotLayout(
config: {
Breakpoints.small: SlotLayout.from(
key: const Key('Body Small'),
builder: (context) => _buildMobile(context, output, outputIndex),
),
Breakpoints.medium: SlotLayout.from(
key: const Key('Body Medium'),
builder: (context) => _buildDesktop(context, output, outputIndex),
),
Breakpoints.large: SlotLayout.from(
key: const Key('Body Large'),
builder: (context) => _buildDesktop(context, output, outputIndex),
),
},
),
child: AdaptiveLayout(
body: SlotLayout(
config: {
Breakpoints.small: SlotLayout.from(
key: const Key('Body Small'),
builder: (context) => _buildMobile(context, output, outputIndex),
),
Breakpoints.medium: SlotLayout.from(
key: const Key('Body Medium'),
builder: (context) => _buildDesktop(context, output, outputIndex),
),
Breakpoints.large: SlotLayout.from(
key: const Key('Body Large'),
builder: (context) => _buildDesktop(context, output, outputIndex),
),
},
),
),
),
Expand Down
1 change: 0 additions & 1 deletion linux/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ add_definitions(-DAPPLICATION_ID="${APPLICATION_ID}" -DWLR_USE_UNSTABLE)
add_executable(${BINARY_NAME}
"main.cc"
"application.cc"
"messaging.c"
"channels/account.cc"
"channels/applications.cc"
"channels/auth.cc"
Expand Down
23 changes: 16 additions & 7 deletions linux/channels/display.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include "display.h"
#include "session.h"
#include "../application-priv.h"
#include "../messaging.h"

static gchar* get_string(FlValue* value) {
if (fl_value_get_type(value) != FL_VALUE_TYPE_STRING) return g_strdup("Unknown");
Expand Down Expand Up @@ -280,34 +279,44 @@ static void method_call_handler(FlMethodChannel* channel, FlMethodCall* method_c
DisplayChannelSurface* surface = g_hash_table_lookup(disp->surfaces, &id);
g_assert(surface->id == id);

uint32_t i = 0;

FlValue* value_size = fl_value_lookup_string(args, "size");
if (value_size != NULL) {
wlr_xdg_toplevel_set_size(surface->xdg, fl_value_get_int(fl_value_lookup_string(value_size, "width")), fl_value_get_int(fl_value_lookup_string(value_size, "height")));
i += wlr_xdg_toplevel_set_size(surface->xdg, fl_value_get_int(fl_value_lookup_string(value_size, "width")), fl_value_get_int(fl_value_lookup_string(value_size, "height")));
}

FlValue* value_maximized = fl_value_lookup_string(args, "maximized");
if (value_maximized != NULL) {
wlr_xdg_toplevel_set_maximized(surface->xdg, fl_value_get_bool(value_maximized));
i += wlr_xdg_toplevel_set_maximized(surface->xdg, fl_value_get_bool(value_maximized));
}

FlValue* value_fullscreen = fl_value_lookup_string(args, "fullscreen");
if (value_fullscreen != NULL) {
wlr_xdg_toplevel_set_fullscreen(surface->xdg, fl_value_get_bool(value_fullscreen));
i += wlr_xdg_toplevel_set_fullscreen(surface->xdg, fl_value_get_bool(value_fullscreen));
}

FlValue* value_resizing = fl_value_lookup_string(args, "resizing");
if (value_resizing != NULL) {
wlr_xdg_toplevel_set_resizing(surface->xdg, fl_value_get_bool(value_resizing));
i += wlr_xdg_toplevel_set_resizing(surface->xdg, fl_value_get_bool(value_resizing));
}

FlValue* value_active = fl_value_lookup_string(args, "active");
if (value_active != NULL) {
wlr_xdg_toplevel_set_activated(surface->xdg, fl_value_get_bool(value_active));
i += wlr_xdg_toplevel_set_activated(surface->xdg, fl_value_get_bool(value_active));
}

FlValue* value_suspended = fl_value_lookup_string(args, "suspended");
if (value_suspended != NULL) {
wlr_xdg_toplevel_set_suspended(surface->xdg, fl_value_get_bool(value_suspended));
i += wlr_xdg_toplevel_set_suspended(surface->xdg, fl_value_get_bool(value_suspended));
}

if (i > 0) {
struct wl_display* wl_display = display_channel_backend_get_display(disp->backend);
struct wl_event_loop* wl_event_loop = wl_display_get_event_loop(wl_display);

wl_event_loop_dispatch(wl_event_loop, 0);
wl_display_flush_clients(wl_display);
}

response = FL_METHOD_RESPONSE(fl_method_success_response_new(NULL));
Expand Down
10 changes: 5 additions & 5 deletions linux/channels/display/surface.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#include "../display.h"
#include "../../application.h"
#include "../../application-priv.h"
#include "../../messaging.h"

static void xdg_toplevel_decor_request_mode(struct wl_listener* listener, void* data);

Expand All @@ -16,7 +15,7 @@ static void xdg_toplevel_emit_request(DisplayChannelSurface* self, const char* n
fl_value_set(value, fl_value_new_string("name"), fl_value_new_string(self->display->socket));
fl_value_set(value, fl_value_new_string("id"), fl_value_new_int(self->id));
fl_value_set(value, fl_value_new_string("reqName"), fl_value_new_string(name));
invoke_method(self->display->channel->channel, "requestSurface", value);
fl_method_channel_invoke_method(self->display->channel->channel, "requestSurface", value, NULL, NULL, NULL);
}

void xdg_toplevel_emit_prop(DisplayChannelSurface* self, const char* name, FlValue* pvalue) {
Expand All @@ -25,7 +24,7 @@ void xdg_toplevel_emit_prop(DisplayChannelSurface* self, const char* name, FlVal
fl_value_set(value, fl_value_new_string("id"), fl_value_new_int(self->id));
fl_value_set(value, fl_value_new_string("propName"), fl_value_new_string(name));
fl_value_set(value, fl_value_new_string("propValue"), pvalue);
invoke_method(self->display->channel->channel, "notifySurface", value);
fl_method_channel_invoke_method(self->display->channel->channel, "notifySurface", value, NULL, NULL, NULL);
}

static void xdg_toplevel_map(struct wl_listener* listener, void* data) {
Expand All @@ -51,7 +50,7 @@ static void xdg_toplevel_destroy(struct wl_listener* listener, void* data) {
g_autoptr(FlValue) value = fl_value_new_map();
fl_value_set(value, fl_value_new_string("name"), fl_value_new_string(self->display->socket));
fl_value_set(value, fl_value_new_string("id"), fl_value_new_int(self->id));
invoke_method(self->display->channel->channel, "removeSurface", value);
fl_method_channel_invoke_method(self->display->channel->channel, "removeSurface", value, NULL, NULL, NULL);

wl_list_remove(&self->map.link);
wl_list_remove(&self->unmap.link);
Expand Down Expand Up @@ -225,6 +224,7 @@ void xdg_surface_new(struct wl_listener* listener, void* data) {

if (xdg_surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL) {
struct wlr_xdg_toplevel* xdg_toplevel = wlr_xdg_toplevel_try_from_wlr_surface(xdg_surface->surface);
wlr_xdg_toplevel_set_wm_capabilities(xdg_toplevel, WLR_XDG_TOPLEVEL_WM_CAPABILITIES_WINDOW_MENU | WLR_XDG_TOPLEVEL_WM_CAPABILITIES_MAXIMIZE | WLR_XDG_TOPLEVEL_WM_CAPABILITIES_FULLSCREEN | WLR_XDG_TOPLEVEL_WM_CAPABILITIES_MINIMIZE);

DisplayChannelSurface* surface = (DisplayChannelSurface*)malloc(sizeof (DisplayChannelSurface));
xdg_surface->data = surface;
Expand Down Expand Up @@ -280,8 +280,8 @@ void xdg_surface_new(struct wl_listener* listener, void* data) {
g_autoptr(FlValue) value = fl_value_new_map();
fl_value_set(value, fl_value_new_string("name"), fl_value_new_string(self->socket));
fl_value_set(value, fl_value_new_string("id"), fl_value_new_int(surface->id));
invoke_method(self->channel->channel, "newSurface", value);

g_hash_table_insert(self->surfaces, &surface->id, self);
fl_method_channel_invoke_method(self->channel->channel, "newSurface", value, NULL, NULL, NULL);
}
}
23 changes: 0 additions & 23 deletions linux/messaging.c

This file was deleted.

13 changes: 0 additions & 13 deletions linux/messaging.h

This file was deleted.

0 comments on commit 9889610

Please sign in to comment.