7

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?

Cactus
  • 27,075
  • 9
  • 69
  • 149
tagelicht
  • 467
  • 3
  • 14
  • What version of GTK+? – andlabs Oct 26 '16 at 04:05
  • Please post your dragging code. Also what custom titlebar did you use, GtkHeaderBar? – andlabs Oct 27 '16 at 00:14
  • No, I am just using a box which has some custom buttons and a title label. The Code im using is without the resizing very rudimentary - here it is: – tagelicht Oct 27 '16 at 01:10
  • 2
    Consider using GtkHeaderBar; it works like a GtkBox but also provides the dragging behavior you want. As for your code, that's not how `gtk_window_move()` works, and in fact `gtk_window_move()` is not guaranteed to work; you'll need to use `gtk_window_begin_move_drag()` instead. If either option works I can elaborate in an answer. – andlabs Oct 27 '16 at 02:10
  • 1
    Finally got the time to look at this again ^^ Well, thanks very much for your reply. I am using a GtkHeaderBar now, but this does not provide any dragging functions I think? At least I found none. But using `begin_move_drag()` does exactly what I was looking for, thanks for that :) – tagelicht Oct 28 '16 at 18:21

1 Answers1

1

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.

Etua
  • 79
  • 1
  • 9