2014-04-08 16:51:06 +04:00
|
|
|
//
|
2013-12-17 23:10:03 +04:00
|
|
|
// Copyright (C) 2013 Tom Beckmann, Rico Tzschichholz
|
2014-04-08 16:51:06 +04:00
|
|
|
//
|
2012-08-07 01:03:11 +04:00
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
2014-04-08 16:51:06 +04:00
|
|
|
//
|
2012-08-07 01:03:11 +04:00
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
2014-04-08 16:51:06 +04:00
|
|
|
//
|
2012-08-07 01:03:11 +04:00
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2014-04-08 16:51:06 +04:00
|
|
|
//
|
2012-08-07 01:03:11 +04:00
|
|
|
|
2013-12-17 23:10:03 +04:00
|
|
|
namespace Gala.Plugins.Zoom
|
2012-08-07 01:03:11 +04:00
|
|
|
{
|
2014-03-12 23:06:23 +04:00
|
|
|
public class Main : Gala.Plugin
|
2012-08-07 01:03:11 +04:00
|
|
|
{
|
2014-04-06 22:03:24 +04:00
|
|
|
const uint MOUSE_POLL_TIME = 50;
|
|
|
|
|
2013-12-17 23:10:03 +04:00
|
|
|
Gala.WindowManager? wm = null;
|
|
|
|
|
2012-08-28 15:44:52 +04:00
|
|
|
uint mouse_poll_timer = 0;
|
|
|
|
float current_zoom = 1.0f;
|
2015-10-22 17:57:27 +03:00
|
|
|
ulong wins_handler_id = 0UL;
|
2013-12-17 23:10:03 +04:00
|
|
|
|
2014-03-12 23:06:23 +04:00
|
|
|
public override void initialize (Gala.WindowManager wm)
|
2012-08-07 01:03:11 +04:00
|
|
|
{
|
2013-12-17 23:10:03 +04:00
|
|
|
this.wm = wm;
|
2019-11-01 00:22:38 +03:00
|
|
|
#if HAS_MUTTER330
|
|
|
|
var display = wm.get_display ();
|
|
|
|
#else
|
2013-12-17 23:10:03 +04:00
|
|
|
var display = wm.get_screen ().get_display ();
|
2019-11-01 00:22:38 +03:00
|
|
|
#endif
|
2013-12-17 23:10:03 +04:00
|
|
|
var schema = new GLib.Settings (Config.SCHEMA + ".keybindings");
|
|
|
|
|
2015-03-12 17:47:16 +03:00
|
|
|
display.add_keybinding ("zoom-in", schema, 0, (Meta.KeyHandlerFunc) zoom_in);
|
|
|
|
display.add_keybinding ("zoom-out", schema, 0, (Meta.KeyHandlerFunc) zoom_out);
|
2012-08-07 01:03:11 +04:00
|
|
|
}
|
2013-12-17 23:10:03 +04:00
|
|
|
|
2014-03-12 23:06:23 +04:00
|
|
|
public override void destroy ()
|
2012-08-07 01:03:11 +04:00
|
|
|
{
|
2013-12-17 23:10:03 +04:00
|
|
|
if (wm == null)
|
|
|
|
return;
|
|
|
|
|
2019-11-01 00:22:38 +03:00
|
|
|
#if HAS_MUTTER330
|
|
|
|
var display = wm.get_display ();
|
|
|
|
#else
|
2013-12-17 23:10:03 +04:00
|
|
|
var display = wm.get_screen ().get_display ();
|
2019-11-01 00:22:38 +03:00
|
|
|
#endif
|
2013-12-17 23:10:03 +04:00
|
|
|
|
|
|
|
display.remove_keybinding ("zoom-in");
|
|
|
|
display.remove_keybinding ("zoom-out");
|
|
|
|
|
2012-08-28 15:44:52 +04:00
|
|
|
if (mouse_poll_timer > 0)
|
|
|
|
Source.remove (mouse_poll_timer);
|
|
|
|
mouse_poll_timer = 0;
|
2012-08-07 01:03:11 +04:00
|
|
|
}
|
2013-12-17 23:10:03 +04:00
|
|
|
|
2015-03-12 17:47:16 +03:00
|
|
|
[CCode (instance_pos = -1)]
|
2019-11-01 00:22:38 +03:00
|
|
|
#if HAS_MUTTER330
|
|
|
|
void zoom_in (Meta.Display display, Meta.Window? window,
|
|
|
|
Clutter.KeyEvent event, Meta.KeyBinding binding)
|
|
|
|
#else
|
2013-12-17 23:10:03 +04:00
|
|
|
void zoom_in (Meta.Display display, Meta.Screen screen,
|
2014-06-03 23:24:52 +04:00
|
|
|
Meta.Window? window, Clutter.KeyEvent event, Meta.KeyBinding binding)
|
2019-11-01 00:22:38 +03:00
|
|
|
#endif
|
2013-12-17 23:10:03 +04:00
|
|
|
{
|
2012-08-28 15:44:52 +04:00
|
|
|
zoom (true);
|
|
|
|
}
|
2013-12-17 23:10:03 +04:00
|
|
|
|
2015-03-12 17:47:16 +03:00
|
|
|
[CCode (instance_pos = -1)]
|
2019-11-01 00:22:38 +03:00
|
|
|
#if HAS_MUTTER330
|
|
|
|
void zoom_out (Meta.Display display, Meta.Window? window,
|
|
|
|
Clutter.KeyEvent event, Meta.KeyBinding binding)
|
|
|
|
#else
|
2013-12-17 23:10:03 +04:00
|
|
|
void zoom_out (Meta.Display display, Meta.Screen screen,
|
2014-06-03 23:24:52 +04:00
|
|
|
Meta.Window? window, Clutter.KeyEvent event, Meta.KeyBinding binding)
|
2019-11-01 00:22:38 +03:00
|
|
|
#endif
|
2013-12-17 23:10:03 +04:00
|
|
|
{
|
2012-08-28 15:44:52 +04:00
|
|
|
zoom (false);
|
|
|
|
}
|
2013-12-17 23:10:03 +04:00
|
|
|
|
2012-08-28 15:44:52 +04:00
|
|
|
void zoom (bool @in)
|
2012-08-07 01:03:11 +04:00
|
|
|
{
|
2012-08-28 15:44:52 +04:00
|
|
|
// Nothing to do if zooming out of our bounds is requested
|
|
|
|
if (current_zoom <= 1.0f && !@in)
|
|
|
|
return;
|
|
|
|
else if (current_zoom >= 2.5f && @in)
|
|
|
|
return;
|
2014-04-08 16:51:06 +04:00
|
|
|
|
2013-12-17 23:10:03 +04:00
|
|
|
var wins = wm.ui_group;
|
2014-04-08 16:51:06 +04:00
|
|
|
|
2012-08-28 15:44:52 +04:00
|
|
|
// Add timer to poll current mouse position to reposition window-group
|
|
|
|
// to show requested zoomed area
|
|
|
|
if (mouse_poll_timer == 0) {
|
|
|
|
float mx, my;
|
|
|
|
var client_pointer = Gdk.Display.get_default ().get_device_manager ().get_client_pointer ();
|
|
|
|
client_pointer.get_position (null, out mx, out my);
|
2015-11-12 11:25:27 +03:00
|
|
|
wins.set_pivot_point (mx / wins.width, my / wins.height);
|
2014-04-08 16:51:06 +04:00
|
|
|
|
2013-12-17 23:10:03 +04:00
|
|
|
mouse_poll_timer = Timeout.add (MOUSE_POLL_TIME, () => {
|
2012-08-28 15:44:52 +04:00
|
|
|
client_pointer.get_position (null, out mx, out my);
|
2015-10-22 17:57:27 +03:00
|
|
|
var new_pivot = Clutter.Point.alloc ();
|
|
|
|
new_pivot.init (mx / wins.width, my / wins.height);
|
|
|
|
if (wins.pivot_point.equals (new_pivot))
|
2012-08-28 16:36:49 +04:00
|
|
|
return true;
|
2014-04-08 16:51:06 +04:00
|
|
|
|
2015-10-19 00:56:40 +03:00
|
|
|
wins.save_easing_state ();
|
|
|
|
wins.set_easing_mode (Clutter.AnimationMode.LINEAR);
|
|
|
|
wins.set_easing_duration (MOUSE_POLL_TIME);
|
2015-10-22 17:57:27 +03:00
|
|
|
wins.pivot_point = new_pivot;
|
2015-10-19 00:56:40 +03:00
|
|
|
wins.restore_easing_state ();
|
2012-08-09 00:04:15 +04:00
|
|
|
return true;
|
|
|
|
});
|
2012-08-07 01:03:11 +04:00
|
|
|
}
|
2014-04-08 16:51:06 +04:00
|
|
|
|
2012-08-28 15:44:52 +04:00
|
|
|
current_zoom += (@in ? 0.5f : -0.5f);
|
2014-04-08 16:51:06 +04:00
|
|
|
|
2012-08-28 15:44:52 +04:00
|
|
|
if (current_zoom <= 1.0f) {
|
|
|
|
current_zoom = 1.0f;
|
2014-04-08 16:51:06 +04:00
|
|
|
|
2012-08-28 16:16:14 +04:00
|
|
|
if (mouse_poll_timer > 0)
|
|
|
|
Source.remove (mouse_poll_timer);
|
2012-08-28 15:44:52 +04:00
|
|
|
mouse_poll_timer = 0;
|
2015-10-22 17:57:27 +03:00
|
|
|
|
2015-10-19 00:56:40 +03:00
|
|
|
wins.save_easing_state ();
|
|
|
|
wins.set_easing_mode (Clutter.AnimationMode.EASE_OUT_CUBIC);
|
|
|
|
wins.set_easing_duration (300);
|
2015-11-12 11:25:27 +03:00
|
|
|
wins.set_scale (1.0f, 1.0f);
|
2015-10-19 00:56:40 +03:00
|
|
|
wins.restore_easing_state ();
|
2015-10-22 17:57:27 +03:00
|
|
|
|
|
|
|
wins_handler_id = wins.transitions_completed.connect (() => {
|
|
|
|
wins.disconnect (wins_handler_id);
|
2015-11-12 11:25:27 +03:00
|
|
|
wins.set_pivot_point (0.0f, 0.0f);
|
2012-08-28 15:44:52 +04:00
|
|
|
});
|
2014-04-08 16:51:06 +04:00
|
|
|
|
2012-08-07 01:03:11 +04:00
|
|
|
return;
|
|
|
|
}
|
2014-04-08 16:51:06 +04:00
|
|
|
|
2015-10-19 00:56:40 +03:00
|
|
|
wins.save_easing_state ();
|
|
|
|
wins.set_easing_mode (Clutter.AnimationMode.EASE_OUT_CUBIC);
|
|
|
|
wins.set_easing_duration (300);
|
2015-11-12 11:25:27 +03:00
|
|
|
wins.set_scale (current_zoom, current_zoom);
|
2015-10-19 00:56:40 +03:00
|
|
|
wins.restore_easing_state ();
|
2012-08-07 01:03:11 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-12-17 23:10:03 +04:00
|
|
|
|
2014-03-12 23:06:23 +04:00
|
|
|
public Gala.PluginInfo register_plugin ()
|
2013-12-17 23:10:03 +04:00
|
|
|
{
|
2014-03-12 23:06:23 +04:00
|
|
|
return Gala.PluginInfo () {
|
|
|
|
name = "Zoom",
|
|
|
|
author = "Gala Developers",
|
|
|
|
plugin_type = typeof (Gala.Plugins.Zoom.Main),
|
|
|
|
provides = Gala.PluginFunction.ADDITION,
|
2014-03-13 00:04:08 +04:00
|
|
|
load_priority = Gala.LoadPriority.IMMEDIATE
|
2014-03-12 23:06:23 +04:00
|
|
|
};
|
2013-12-17 23:10:03 +04:00
|
|
|
}
|
|
|
|
|