Created
April 23, 2016 01:15
-
-
Save jtanx/ec89d10b822991db7adf9789f39691f7 to your computer and use it in GitHub Desktop.
GDK transient test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -ev | |
gcc -Wall -Werror -pedantic -std=c99 -g `pkg-config --cflags gdk-3.0` gdktransient.c `pkg-config --libs gdk-3.0` -o gdk | |
./gdk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <glib.h> | |
#include <gdk/gdk.h> | |
GMainLoop *mainloop; | |
GdkWindow *win1, *win2; | |
static void event_func(GdkEvent *ev, gpointer data) { | |
switch (ev->type) { | |
case GDK_DELETE: | |
gdk_window_destroy(gdk_event_get_window(ev)); | |
break; | |
case GDK_EXPOSE: { | |
GdkWindow *w = gdk_event_get_window(ev); | |
gdk_window_begin_paint_region(w, ((GdkEventExpose *)ev)->region); | |
cairo_t *cr = gdk_cairo_create(w); | |
if (w == win1) { | |
cairo_set_source_rgb(cr, 1, 1, 1); | |
} else if (w == win2) { | |
cairo_set_source_rgb(cr, 1, 0, 0); | |
} | |
cairo_rectangle(cr, 0, 0, gdk_window_get_width(w), gdk_window_get_height(w)); | |
cairo_fill(cr); | |
cairo_destroy(cr); | |
gdk_window_end_paint(w); | |
} | |
break; | |
default: | |
break; | |
} | |
} | |
int main(int argc, char **argv) { | |
gdk_init(&argc, &argv); | |
GdkWindowAttr attr; | |
attr.title = argv[0]; | |
attr.event_mask = GDK_EXPOSURE_MASK; | |
attr.window_type = GDK_WINDOW_TOPLEVEL; | |
attr.wclass = GDK_INPUT_OUTPUT; | |
attr.width = 400; | |
attr.height = 400; | |
// Main (toplevel window) | |
win1 = gdk_window_new(NULL, &attr, 0); | |
// Transient window | |
attr.width = attr.height = 200; | |
win2 = gdk_window_new(NULL, &attr, 0); | |
gdk_window_set_transient_for(win2, win1); | |
gdk_event_handler_set(event_func, NULL, NULL); | |
gdk_window_show(win1); | |
gdk_window_show(win2); | |
mainloop = g_main_loop_new(g_main_context_default(), FALSE); | |
g_main_loop_run(mainloop); | |
gdk_window_destroy(win2); | |
gdk_window_destroy(win1); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment