GTK - Set widget's window fullscreen - c

I have been trying to set a widget's window to fullscreen.
I tried getting the root window of the widget using gtk_widget_get_root(_window) and then using gtk_window_fullscreen() to set it to fullscreen, but the documentation says that gtk_widget_get_root_window() and gtk_widget_get_parent_window() (which I tried too) return a GdkWindow *, not a GtkWindow * as needed.
I tried casting GdkWindow* to GtkWindow* but it gives me this error:
Gtk-CRITICAL **: IA__gtk_window_fullscreen: assertion `GTK_IS_WINDOW
(window)' failed
The code would look like this:
gtk_window_fullscreen (GTK_WINDOW(gtk_widget_get_root_window (widget)));
I've also noticed that a widget has a field "window" but it is also GdkWindow * type.
I don't have the window widget in the function where I want to set it fullscreen...

GtkWindow and GdkWindow are totally different things.
When we think about "window", we usually mean a graphical component - the toplevel, resizable "box" with minimize/maximize buttons etc. This is what is represented by GtkWindow.
GDK however has another meaning for "window". The GdkWindow is not a graphical component, but an abstract resource inside GDK representing some rectangular region on the screen. It is probably closely related to some low-level resource inside Xorg/Win32 etc.
If you want to obtain the toplevel GtkWindow containing a given widget, you could probably use gtk_widget_get_toplevel or gtk_widget_get_ancestor

Related

Gtk Window to Gdk Surface in GTK4

I was wondering how I could get the X11 window ID for a Gtk Window in gtk4. I have seen other answers before regarding gtk3, but they don't seem to work in the latest gtk4. I found gdk_x11_surface_get_xid, but I can't pass a GtkWidget to that. I tried using the GDK_SURFACE cast, but I get:
invalid cast from 'GtkApplicationWindow' to 'GdkSurface'
Is there any way to resolve this, and get the x11 window id from a GtkWindow?

GTK3 Set GtkButton size

I have a very simple code, wich create a GtkWindow and place in it a GtkButton.
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_widget_set_size_request(_window, 800, 450);
gtk_window_set_decorated(GTK_WINDOW (_window), FALSE);
gtk_window_set_position(GTK_WINDOW (_window),GTK_WIN_POS_CENTER_ALWAYS);
gtk_window_set_resizable(GTK_WINDOW (_window), FALSE);
_startbutton = gtk_button_new_with_label("myLabel");
gtk_container_add(GTK_CONTAINER(_window), _startbutton);
gtk_widget_show_all(_window);
Yet, this doesn't work as expected because the button fills the whole window.
I tried to find a way to change the button size, but all the methods that i found use some methods that are deprecated...
Can someone explain to me the way to do this ?
Because the GtkButton is the only control in the GtkWindow, it will be given the entire area of the GtkWindow to fill. If you want to do anything more complicated, you will need to use layout containers like GtkBox and GtkGrid to explicitly lay out the button, usually in relation to other controls that you will also have in the window.
Once you do lay out your controls, you can use expansion and alignment to control how the button makes use of its allotted space.

GTK3 - textview transparency to show applications behind

I am currently working on an existing Linux application called Xpad, which is a sticky notes application written in C. I try to implement transparency but I have a hard time achieving what I want. A sticky note looks like this.
I have a (toplevel) gtk_window with a gtk_textview.
If the background color of the textview is set with the function gtk_widget_override_background_color() to a transparant color (GdkRGBA where alpha value is smaller than 1), the color of the gtk_window behind it, becomes more visible.
However, I don't want to see the gtk_window, but the applications behind the gtk_window, such as the browser, libreoffice, or the desktop.
If the gtk_window is set to a certain transparancy, either with gtk_widget_override_background_color() or with gtk_widget_set_opacity(), the whole widget, including the window decorations become (partially) transparent.
To make the relations between the visible objects more clear, I have created a diagram of the different parts, and marked the place where I believe the transparency issue is taking place.
Anybody have any ideas how to make the textview background transparent, without making the window decorations transparent, so I can see whatever is behind this application?
Set a proper RGBA visual for the widget
w = //some GtkWidget or GtkWidget derived klass (i.e. GtkWindow)
gtk_widget_set_app_paintable (w, TRUE); // important or you will get solid color
// the next 3 lines should be wrapped in a func which is also hooked to "screen-changed"
GdkScreen *screen = gtk_widget_get_screen (w);
GdkVisual *visual = gdk_screen_get_rgba_visual (screen);
gtk_widget_set_visual(w, visual);
gtk_widget_show_all(w);
g_signal_connect(G_OBJECT(w), "screen-changed", G_CALLBACK(screen_changed_contaniing_above_code), NULL);

Specify window painting region in WINAPI

I'm using one 3rd party SDK which get hwnd (window handle) and paints something on my window. And i want to specify window painting region (left, right, top, bottom) ? How it's possible to do it ? I'm found WINAPI function SetWindowRgn, but it's not good for me because this function specify whole window region. I need specify just window painting area.
SetWindowRgn() is exactly what you need. You can create your region from a rectangle using CreateRectRgn(). A good introduction to window regions can be found here.
Alternatively you can modify the non-client area of your window, but I would not recommend that, because it has several side-effects.
If it's possible to give this library an HDC instead of the window handle - you should do this.
That is, get the drawing DC for your window's client area (GetDC), create the needed clipping region, and set it (SelectClipRgn).
In case your library insists on accepting the window handle - I can propose the following solution:
Inside your window create another child window, set the appropriate region for it. And give the handle of that window to your library.

GdkDrawingArea on GtkImage

How can I impose GdkDrawingArea on the GtkImage for painting on an image, for example?
GtkDrawingArea and GtkImage are different classes, so you must choose one of them. You can still draw on GtkImage (and on any other widget), by connecting to expose_event signal.
You could also use plain GtkDrawingArea - displaying image is a matter of calling gdk_draw_pixbuf function.

Resources