2015-02-05 23:15:55 +03:00
|
|
|
//
|
|
|
|
// Copyright (C) 2015 Rory J Sanderson
|
|
|
|
//
|
|
|
|
// 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/>.
|
|
|
|
//
|
|
|
|
|
|
|
|
using Clutter;
|
|
|
|
using Meta;
|
|
|
|
|
2020-01-15 03:44:21 +03:00
|
|
|
namespace Gala.Plugins.MaskCorners {
|
|
|
|
public class Main : Gala.Plugin {
|
2020-01-09 22:26:30 +03:00
|
|
|
Gala.WindowManager? wm = null;
|
|
|
|
Display display;
|
|
|
|
Settings settings;
|
2015-02-05 23:15:55 +03:00
|
|
|
|
2020-01-09 22:26:30 +03:00
|
|
|
List<Actor>[] cornermasks;
|
2020-07-17 20:20:06 +03:00
|
|
|
private const int DEFAULT_CORNER_RADIUS = 6;
|
|
|
|
private int corner_radius = DEFAULT_CORNER_RADIUS;
|
2015-02-05 23:15:55 +03:00
|
|
|
|
2020-01-15 03:44:21 +03:00
|
|
|
public override void initialize (Gala.WindowManager wm) {
|
2020-01-09 22:26:30 +03:00
|
|
|
this.wm = wm;
|
|
|
|
display = wm.get_display ();
|
|
|
|
settings = Settings.get_default ();
|
2015-02-05 23:15:55 +03:00
|
|
|
|
2020-01-09 22:26:30 +03:00
|
|
|
setup_cornermasks ();
|
2015-02-05 23:15:55 +03:00
|
|
|
|
2020-01-09 22:26:30 +03:00
|
|
|
settings.changed.connect (resetup_cornermasks);
|
|
|
|
}
|
2015-02-05 23:15:55 +03:00
|
|
|
|
2020-01-15 03:44:21 +03:00
|
|
|
public override void destroy () {
|
2020-01-09 22:26:30 +03:00
|
|
|
destroy_cornermasks ();
|
|
|
|
}
|
2015-02-05 23:15:55 +03:00
|
|
|
|
2020-01-15 03:44:21 +03:00
|
|
|
void setup_cornermasks () {
|
2020-01-09 22:26:30 +03:00
|
|
|
if (!settings.enable)
|
|
|
|
return;
|
2015-02-05 23:15:55 +03:00
|
|
|
|
2020-01-09 22:26:30 +03:00
|
|
|
var scale = Utils.get_ui_scaling_factor ();
|
2017-10-01 14:59:36 +03:00
|
|
|
|
2020-01-09 22:26:30 +03:00
|
|
|
int n_monitors = display.get_n_monitors ();
|
|
|
|
cornermasks = new List<Actor>[n_monitors];
|
2020-07-17 20:20:06 +03:00
|
|
|
corner_radius = DEFAULT_CORNER_RADIUS * scale;
|
2015-02-05 23:15:55 +03:00
|
|
|
|
2020-01-09 22:26:30 +03:00
|
|
|
if (settings.only_on_primary) {
|
|
|
|
add_cornermasks (display.get_primary_monitor ());
|
|
|
|
} else {
|
|
|
|
for (int m = 0; m < n_monitors; m++)
|
|
|
|
add_cornermasks (m);
|
|
|
|
}
|
2015-02-05 23:15:55 +03:00
|
|
|
|
2020-01-09 22:26:30 +03:00
|
|
|
if (settings.disable_on_fullscreen)
|
|
|
|
display.in_fullscreen_changed.connect (fullscreen_changed);
|
2019-11-01 00:22:38 +03:00
|
|
|
|
|
|
|
unowned Meta.MonitorManager monitor_manager = Meta.MonitorManager.@get ();
|
2020-01-09 22:26:30 +03:00
|
|
|
monitor_manager.monitors_changed.connect (resetup_cornermasks);
|
2019-11-01 00:22:38 +03:00
|
|
|
|
2020-01-09 22:26:30 +03:00
|
|
|
display.gl_video_memory_purged.connect (resetup_cornermasks);
|
|
|
|
}
|
2015-02-05 23:15:55 +03:00
|
|
|
|
2020-01-15 03:44:21 +03:00
|
|
|
void destroy_cornermasks () {
|
2020-01-09 22:26:30 +03:00
|
|
|
display.gl_video_memory_purged.disconnect (resetup_cornermasks);
|
2018-10-20 19:02:04 +03:00
|
|
|
|
2019-11-01 00:22:38 +03:00
|
|
|
unowned Meta.MonitorManager monitor_manager = Meta.MonitorManager.@get ();
|
2020-01-09 22:26:30 +03:00
|
|
|
monitor_manager.monitors_changed.disconnect (resetup_cornermasks);
|
|
|
|
display.in_fullscreen_changed.disconnect (fullscreen_changed);
|
2015-02-05 23:15:55 +03:00
|
|
|
|
2020-01-09 22:26:30 +03:00
|
|
|
foreach (unowned List<Actor> list in cornermasks) {
|
|
|
|
foreach (Actor actor in list)
|
|
|
|
actor.destroy ();
|
|
|
|
}
|
|
|
|
}
|
2015-02-05 23:15:55 +03:00
|
|
|
|
2020-01-15 03:44:21 +03:00
|
|
|
void resetup_cornermasks () {
|
2020-01-09 22:26:30 +03:00
|
|
|
destroy_cornermasks ();
|
|
|
|
setup_cornermasks ();
|
|
|
|
}
|
2015-02-05 23:15:55 +03:00
|
|
|
|
2020-01-15 03:44:21 +03:00
|
|
|
void fullscreen_changed () {
|
2020-01-09 22:26:30 +03:00
|
|
|
for (int i = 0; i < display.get_n_monitors (); i++) {
|
|
|
|
foreach (Actor actor in cornermasks[i]) {
|
|
|
|
if (display.get_monitor_in_fullscreen (i))
|
|
|
|
actor.hide ();
|
|
|
|
else
|
|
|
|
actor.show ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-02-05 23:15:55 +03:00
|
|
|
|
2020-01-15 03:44:21 +03:00
|
|
|
void add_cornermasks (int monitor_no) {
|
2020-01-09 22:26:30 +03:00
|
|
|
var monitor_geometry = display.get_monitor_geometry (monitor_no);
|
2015-02-05 23:15:55 +03:00
|
|
|
|
2020-01-09 22:26:30 +03:00
|
|
|
Canvas canvas = new Canvas ();
|
|
|
|
canvas.set_size (corner_radius, corner_radius);
|
|
|
|
canvas.draw.connect (draw_cornermask);
|
|
|
|
canvas.invalidate ();
|
|
|
|
|
|
|
|
Actor actor = new Actor ();
|
|
|
|
actor.set_content (canvas);
|
|
|
|
actor.set_size (corner_radius, corner_radius);
|
|
|
|
actor.set_position (monitor_geometry.x, monitor_geometry.y);
|
|
|
|
actor.set_pivot_point ((float) 0.5, (float) 0.5);
|
|
|
|
|
|
|
|
cornermasks[monitor_no].append (actor);
|
|
|
|
wm.stage.add_child (actor);
|
|
|
|
|
|
|
|
for (int p = 1; p < 4; p++) {
|
|
|
|
Clone clone = new Clone (actor);
|
|
|
|
clone.rotation_angle_z = p * 90;
|
|
|
|
|
|
|
|
switch (p) {
|
|
|
|
case 1:
|
|
|
|
clone.set_position (monitor_geometry.x + monitor_geometry.width, monitor_geometry.y);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
clone.set_position (monitor_geometry.x + monitor_geometry.width, monitor_geometry.y + monitor_geometry.height);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
clone.set_position (monitor_geometry.x, monitor_geometry.y + monitor_geometry.height);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
cornermasks[monitor_no].append (clone);
|
|
|
|
wm.stage.add_child (clone);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-15 03:44:21 +03:00
|
|
|
bool draw_cornermask (Cairo.Context context) {
|
2020-01-09 22:26:30 +03:00
|
|
|
var buffer = new Granite.Drawing.BufferSurface (corner_radius, corner_radius);
|
|
|
|
var buffer_context = buffer.context;
|
|
|
|
|
|
|
|
buffer_context.arc (corner_radius, corner_radius, corner_radius, Math.PI, 1.5 * Math.PI);
|
|
|
|
buffer_context.line_to (0, 0);
|
|
|
|
buffer_context.line_to (0, corner_radius);
|
|
|
|
buffer_context.set_source_rgb (0, 0, 0);
|
|
|
|
buffer_context.fill ();
|
|
|
|
|
|
|
|
context.set_operator (Cairo.Operator.CLEAR);
|
|
|
|
context.paint ();
|
|
|
|
context.set_operator (Cairo.Operator.OVER);
|
|
|
|
context.set_source_surface (buffer.surface, 0, 0);
|
|
|
|
context.paint ();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2015-02-05 23:15:55 +03:00
|
|
|
}
|
|
|
|
|
2020-01-15 03:44:21 +03:00
|
|
|
public Gala.PluginInfo register_plugin () {
|
|
|
|
return {
|
2020-01-09 22:26:30 +03:00
|
|
|
"Mask Corners",
|
|
|
|
"Gala Developers",
|
|
|
|
typeof (Gala.Plugins.MaskCorners.Main),
|
|
|
|
Gala.PluginFunction.ADDITION,
|
|
|
|
Gala.LoadPriority.IMMEDIATE
|
|
|
|
};
|
2015-02-05 23:15:55 +03:00
|
|
|
}
|