2012-06-01 01:17:10 +04:00
|
|
|
//
|
|
|
|
// Copyright (C) 2012 Tom Beckmann, Rico Tzschichholz
|
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
//
|
2012-05-22 18:44:37 +04:00
|
|
|
|
2012-06-01 01:17:10 +04:00
|
|
|
using Clutter;
|
|
|
|
using Granite.Drawing;
|
2012-05-22 18:44:37 +04:00
|
|
|
|
2012-06-01 01:17:10 +04:00
|
|
|
namespace Gala
|
|
|
|
{
|
2012-06-27 17:46:56 +04:00
|
|
|
struct WindowPair
|
|
|
|
{
|
|
|
|
unowned Meta.Window window;
|
|
|
|
Clone clone;
|
|
|
|
}
|
|
|
|
|
|
|
|
public class WindowSwitcher : Clutter.Group
|
2012-06-01 01:17:10 +04:00
|
|
|
{
|
|
|
|
Gala.Plugin plugin;
|
2012-06-01 22:54:17 +04:00
|
|
|
|
2012-06-27 17:46:56 +04:00
|
|
|
List<WindowPair?>? window_list = null;
|
2012-06-01 22:54:17 +04:00
|
|
|
|
2012-06-27 17:07:13 +04:00
|
|
|
Meta.Window? current_window;
|
2012-06-01 22:54:17 +04:00
|
|
|
|
2012-06-01 01:17:10 +04:00
|
|
|
public WindowSwitcher (Gala.Plugin _plugin)
|
|
|
|
{
|
|
|
|
plugin = _plugin;
|
|
|
|
}
|
2012-06-01 22:54:17 +04:00
|
|
|
|
2012-06-01 01:17:10 +04:00
|
|
|
public override bool key_release_event (Clutter.KeyEvent event)
|
|
|
|
{
|
|
|
|
if (((event.modifier_state & ModifierType.MOD1_MASK) == 0) ||
|
|
|
|
event.keyval == Key.Alt_L) {
|
2012-06-09 03:16:11 +04:00
|
|
|
|
2012-06-27 17:46:56 +04:00
|
|
|
foreach (var win in window_list) {
|
|
|
|
remove_child (win.clone);
|
|
|
|
win.clone.destroy ();
|
|
|
|
}
|
|
|
|
|
|
|
|
Meta.Compositor.get_window_actors (plugin.get_screen ()).foreach ((w) => {
|
|
|
|
var meta_win = w.get_meta_window ();
|
|
|
|
if (!meta_win.minimized &&
|
|
|
|
(meta_win.get_workspace () == plugin.get_screen ().get_active_workspace ()) ||
|
|
|
|
meta_win.is_on_all_workspaces ())
|
|
|
|
w.show ();
|
2012-06-09 03:16:11 +04:00
|
|
|
});
|
|
|
|
|
2012-06-09 14:46:48 +04:00
|
|
|
window_list = null;
|
|
|
|
|
2012-06-01 01:17:10 +04:00
|
|
|
plugin.end_modal ();
|
|
|
|
current_window.activate (event.time);
|
2012-06-27 17:46:56 +04:00
|
|
|
current_window = null;
|
2012-06-01 01:17:10 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override bool captured_event (Clutter.Event event)
|
|
|
|
{
|
|
|
|
if (!(event.get_type () == EventType.KEY_PRESS))
|
|
|
|
return false;
|
|
|
|
|
2012-06-05 22:19:55 +04:00
|
|
|
var screen = plugin.get_screen ();
|
|
|
|
var display = screen.get_display ();
|
|
|
|
|
2012-06-01 01:17:10 +04:00
|
|
|
bool backward = (event.get_state () & X.KeyMask.ShiftMask) != 0;
|
2012-06-05 22:19:55 +04:00
|
|
|
var action = display.get_keybinding_action (event.get_key_code (), event.get_state ());
|
2012-06-01 01:17:10 +04:00
|
|
|
|
2012-06-09 03:16:11 +04:00
|
|
|
var prev_win = current_window;
|
2012-06-01 01:17:10 +04:00
|
|
|
switch (action) {
|
|
|
|
case Meta.KeyBindingAction.SWITCH_GROUP:
|
|
|
|
case Meta.KeyBindingAction.SWITCH_WINDOWS:
|
2012-06-09 14:46:48 +04:00
|
|
|
current_window = display.get_tab_next (Meta.TabList.NORMAL, screen,
|
2012-06-05 22:19:55 +04:00
|
|
|
screen.get_active_workspace (), current_window, backward);
|
2012-06-01 01:17:10 +04:00
|
|
|
break;
|
|
|
|
case Meta.KeyBindingAction.SWITCH_GROUP_BACKWARD:
|
|
|
|
case Meta.KeyBindingAction.SWITCH_WINDOWS_BACKWARD:
|
2012-06-09 14:46:48 +04:00
|
|
|
current_window = display.get_tab_next (Meta.TabList.NORMAL, screen,
|
2012-06-05 22:19:55 +04:00
|
|
|
screen.get_active_workspace (), current_window, true);
|
2012-06-01 01:17:10 +04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-06-09 03:16:11 +04:00
|
|
|
if (prev_win != current_window) {
|
|
|
|
dim_windows ();
|
|
|
|
}
|
|
|
|
|
2012-06-01 01:17:10 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-06-09 03:16:11 +04:00
|
|
|
void dim_windows ()
|
|
|
|
{
|
2012-06-27 17:46:56 +04:00
|
|
|
foreach (var win in window_list) {
|
|
|
|
if (win.window == current_window) {
|
|
|
|
win.clone.get_parent ().set_child_above_sibling (win.clone, null);
|
|
|
|
win.clone.depth = -200.0f;
|
|
|
|
win.clone.opacity = 0;
|
|
|
|
win.clone.animate (Clutter.AnimationMode.EASE_OUT_QUAD, 250, depth : 0.0f, opacity : 255);
|
2012-06-09 15:17:01 +04:00
|
|
|
} else {
|
2012-06-27 17:46:56 +04:00
|
|
|
win.clone.animate (Clutter.AnimationMode.EASE_OUT_QUAD, 250, depth : -200.0f, opacity : 0);
|
2012-06-09 15:17:01 +04:00
|
|
|
}
|
2012-06-27 17:46:56 +04:00
|
|
|
}
|
2012-06-09 03:16:11 +04:00
|
|
|
}
|
|
|
|
|
2012-06-27 17:07:13 +04:00
|
|
|
public void handle_switch_windows (Meta.Display display, Meta.Screen screen, Meta.Window? window,
|
|
|
|
X.Event event, Meta.KeyBinding binding)
|
2012-06-01 01:17:10 +04:00
|
|
|
{
|
2012-06-27 17:46:56 +04:00
|
|
|
var windows = display.get_tab_list (Meta.TabList.NORMAL, screen, screen.get_active_workspace ());
|
|
|
|
if (windows.length () <= 1)
|
2012-06-27 17:07:13 +04:00
|
|
|
return;
|
2012-06-27 17:46:56 +04:00
|
|
|
|
|
|
|
window_list = new List<WindowPair?> ();
|
|
|
|
foreach (var win in windows) {
|
|
|
|
|
|
|
|
var actor = win.get_compositor_private () as Actor;
|
|
|
|
|
|
|
|
var clone = new Clone (actor);
|
|
|
|
WindowPair pair = {win, clone};
|
|
|
|
|
|
|
|
clone.x = actor.x;
|
|
|
|
clone.y = actor.y;
|
|
|
|
|
|
|
|
add_child (clone);
|
|
|
|
window_list.append (pair);
|
2012-06-27 17:07:13 +04:00
|
|
|
}
|
|
|
|
|
2012-06-27 17:46:56 +04:00
|
|
|
Meta.Compositor.get_window_actors (screen).foreach ((w) => {
|
|
|
|
var type = w.get_meta_window ().window_type;
|
|
|
|
if (type != Meta.WindowType.DOCK && type != Meta.WindowType.DESKTOP && type != Meta.WindowType.NOTIFICATION)
|
|
|
|
w.hide ();
|
|
|
|
});
|
|
|
|
|
2012-06-27 17:07:13 +04:00
|
|
|
plugin.begin_modal ();
|
2012-06-09 03:16:11 +04:00
|
|
|
|
2012-06-27 17:07:13 +04:00
|
|
|
bool backward = (binding.get_name () == "switch-windows-backward");
|
2012-06-01 15:42:36 +04:00
|
|
|
|
2012-06-27 17:07:13 +04:00
|
|
|
/*list windows*/
|
2012-06-27 17:46:56 +04:00
|
|
|
current_window = plugin.get_next_window (screen.get_active_workspace (), backward);
|
2012-06-01 01:17:10 +04:00
|
|
|
if (current_window == null)
|
|
|
|
return;
|
2012-06-01 15:42:36 +04:00
|
|
|
|
2012-06-01 01:17:10 +04:00
|
|
|
if (binding.get_mask () == 0) {
|
|
|
|
current_window.activate (display.get_current_time ());
|
|
|
|
return;
|
|
|
|
}
|
2012-06-01 15:42:36 +04:00
|
|
|
|
2012-06-09 03:16:11 +04:00
|
|
|
dim_windows ();
|
2012-06-01 16:20:36 +04:00
|
|
|
grab_key_focus ();
|
|
|
|
}
|
2012-06-01 01:17:10 +04:00
|
|
|
}
|
|
|
|
}
|