Skip to content

Commit

Permalink
add initiate-moveresize handling to html5 client (only "move" and "ca…
Browse files Browse the repository at this point in the history
…ncel" are handled for now)

git-svn-id: https://xpra.org/svn/Xpra/trunk@15519 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Apr 5, 2017
1 parent 3828376 commit 6e35b42
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 52 deletions.
16 changes: 16 additions & 0 deletions src/html5/js/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ XpraClient.prototype.init_packet_handlers = function() {
'window-icon': this._process_window_icon,
'window-resized': this._process_window_resized,
'window-move-resize': this._process_window_move_resize,
'initiate-moveresize': this._process_initiate_moveresize,
'configure-override-redirect': this._process_configure_override_redirect,
'desktop_size': this._process_desktop_size,
'draw': this._process_draw,
Expand Down Expand Up @@ -894,6 +895,7 @@ XpraClient.prototype._make_hello = function() {
"notify-startup-complete" : true,
"generic-rgb-encodings" : true,
"window.raise" : true,
"window.initiate-moveresize": true,
"metadata.supported" : [
"fullscreen", "maximized", "above", "below",
//"set-initial-position", "group-leader",
Expand Down Expand Up @@ -1554,6 +1556,20 @@ XpraClient.prototype._process_window_metadata = function(packet, ctx) {
}
}

XpraClient.prototype._process_initiate_moveresize = function(packet, ctx) {
var wid = packet[1],
win = ctx.id_to_window[wid];
if (win!=null) {
var x_root = packet[2],
y_root = packet[3],
direction = packet[4],
button = packet[5],
source_indication = packet[6];
win.initiate_moveresize(x_root, y_root, direction, button, source_indication)
}
}


XpraClient.prototype.on_last_window = function() {
//this hook can be overriden
}
Expand Down
27 changes: 27 additions & 0 deletions src/html5/js/Utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,3 +320,30 @@ var Utilities = {
return headers;
}
};

var MOVERESIZE_SIZE_TOPLEFT = 0;
var MOVERESIZE_SIZE_TOP = 1;
var MOVERESIZE_SIZE_TOPRIGHT = 2;
var MOVERESIZE_SIZE_RIGHT = 3;
var MOVERESIZE_SIZE_BOTTOMRIGHT = 4;
var MOVERESIZE_SIZE_BOTTOM = 5;
var MOVERESIZE_SIZE_BOTTOMLEFT = 6;
var MOVERESIZE_SIZE_LEFT = 7;
var MOVERESIZE_MOVE = 8;
var MOVERESIZE_SIZE_KEYBOARD = 9;
var MOVERESIZE_MOVE_KEYBOARD = 10;
var MOVERESIZE_CANCEL = 11;
var MOVERESIZE_DIRECTION_STRING = {
0 : "SIZE_TOPLEFT",
1 : "SIZE_TOP",
2 : "SIZE_TOPRIGHT",
3 : "SIZE_RIGHT",
4 : "SIZE_BOTTOMRIGHT",
5 : "SIZE_BOTTOM",
6 : "SIZE_BOTTOMLEFT",
7 : "SIZE_LEFT",
8 : "MOVE",
9 : "SIZE_KEYBOARD",
10 : "MOVE_KEYBOARD",
11 : "CANCEL",
};
119 changes: 67 additions & 52 deletions src/html5/js/Window.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ function XpraWindow(client, canvas_state, wid, x, y, w, h, metadata, override_re
this.topoffset = parseInt(jQuery(this.div).css('border-top-width'), 10);
this.bottomoffset = parseInt(jQuery(this.div).css('border-bottom-width'), 10);

this.mousedown_event = null;
// Hook up the events we want to receive:
jQuery(this.canvas).mousedown(function (e) {
me.on_mousedown(e);
Expand All @@ -105,50 +106,50 @@ function XpraWindow(client, canvas_state, wid, x, y, w, h, metadata, override_re

// create the decoration as part of the window, style is in CSS
jQuery(this.div).addClass("window");
jQuery(this.div).addClass("window-" + this.windowtype);
// add a title bar to this window if we need to
if((this.windowtype == "NORMAL") || (this.windowtype == "DIALOG") || (this.windowtype == "UTILITY")) {
if(!this.override_redirect) {
// create header
jQuery(this.div).prepend('<div id="head' + String(wid) + '" class="windowhead"> '+
'<span class="windowicon"><img src="../icons/noicon.png" id="windowicon' + String(wid) + '" /></span> '+
'<span class="windowtitle" id="title' + String(wid) + '">' + this.title + '</span> '+
'<span class="windowbuttons"> '+
'<span id="maximize' + String(wid) + '"><img src="../icons/maximize.png" /></span> '+
'<span id="close' + String(wid) + '"><img src="../icons/close.png" /></span> '+
'</span></div>');
// make draggable
jQuery(this.div).draggable({
cancel: "canvas",
stop: function(e, ui) {
me.handle_moved(ui);
}
});
// attach resize handles
jQuery(this.div).resizable({
helper: "ui-resizable-helper",
stop: function(e, ui) {
me.handle_resized(ui);
}
});
this.d_header = '#head' + String(wid);
this.d_closebtn = '#close' + String(wid);
this.d_maximizebtn = '#maximize' + String(wid);
// adjust top offset
this.topoffset = this.topoffset + parseInt(jQuery(this.d_header).css('height'), 10);
// assign some interesting callbacks
jQuery(this.d_header).click(function() {
set_focus_cb(me);
});
jQuery(this.d_closebtn).click(function() {
window_closed_cb(me);
});
jQuery(this.d_maximizebtn).click(function() {
me.toggle_maximized();
});
} else {
jQuery(this.div).addClass("override-redirect");
}
if (this.windowtype) {
jQuery(this.div).addClass("window-" + this.windowtype);
}

if(this.override_redirect) {
jQuery(this.div).addClass("override-redirect");
}
else if((this.windowtype == "") || (this.windowtype == "NORMAL") || (this.windowtype == "DIALOG") || (this.windowtype == "UTILITY")) {
// add a title bar to this window if we need to
// create header
jQuery(this.div).prepend('<div id="head' + String(wid) + '" class="windowhead"> '+
'<span class="windowicon"><img src="../icons/noicon.png" id="windowicon' + String(wid) + '" /></span> '+
'<span class="windowtitle" id="title' + String(wid) + '">' + this.title + '</span> '+
'<span class="windowbuttons"> '+
'<span id="maximize' + String(wid) + '"><img src="../icons/maximize.png" /></span> '+
'<span id="close' + String(wid) + '"><img src="../icons/close.png" /></span> '+
'</span></div>');
// make draggable
jQuery(this.div).draggable({ cancel: "canvas" });
jQuery(this.div).on("dragstop",function(ev,ui){
me.handle_moved(ui);
});
// attach resize handles
jQuery(this.div).resizable({
helper: "ui-resizable-helper",
stop: function(e, ui) {
me.handle_resized(ui);
}
});
this.d_header = '#head' + String(wid);
this.d_closebtn = '#close' + String(wid);
this.d_maximizebtn = '#maximize' + String(wid);
// adjust top offset
this.topoffset = this.topoffset + parseInt(jQuery(this.d_header).css('height'), 10);
// assign some interesting callbacks
jQuery(this.d_header).click(function() {
set_focus_cb(me);
});
jQuery(this.d_closebtn).click(function() {
window_closed_cb(me);
});
jQuery(this.d_maximizebtn).click(function() {
me.toggle_maximized();
});
}

// create the spinner overlay div
Expand Down Expand Up @@ -325,22 +326,19 @@ XpraWindow.prototype.on_mousedown = function(e) {
// pass the click to the area:
var modifiers = [];
var buttons = [];
this.mousedown_event = e;
this.handle_mouse_click(mouse.button, true, mx, my, modifiers, buttons);
return;
};

XpraWindow.prototype.on_mouseup = function(e) {
// if not handling it ourselves, pass it down:
var mouse = this.getMouse(e),
mx = Math.round(mouse.x),
my = Math.round(mouse.y);
if (!this.dragging) {
var modifiers = [];
var buttons = [];
this.handle_mouse_click(mouse.button, false, mx, my, modifiers, buttons);
}

this.dragging = false;
var modifiers = [];
var buttons = [];
this.mousedown_event = null;
this.handle_mouse_click(mouse.button, false, mx, my, modifiers, buttons);
};

XpraWindow.prototype.on_mousescroll = function(e) {
Expand Down Expand Up @@ -665,6 +663,23 @@ XpraWindow.prototype.resize = function(w, h) {
this.move_resize(this.x, this.y, w, h);
};

XpraWindow.prototype.initiate_moveresize = function(x_root, y_root, direction, button, source_indication) {
var dir_str = MOVERESIZE_DIRECTION_STRING[direction];
this.log("initiate_moveresize", dir_str, [x_root, y_root, direction, button, source_indication]);
if (direction==MOVERESIZE_MOVE) {
var e = this.mousedown_event;
e.type = "mousedown.draggable";
e.target = this.div[0];
this.div.trigger(e);
//jQuery(this.div).trigger("mousedown");
}
else if (direction==MOVERESIZE_CANCEL) {
jQuery(this.div).draggable('disable');
jQuery(this.div).draggable('enable');
}
}


/**
* Returns the geometry of the window backing image,
* the inner window geometry (without any borders or top bar).
Expand Down

0 comments on commit 6e35b42

Please sign in to comment.