Skip to content

Commit

Permalink
Adapt to the latest Mutter API
Browse files Browse the repository at this point in the history
  • Loading branch information
worldofpeace authored and Corentin Noël committed Nov 12, 2019
1 parent a7533f5 commit 5011b53
Show file tree
Hide file tree
Showing 4 changed files with 186 additions and 19 deletions.
16 changes: 16 additions & 0 deletions compositor/DBusAccelerator.vala
Expand Up @@ -44,6 +44,7 @@ namespace GreeterCompositor {

public struct Accelerator {
public string name;
public Meta.KeyBindingFlags grab_flags;
public ActionMode flags;
}

Expand Down Expand Up @@ -74,7 +75,11 @@ namespace GreeterCompositor {
wm = _wm;
grabbed_accelerators = new GLib.List<GrabbedAccelerator> ();

#if HAS_MUTTER330
wm.get_display ().accelerator_activated.connect (on_accelerator_activated);
#else
wm.get_screen ().get_display ().accelerator_activated.connect (on_accelerator_activated);
#endif
}

private void on_accelerator_activated (uint action, uint device_id, uint timestamp) {
Expand All @@ -100,7 +105,14 @@ namespace GreeterCompositor {
}
}

#if HAS_MUTTER332
uint action = wm.get_display ().grab_accelerator (accelerator.name, accelerator.grab_flags);
#elif HAS_MUTTER330
uint action = wm.get_display ().grab_accelerator (accelerator.name);
#else
uint action = wm.get_screen ().get_display ().grab_accelerator (accelerator.name);
#endif

if (action > 0) {
var accel = new GrabbedAccelerator ();
accel.action = action;
Expand All @@ -124,7 +136,11 @@ namespace GreeterCompositor {
public bool ungrab_accelerator (uint action) throws GLib.Error {
foreach (unowned GrabbedAccelerator accel in grabbed_accelerators) {
if (accel.action == action) {
#if HAS_MUTTER330
bool ret = wm.get_display ().ungrab_accelerator (action);
#else
bool ret = wm.get_screen ().get_display ().ungrab_accelerator (action);
#endif
grabbed_accelerators.remove (accel);
return ret;
}
Expand Down
57 changes: 42 additions & 15 deletions compositor/SystemBackground.vala
Expand Up @@ -19,35 +19,62 @@
* Authors: Corentin Noël <corentin@elementary.io>
*/

public class Greeter.SystemBackground : Meta.BackgroundActor {
#if HAS_MUTTER334
public class Greeter.SystemBackground : GLib.Object {
#else
public class Greeter.SystemBackground : Meta.BackgroundActor {
#endif
const Clutter.Color DEFAULT_BACKGROUND_COLOR = { 0x2e, 0x34, 0x36, 0xff };

static Meta.Background? system_background = null;

#if HAS_MUTTER334
public Meta.BackgroundActor background_actor { get; construct; }
#endif

public signal void loaded ();

public SystemBackground (Meta.Screen screen) {
Object (meta_screen: screen, monitor: 0);
}
#if HAS_MUTTER330
public SystemBackground (Meta.Display display) {
#if HAS_MUTTER334
Object (background_actor: new Meta.BackgroundActor (display, 0));
#else
Object (meta_display: display, monitor: 0);
#endif
}
#else
public SystemBackground (Meta.Screen screen) {
Object (meta_screen: screen, monitor: 0);
}
#endif

construct {
if (system_background == null) {
#if HAS_MUTTER334
system_background = new Meta.Background (background_actor.meta_display);
#elif HAS_MUTTER330
system_background = new Meta.Background (meta_display);
#else
system_background = new Meta.Background (meta_screen);
#endif
var background_file = GLib.File.new_for_uri ("resource:///io/elementary/desktop/gala/texture.png");
system_background.set_color (DEFAULT_BACKGROUND_COLOR);
system_background.set_file (texture_file, GDesktop.BackgroundStyle.WALLPAPER);
}

background = system_background;
#if HAS_MUTTER334
background_actor.background = system_background;
#else
background = system_background;
#endif
}

public void refresh () {
if (system_background != null) {
this.set_wallpaper ();
}
}

public void set_wallpaper () {
var texture_file = GLib.File.new_for_uri ("resource:///io/elementary/greeter/texture.png");
this.background.set_color (DEFAULT_BACKGROUND_COLOR);
this.background.set_file (texture_file, GDesktop.BackgroundStyle.WALLPAPER);
// Meta.Background.refresh_all does not refresh backgrounds with the WALLPAPER style.
// (Last tested with mutter 3.28)
// As a workaround, re-apply the current color again to force the wallpaper texture
// to be rendered from scratch.
if (system_background != null)
system_background.set_color (DEFAULT_BACKGROUND_COLOR);
}

}
21 changes: 20 additions & 1 deletion compositor/Utils.vala
Expand Up @@ -82,8 +82,12 @@ namespace GreeterCompositor {
* @param backward Whether to get the previous one instead
*/
public static Meta.Window get_next_window (Meta.Workspace workspace, bool backward = false) {
#if HAS_MUTTER330
var display = workspace.get_display ();
#else
var screen = workspace.get_screen ();
var display = screen.get_display ();
#endif

var window = display.get_tab_next (Meta.TabList.NORMAL, workspace, null, backward);

Expand Down Expand Up @@ -161,7 +165,21 @@ namespace GreeterCompositor {

return container;
}

#if HAS_MUTTER330
/**
* Ring the system bell, will most likely emit a <beep> error sound or, if the
* audible bell is disabled, flash the display
*
* @param display The display to flash, if necessary
*/
public static void bell (Meta.Display display) {
if (Meta.Prefs.bell_is_audible ()) {
Gdk.beep ();
} else {
display.get_compositor ().flash_display (display);
}
}
#else
/**
* Ring the system bell, will most likely emit a <beep> error sound or, if the
* audible bell is disabled, flash the screen
Expand All @@ -175,5 +193,6 @@ namespace GreeterCompositor {
screen.get_display ().get_compositor ().flash_screen (screen);
}
}
#endif
}
}
111 changes: 108 additions & 3 deletions compositor/WindowManager.vala
Expand Up @@ -76,45 +76,86 @@ namespace GreeterCompositor {
info = Meta.PluginInfo () {name = "GreeterCompositor", version = Constants.VERSION, author = "elementary LLC.",
license = "GPLv3", description = "The greeter compositor"};

#if !HAS_MUTTER332
Prefs.set_ignore_request_hide_titlebar (true);
#endif
}

public override void start () {
Util.later_add (LaterType.BEFORE_REDRAW, show_stage);

#if HAS_MUTTER330
unowned Meta.Display display = get_display ();
#elif HAS_MUTTER322
unowned Meta.Display display = get_screen ().get_display ();
#endif
#if HAS_MUTTER322
get_screen ().get_display ().gl_video_memory_purged.connect (refresh_background);
display.gl_video_memory_purged.connect (() => {
refresh_background ();
});
#endif
}

void refresh_background () {
#if HAS_MUTTER330
unowned Meta.Display display = get_display ();
var system_background = new Greeter.SystemBackground (display);
#else
var screen = get_screen ();
var system_background = new Greeter.SystemBackground (screen);
#endif

system_background.refresh ();
}

bool show_stage () {
#if HAS_MUTTER330
unowned Meta.Display display = get_display ();
#else
var screen = get_screen ();
#endif
MediaFeedback.init ();
DBus.init (this);
DBusAccelerator.init (this);

#if HAS_MUTTER330
stage = Compositor.get_stage_for_display (display) as Clutter.Stage;
#else
stage = Compositor.get_stage_for_screen (screen) as Clutter.Stage;
#endif

#if HAS_MUTTER330
var system_background = new Greeter.SystemBackground (display);
#else
var system_background = new Greeter.SystemBackground (screen);
#endif

#if HAS_MUTTER334
system_background.background_actor.add_constraint (new Clutter.BindConstraint (stage,
Clutter.BindCoordinate.ALL, 0));
stage.insert_child_below (system_background.background_actor, null);
#else
system_background.add_constraint (new Clutter.BindConstraint (stage, Clutter.BindCoordinate.ALL, 0));
system_background.set_wallpaper ();
stage.insert_child_below (system_background, null);
#endif

ui_group = new Clutter.Actor ();
ui_group.reactive = true;
stage.add_child (ui_group);

#if HAS_MUTTER330
window_group = Compositor.get_window_group_for_display (display);
#else
window_group = Compositor.get_window_group_for_screen (screen);
#endif
stage.remove_child (window_group);
ui_group.add_child (window_group);

#if HAS_MUTTER330
top_window_group = Compositor.get_top_window_group_for_display (display);
#else
top_window_group = Compositor.get_top_window_group_for_screen (screen);
#endif
stage.remove_child (top_window_group);
ui_group.add_child (top_window_group);

Expand Down Expand Up @@ -156,10 +197,21 @@ namespace GreeterCompositor {
public uint32[] get_all_xids () {
var list = new Gee.ArrayList<uint32> ();

#if HAS_MUTTER330
unowned Meta.Display display = get_display ();
unowned Meta.WorkspaceManager manager = display.get_workspace_manager ();
for (int i = 0; i < manager.get_n_workspaces (); i++) {
foreach (var window in manager.get_workspace_by_index (i).list_windows ()) {
list.add ((uint32)window.get_xwindow ());
}
}
#else
foreach (var workspace in get_screen ().get_workspaces ()) {
foreach (var window in workspace.list_windows ())
foreach (var window in workspace.list_windows ()) {
list.add ((uint32)window.get_xwindow ());
}
}
#endif

return list.to_array ();
}
Expand All @@ -171,6 +223,19 @@ namespace GreeterCompositor {
if (window == null)
return;

#if HAS_MUTTER330
unowned Meta.Display display = get_display ();
unowned Meta.WorkspaceManager manager = display.get_workspace_manager ();

var active = manager.get_active_workspace ();
var next = active.get_neighbor (direction);

//dont allow empty workspaces to be created by moving, if we have dynamic workspaces
if (Prefs.get_dynamic_workspaces () && Utils.get_n_windows (active) == 1 && next.index () == manager.n_workspaces - 1) {
Utils.bell (display);
return;
}
#else
var screen = get_screen ();
var display = screen.get_display ();

Expand All @@ -182,6 +247,7 @@ namespace GreeterCompositor {
Utils.bell (screen);
return;
}
#endif

moving = window;

Expand Down Expand Up @@ -214,6 +280,39 @@ namespace GreeterCompositor {
if (!Prefs.get_dynamic_workspaces ())
return;

#if HAS_MUTTER330
unowned Meta.Display display = get_display ();
var time = display.get_current_time ();
unowned Meta.Workspace win_ws = window.get_workspace ();
unowned Meta.WorkspaceManager manager = display.get_workspace_manager ();

if (which_change == Meta.SizeChange.FULLSCREEN) {
// Do nothing if the current workspace would be empty
if (Utils.get_n_windows (win_ws) <= 1)
return;

var old_ws_index = win_ws.index ();
var new_ws_index = old_ws_index + 1;
//InternalUtils.insert_workspace_with_window (new_ws_index, window);

var new_ws_obj = manager.get_workspace_by_index (new_ws_index);
window.change_workspace (new_ws_obj);
new_ws_obj.activate_with_focus (window, time);

ws_assoc.insert (window, old_ws_index);
} else if (ws_assoc.contains (window)) {
var old_ws_index = ws_assoc.get (window);
var new_ws_index = win_ws.index ();

if (new_ws_index != old_ws_index && old_ws_index < manager.get_n_workspaces ()) {
var old_ws_obj = manager.get_workspace_by_index (old_ws_index);
window.change_workspace (old_ws_obj);
old_ws_obj.activate_with_focus (window, time);
}

ws_assoc.remove (window);
}
#else
unowned Meta.Screen screen = get_screen ();
var time = screen.get_display ().get_current_time ();
unowned Meta.Workspace win_ws = window.get_workspace ();
Expand Down Expand Up @@ -244,6 +343,7 @@ namespace GreeterCompositor {

ws_assoc.remove (window);
}
#endif
}

public override void size_change (Meta.WindowActor actor, Meta.SizeChange which_change, Meta.Rectangle old_frame_rect, Meta.Rectangle old_buffer_rect) {
Expand Down Expand Up @@ -347,8 +447,13 @@ namespace GreeterCompositor {
if (windows == null || parents == null)
return;

#if HAS_MUTTER330
unowned Meta.Display display = get_display ();
var active_workspace = display.get_workspace_manager ().get_active_workspace ();
#else
var screen = get_screen ();
var active_workspace = screen.get_active_workspace ();
#endif

for (var i = 0; i < windows.length (); i++) {
var actor = windows.nth_data (i);
Expand Down

0 comments on commit 5011b53

Please sign in to comment.