don't leak X resources.

2006-06-30  Sven Neumann  <sven@gimp.org>

	* plug-ins/common/screenshot.c (select_window_x11): don't leak X
	resources.
This commit is contained in:
Sven Neumann
2006-06-30 09:02:39 +00:00
committed by Sven Neumann
parent 435303b6d9
commit d00f0c76e3
2 changed files with 53 additions and 49 deletions

View File

@ -1,3 +1,8 @@
2006-06-30 Sven Neumann <sven@gimp.org>
* plug-ins/common/screenshot.c (select_window_x11): don't leak X
resources.
2006-06-30 Simon Budig <simon@gimp.org> 2006-06-30 Simon Budig <simon@gimp.org>
* app/widgets/gimpstrokeeditor.c: unref the old StrokeOptions * app/widgets/gimpstrokeeditor.c: unref the old StrokeOptions

View File

@ -376,34 +376,37 @@ run (const gchar *name,
static GdkNativeWindow static GdkNativeWindow
select_window_x11 (GdkScreen *screen) select_window_x11 (GdkScreen *screen)
{ {
Display *x_dpy; Display *x_dpy = GDK_SCREEN_XDISPLAY (screen);
Cursor x_cursor; gint x_scr = GDK_SCREEN_XNUMBER (screen);
XEvent x_event; Window x_root = RootWindow (x_dpy, x_scr);
Window x_win; Window x_win = None;
Window x_root; GC x_gc = None;
XGCValues gc_values; Cursor x_cursor = XCreateFontCursor (x_dpy, GDK_CROSSHAIR);
GC gc = NULL;
GdkKeymapKey *keys = NULL; GdkKeymapKey *keys = NULL;
gint x_scr;
gint status; gint status;
gint buttons; gint i, num_keys;
gint buttons = 0;
gint mask = ButtonPressMask | ButtonReleaseMask; gint mask = ButtonPressMask | ButtonReleaseMask;
gint x, y, w, h;
gint num_keys;
gint i;
gboolean cancel = FALSE; gboolean cancel = FALSE;
x_dpy = GDK_SCREEN_XDISPLAY (screen); if (shootvals.shoot_type == SHOOT_REGION)
x_scr = GDK_SCREEN_XNUMBER (screen); mask |= PointerMotionMask;
x_win = None; status = XGrabPointer (x_dpy, x_root, False,
x_root = RootWindow (x_dpy, x_scr); mask, GrabModeSync, GrabModeAsync,
x_cursor = XCreateFontCursor (x_dpy, GDK_CROSSHAIR); x_root, x_cursor, CurrentTime);
buttons = 0;
if (status != GrabSuccess)
{
g_message (_("Error grabbing the pointer"));
XFreeCursor (x_dpy, x_cursor);
return 0;
}
if (shootvals.shoot_type == SHOOT_REGION) if (shootvals.shoot_type == SHOOT_REGION)
{ {
mask |= PointerMotionMask; XGCValues gc_values;
gc_values.function = GXxor; gc_values.function = GXxor;
gc_values.plane_mask = AllPlanes; gc_values.plane_mask = AllPlanes;
@ -420,7 +423,7 @@ select_window_x11 (GdkScreen *screen)
gc_values.clip_mask = None; gc_values.clip_mask = None;
gc_values.subwindow_mode = IncludeInferiors; gc_values.subwindow_mode = IncludeInferiors;
gc = XCreateGC (x_dpy, x_root, x_gc = XCreateGC (x_dpy, x_root,
GCFunction | GCPlaneMask | GCForeground | GCLineWidth | GCFunction | GCPlaneMask | GCForeground | GCLineWidth |
GCLineStyle | GCCapStyle | GCJoinStyle | GCLineStyle | GCCapStyle | GCJoinStyle |
GCGraphicsExposures | GCBackground | GCFillStyle | GCGraphicsExposures | GCBackground | GCFillStyle |
@ -429,16 +432,6 @@ select_window_x11 (GdkScreen *screen)
&gc_values); &gc_values);
} }
status = XGrabPointer (x_dpy, x_root, False,
mask, GrabModeSync, GrabModeAsync,
x_root, x_cursor, CurrentTime);
if (status != GrabSuccess)
{
g_message (_("Error grabbing the pointer"));
return 0;
}
if (gdk_keymap_get_entries_for_keyval (NULL, GDK_Escape, &keys, &num_keys)) if (gdk_keymap_get_entries_for_keyval (NULL, GDK_Escape, &keys, &num_keys))
{ {
gdk_error_trap_push (); gdk_error_trap_push ();
@ -467,6 +460,9 @@ select_window_x11 (GdkScreen *screen)
while (! cancel && ((x_win == None) || (buttons != 0))) while (! cancel && ((x_win == None) || (buttons != 0)))
{ {
XEvent x_event;
gint x, y, w, h;
XAllowEvents (x_dpy, SyncPointer, CurrentTime); XAllowEvents (x_dpy, SyncPointer, CurrentTime);
XWindowEvent (x_dpy, x_root, mask | KeyPressMask, &x_event); XWindowEvent (x_dpy, x_root, mask | KeyPressMask, &x_event);
@ -502,7 +498,7 @@ select_window_x11 (GdkScreen *screen)
h = ABS (shootvals.y2 - shootvals.y1); h = ABS (shootvals.y2 - shootvals.y1);
if (w > 0 && h > 0) if (w > 0 && h > 0)
XDrawRectangle (x_dpy, x_root, gc, x, y, w, h); XDrawRectangle (x_dpy, x_root, x_gc, x, y, w, h);
shootvals.x2 = x_event.xbutton.x_root; shootvals.x2 = x_event.xbutton.x_root;
shootvals.y2 = x_event.xbutton.y_root; shootvals.y2 = x_event.xbutton.y_root;
@ -518,7 +514,7 @@ select_window_x11 (GdkScreen *screen)
h = ABS (shootvals.y2 - shootvals.y1); h = ABS (shootvals.y2 - shootvals.y1);
if (w > 0 && h > 0) if (w > 0 && h > 0)
XDrawRectangle (x_dpy, x_root, gc, x, y, w, h); XDrawRectangle (x_dpy, x_root, x_gc, x, y, w, h);
shootvals.x2 = x_event.xmotion.x_root; shootvals.x2 = x_event.xmotion.x_root;
shootvals.y2 = x_event.xmotion.y_root; shootvals.y2 = x_event.xmotion.y_root;
@ -529,7 +525,7 @@ select_window_x11 (GdkScreen *screen)
h = ABS (shootvals.y2 - shootvals.y1); h = ABS (shootvals.y2 - shootvals.y1);
if (w > 0 && h > 0) if (w > 0 && h > 0)
XDrawRectangle (x_dpy, x_root, gc, x, y, w, h); XDrawRectangle (x_dpy, x_root, x_gc, x, y, w, h);
} }
break; break;
@ -579,7 +575,10 @@ select_window_x11 (GdkScreen *screen)
} }
XUngrabPointer (x_dpy, CurrentTime); XUngrabPointer (x_dpy, CurrentTime);
XFreeCursor (x_dpy, x_cursor); XFreeCursor (x_dpy, x_cursor);
if (x_gc != None)
XFreeGC (x_dpy, x_gc);
return x_win; return x_win;
} }