LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   GdkWindow not receiving GDK_EXPOSE events (https://www.linuxquestions.org/questions/linux-software-2/gdkwindow-not-receiving-gdk_expose-events-4175487526/)

buginprogram 12-10-2013 02:29 PM

GdkWindow not receiving GDK_EXPOSE events
 
Hi!

I'm writing a simple desktop manager using GDK to handle a virtual root window. So far I've managed to draw successfully in the window (and stop it rising to the top), but now my issue is that it doesn't receive GDK_EXPOSE events like it should.

Thus, when I drag a terminal window over it and back again, the red square which I've drawn partially disappears. I've also put some "printf" statements in to see what event's I'm receiving, and I'm not receiving any GDK_EXPOSE events when I cover and then uncover parts of the window.

The same thing happens when I create it as a normal window, so the problem is not related to that fact that it's a virtual root window.

Here is a full code listing:
Code:

#include <gdk/gdk.h>
#include <cairo.h>

GdkDisplay                *g_dpy;
GdkWindow                *g_wd;
GdkEvent                *g_evt;
GdkVisual                *g_vis;
GdkColormap                *g_cmap;
GdkGC                        *g_gc;

cairo_t                        *g_ccontext;

int                        g_width;
int                        g_height;

int                        button;

void drawtile(int x, int y, int width, int height, double r, double g, double b)
{
        /*GdkColor        fgc;

        fgc.red = r;
        fgc.green = g;
        fgc.blue = b;
        gdk_rgb_find_color(g_cmap, &fgc);

        gdk_gc_set_foreground(g_gc, &fgc);
        gdk_draw_rectangle(g_wd, g_gc, TRUE, x, y, width, height);*/

        cairo_identity_matrix(g_ccontext);
        cairo_scale(g_ccontext, 1, 1);
        cairo_set_source_rgb(g_ccontext, r, g, b);
        cairo_rectangle(g_ccontext, x, y, width, height);
        cairo_fill(g_ccontext);
}

void draw()
{
        GdkRectangle        prect;
        prect.x = 0;
        prect.y = 0;
        prect.width = g_width;
        prect.height = g_height;
        // gdk_window_begin_paint_rect(g_wd, &prect);

        gdk_window_clear(g_wd);
        drawtile(100, 100, 100, 100, 0.5, 0, 0);

        // gdk_window_end_paint(g_wd);
}

GdkWindow* createwindow()
{
        GdkWindow        *wd;
        GdkWindowAttr        *wattr;
        GdkColor        bgc;

        g_dpy = gdk_display_get_default();
        gdk_drawable_get_size(gdk_get_default_root_window(), &g_width, &g_height);

        wattr->event_mask = GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK;
        wattr->x = 0;
        wattr->y = 0;
        wattr->width = g_width;
        wattr->height = g_height;
        wattr->wclass = GDK_INPUT_OUTPUT;
        wattr->window_type = GDK_WINDOW_TOPLEVEL;
        wattr->type_hint = GDK_WINDOW_TYPE_HINT_DESKTOP;

        wd = gdk_window_new(NULL, wattr, GDK_WA_X | GDK_WA_Y | GDK_WA_TYPE_HINT);

        g_vis = gdk_drawable_get_visual(wd);
        g_cmap = gdk_colormap_new(g_vis, TRUE);
        g_gc = gdk_gc_new(wd);

        bgc.red = 0;
        bgc.green = 0;
        bgc.blue = 32768;
        gdk_rgb_find_color(g_cmap, &bgc);
        gdk_window_set_background(wd, &bgc);

        gdk_window_show(wd);

        return wd;
}

void handlegdkevents()
{
        g_evt = gdk_display_get_event(g_dpy);
        if (g_evt != NULL)
        {
                // printf("got event\n");
                printf("%d\n", g_evt->type);
                if (g_evt->type == GDK_MAP)
                {
                        draw();
                }
                if (g_evt->type == GDK_EXPOSE)
                {
                        printf("expose event\n");
                        draw();
                }
                if (g_evt->type == GDK_BUTTON_PRESS)
                {
                        printf("press event\n");
                        button = 1 - button;
                        draw();
                }
                gdk_event_free(g_evt);
        }
}

int main(int argc, char *argv[])
{
        gdk_init(&argc, &argv);

        /*Create the window.*/
        g_wd = createwindow();
        g_ccontext = gdk_cairo_create(g_wd);

        /*Event loop.*/
        button = 0;
        while(1 == 1)
        {
                handlegdkevents();
        }

        /*Cleanup.*/
        gdk_gc_destroy(g_gc);
        gdk_widget_destroy(g_wd);

        return 0;
}

When run, the message "expose event" never comes up in my terminal window.

Why is this?

Thanks,

buginprogram

P.S. Where is the best place for Linux Programming questions? I didn't want to ask in the non-Linux Programming forum, so my last question I asked in the Linux-General forum, but it didn't get much attention. Linux-Software appears to be for software users, not software developers...

buginprogram 12-15-2013 03:11 PM

bump


All times are GMT -5. The time now is 03:26 PM.