LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 12-10-2013, 02:29 PM   #1
buginprogram
LQ Newbie
 
Registered: Dec 2013
Distribution: Xubuntu 8.04
Posts: 20

Rep: Reputation: Disabled
Question 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...
 
Old 12-15-2013, 03:11 PM   #2
buginprogram
LQ Newbie
 
Registered: Dec 2013
Distribution: Xubuntu 8.04
Posts: 20

Original Poster
Rep: Reputation: Disabled
bump
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Not receiving mails from only root user(receiving from others) in RHEL 4.5 narunice Linux - General 1 11-18-2010 08:20 AM
Keyboard events interrupting mouse events. miner49er Linux - Hardware 3 11-04-2008 04:16 AM
Hang on triggering udev events- is there a buildup of events? sonichedgehog Slackware 20 07-11-2008 02:49 AM
ACPI events Lockywolf Slackware 1 10-24-2007 01:18 PM
acpi events? raven Linux - Laptop and Netbook 2 10-12-2003 02:23 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 07:05 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration