GNOME Bugzilla – Bug 642355
patch to expose MetaWindow.move(), .resize() and add/expose .move_frame() to javascript
Last modified: 2011-03-09 19:02:00 UTC
I've worked on window.c and window.h in mutter a tiny bit to expose the existing meta_window_move() and meta_window_resize() methods to javascript. Their behavior is unchanged. Additionally, I've implemented and exposed a new method called meta_window_move_frame() that has the same signature as meta_window_move(). It's only difference is that it moves the window, offset by the "distance" of the child window from the enclosing frame/window decoration. If the window does not have a frame, it behaves exactly as meta_window_move() does. You can verify this behavior in lg by doing something like (assuming that get_windows()[0] is visible on your workspace): rect = Shell.WindowTracker.get_default().get_running_apps('')[0].get_windows()[0].get_outer_rect(); Shell.WindowTracker.get_default().get_running_apps('')[0].get_windows()[0].move_frame(true, rect.x, rect.y) the window should not change positions (since you're trying to move, by the frame's northwest edge, the window to the current position of the frame as specified by get_outer_rect() ). If, however, you did: rect = Shell.WindowTracker.get_default().get_running_apps('')[0].get_windows()[0].get_outer_rect(); Shell.WindowTracker.get_default().get_running_apps('')[0].get_windows()[0].move(true, rect.x, rect.y) (notice we're calling .move() and not .move_frame(), here).. In the above case, the window will slowly "inch" up towards the top right, by an amount equal to the offset between the origin of the frame and origin of the window itself. .resize() pretty much works as advertised and I have nothing to add. ----- I exposed these methods to javascript as they're pretty useful for any extensions that have to do any kind of window manipulation/management (I'm playing around with a tiling wm extension concept, personally).
Created attachment 180878 [details] [review] exposing MetaWindow.move() and .resize() in javascript and adding .move_frame() .move() and .resize() are straightforward exposures of existing methods .move_frame() is a version of .move() that moves a window using the frame's origin as the reference point for moving the window. If the window doesn't have a frame, then it besides the same as .move()
Review of attachment 180878 [details] [review]: ::: src/core/window.c @@ +4485,3 @@ + * @root_y_nw: desired y pos + * + * Moves the window to the desired location on window's assigned workspace. NOTE: does NOT place according to the origin of the enclosing frame/window-decoration, but according to the origin of the window, itself. Can you reflow doc comments so they're at least less than 100 columns max? Some people of course say 80, but I find in practice 100 is a lot more reasonable. @@ +4526,3 @@ + if (window->frame) { + // offset by the distance between the origin of the window + // and the origin of the enclosing window decorations Don't use C++ style comments please.
I added this patch (with the c++ style comments removed) to the patch series in bug 609258 as i needed it there too.
Created attachment 182970 [details] [review] expose MetaWindow .move(), resize() and add/expose .move_frame() the latter move method will place the window by the origin of the enclosing window decoration/frame, while the former will place by the origin of the inner window, itself.
the previous patch implements the changes recommended by Colin Walters above, as well as accounting for the recently changed location of window.h (moved from /src/include to /src/meta)
Review of attachment 182970 [details] [review]: ::: src/core/window.c @@ +4529,3 @@ + int x = root_x_nw; + int y = root_y_nw; + if (window->frame) { One more minor thing - mutter is GNU style code, so braces on a new line (just look at other code). ::: src/meta/window.h @@ +100,3 @@ +/* move a window by the origin of the enclosing frame */ +void meta_window_move_frame(MetaWindow *window, gboolean user_op, int root_x_nw, int root_y_nw); +/* resize a window */ While I know there is another comment above, let's not add noise to the header with these comments; the gtk-doc should be the canonical location. (I took this opportunity to move the other comment to gtk-doc).
Attachment 182970 [details] pushed as 70ffb56 - expose MetaWindow .move(), resize() and add/expose .move_frame()