LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Creating a *top* level window, GTK/GDK/OpenGL... (https://www.linuxquestions.org/questions/programming-9/creating-a-%2Atop%2A-level-window-gtk-gdk-opengl-819555/)

andrei_b 07-13-2010 05:27 AM

Creating a *top* level window, GTK/GDK/OpenGL...
 
Hi!

Is it possible to create a window (with GTK+, GDK, or by using OpenGL, or Clutter) that stays on the top of all the other windows, even over a full-screened window?

I want to create a small window that remains visible when I enter the full-screen mode of a video player (VLC for example).

Thank you in advance!

kalleanka 07-13-2010 12:36 PM

Yes its possible.

First you need to grab the "deskop window" from your window manager or make a fixed window yourself or do it in X directly(not recommende).

Then with that window you have to add a child and raise the window set signals so you lower it or raise it as you want(wen entering, leaving etc) or you can set it so its fixed on top.


its quite a lot of work.

andrei_b 07-17-2010 04:57 AM

Here I found an example on creating a window with xlib:
http://en.wikipedia.org/wiki/Xlib

Do you think I should get the Display object of the 'VLC media player' window and start drawing on it? Do I need special permissions to do that?

I also tried the following (Clutter and X11 together):

Code:

clutter_init (&argc, &argv);
ClutterActor* stage = clutter_stage_new();

// 'p' is the xid of 'VLC media player' main window
// I found 'p' using "xwininfo -root -tree" command
clutter_x11_set_stage_foreign(stage, (Window)(p));
clutter_container_add_actor ((stage, rectangle);
// rectangle is just an object (a ClutterActor, more precisely).

With this, I've got the following run-time error [where 0x4800037 is the xid of VLC's window]:
ClutterGLX-CRITICAL **: Unable to make the stage window 0x4800037 the current GLX drawable

Clutter library is using OpenGL for rendering. Could this be a problem?
Anyway, using Clutter is not actually a 'must'. I haven't try with GTK yet.

Example of what I would like to do: when I watch a video (full screen), I sometimes get notifications from Network Manager (it gives me information regarding the Internet connection). I want to do something similar, I want to draw on the top of the 'fullscreen'.

Is the X11 example from Wikipedia (link above) a good start to do that? Any advice is welcome.

Thank you in advance!

kalleanka 08-27-2010 08:21 AM

hi,

I tried it in gtk and its simple. Here you have some code to play with. Dont forget to compile with `pkg-config --cflags --libs gtk+-2.0`. Most functions are from http://library.gnome.org/devel/gtk/s...GtkWindow.html and http://library.gnome.org/devel/gtk/s...GtkWidget.html. Dont forget that the window manager needs to support the functions you use and some of them are only supported in X.

I hope this helps.

Code:



#include <stdio.h>
#include <stdlib.h>

#include <gtk/gtk.h>


int main(int argc, char **argv)
{
    GtkWidget *window;
    GtkWidget *vbox;
    GtkWidget *button;

    gtk_init(&argc, &argv);

    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_container_set_border_width(GTK_CONTAINER(window), 10);
    g_signal_connect(window, "delete_event", (GCallback)gtk_main_quit, 0);

    vbox = gtk_vbox_new(TRUE, 0);
    gtk_container_add(GTK_CONTAINER(window), vbox);

    button = gtk_button_new_with_label("Hide");
    gtk_box_pack_start(GTK_BOX(vbox), button, TRUE,TRUE, 0);
    g_signal_connect_swapped(button, "clicked",
    (GCallback)gtk_widget_hide, window);

    button = gtk_button_new_from_stock(GTK_STOCK_QUIT);
    gtk_box_pack_start(GTK_BOX(vbox), button, TRUE,TRUE, 0);
    g_signal_connect(button, "clicked", (GCallback)gtk_main_quit, 0);

    gtk_window_set_decorated(GTK_WINDOW(window), FALSE);

    // gtk_window_set_default_size(GTK_WINDOW(window),500,500);

    // gtk_window_stick(GTK_WINDOW(window)); /* on all desktops or not */

    gtk_window_set_keep_above(GTK_WINDOW(window), TRUE);

    //gtk_window_set_keep_below(GTK_WINDOW(window),TRUE);

    gtk_window_set_skip_taskbar_hint(GTK_WINDOW(window), TRUE);
    gtk_window_set_skip_pager_hint(GTK_WINDOW(window), TRUE);

    gtk_window_move(GTK_WINDOW(window), 100, 100);

    // gtk_window_set_opacity(GTK_WINDOW(window), 0); /* not working hmmmm*/

    gtk_widget_show_all(window);

    gtk_main();

    return (EXIT_SUCCESS);
}


andrei_b 09-03-2010 01:40 AM

Thank you a lot for your help, kalleanka!
The example works fine :)

The only problem is that an application running in full screen mode covers the little window. Well, that is not actually a problem, I think I was a little stubborn about creating such a window. I realize now that it isn't really possible. That is, when an application goes into full screen mode, it says: "The screen is only mine now, so... stay away of it!"

Regards,
andrei


All times are GMT -5. The time now is 02:12 PM.