Skip to content

Commit

Permalink
[linux] Implement popUpWindowMenu metnod #141
Browse files Browse the repository at this point in the history
  • Loading branch information
lijy91 committed May 8, 2022
1 parent c243222 commit c68fb44
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 19 deletions.
8 changes: 0 additions & 8 deletions example/linux/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ list(APPEND FLUTTER_PLUGIN_LIST
window_manager
)

list(APPEND FLUTTER_FFI_PLUGIN_LIST
)

set(PLUGIN_BUNDLED_LIBRARIES)

foreach(plugin ${FLUTTER_PLUGIN_LIST})
Expand All @@ -18,8 +15,3 @@ foreach(plugin ${FLUTTER_PLUGIN_LIST})
list(APPEND PLUGIN_BUNDLED_LIBRARIES $<TARGET_FILE:${plugin}_plugin>)
list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries})
endforeach(plugin)

foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST})
add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/linux plugins/${ffi_plugin})
list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries})
endforeach(ffi_plugin)
38 changes: 27 additions & 11 deletions linux/window_manager_plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -357,23 +357,19 @@ static FlMethodResponse* set_always_on_top(WindowManagerPlugin* self,

static FlMethodResponse* is_always_on_bottom(WindowManagerPlugin* self) {
return FL_METHOD_RESPONSE(fl_method_success_response_new(
fl_value_new_bool(self->_is_always_on_bottom))
);
fl_value_new_bool(self->_is_always_on_bottom)));
}

static FlMethodResponse* set_always_on_bottom(
WindowManagerPlugin* self,
FlValue* args) {
bool isAlwaysOnBottom = fl_value_get_bool(
fl_value_lookup_string(args, "isAlwaysOnBottom")
);
static FlMethodResponse* set_always_on_bottom(WindowManagerPlugin* self,
FlValue* args) {
bool isAlwaysOnBottom =
fl_value_get_bool(fl_value_lookup_string(args, "isAlwaysOnBottom"));

gtk_window_set_keep_below(get_window(self), isAlwaysOnBottom);
self->_is_always_on_bottom = isAlwaysOnBottom;

return FL_METHOD_RESPONSE(fl_method_success_response_new(
fl_value_new_bool(true)
));
return FL_METHOD_RESPONSE(
fl_method_success_response_new(fl_value_new_bool(true)));
}

static FlMethodResponse* get_title(WindowManagerPlugin* self) {
Expand Down Expand Up @@ -440,6 +436,24 @@ static FlMethodResponse* get_opacity(WindowManagerPlugin* self) {
fl_method_success_response_new(fl_value_new_float(1)));
}

static FlMethodResponse* pop_up_window_menu(WindowManagerPlugin* self) {
GdkDisplay* display = gdk_display_get_default();
GdkSeat* seat = gdk_display_get_default_seat(display);
GdkDevice* pointer = gdk_seat_get_pointer(seat);

int x, y;
gdk_device_get_position(pointer, NULL, &x, &y);

GdkEvent* event = gdk_event_new(GDK_BUTTON_PRESS);
event->key.window = get_gdk_window(self);
event->button.x_root = x;
event->button.y_root = y;
gdk_window_show_window_menu(get_gdk_window(self), event);

return FL_METHOD_RESPONSE(
fl_method_success_response_new(fl_value_new_float(1)));
}

static FlMethodResponse* start_dragging(WindowManagerPlugin* self) {
auto window = get_window(self);
auto screen = gtk_window_get_screen(window);
Expand Down Expand Up @@ -613,6 +627,8 @@ static void window_manager_plugin_handle_method_call(
response = set_skip_taskbar(self, args);
} else if (strcmp(method, "getOpacity") == 0) {
response = get_opacity(self);
} else if (strcmp(method, "popUpWindowMenu") == 0) {
response = pop_up_window_menu(self);
} else if (strcmp(method, "startDragging") == 0) {
response = start_dragging(self);
} else if (strcmp(method, "startResizing") == 0) {
Expand Down

0 comments on commit c68fb44

Please sign in to comment.