Gtk Move window out of bounds

I am currently writing a gtk program that uses a custom title bar (i.e. it is not formatted by the window manager). But since using a custom title bar also disables window drag and drop support, I wrote my drag and drop function, which moves the window by calling window.move(x, y) :

 bool on_titlebar_drag(GdkEvent* event) { static int drag_x_offset = 0; static int drag_y_offset = 0; int x, y; if (event->type == GDK_BUTTON_PRESS) { drag_x_offset = event->button.x; drag_y_offset = event->button.y; } else if(event->type == GDK_BUTTON_RELEASE) { drag_x_offset = 0; drag_y_offset = 0; } else if(event->type == GDK_MOTION_NOTIFY) { x = event->motion.x_root - drag_x_offset; y = event->motion.y_root - drag_y_offset; mainWindow.move(x, y); } return true; } 

This works just fine, except that it cannot move the window off the screen, just like the normal behavior for other windows, so you can drag it “out of sight” to make room for others.

I am trying to resize the window smaller as soon as it touches the screen by calling window.resize(width, height) , but this is not what I intend to do, because resizing also reduces the size of the contents of the window to a smaller scale, while I would just like to reduce its physical size. I also tried using set_allocation and size_allocate , the two did not make any changes at all.

My question is: did you know that you can move the window off the screen (not completely, but so that the window is not completely on the screen), or to resize the window without changing its contents?

+5
source share

Source: https://habr.com/ru/post/1258635/


All Articles