Window margin is not aligned


I am implementing a Window derived from Gtk.ApplicaitonWindow. The reason I want to make this Window is to allow me to create “custom headerbars” like in Mac OS. This is what I have so far:

Peek 2020-01-02 01-39

(the overflow is intended, it is in fact one of the features I planned)

To make this frameless (not decorated) Window be resizable I had to manually handle the click event on the borders (also had to set the cursors manually), and that is where my Window differs from GTK’s. I can only resize the Window from the inside (x <= 4 for example), but GTK’s handles appear on the outside:

Peek 2020-01-01 23-48

I dug up GDK files on Gitlab and couldn’t find anything, I did however find something on Adwaita’s files (GTK default theme). In _common.scss#L4541 there is a 10px margin in window decoration and the comment above that line suggests that that area is used to resize the window. So my question is: how can I handle mouse events 10px outside (around) my Window?


I just realized setting the margin via CSS does nothing, but doing it by setting the margin property kinda works, the issue now is that setting the margin via property only works for bottom and right, left and top don’t seem to respect that.

Update 2

If I set a 100px margin on all sides, bottom and right will get 200px, the window gets the margin but it isn’t drawn in the center of the margin.

See if adjusting the cursor hot spot suits your need.

How would I do that? I can’t capture mouse events outside the window.

If you use gdk_cursor_new_from_pixbuf

you can set the hot spot. By changing the spot, part of the cursor can move outside while the pointer remains inside and you can still receive the events.

Hi! I am not sure I understand exactly what you want to get. Anyway, you can use the Gtk Inspector to set CSS snippets at runtime:

decoration {
  margin: 30px;
  box-shadow: 0px 0px 2px 30px rgba(0, 0, 0, 0.2);

Also take a look at gtk_window_begin_resize_drag

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.