# HG changeset patch # User bsmith@81767d24-ef19-dc11-ae90-00e081727c95 # Date 1304637085 0 # Node ID 5c5447fd0cc94ce4159f56ad8863c126572de93d # Parent 32830f1683c92d11bec5eedefe8fe700ba1a2d31 Step 1 in the modernization of the GTK1/2 module... see comments in GTK3 commit. diff -r 32830f1683c9 -r 5c5447fd0cc9 gtk/dw.c --- a/gtk/dw.c Thu May 05 22:15:48 2011 +0000 +++ b/gtk/dw.c Thu May 05 23:11:25 2011 +0000 @@ -110,8 +110,6 @@ ".bmp", }; -#define DW_THREAD_LIMIT 50 - #ifndef max # define max(a,b) (((a) > (b)) ? (a) : (b)) #endif @@ -122,12 +120,9 @@ FILE *dbgfp = NULL; -DWTID _dw_thread_list[DW_THREAD_LIMIT]; -GdkColor _foreground[DW_THREAD_LIMIT]; -GdkColor _background[DW_THREAD_LIMIT]; -int _transparent[DW_THREAD_LIMIT]; -GtkClipboard *_clipboard_object[DW_THREAD_LIMIT]; -gchar *_clipboard_contents[DW_THREAD_LIMIT]; +pthread_key_t _dw_fg_color_key; +pthread_key_t _dw_bg_color_key; +pthread_key_t _dw_mutex_key; GtkWidget *last_window = NULL, *popup = NULL; @@ -136,12 +131,11 @@ #endif static int _dw_ignore_click = 0, _dw_ignore_expand = 0, _dw_color_active = 0; static pthread_t _dw_thread = (pthread_t)-1; -static int _dw_mutex_locked[DW_THREAD_LIMIT]; /* Use default border size for the default enlightenment theme */ static int _dw_border_width = 12, _dw_border_height = 28; -#define DW_MUTEX_LOCK { int index = _find_thread_index(dw_thread_id()); if(pthread_self() != _dw_thread && _dw_mutex_locked[index] == FALSE) { gdk_threads_enter(); _dw_mutex_locked[index] = TRUE; _locked_by_me = TRUE; } } -#define DW_MUTEX_UNLOCK { if(pthread_self() != _dw_thread && _locked_by_me == TRUE) { gdk_threads_leave(); _dw_mutex_locked[_find_thread_index(dw_thread_id())] = FALSE; _locked_by_me = FALSE; } } +#define DW_MUTEX_LOCK { if(pthread_self() != _dw_thread && !pthread_getspecific(_dw_mutex_key)) { gdk_threads_enter(); pthread_setspecific(_dw_mutex_key, (void *)1); _locked_by_me = TRUE; } } +#define DW_MUTEX_UNLOCK { if(pthread_self() != _dw_thread && _locked_by_me == TRUE) { gdk_threads_leave(); pthread_setspecific(_dw_mutex_key, NULL); _locked_by_me = FALSE; } } #define DEFAULT_SIZE_WIDTH 12 #define DEFAULT_SIZE_HEIGHT 6 @@ -1953,61 +1947,13 @@ } #endif -/* Find the index of a given thread */ -static int _find_thread_index(DWTID tid) -{ - int z; - - for(z=0;zpixel = foreground->red = foreground->green = foreground->blue = 0; + pthread_setspecific(_dw_fg_color_key, foreground); + pthread_setspecific(_dw_bg_color_key, NULL); } /* Try to load the mozilla embed shared libary */ @@ -2142,8 +2088,11 @@ if(tmp) _dw_border_height = atoi(tmp); - for(z=0;zwindow : pixmap->pixmap, gc, x, y, layout, foreground, background); + else gdk_draw_layout(handle ? handle->window : pixmap->pixmap, gc, x, y, layout); - else - gdk_draw_layout_with_colors(handle ? handle->window : pixmap->pixmap, gc, x, y, layout, &_foreground[index], &_background[index]); g_object_unref(layout); } @@ -7785,7 +7750,8 @@ if(font) { gint ascent, descent, width, junk_ascent, junk_descent, junk_width; - int index = _find_thread_index(dw_thread_id()); + GdkColor *foreground = pthread_getspecific(_dw_fg_color_key); + GdkColor *background = pthread_getspecific(_dw_bg_color_key); /* gdk_text_extents() calculates ascent and descent based on the string, so * a string without a character with a descent or without an ascent will have @@ -7794,15 +7760,15 @@ gdk_text_extents(font, text, strlen(text), NULL, NULL, &width, &junk_ascent, &junk_descent); /* force ascent/descent to be maximum values */ gdk_text_extents(font, "(g", 2, NULL, NULL, &junk_width, &ascent, &descent); - if(!_transparent[index]) + if(background) { GdkGC *gc2 = NULL; gc2 = gdk_gc_new(handle ? handle->window : pixmap->pixmap); if(gc2) { - gdk_gc_set_foreground(gc2, &_background[index]); - gdk_gc_set_background(gc2, &_background[index]); + gdk_gc_set_foreground(gc2, background); + gdk_gc_set_background(gc2, background); } gdk_draw_rectangle(handle ? handle->window : pixmap->pixmap, gc2, TRUE, x, y, width, ascent + descent + 1); gdk_gc_unref(gc2); @@ -11511,20 +11477,23 @@ */ char *dw_clipboard_get_text() { - int _locked_by_me = FALSE, index = _find_thread_index(dw_thread_id()); - - DW_MUTEX_LOCK; - if ( _clipboard_object[index] == NULL ) - { - _clipboard_object[index] = gtk_clipboard_get( GDK_SELECTION_CLIPBOARD ); - } - if ( _clipboard_contents[index] != NULL ) - { - g_free( _clipboard_contents[index] ); - } - _clipboard_contents[index] = gtk_clipboard_wait_for_text( _clipboard_object[index] ); - DW_MUTEX_UNLOCK; - return (char *)_clipboard_contents[index]; + int _locked_by_me = FALSE; + GtkClipboard *clipboard_object; + char *ret = NULL; + + DW_MUTEX_LOCK; + if((clipboard_object = gtk_clipboard_get( GDK_SELECTION_CLIPBOARD ))) + { + gchar *clipboard_contents; + + if((clipboard_contents = gtk_clipboard_wait_for_text( clipboard_object ))) + { + ret = strdup((char *)clipboard_contents); + g_free(clipboard_contents); + } + } + DW_MUTEX_UNLOCK; + return ret; } /* @@ -11534,14 +11503,14 @@ */ void dw_clipboard_set_text( char *str, int len ) { - int _locked_by_me = FALSE, index = _find_thread_index(dw_thread_id()); - - DW_MUTEX_LOCK; - if ( _clipboard_object[index] == NULL ) - { - _clipboard_object[index] = gtk_clipboard_get( GDK_SELECTION_CLIPBOARD ); - } - gtk_clipboard_set_text( _clipboard_object[index], str, len ); + int _locked_by_me = FALSE; + GtkClipboard *clipboard_object; + + DW_MUTEX_LOCK; + if((clipboard_object = gtk_clipboard_get( GDK_SELECTION_CLIPBOARD ))) + { + gtk_clipboard_set_text( clipboard_object, str, len ); + } DW_MUTEX_UNLOCK; }