mirror of
https://github.com/elementary/gala.git
synced 2024-12-25 10:13:04 +03:00
Add action system for hot corner configuration
This commit is contained in:
parent
40b3f97b11
commit
6cbee63b73
@ -1,10 +1,46 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<schemalist>
|
||||
|
||||
<enum id="gala-action-type">
|
||||
<value nick="None" value="0" />
|
||||
<value nick="ShowWorkspaceView" value="1" />
|
||||
<value nick="SwitchLeft" value="2" />
|
||||
<value nick="SwitchRight" value="3" />
|
||||
<value nick="MoveLeft" value="4" />
|
||||
<value nick="MoveRight" value="5" />
|
||||
<value nick="MaximizeCurrent" value="6" />
|
||||
<value nick="MinimizeCurrent" value="7" />
|
||||
<value nick="OpenLauncher" value="8" />
|
||||
<value nick="CustomCommand" value="9" />
|
||||
</enum>
|
||||
|
||||
<schema path="/org/pantheon/desktop/gala/behavior/" id="org.pantheon.desktop.gala.behavior" gettext-domain="gala">
|
||||
<key type="b" name="enable-manager-corner">
|
||||
<default>false</default>
|
||||
<summary>Make the lower right a hot corner to reveal the manager</summary>
|
||||
<description>This turns the lower right corner to a hot corner, showing some icons allowing you to do tasks like window tiling</description>
|
||||
|
||||
<key enum="gala-action-type" name="hotcorner-topleft">
|
||||
<default>"None"</default>
|
||||
<summary>Action for the top left corner</summary>
|
||||
<description></description>
|
||||
</key>
|
||||
<key enum="gala-action-type" name="hotcorner-topright">
|
||||
<default>"None"</default>
|
||||
<summary>Action for the top right corner</summary>
|
||||
<description></description>
|
||||
</key>
|
||||
<key enum="gala-action-type" name="hotcorner-bottomleft">
|
||||
<default>"None"</default>
|
||||
<summary>Action for the bottom left corner</summary>
|
||||
<description></description>
|
||||
</key>
|
||||
<key enum="gala-action-type" name="hotcorner-bottomright">
|
||||
<default>"None"</default>
|
||||
<summary>Action for the bottom right corner</summary>
|
||||
<description></description>
|
||||
</key>
|
||||
|
||||
<key type="s" name="hotcorner-custom-command">
|
||||
<default>''</default>
|
||||
<summary>The command that will be executed for the hotcorner action CUSTOM_COMMAND</summary>
|
||||
<description></description>
|
||||
</key>
|
||||
<key type="b" name="edge-tiling">
|
||||
<default>true</default>
|
||||
|
104
src/Plugin.vala
104
src/Plugin.vala
@ -19,6 +19,21 @@ using Meta;
|
||||
|
||||
namespace Gala
|
||||
{
|
||||
|
||||
public enum ActionType
|
||||
{
|
||||
NONE = 0,
|
||||
SHOW_WORKSPACE_VIEW,
|
||||
WORKSPACE_LEFT,
|
||||
WORKSPACE_RIGHT,
|
||||
MOVE_TO_WORKSPACE_LEFT,
|
||||
MOVE_TO_WORKSPACE_RIGHT,
|
||||
MAXIMIZE_CURRENT,
|
||||
MINIMIZE_CURRENT,
|
||||
OPEN_LAUNCHER,
|
||||
CUSTOM_COMMAND
|
||||
}
|
||||
|
||||
public class Plugin : Meta.Plugin
|
||||
{
|
||||
WindowSwitcher winswitcher;
|
||||
@ -116,32 +131,45 @@ namespace Gala
|
||||
Utils.reload_shadow ();
|
||||
ShadowSettings.get_default ().notify.connect (Utils.reload_shadow);
|
||||
|
||||
/*hot corner*/
|
||||
/*hot corner, getting enum values from GraniteServicesSettings did not work, so we use GSettings directly*/
|
||||
var geometry = screen.get_monitor_geometry (screen.get_primary_monitor ());
|
||||
|
||||
var hot_corner = new Clutter.Rectangle ();
|
||||
hot_corner.x = geometry.x + geometry.width - 1;
|
||||
hot_corner.y = geometry.y + geometry.height - 1;
|
||||
var top_left = create_hotcorner (geometry.x, geometry.y, "hotcorner-topleft");
|
||||
var top_right = create_hotcorner (geometry.x + geometry.width - 1, geometry.y, "hotcorner-topright");
|
||||
var bottom_left = create_hotcorner (geometry.x, geometry.y + geometry.height - 1, "hotcorner-bottomleft");
|
||||
var bottom_right = create_hotcorner (geometry.x + geometry.width - 1, geometry.y + geometry.height - 1, "hotcorner-bottomright");
|
||||
|
||||
update_input_area ();
|
||||
|
||||
BehaviorSettings.get_default ().schema.changed.connect ((key) => update_input_area ());
|
||||
}
|
||||
|
||||
Clutter.Actor create_hotcorner (float x, float y, string key)
|
||||
{
|
||||
var hot_corner = new Clutter.Actor ();
|
||||
hot_corner.x = x;
|
||||
hot_corner.y = y;
|
||||
hot_corner.width = 1;
|
||||
hot_corner.height = 1;
|
||||
hot_corner.opacity = 0;
|
||||
hot_corner.reactive = true;
|
||||
|
||||
Compositor.get_stage_for_screen (get_screen ()).add_child (hot_corner);
|
||||
|
||||
hot_corner.enter_event.connect (() => {
|
||||
workspace_view.show ();
|
||||
run (this, (ActionType)BehaviorSettings.get_default ().schema.get_enum (key));
|
||||
return false;
|
||||
});
|
||||
|
||||
stage.add_child (hot_corner);
|
||||
|
||||
update_input_area ();
|
||||
|
||||
BehaviorSettings.get_default ().notify["enable-manager-corner"].connect (update_input_area);
|
||||
return hot_corner;
|
||||
}
|
||||
|
||||
public void update_input_area ()
|
||||
{
|
||||
if (BehaviorSettings.get_default ().enable_manager_corner)
|
||||
if (BehaviorSettings.get_default ().schema.get_enum ("hotcorner-topleft") != ActionType.NONE ||
|
||||
BehaviorSettings.get_default ().schema.get_enum ("hotcorner-topright") != ActionType.NONE ||
|
||||
BehaviorSettings.get_default ().schema.get_enum ("hotcorner-bottomleft") != ActionType.NONE ||
|
||||
BehaviorSettings.get_default ().schema.get_enum ("hotcorner-bottomright") != ActionType.NONE)
|
||||
Utils.set_input_area (get_screen (), Utils.InputArea.HOT_CORNER);
|
||||
else
|
||||
Utils.set_input_area (get_screen (), Utils.InputArea.NONE);
|
||||
@ -213,6 +241,60 @@ namespace Gala
|
||||
win.clear_effects ();*/
|
||||
}
|
||||
|
||||
public static void run (Plugin plugin, ActionType type)
|
||||
{
|
||||
var screen = plugin.get_screen ();
|
||||
var display = screen.get_display ();
|
||||
var current = display.get_focus_window ();
|
||||
|
||||
switch (type) {
|
||||
case ActionType.SHOW_WORKSPACE_VIEW:
|
||||
plugin.workspace_view.show ();
|
||||
break;
|
||||
case ActionType.WORKSPACE_LEFT:
|
||||
plugin.workspace_view.switch_to_next_workspace (MotionDirection.LEFT);
|
||||
break;
|
||||
case ActionType.WORKSPACE_RIGHT:
|
||||
plugin.workspace_view.switch_to_next_workspace (MotionDirection.RIGHT);
|
||||
break;
|
||||
case ActionType.MOVE_TO_WORKSPACE_LEFT:
|
||||
plugin.move_window (current, MotionDirection.LEFT);
|
||||
break;
|
||||
case ActionType.MOVE_TO_WORKSPACE_RIGHT:
|
||||
plugin.move_window (current, MotionDirection.RIGHT);
|
||||
break;
|
||||
case ActionType.MAXIMIZE_CURRENT:
|
||||
if (current == null)
|
||||
break;
|
||||
if (current.get_maximized () == (MaximizeFlags.HORIZONTAL | MaximizeFlags.VERTICAL))
|
||||
current.unmaximize (MaximizeFlags.HORIZONTAL | MaximizeFlags.VERTICAL);
|
||||
else
|
||||
current.maximize (MaximizeFlags.HORIZONTAL | MaximizeFlags.VERTICAL);
|
||||
break;
|
||||
case ActionType.MINIMIZE_CURRENT:
|
||||
if (current != null)
|
||||
current.minimize ();
|
||||
break;
|
||||
case ActionType.OPEN_LAUNCHER:
|
||||
try {
|
||||
Process.spawn_command_line_async (BehaviorSettings.get_default ().panel_main_menu_action);
|
||||
} catch (Error e) {
|
||||
warning (e.message);
|
||||
}
|
||||
break;
|
||||
case ActionType.CUSTOM_COMMAND:
|
||||
try {
|
||||
Process.spawn_command_line_async (BehaviorSettings.get_default ().hotcorner_custom_command);
|
||||
} catch (Error e) {
|
||||
warning (e.message);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
warning ("Trying to run unknown action");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* effects
|
||||
*/
|
||||
|
@ -23,7 +23,12 @@ namespace Gala
|
||||
public string panel_main_menu_action { get; set; }
|
||||
public string toggle_recording_action { get; set; }
|
||||
public string overlay_action { get; set; }
|
||||
public bool enable_manager_corner { get; set; }
|
||||
public string hotcorner_custom_command { get; set; }
|
||||
|
||||
public ActionType hotcorner_topleft { get; set; }
|
||||
public ActionType hotcorner_topright { get; set; }
|
||||
public ActionType hotcorner_bottomleft { get; set; }
|
||||
public ActionType hotcorner_bottomright { get; set; }
|
||||
|
||||
static BehaviorSettings? instance = null;
|
||||
|
||||
|
@ -105,24 +105,35 @@ namespace Gala.Utils
|
||||
{
|
||||
var display = screen.get_display ();
|
||||
|
||||
X.Xrectangle rect;
|
||||
X.Xrectangle[] rects;
|
||||
int width, height;
|
||||
screen.get_size (out width, out height);
|
||||
var geometry = screen.get_monitor_geometry (screen.get_primary_monitor ());
|
||||
|
||||
switch (area) {
|
||||
case InputArea.FULLSCREEN:
|
||||
rect = {0, 0, (ushort)width, (ushort)height};
|
||||
X.Xrectangle rect = {0, 0, (ushort)width, (ushort)height};
|
||||
rects = {rect};
|
||||
break;
|
||||
case InputArea.HOT_CORNER: //leave one pix in the bottom left
|
||||
rect = {(short)(geometry.x + geometry.width - 1), (short)(geometry.y + geometry.height - 1), 1, 1};
|
||||
case InputArea.HOT_CORNER: //if action type is none, make them 0 sized
|
||||
short tl_size = (BehaviorSettings.get_default ().schema.get_enum ("hotcorner-topleft") != ActionType.NONE)?1:0;
|
||||
short tr_size = (BehaviorSettings.get_default ().schema.get_enum ("hotcorner-topright") != ActionType.NONE)?1:0;
|
||||
short bl_size = (BehaviorSettings.get_default ().schema.get_enum ("hotcorner-bottomleft") != ActionType.NONE)?1:0;
|
||||
short br_size = (BehaviorSettings.get_default ().schema.get_enum ("hotcorner-bottomright") != ActionType.NONE)?1:0;
|
||||
|
||||
X.Xrectangle topleft = {(short)geometry.x, (short)geometry.y, tl_size, tl_size};
|
||||
X.Xrectangle topright = {(short)(geometry.x + geometry.width - 1), (short)geometry.y, tr_size, tr_size};
|
||||
X.Xrectangle bottomleft = {(short)geometry.x, (short)(geometry.y + geometry.height - 1), bl_size, bl_size};
|
||||
X.Xrectangle bottomright = {(short)(geometry.x + geometry.width - 1), (short)(geometry.y + geometry.height - 1), br_size, br_size};
|
||||
|
||||
rects = {topleft, topright, bottomleft, bottomright};
|
||||
break;
|
||||
default:
|
||||
Util.empty_stage_input_region (screen);
|
||||
return;
|
||||
}
|
||||
|
||||
var xregion = X.Fixes.create_region (display.get_xdisplay (), {rect});
|
||||
var xregion = X.Fixes.create_region (display.get_xdisplay (), rects);
|
||||
Util.set_stage_input_region (screen, xregion);
|
||||
}
|
||||
|
||||
|
@ -197,7 +197,7 @@ namespace Gala
|
||||
}
|
||||
}
|
||||
|
||||
void switch_to_next_workspace (MotionDirection direction)
|
||||
internal void switch_to_next_workspace (MotionDirection direction)
|
||||
{
|
||||
var screen = plugin.get_screen ();
|
||||
var display = screen.get_display ();
|
||||
|
Loading…
Reference in New Issue
Block a user