Skip to content

Commit

Permalink
Remove GTK usage and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
leolost2605 committed Nov 22, 2024
1 parent 50f89d3 commit 9d6c66d
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 88 deletions.
3 changes: 3 additions & 0 deletions src/Widgets/ScreenShield.vala
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ namespace Gala {

expand_to_screen_size ();

unowned var monitor_manager = wm.get_display ().get_context ().get_backend ().get_monitor_manager ();
monitor_manager.monitors_changed.connect (expand_to_screen_size);

init_dbus_interfaces.begin ();
}

Expand Down
156 changes: 68 additions & 88 deletions src/WindowManager.vala
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ namespace Gala {
/**
* {@inheritDoc}
*/
public Gala.ActivatableComponent workspace_view { get; protected set; }

public ScreenShield? screen_shield { get; private set; }
public Gala.ActivatableComponent workspace_view { get; protected set; }

public PointerLocator pointer_locator { get; private set; }

Expand Down Expand Up @@ -153,9 +151,6 @@ namespace Gala {
private void show_stage () {
unowned Meta.Display display = get_display ();

screen_shield = new ScreenShield (this);
screensaver = new ScreenSaverManager (screen_shield);

DBus.init (this);
DBusAccelerator.init (display);
MediaFeedback.init ();
Expand Down Expand Up @@ -239,8 +234,51 @@ namespace Gala {
stage.remove_child (feedback_group);
ui_group.add_child (feedback_group);

// initialize plugins and add default components if no plugin overrides them
unowned var plugin_manager = PluginManager.get_default ();
plugin_manager.initialize (this);
plugin_manager.regions_changed.connect (update_input_area);

if (plugin_manager.workspace_view_provider == null
|| (workspace_view = (plugin_manager.get_plugin (plugin_manager.workspace_view_provider) as ActivatableComponent)) == null) {
workspace_view = new MultitaskingView (this);
ui_group.add_child ((Clutter.Actor) workspace_view);
}

if (plugin_manager.window_switcher_provider == null) {
window_switcher = new WindowSwitcher (this, gesture_tracker);
ui_group.add_child (window_switcher);

Meta.KeyBinding.set_custom_handler ("switch-applications", (Meta.KeyHandlerFunc) window_switcher.handle_switch_windows);
Meta.KeyBinding.set_custom_handler ("switch-applications-backward", (Meta.KeyHandlerFunc) window_switcher.handle_switch_windows);
Meta.KeyBinding.set_custom_handler ("switch-windows", (Meta.KeyHandlerFunc) window_switcher.handle_switch_windows);
Meta.KeyBinding.set_custom_handler ("switch-windows-backward", (Meta.KeyHandlerFunc) window_switcher.handle_switch_windows);
Meta.KeyBinding.set_custom_handler ("switch-group", (Meta.KeyHandlerFunc) window_switcher.handle_switch_windows);
Meta.KeyBinding.set_custom_handler ("switch-group-backward", (Meta.KeyHandlerFunc) window_switcher.handle_switch_windows);
}

if (plugin_manager.window_overview_provider == null
|| (window_overview = (plugin_manager.get_plugin (plugin_manager.window_overview_provider) as ActivatableComponent)) == null) {
window_overview = new WindowOverview (this);
ui_group.add_child ((Clutter.Actor) window_overview);
}

// Add the remaining components that should be on top
notification_group = new Clutter.Actor ();
ui_group.add_child (notification_group);

pointer_locator = new PointerLocator (display);
ui_group.add_child (pointer_locator);
ui_group.add_child (new DwellClickTimer (display));

var screen_shield = new ScreenShield (this);
screensaver = new ScreenSaverManager (screen_shield);
ui_group.add_child (screen_shield);

FilterManager.init (this);

zoom = new Zoom (this);

/*keybindings*/
var keybinding_settings = new GLib.Settings ("io.elementary.desktop.wm.keybindings");

Expand All @@ -261,6 +299,14 @@ namespace Gala {
display.add_keybinding ("window-screenshot-clip", keybinding_settings, Meta.KeyBindingFlags.IGNORE_AUTOREPEAT, (Meta.KeyHandlerFunc) handle_screenshot);
display.add_keybinding ("area-screenshot-clip", keybinding_settings, Meta.KeyBindingFlags.IGNORE_AUTOREPEAT, (Meta.KeyHandlerFunc) handle_screenshot);

display.add_keybinding ("expose-all-windows", keybinding_settings, Meta.KeyBindingFlags.IGNORE_AUTOREPEAT, () => {
if (window_overview.is_opened ()) {
window_overview.close ();
} else {
window_overview.open ();
}
});

display.overlay_key.connect (() => {
launch_action ("overlay-action");
});
Expand All @@ -269,6 +315,14 @@ namespace Gala {
launch_action ("toggle-recording-action");
});

Meta.KeyBinding.set_custom_handler ("show-desktop", () => {
if (workspace_view.is_opened ()) {
workspace_view.close ();
} else {
workspace_view.open ();
}
});

Meta.KeyBinding.set_custom_handler ("switch-to-workspace-up", () => {});
Meta.KeyBinding.set_custom_handler ("switch-to-workspace-down", () => {});
Meta.KeyBinding.set_custom_handler ("switch-to-workspace-left", (Meta.KeyHandlerFunc) handle_switch_to_workspace);
Expand All @@ -284,89 +338,20 @@ namespace Gala {
}

unowned var monitor_manager = display.get_context ().get_backend ().get_monitor_manager ();
monitor_manager.monitors_changed.connect (on_monitors_changed);
monitor_manager.monitors_changed.connect (update_ui_group_size);

hot_corner_manager = new HotCornerManager (this, behavior_settings, new_behavior_settings);
hot_corner_manager.on_configured.connect (update_input_area);
hot_corner_manager.configure ();

zoom = new Zoom (this);

// Most things inside this "later" depend on GTK. We get segfaults if we try to do GTK stuff before the window manager
// is initialized, so we hold this stuff off until we're ready to draw
laters.add (Meta.LaterType.BEFORE_REDRAW, () => {
unowned string xdg_session_type = Environment.get_variable ("XDG_SESSION_TYPE");
if (xdg_session_type == "x11") {
string[] args = {};
unowned string[] _args = args;
Gtk.init (ref _args);
}

// initialize plugins and add default components if no plugin overrides them
unowned var plugin_manager = PluginManager.get_default ();
plugin_manager.initialize (this);
plugin_manager.regions_changed.connect (update_input_area);

if (plugin_manager.workspace_view_provider == null
|| (workspace_view = (plugin_manager.get_plugin (plugin_manager.workspace_view_provider) as ActivatableComponent)) == null) {
workspace_view = new MultitaskingView (this);
ui_group.add_child ((Clutter.Actor) workspace_view);
}

Meta.KeyBinding.set_custom_handler ("show-desktop", () => {
if (workspace_view.is_opened ())
workspace_view.close ();
else
workspace_view.open ();
});

if (plugin_manager.window_switcher_provider == null) {
window_switcher = new WindowSwitcher (this, gesture_tracker);
ui_group.add_child (window_switcher);

Meta.KeyBinding.set_custom_handler ("switch-applications", (Meta.KeyHandlerFunc) window_switcher.handle_switch_windows);
Meta.KeyBinding.set_custom_handler ("switch-applications-backward", (Meta.KeyHandlerFunc) window_switcher.handle_switch_windows);
Meta.KeyBinding.set_custom_handler ("switch-windows", (Meta.KeyHandlerFunc) window_switcher.handle_switch_windows);
Meta.KeyBinding.set_custom_handler ("switch-windows-backward", (Meta.KeyHandlerFunc) window_switcher.handle_switch_windows);
Meta.KeyBinding.set_custom_handler ("switch-group", (Meta.KeyHandlerFunc) window_switcher.handle_switch_windows);
Meta.KeyBinding.set_custom_handler ("switch-group-backward", (Meta.KeyHandlerFunc) window_switcher.handle_switch_windows);
}

if (plugin_manager.window_overview_provider == null
|| (window_overview = (plugin_manager.get_plugin (plugin_manager.window_overview_provider) as ActivatableComponent)) == null) {
window_overview = new WindowOverview (this);
ui_group.add_child ((Clutter.Actor) window_overview);
}

notification_group = new Clutter.Actor ();
ui_group.add_child (notification_group);

pointer_locator = new PointerLocator (display);
ui_group.add_child (pointer_locator);
ui_group.add_child (new DwellClickTimer (display));

ui_group.add_child (screen_shield);

display.add_keybinding ("expose-all-windows", keybinding_settings, Meta.KeyBindingFlags.IGNORE_AUTOREPEAT, () => {
if (window_overview.is_opened ()) {
window_overview.close ();
} else {
window_overview.open ();
}
});

plugin_manager.load_waiting_plugins ();

return false;
});

update_input_area ();


display.window_created.connect ((window) => window_created (window));

stage.show ();

plugin_manager.load_waiting_plugins ();

Idle.add (() => {
// let the session manager move to the next phase
#if WITH_SYSTEMD
Expand Down Expand Up @@ -416,11 +401,6 @@ namespace Gala {
} catch (Error e) { warning (e.message); }
}

private void on_monitors_changed () {
update_ui_group_size ();
screen_shield.expand_to_screen_size ();
}

[CCode (instance_pos = -1)]
private void handle_cycle_workspaces (Meta.Display display, Meta.Window? window, Clutter.KeyEvent event,
Meta.KeyBinding binding) {
Expand Down Expand Up @@ -1023,26 +1003,26 @@ namespace Gala {
current.stick ();
break;
case ActionType.SWITCH_TO_WORKSPACE_PREVIOUS:
switch_to_next_workspace (Meta.MotionDirection.LEFT, Gtk.get_current_event_time ());
switch_to_next_workspace (Meta.MotionDirection.LEFT, Meta.CURRENT_TIME);
break;
case ActionType.SWITCH_TO_WORKSPACE_NEXT:
switch_to_next_workspace (Meta.MotionDirection.RIGHT, Gtk.get_current_event_time ());
switch_to_next_workspace (Meta.MotionDirection.RIGHT, Meta.CURRENT_TIME);
break;
case ActionType.MOVE_CURRENT_WORKSPACE_LEFT:
unowned var workspace_manager = get_display ().get_workspace_manager ();
unowned var active_workspace = workspace_manager.get_active_workspace ();
unowned var target_workspace = active_workspace.get_neighbor (Meta.MotionDirection.LEFT);
move_window (current, target_workspace, Gtk.get_current_event_time ());
move_window (current, target_workspace, Meta.CURRENT_TIME);
break;
case ActionType.MOVE_CURRENT_WORKSPACE_RIGHT:
unowned var workspace_manager = get_display ().get_workspace_manager ();
unowned var active_workspace = workspace_manager.get_active_workspace ();
unowned var target_workspace = active_workspace.get_neighbor (Meta.MotionDirection.RIGHT);
move_window (current, target_workspace, Gtk.get_current_event_time ());
move_window (current, target_workspace, Meta.CURRENT_TIME);
break;
case ActionType.CLOSE_CURRENT:
if (current != null && current.can_close ())
current.@delete (Gtk.get_current_event_time ());
current.@delete (Meta.CURRENT_TIME);
break;
case ActionType.OPEN_LAUNCHER:
try {
Expand Down

0 comments on commit 9d6c66d

Please sign in to comment.