Log In
New Account
  
Home My Page Project Cloud Code Snippets Project Openings

Browse | Submit A New Snippet | Create A Package

 

Turning a plain X11 Window into a GTK Window

Type:
Sample Code (HOWTO)
Category:
Other
License:
BSD License
Language:
C
 
Description:
While ordinary X11 program compile and run on the Nokia 770, the virtual keyboard/handwriting recognition only interacts with GDK. So the first step, is to create a GDK wrapper around a plain X11 window. I'll show how the soft keyboard can be turned on/off in a separate snippet.

Versions Of This Snippet::

Rene Hexel
Snippet ID Download Version Date Posted Author Delete
312006-11-13 22:02Rene Hexel

Download a raw-text version of this code by clicking on "Download Version"

 


Latest Snippet Version: :1

...
#include <X11/Xlib.h>
#include <X11/Xutil.h>

/* After the standard includes, add the following: */
#include <hildon-widgets/hildon-program.h>
#include <gtk/gtkmain.h>
#include <gtk/gtk.h>

...

int main(int argc, char *argv[])
{
    Display    *dpy;            /* the X display to use */
    Window      win;            /* the actual X window */
    ...                         /* other variables we might use */
    /*
     * Add this to turn your program into a Hildon program:
     */
    HildonProgram *program;
    GdkWindow *gdkWindow;

    gtk_init(&argc, &argv);
    program = HILDON_PROGRAM(hildon_program_get_instance());
    g_set_application_name("Hello maemo!");

    /* Find the code that opens the Display and creates the X Window: */
    ...
    dpy = XOpenDisplay(NULL);
    ...
    win = XCreateWindow(dpy, ...);
    ...
    XMapWindow(dpy, win);

    /*
     * Now that the window has been mapped, we can turn it into a GDK window:
     */
    gdkWindow = gdk_window_foreign_new(win);
    ...

    /*
     * Add gtk_main_iteration() to the X11 event loop:
     */
    while (!quit)
    {
        XEvent event;

        XNextEvent(dpy, &event);

        ... /* handle X event as usual, then handle GTK events: */

        while (gtk_events_pending()) gtk_main_iteration();
    }

    /* Unreference the GDK window before destroying the X window: *
    
    g_object_unref(gdkWindow);
}

		

Submit a new version

You can submit a new version of this snippet if you have modified it and you feel it is appropriate to share with others..


Terms of Use    Privacy Policy    Contribution Guidelines    Feedback

Powered By GForge Collaborative Development Environment