Use exact positioning instead of maximize to get rid of flashing

This commit is contained in:
Balazs Gyurak
2019-12-07 21:30:10 +00:00
parent 6a91c31800
commit 28e87a64d6

View File

@@ -4,7 +4,7 @@ const Mainloop = imports.mainloop;
const Gio = imports.gi.Gio; const Gio = imports.gi.Gio;
let _close = 50; let _close = 50;
var debug = false; var debug = true;
var _log = function(){} var _log = function(){}
if (debug) if (debug)
@@ -87,78 +87,83 @@ function placeWindow(loc, app) {
_log("placeWindow: " + loc); _log("placeWindow: " + loc);
let x, y, w, h = 0 let x, y, w, h = 0
var space = app.get_work_area_current_monitor() var space = app.get_work_area_current_monitor()
unMaximizeIfMaximized(app);
switch (loc) { switch (loc) {
case "left": case "left":
x = space.x; x = space.x;
y = space.y; y = space.y;
w = Math.floor(space.width/2); w = Math.floor(space.width/2);
h = space.height; h = space.height;
if (!app.maximizedVertically)
app.maximize(Meta.MaximizeFlags.VERTICAL)
if (app.maximized_horizontally)
app.unmaximize(Meta.MaximizeFlags.HORIZONTAL);
app.move_resize_frame(true, x, y, w, h)
break; break;
case "topleft": case "topleft":
x = space.x; x = space.x;
y = space.y; y = space.y;
w = Math.floor(space.width/2); w = Math.floor(space.width/2);
h = Math.floor(space.height/2); h = Math.floor(space.height/2);
if (app.maximized_horizontally || app.maximizedVertically)
app.unmaximize(Meta.MaximizeFlags.HORIZONTAL | Meta.MaximizeFlags.VERTICAL);
app.move_resize_frame(true, x, y, w, h)
break; break;
case "bottomleft": case "bottomleft":
x = space.x; x = space.x;
y = Math.floor(space.height/2)+space.y; y = Math.floor(space.height/2)+space.y;
w = Math.floor(space.width/2); w = Math.floor(space.width/2);
h = Math.floor(space.height/2); h = Math.floor(space.height/2);
if (app.maximized_horizontally || app.maximizedVertically)
app.unmaximize(Meta.MaximizeFlags.HORIZONTAL | Meta.MaximizeFlags.VERTICAL);
app.move_resize_frame(true, x, y, w, h)
break; break;
case "right": case "right":
x = Math.floor(space.width/2+space.x); x = Math.floor(space.width/2+space.x);
y = space.y; y = space.y;
w = Math.floor(space.width/2); w = Math.floor(space.width/2);
h = space.height; h = space.height;
if (!app.maximizedVertically)
app.maximize(Meta.MaximizeFlags.VERTICAL)
if (app.maximized_horizontally)
app.unmaximize(Meta.MaximizeFlags.HORIZONTAL);
app.move_resize_frame(true, x, y, w, h)
break; break;
case "topright": case "topright":
x = Math.floor(space.width/2+space.x); x = Math.floor(space.width/2+space.x);
y = space.y; y = space.y;
w = Math.floor(space.width/2); w = Math.floor(space.width/2);
h = Math.floor(space.height/2); h = Math.floor(space.height/2);
if (app.maximized_horizontally || app.maximizedVertically)
app.unmaximize(Meta.MaximizeFlags.HORIZONTAL | Meta.MaximizeFlags.VERTICAL);
app.move_resize_frame(true, x, y, w, h)
break; break;
case "bottomright": case "bottomright":
x = Math.floor(space.width/2+space.x); x = Math.floor(space.width/2+space.x);
y = Math.floor(space.height/2)+space.y; y = Math.floor(space.height/2)+space.y;
w = Math.floor(space.width/2); w = Math.floor(space.width/2);
h = Math.floor(space.height/2); h = Math.floor(space.height/2);
if (app.maximized_horizontally || app.maximizedVertically)
app.unmaximize(Meta.MaximizeFlags.HORIZONTAL | Meta.MaximizeFlags.VERTICAL);
app.move_resize_frame(true, x, y, w, h)
break; break;
case "maximize": case "maximize":
if (!app.maximized_horizontally || !app.maximizedVertically) x = space.x;
app.maximize(Meta.MaximizeFlags.HORIZONTAL | Meta.MaximizeFlags.VERTICAL); y = space.y;
w = space.width;
h = space.height;
break; break;
case "floating": case "floating":
if (app.maximized_horizontally || app.maximizedVertically) let rect = app.originalFloatingRectangle || getDefaultFloatingRectangle(space);
app.unmaximize(Meta.MaximizeFlags.HORIZONTAL | Meta.MaximizeFlags.VERTICAL); x = rect.x;
y = rect.y;
w = rect.width;
h = rect.height;
break; break;
} }
app.move_resize_frame(true, x, y, w, h);
let window = app.get_frame_rect() let window = app.get_frame_rect()
_log("window.x: "+window.x+" window.y: "+window.y+" window.width: "+window.width+" window.height: "+window.height) _log("window.x: "+window.x+" window.y: "+window.y+" window.width: "+window.width+" window.height: "+window.height)
} }
function unMaximizeIfMaximized(app) {
if (app.maximized_horizontally || app.maximized_vertically) {
app.unmaximize(Meta.MaximizeFlags.BOTH);
}
}
function getDefaultFloatingRectangle(workspace) {
let padding = 100;
return {
x: workspace.x + padding,
y: workspace.y + padding,
width: workspace.width - padding * 2,
height: workspace.height - padding * 2
};
}
function getMonitorArray() { function getMonitorArray() {
var monitors = []; var monitors = [];
for (var i = 0; i < Main.layoutManager.monitors.length; i++) { for (var i = 0; i < Main.layoutManager.monitors.length; i++) {
@@ -179,11 +184,17 @@ function getMonitorArray() {
} }
function moveWindow(direction) { function moveWindow(direction) {
_log("---");
_log("moveWindow: " + direction); _log("moveWindow: " + direction);
var app = global.display.focus_window; var app = global.display.focus_window;
var space = app.get_work_area_current_monitor() var space = app.get_work_area_current_monitor()
let pos = getPosition(app, space); let pos = getPosition(app, space);
_log("pos: " + pos); _log("pos: " + pos);
if (pos == "floating") {
app.originalFloatingRectangle = app.get_frame_rect();
}
//var monitors = getMonitorArray(); //var monitors = getMonitorArray();
var curMonitor = app.get_monitor(); var curMonitor = app.get_monitor();
let monitorToLeft = -1; let monitorToLeft = -1;