Skip to content

Commit

Permalink
* more complete implementation of size-constraints: integrate with ma…
Browse files Browse the repository at this point in the history
…ximized flag handling and disable resizing if the window is meant to have a fixed size

* add sample test applications

git-svn-id: https://xpra.org/svn/Xpra/trunk@15631 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Apr 15, 2017
1 parent b65fa29 commit 5934595
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 25 deletions.
74 changes: 49 additions & 25 deletions src/html5/js/Window.js
Original file line number Diff line number Diff line change
Expand Up @@ -498,25 +498,7 @@ XpraWindow.prototype.set_metadata_safe = function(metadata) {
}
}
if (this.resizable && "size-constraints" in metadata) {
var mw, mh;
var size_constraints = metadata["size-constraints"];
var min_size = size_constraints["minimum-size"];
mw=null, mh=null;
if (min_size) {
mw = min_size[0];
mh = min_size[1];
}
jQuery(this.div).resizable("option", "minWidth", mw);
jQuery(this.div).resizable("option", "minHeight", mh);
var max_size = size_constraints["maximum-size"];
mw=null, mh=null;
if (max_size) {
mw = max_size[0];
mh = max_size[1];
}
jQuery(this.div).resizable("option", "maxWidth", mw);
jQuery(this.div).resizable("option", "maxHeight", mh);
//TODO: aspectRatio, grid
this.apply_size_constraints();
}
if ("class-instance" in metadata) {
var wm_class = metadata["class-instance"];
Expand All @@ -542,6 +524,52 @@ XpraWindow.prototype.set_metadata_safe = function(metadata) {
}
};

XpraWindow.prototype.apply_size_constraints = function() {
var size_constraints = this.metadata["size-constraints"];
if (this.maximized) {
jQuery(this.div).draggable('disable');
}
else {
jQuery(this.div).draggable('enable');
}
var min_size = null, max_size = null;
if (size_constraints) {
min_size = size_constraints["minimum-size"];
max_size = size_constraints["maximum-size"];
}
var minw=null, minh=null;
if (min_size) {
minw = min_size[0];
minh = min_size[1];
}
var maxw=null, maxh=null;
if (max_size) {
maxw = max_size[0];
maxh = max_size[1];
}
//TODO: adjust size for title bar!
if(minw>0 && minw==maxw && minh>0 && minh==maxh) {
jQuery(this.d_maximizebtn).hide();
jQuery(this.div).resizable('disable');
} else {
jQuery(this.d_maximizebtn).show();
if (!this.maximized) {
jQuery(this.div).resizable('enable');
}
else {
jQuery(this.div).resizable('disable');
}
}
if (!this.maximized) {
jQuery(this.div).resizable("option", "minWidth", minw);
jQuery(this.div).resizable("option", "minHeight", minh);
jQuery(this.div).resizable("option", "maxWidth", maxw);
jQuery(this.div).resizable("option", "maxHeight", maxh);
}
//TODO: aspectRatio, grid
}


/**
* Apply new metadata settings.
*/
Expand Down Expand Up @@ -593,12 +621,8 @@ XpraWindow.prototype.set_maximized = function(maximized) {
this.max_save_restore(maximized);
this.maximized = maximized;
this.handle_resized();
// disable the draggable event when maximized
if(this.maximized) {
jQuery(this.div).draggable('disable');
} else {
jQuery(this.div).draggable('enable');
}
// this will take care of disabling the "draggable" code:
this.apply_size_constraints();
};

/**
Expand Down
26 changes: 26 additions & 0 deletions src/tests/xpra/test_apps/test_window_fixed_size.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env python

import gtk

WIDTH = 400
HEIGHT = 200

def make_win(width=WIDTH, height=HEIGHT):
window = gtk.Window(gtk.WINDOW_TOPLEVEL)
window.set_title("Fixed Sized Window")
#window.set_size_request(width, height)
window.connect("delete_event", gtk.mainquit)
window.set_geometry_hints(window,
min_width=WIDTH, min_height=HEIGHT,
max_width=WIDTH, max_height=HEIGHT,
)
window.set_resizable(False)
window.show_all()

def main():
make_win()
gtk.main()


if __name__ == "__main__":
main()
31 changes: 31 additions & 0 deletions src/tests/xpra/test_apps/test_window_size_hints.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env python

import gtk

width = 400
height = 200

def make_win(min_width=0, min_height=0, max_width=0, max_height=0):
window = gtk.Window(gtk.WINDOW_TOPLEVEL)
window.set_title("Size Hints Test")
#window.set_size_request(width, height)
window.connect("delete_event", gtk.mainquit)
window.set_geometry_hints(window,
min_width=min_width, min_height=min_height,
max_width=max_width, max_height=max_height,
base_width=100, base_height=100,
width_inc=8, height_inc=8,
#min_aspect=1, max_aspect=1,
)
window.show_all()

def main():
make_win()
make_win(0, 0, width, height)
make_win(width//2, height//2)
make_win(width//2, height//2, width*2, height*2)
gtk.main()


if __name__ == "__main__":
main()

0 comments on commit 5934595

Please sign in to comment.