Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a Gala plugin to show window previews #3

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/DockController.vala
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ namespace Plank

public DockItemProvider? default_provider { get; private set; }

public bool PreviewMode { get; set; default = false; }

DBusManager dbus_manager;
Gee.ArrayList<unowned DockItem> visible_items;
Gee.ArrayList<unowned DockItem> items;
Expand Down
13 changes: 10 additions & 3 deletions lib/HideManager.vala
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ namespace Plank
Hovered = hovered;
update_needed = true;
}

// disable hiding if menu is visible or drags are active
var disabled = (window.menu_is_visible () || drag_manager.InternalDragActive || drag_manager.ExternalDragActive);
if (Disabled != disabled) {
Expand All @@ -244,6 +244,13 @@ namespace Plank

thaw_notify ();
}

public void update_hovered_force ()
{
freeze_notify ();
update_hidden ();
thaw_notify ();
}

void prefs_changed (Object prefs, ParamSpec prop)
{
Expand Down Expand Up @@ -277,12 +284,12 @@ namespace Plank

void update_hidden ()
{
if (Disabled) {
if (Disabled || controller.PreviewMode) {
if (Hidden)
Hidden = false;
return;
}

switch (controller.prefs.HideMode) {
default:
case HideType.NONE:
Expand Down
52 changes: 51 additions & 1 deletion lib/Widgets/DockWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@

namespace Plank
{
[DBus (name = "org.pantheon.gala.plank")]
interface GalaPlugin : Object {
public signal void disable_preview_mode ();
public abstract bool get_preview_is_hovered ();
public abstract bool show_window_preview (string launcher, int x, int y);
}

/**
* The main window for all docks.
*/
Expand Down Expand Up @@ -54,6 +61,8 @@ namespace Plank
*/
Gtk.Menu? menu;

GalaPlugin? plugin;

uint hover_reposition_timer_id = 0U;

uint long_press_timer_id = 0U;
Expand Down Expand Up @@ -91,6 +100,16 @@ namespace Plank
Gdk.EventMask.STRUCTURE_MASK);

controller.prefs.notify["HideMode"].connect (set_struts);

try {
plugin = Bus.get_proxy_sync (BusType.SESSION, "org.pantheon.gala.plank", "/org/pantheon/gala/plank");
plugin.disable_preview_mode.connect (() => {
controller.PreviewMode = false;
controller.hide_manager.update_hovered_force ();
});
} catch (Error e) {
warning (e.message);
}
}

~DockWindow ()
Expand Down Expand Up @@ -214,6 +233,16 @@ namespace Plank
if (!menu_is_visible ()) {
set_hovered_provider (null);
set_hovered (null);

Timeout.add (500, () => {
if (controller.PreviewMode && HoveredItem == null
&& plugin != null && !plugin.get_preview_is_hovered ()) {
plugin.show_window_preview ("", -1, -1);
plugin.disable_preview_mode ();
}

return false;
});
} else
controller.hover.hide ();

Expand Down Expand Up @@ -366,9 +395,25 @@ namespace Plank

controller.hover.hide ();

if (plugin != null) {
if (HoveredItem != null) {
int x, y;
controller.position_manager.get_hover_position (HoveredItem, out x, out y);

bool shown = plugin.show_window_preview (HoveredItem.Launcher, x, y);
controller.PreviewMode = shown;
controller.hide_manager.update_hovered_force ();
} else if (!controller.PreviewMode) {
bool shown = plugin.show_window_preview ("", -1, -1);
controller.PreviewMode = shown;
controller.hide_manager.update_hovered_force ();
}
}

if (HoveredItem == null
|| !controller.prefs.TooltipsEnabled
|| controller.drag_manager.InternalDragActive)
|| controller.drag_manager.InternalDragActive
|| controller.PreviewMode)
return;

// don't be that demanding this delay is still fast enough
Expand Down Expand Up @@ -600,6 +645,11 @@ namespace Plank
menu = null;
}

if (plugin != null) {
plugin.show_window_preview ("", -1, -1);
plugin.disable_preview_mode ();
}

Gee.ArrayList<Gtk.MenuItem>? menu_items = null;
Gtk.MenuPositionFunc? position_func = null;
var button = PopupButton.from_event_button (event);
Expand Down