Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gtk Move window beyond constraints

Tags:

c++

c

gtk

gtkmm

I am currently writing a gtk program that uses a custom title bar (i.e., it is not being decorated by the window manager). But since using a custom title bar also disables support of dragging the window around, I wrote my custom drag 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 of the fact that it cannot move the window beyond the screen limits, like the normal behaviour for other windows, so you can drag it "out of sight" to make place 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 resizes the window contents to the smaller scale, while I would just like to make its physical size smaller. I have also tried using set_allocation and size_allocate, these two didnt make any change at all.

My question is, do you know a way to either be able to move the window beyond the screen borders (not totally, but in a way that the window is not fully on-screen), or to change the size of the window without resizing its contents?

like image 794
tagelicht Avatar asked Oct 22 '16 12:10

tagelicht


1 Answers

If you are using GTK 3.10 or newer you can use gtk_window_set_titlebar

gtk_window_set_titlebar (GtkWindow *window, GtkWidget *titlebar) the only arguments you need are the window that you want to customise and the GtkWidget that will serve as the titlebar. Using GtkHeaderBar is suggested but in your case you can use any custom GtkWidget and get draggable bar which will tug the whole window as would the one from the window manager.

like image 125
Etua Avatar answered Sep 22 '22 14:09

Etua