diff --git a/INSTALL.in b/INSTALL.in index 477011318..05eaefa06 100644 --- a/INSTALL.in +++ b/INSTALL.in @@ -4,8 +4,8 @@ Prerequisites GTK+ requires the following packages: - The GLib, Pango, GdkPixbuf, ATK and cairo libraries, available at the same - location as GTK+. GTK+ @GTK_VERSION@ requires at least GLib 2.28.0, - Pango 1.20, GdkPixbuf 2.21.0, ATK 1.29.2 and cairo 1.6.0. + location as GTK+. GTK+ @GTK_VERSION@ requires at least GLib 2.38.0, + Pango 1.22, GdkPixbuf 2.21.0, ATK 1.29.2, cairo 1.6 and FriBidi 0.19.2. - gobject-introspection 0.9.3 or newer. diff --git a/config.h.win32.in b/config.h.win32.in index b7236b720..a11705ac8 100644 --- a/config.h.win32.in +++ b/config.h.win32.in @@ -150,12 +150,6 @@ /* Define to 1 if you have the header file. */ #define HAVE_SYS_STAT_H 1 -/* Define to 1 if sys/sysinfo.h is available */ -/* #undef HAVE_SYS_SYSINFO_H */ - -/* Define to 1 if sys/systeminfo.h is available */ -/* #undef HAVE_SYS_SYSTEMINFO_H */ - /* Define to 1 if you have the header file. */ #ifndef _MSC_VER #define HAVE_SYS_TIME_H 1 @@ -280,12 +274,6 @@ /* Whether to load modules via .la files rather than directly */ /* #undef USE_LA_MODULES */ -/* Define to 1 if medialib is available and should be used */ -/* #undef USE_MEDIALIB */ - -/* Define to 1 if medialib 2.5 is available */ -/* #undef USE_MEDIALIB25 */ - /* Define to 1 if XXM is available and should be used */ #ifndef _MSC_VER # define USE_MMX 1 diff --git a/configure.ac b/configure.ac index 04536e910..0609791a9 100644 --- a/configure.ac +++ b/configure.ac @@ -13,8 +13,8 @@ AC_PREREQ(2.62) m4_define([gtk_major_version], [2]) m4_define([gtk_minor_version], [24]) -m4_define([gtk_micro_version], [33]) -m4_define([gtk_interface_age], [33]) +m4_define([gtk_micro_version], [34]) +m4_define([gtk_interface_age], [34]) m4_define([gtk_binary_age], [m4_eval(100 * gtk_minor_version + gtk_micro_version)]) m4_define([gtk_version], @@ -32,6 +32,8 @@ m4_define([gtk_api_version], [2.0]) m4_define([gtk_binary_version], [2.10.0]) # required versions of other packages +# What the code needs, no more: newer API is used only where a version +# check allows it (GLib 2.38 for g_file_trash_async) m4_define([glib_required_version], [2.38.0]) m4_define([pango_required_version], [1.22]) m4_define([atk_required_version], [1.29.2]) @@ -250,6 +252,10 @@ AC_ARG_ENABLE(xrandr, [AS_HELP_STRING([--enable-xrandr], [support XRandR extension if available [default=yes]])],, [enable_xrandr="yes"]) +AC_ARG_ENABLE(xinput2, + [AS_HELP_STRING([--enable-xinput2], + [smooth scrolling with XInput 2.1 if available [default=yes]])],, + [enable_xinput2="yes"]) AC_ARG_ENABLE(xfixes, [AS_HELP_STRING([--enable-xfixes], [support XFixes extension if available [default=yes]])],, @@ -347,6 +353,25 @@ changequote([,])dnl CPPFLAGS="$CPPFLAGS -DG_DISABLE_SINGLE_INCLUDES -DATK_DISABLE_SINGLE_INCLUDES -DGDK_PIXBUF_DISABLE_SINGLE_INCLUDES -DGTK_DISABLE_SINGLE_INCLUDES" +# A 64-bit time_t on 32-bit Windows: msvcrt.dll has had the 64-bit time +# functions since Windows 2000 (so XP and ReactOS have them), but MinGW +# keeps time_t at 32 bits there unless asked. It changes the ABI of the +# time_t functions of GtkRecentInfo, so programs must be built the same +# way; gtk+-2.0.pc passes the flag on. The _unix functions of +# GtkRecentInfo give 64-bit times either way. +AC_ARG_ENABLE(win32-time64, + [AS_HELP_STRING([--enable-win32-time64], + [on 32-bit Windows, build with a 64-bit time_t (changes the ABI of the time_t functions of GtkRecentInfo) [default=no]])],, + [enable_win32_time64=no]) +win32_time64_cflags= +if test x"$os_win32" = xyes && test x"$enable_win32_time64" = xyes; then + case "$host" in + x86_64-*|aarch64-*) ;; + *) win32_time64_cflags='-D__MINGW_USE_VC2005_COMPAT' + CFLAGS="$CFLAGS $win32_time64_cflags" ;; + esac +fi + # Ensure MSVC-compatible struct packing convention is used when # compiling for Win32 with gcc. # What flag to depends on gcc version: gcc3 uses "-mms-bitfields", while @@ -477,6 +502,100 @@ AC_SUBST(REBUILD) AC_CHECK_FUNCS(lstat mkstemp flockfile getc_unlocked _getc_nolock) AC_CHECK_FUNCS(localtime_r) +# +# Vector instructions for GdkRGB. Each instruction set has a file of its +# own, compiled with the flags found here; CPUs without it are told apart +# at run time (getauxval() or elf_aux_info() where cpuid doesn't). +# +AC_CHECK_FUNCS(getauxval elf_aux_info) + +dnl GTK_CHECK_SIMD_FLAGS(NAME, FLAGS|OTHER FLAGS, PROLOGUE, BODY): +dnl sets NAME_CFLAGS to the first flags the test compiles with +AC_DEFUN([GTK_CHECK_SIMD_FLAGS], +[AC_MSG_CHECKING([for flags to compile $1 code]) +$1_CFLAGS= +gtk_save_CFLAGS="$CFLAGS" +gtk_simd_list='$2' +gtk_save_IFS="$IFS" +IFS='|' +for gtk_simd_flags in $gtk_simd_list; do + IFS="$gtk_save_IFS" + CFLAGS="$gtk_save_CFLAGS $gtk_simd_flags" + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[$3]], [[$4]])], + [$1_CFLAGS="$gtk_simd_flags" + break]) +done +IFS="$gtk_save_IFS" +CFLAGS="$gtk_save_CFLAGS" +AC_MSG_RESULT([${$1_CFLAGS:-none}]) +AC_SUBST($1_CFLAGS)]) + +MMX_CFLAGS= +SSE2_CFLAGS= +SSSE3_CFLAGS= +AVX2_CFLAGS= +ALTIVEC_CFLAGS= +ARMV6_CFLAGS= +NEON_CFLAGS= +case "$host_cpu" in + i?86|x86_64|amd64) + GTK_CHECK_SIMD_FLAGS([MMX], [-mmmx], + [#include + #ifndef __MMX__ + #error no MMX + #endif], + [__m64 v = _mm_setzero_si64 (); v = _mm_mullo_pi16 (v, v); _mm_empty ();]) + GTK_CHECK_SIMD_FLAGS([SSE2], [-msse2], + [#include + #ifndef __SSE2__ + #error no SSE2 + #endif], + [__m128i v = _mm_setzero_si128 (); v = _mm_mullo_epi16 (v, v); (void) v;]) + GTK_CHECK_SIMD_FLAGS([SSSE3], [-mssse3], + [#include + #ifndef __SSSE3__ + #error no SSSE3 + #endif], + [__m128i v = _mm_setzero_si128 (); v = _mm_shuffle_epi8 (v, v); (void) v;]) + dnl not with MinGW: GCC does not align its stack for AVX there (GCC + dnl bug 54412), and unoptimized builds would crash on spills + case "$host_os" in + mingw*|cygwin*) ;; + *) + GTK_CHECK_SIMD_FLAGS([AVX2], [-mavx2], + [#include + #ifndef __AVX2__ + #error no AVX2 + #endif], + [__m256i v = _mm256_setzero_si256 (); v = _mm256_shuffle_epi8 (v, v); (void) v;]) + ;; + esac + ;; + powerpc*|ppc*) + GTK_CHECK_SIMD_FLAGS([ALTIVEC], [-maltivec], + [#include + #if !defined(__ALTIVEC__) || !defined(__BIG_ENDIAN__) + #error no big endian AltiVec + #endif], + [vector unsigned short v = vec_splats ((unsigned short) 1); v = vec_mladd (v, v, v); (void) v;]) + ;; + arm*) + dnl the media instructions of ARMv6, for builds for older ARMs too + GTK_CHECK_SIMD_FLAGS([ARMV6], [|-march=armv6], + [#if !defined(__ARM_ARCH_6__) && !(defined(__ARM_ARCH) && __ARM_ARCH >= 6) + #error no ARMv6 + #endif], + [unsigned int r, x = 1; __asm__ ("uxtab16 %0, %1, %2, ror #8" : "=r" (r) : "r" (x), "r" (x)); (void) r;]) + dnl toolchains for the Raspberry Pi 1 default to ARMv6, which has no NEON + GTK_CHECK_SIMD_FLAGS([NEON], [-mfpu=neon|-march=armv7-a -mfpu=neon], + [#include + #if !defined(__ARM_NEON) && !defined(__ARM_NEON__) + #error no NEON + #endif], + [uint8x8x4_t v = vld4_u8 ((const unsigned char *) 0); (void) v;]) + ;; +esac + # _NL_TIME_FIRST_WEEKDAY is an enum and not a define AC_MSG_CHECKING([for _NL_TIME_FIRST_WEEKDAY]) AC_LINK_IFELSE( @@ -958,38 +1077,6 @@ AM_CONDITIONAL(INCLUDE_IM_XIM, [test x"$INCLUDE_xim" = xyes]) AC_HEADER_SYS_WAIT -# Checks to see whether we should include mediaLib -# support. -# -AC_CHECK_HEADER(sys/systeminfo.h, - AC_DEFINE(HAVE_SYS_SYSTEMINFO_H, 1, - [Define to 1 if sys/systeminfo.h is available])) -AC_CHECK_HEADER(sys/sysinfo.h, - AC_DEFINE(HAVE_SYS_SYSINFO_H, 1, - [Define to 1 if sys/sysinfo.h is available])) - -AC_MSG_CHECKING(for mediaLib 2.3) -use_mlib25=no -# Check for a mediaLib 2.3 function since that is what the GTK+ mediaLib -# patch requires. -AC_CHECK_LIB(mlib, mlib_ImageSetStruct, use_mlib=yes, use_mlib=no) -if test $use_mlib = yes; then - AC_DEFINE(USE_MEDIALIB, 1, - [Define to 1 if medialib is available and should be used]) - MEDIA_LIB=-lmlib - - AC_MSG_CHECKING(for mediaLib 2.5) - # Check for a mediaLib 2.5 function since that is what is needed for - # gdk_rgb_convert integration. - AC_CHECK_LIB(mlib, mlib_VideoColorRGBint_to_BGRAint, use_mlib25=yes, use_mlib25=no) - if test $use_mlib25 = yes; then - AC_DEFINE(USE_MEDIALIB25, 1, - [Define to 1 if medialib 2.5 is available]) - fi -fi -AM_CONDITIONAL(USE_MEDIALIB, test $use_mlib = yes) -AM_CONDITIONAL(USE_MEDIALIB25, test $use_mlib25 = yes) - dnl Look for a host system's gdk-pixbuf-csource if we are cross-compiling AM_CONDITIONAL(CROSS_COMPILING, test $cross_compiling = yes) @@ -1274,6 +1361,24 @@ if test "x$gdktarget" = "xx11"; then AM_CONDITIONAL(XINPUT_XFREE, test x$with_xinput = xxfree || test x$with_xinput = xyes) + # XInput 2.1 has the scroll valuators of high resolution wheels and + # touchpads; it is independent of the XInput 1 devices above + + if test "x$enable_xinput2" != "xno" && $PKG_CONFIG --exists "xi >= 1.5" ; then + AC_DEFINE(HAVE_XINPUT2, 1, [Have XInput 2.1 for smooth scrolling]) + + # libXi 1.8 knows the touchpad gestures of XInput 2.4; whether the + # X server has them is asked at run time + if $PKG_CONFIG --exists "xi >= 1.8" ; then + AC_DEFINE(HAVE_XINPUT2_GESTURES, 1, [Have libXi 1.8 for the touchpad gestures of XInput 2.4]) + fi + + case " $X_PACKAGES " in + *" xi "*) ;; + *) X_PACKAGES="$X_PACKAGES xi" ;; + esac + fi + # Check for the RANDR extension if test "x$enable_xrandr" != "xno" && $PKG_CONFIG --exists "xrandr >= 1.2.99" ; then AC_DEFINE(HAVE_RANDR, 1, [Have the Xrandr extension library]) @@ -1478,7 +1583,7 @@ GTK_DEP_LIBS="$GDK_EXTRA_LIBS $GTK_DEP_LIBS_FOR_X `$PKG_CONFIG --libs $PANGO_PAC GTK_DEP_CFLAGS="`$PKG_CONFIG --cflags gthread-2.0 $GDK_PACKAGES $GTK_PACKAGES` $GDK_EXTRA_CFLAGS $GTK_EXTRA_CFLAGS" if test x"$os_win32" = xyes; then - GTK_EXTRA_CFLAGS="$msnative_struct" + GTK_EXTRA_CFLAGS="$msnative_struct $win32_time64_cflags" fi GLIB_PREFIX="`$PKG_CONFIG --variable=prefix glib-2.0`" diff --git a/demos/gtk-demo/appwindow.c b/demos/gtk-demo/appwindow.c index c80d00d02..6cab50f1b 100644 --- a/demos/gtk-demo/appwindow.c +++ b/demos/gtk-demo/appwindow.c @@ -466,6 +466,7 @@ do_appwindow (GtkWidget *do_widget) g_object_set_data_full (G_OBJECT (window), "ui-manager", merge, g_object_unref); gtk_ui_manager_insert_action_group (merge, action_group, 0); + g_object_unref (action_group); gtk_window_add_accel_group (GTK_WINDOW (window), gtk_ui_manager_get_accel_group (merge)); diff --git a/demos/gtk-demo/assistant.c b/demos/gtk-demo/assistant.c index a00c59537..f72d20fc6 100644 --- a/demos/gtk-demo/assistant.c +++ b/demos/gtk-demo/assistant.c @@ -194,6 +194,8 @@ do_assistant (GtkWidget *do_widget) create_page3 (assistant); create_page4 (assistant); + g_signal_connect (assistant, "destroy", + G_CALLBACK (gtk_widget_destroyed), &assistant); g_signal_connect (G_OBJECT (assistant), "cancel", G_CALLBACK (on_assistant_close_cancel), &assistant); g_signal_connect (G_OBJECT (assistant), "close", diff --git a/demos/gtk-demo/builder.c b/demos/gtk-demo/builder.c index 80374c94b..0d08aa853 100644 --- a/demos/gtk-demo/builder.c +++ b/demos/gtk-demo/builder.c @@ -27,6 +27,19 @@ about_activate (GtkAction *action) gtk_widget_hide (about_dlg); } +/* the about dialog and the builder go with the window */ +static void +window_destroyed (GtkWidget *window, + gpointer user_data) +{ + GObject *about_dlg = gtk_builder_get_object (builder, "aboutdialog1"); + + if (about_dlg) + gtk_widget_destroy (GTK_WIDGET (about_dlg)); + g_object_unref (builder); + builder = NULL; +} + GtkWidget * do_builder (GtkWidget *do_widget) { @@ -51,6 +64,8 @@ do_builder (GtkWidget *do_widget) gtk_widget_get_screen (do_widget)); g_signal_connect (window, "destroy", G_CALLBACK (gtk_widget_destroyed), &window); + g_signal_connect (window, "destroy", + G_CALLBACK (window_destroyed), NULL); } if (!gtk_widget_get_visible (window)) diff --git a/demos/gtk-demo/images.c b/demos/gtk-demo/images.c index 9eaac39c0..0066f7f91 100644 --- a/demos/gtk-demo/images.c +++ b/demos/gtk-demo/images.c @@ -389,6 +389,8 @@ do_images (GtkWidget *do_widget) } image = gtk_image_new_from_pixbuf (pixbuf); + if (pixbuf) + g_object_unref (pixbuf); gtk_container_add (GTK_CONTAINER (frame), image); diff --git a/demos/gtk-demo/list_store.c b/demos/gtk-demo/list_store.c index 009cd9799..848c0a145 100644 --- a/demos/gtk-demo/list_store.c +++ b/demos/gtk-demo/list_store.c @@ -216,6 +216,14 @@ window_closed (GtkWidget *widget, return FALSE; } +/* destroyed without being closed, the spinner must stop all the same */ +static void +window_destroyed (GtkWidget *widget, + gpointer user_data) +{ + window_closed (widget, NULL, user_data); +} + GtkWidget * do_list_store (GtkWidget *do_widget) { @@ -233,7 +241,7 @@ do_list_store (GtkWidget *do_widget) gtk_window_set_title (GTK_WINDOW (window), "GtkListStore demo"); g_signal_connect (window, "destroy", - G_CALLBACK (gtk_widget_destroyed), &window); + G_CALLBACK (window_destroyed), NULL); gtk_container_set_border_width (GTK_CONTAINER (window), 8); vbox = gtk_vbox_new (FALSE, 8); diff --git a/docs/reference/gdk/gdk2-sections.txt b/docs/reference/gdk/gdk2-sections.txt index 4987c31ee..cac4956d4 100644 --- a/docs/reference/gdk/gdk2-sections.txt +++ b/docs/reference/gdk/gdk2-sections.txt @@ -1174,6 +1174,8 @@ gdk_get_show_events gdk_set_show_events gdk_event_set_screen gdk_event_get_screen +gdk_event_get_scroll_deltas +gdk_event_get_pointer_emulated gdk_setting_get diff --git a/docs/reference/gdk/tmpl/rgb.sgml b/docs/reference/gdk/tmpl/rgb.sgml index 19ccc0097..f38b86b84 100644 --- a/docs/reference/gdk/tmpl/rgb.sgml +++ b/docs/reference/gdk/tmpl/rgb.sgml @@ -34,13 +34,6 @@ created in grayscale and direct color modes, and the visual is changed in cases where a "better" visual than the default is available. - -If GDK is built with the Sun mediaLib library, the GdkRGB functions are -accelerated using mediaLib, which provides hardware acceleration on Intel, -AMD, and Sparc chipsets. If desired, mediaLib support can be turned off -by setting the GDK_DISABLE_MEDIALIB environment variable. - - A simple example program using GdkRGB diff --git a/docs/reference/gtk/running.sgml b/docs/reference/gtk/running.sgml index 1721ba239..9c44b58cd 100644 --- a/docs/reference/gtk/running.sgml +++ b/docs/reference/gtk/running.sgml @@ -407,6 +407,33 @@ nevertheless. + + <envar>GDK_CORE_DEVICE_EVENTS</envar> + + + If set, GDK does not use XInput 2.1 and scrolls only by whole + wheel steps, as before smooth scrolling. + + + + + <envar>GDK_DISABLE_SIMD</envar>, <envar>GDK_RGB_SIMD</envar> + + + GDK converts and blends pixels with the vector instructions of the + CPU where it has them (MMX, the integer part of SSE, 3DNow!, SSE2, SSSE3, + AltiVec, NEON), with the same results as its C code. If + GDK_DISABLE_SIMD is set to anything but 0, only the + C code is used. GDK_RGB_SIMD chooses by hand, to + compare: c for none, the name of an instruction + set for that one, or kernel=set for a single + kernel, several separated by commas. The program + rgbsimdbench in the gdk + directory of the sources (make rgbsimdbench) + lists the kernels and sets and times them on the machine. + + + <envar>XDG_DATA_HOME</envar>, <envar>XDG_DATA_DIRS</envar> diff --git a/gdk/Makefile.am b/gdk/Makefile.am index 2b68f98a6..02727f6b7 100644 --- a/gdk/Makefile.am +++ b/gdk/Makefile.am @@ -22,7 +22,6 @@ EXTRA_DIST += \ gdkkeysyms-update.pl \ gdk.def \ gdkmarshalers.list \ - gdkmedialib.h \ gdkwindowimpl.h \ makeenums.pl \ makefile.msc \ @@ -51,7 +50,7 @@ endif # libtool stuff: set version and export symbols for resolving # since automake doesn't support conditionalized libsomething_la_LDFLAGS # we use the general approach here -LDADD = \ +gdk_ldflags = \ $(GTK_LINK_FLAGS) \ -version-info $(LT_VERSION_INFO) \ -export-dynamic \ @@ -59,13 +58,6 @@ LDADD = \ $(no_undefined) \ $(LIBTOOL_EXPORT_OPTIONS) -if USE_MEDIALIB -medialib_sources = \ - gdkmedialib.c -else -medialib_sources = -endif - # # setup source file variables # @@ -115,11 +107,11 @@ gdk_built_private_headers = \ gdk_private_headers = \ gdkinternals.h \ gdkintl.h \ + gdkrgbsimd.h \ gdkpoly-generic.h \ gdkregion-generic.h gdk_c_sources = \ - $(medialib_sources) \ gdk.c \ gdkapplaunchcontext.c \ gdkcairo.c \ @@ -145,7 +137,7 @@ gdk_c_sources = \ gdkrectangle.c \ gdkregion-generic.c \ gdkrgb.c \ - gdkrgb16.c \ + gdkrgbsimd.c \ gdkscreen.c \ gdkselection.c \ gdkvisual.c \ @@ -174,22 +166,59 @@ common_sources = \ gdkmarshalers.c \ gdkmarshalers.h +# Vector versions of GdkRGB loops, each built with the flags of its +# instruction set. configure leaves the flags empty where the compiler +# can't do them, and the file then has nothing but an empty function. +noinst_LTLIBRARIES = \ + libgdk-rgb-mmx.la \ + libgdk-rgb-sse2.la \ + libgdk-rgb-ssse3.la \ + libgdk-rgb-avx2.la \ + libgdk-rgb-altivec.la \ + libgdk-rgb-armv6.la \ + libgdk-rgb-neon.la + +libgdk_rgb_mmx_la_SOURCES = gdkrgb-mmx.c +libgdk_rgb_mmx_la_CFLAGS = $(MMX_CFLAGS) +libgdk_rgb_sse2_la_SOURCES = gdkrgb-sse2.c +libgdk_rgb_sse2_la_CFLAGS = $(SSE2_CFLAGS) +libgdk_rgb_ssse3_la_SOURCES = gdkrgb-ssse3.c +libgdk_rgb_ssse3_la_CFLAGS = $(SSSE3_CFLAGS) +libgdk_rgb_avx2_la_SOURCES = gdkrgb-avx2.c +libgdk_rgb_avx2_la_CFLAGS = $(AVX2_CFLAGS) +libgdk_rgb_altivec_la_SOURCES = gdkrgb-altivec.c +libgdk_rgb_altivec_la_CFLAGS = $(ALTIVEC_CFLAGS) +libgdk_rgb_armv6_la_SOURCES = gdkrgb-armv6.c +libgdk_rgb_armv6_la_CFLAGS = $(ARMV6_CFLAGS) +libgdk_rgb_neon_la_SOURCES = gdkrgb-neon.c +libgdk_rgb_neon_la_CFLAGS = $(NEON_CFLAGS) + +gdk_rgb_simd_libs = $(noinst_LTLIBRARIES) + +# Checks and times the kernels on this machine against the C code: +# make rgbsimdbench && ./rgbsimdbench +EXTRA_PROGRAMS = rgbsimdbench +rgbsimdbench_SOURCES = rgbsimdbench.c gdkrgbsimd.c +rgbsimdbench_CFLAGS = $(AM_CFLAGS) +rgbsimdbench_LDADD = $(gdk_rgb_simd_libs) $(GDK_DEP_LIBS) +CLEANFILES += rgbsimdbench + libgdk_directfb_2_0_la_SOURCES = $(common_sources) -libgdk_directfb_2_0_la_LIBADD = directfb/libgdk-directfb.la $(GDK_DEP_LIBS) -libgdk_directfb_2_0_la_LDFLAGS = $(LDADD) +libgdk_directfb_2_0_la_LIBADD = directfb/libgdk-directfb.la $(gdk_rgb_simd_libs) $(GDK_DEP_LIBS) +libgdk_directfb_2_0_la_LDFLAGS = $(gdk_ldflags) libgdk_x11_2_0_la_SOURCES = $(common_sources) -libgdk_x11_2_0_la_LIBADD = x11/libgdk-x11.la $(GDK_DEP_LIBS) -libgdk_x11_2_0_la_LDFLAGS = $(LDADD) +libgdk_x11_2_0_la_LIBADD = x11/libgdk-x11.la $(gdk_rgb_simd_libs) $(GDK_DEP_LIBS) +libgdk_x11_2_0_la_LDFLAGS = $(gdk_ldflags) libgdk_quartz_2_0_la_SOURCES = $(common_sources) gdkkeynames.c -libgdk_quartz_2_0_la_LIBADD = quartz/libgdk-quartz.la $(GDK_DEP_LIBS) -libgdk_quartz_2_0_la_LDFLAGS = $(LDADD) +libgdk_quartz_2_0_la_LIBADD = quartz/libgdk-quartz.la $(gdk_rgb_simd_libs) $(GDK_DEP_LIBS) +libgdk_quartz_2_0_la_LDFLAGS = $(gdk_ldflags) libgdk_win32_2_0_la_SOURCES = $(common_sources) gdkkeynames.c -libgdk_win32_2_0_la_LIBADD = win32/libgdk-win32.la $(GDK_DEP_LIBS) -libgdk_win32_2_0_la_DEPENDENCIES = win32/libgdk-win32.la win32/rc/gdk-win32-res.o gdk.def -libgdk_win32_2_0_la_LDFLAGS = -Wl,win32/rc/gdk-win32-res.o -export-symbols $(srcdir)/gdk.def $(LDADD) +libgdk_win32_2_0_la_LIBADD = win32/libgdk-win32.la $(gdk_rgb_simd_libs) $(GDK_DEP_LIBS) +libgdk_win32_2_0_la_DEPENDENCIES = win32/libgdk-win32.la $(gdk_rgb_simd_libs) win32/rc/gdk-win32-res.o gdk.def +libgdk_win32_2_0_la_LDFLAGS = -Wl,win32/rc/gdk-win32-res.o -export-symbols $(srcdir)/gdk.def $(gdk_ldflags) if HAVE_INTROSPECTION @@ -478,7 +507,7 @@ INTROSPECTION_INTERMEDIATE_ITEMS = \ $(top_builddir)/build/win32/Gdk-2.0.gir.msvc.introspect \ $(top_builddir)/build/win32/Gdk_2_0_gir_list -Gdk_2_0_gir_MSVC_FILES = $(filter-out gdkmedialib.c, $(base_introspection_files)) +Gdk_2_0_gir_MSVC_FILES = $(base_introspection_files) Gdk_2_0_gir_MSVC_EXPORT_PACKAGES = $(Gdk_2_0_gir_EXPORT_PACKAGES) Gdk_2_0_gir_MSVC_INCLUDE_GIRS = $(Gdk_2_0_gir_INCLUDES) Gdk_2_0_gir_MSVC_LIBS = gdk-win32-2.0 diff --git a/gdk/directfb/gdkevents-directfb.c b/gdk/directfb/gdkevents-directfb.c index fd32145ed..2a2fb2a29 100644 --- a/gdk/directfb/gdkevents-directfb.c +++ b/gdk/directfb/gdkevents-directfb.c @@ -366,11 +366,9 @@ gdk_event_send_client_message_for_display (GdkDisplay *display, guint32 gdk_directfb_get_time (void) { - GTimeVal tv; - - g_get_current_time (&tv); - - return (guint32) tv.tv_sec * 1000 + tv.tv_usec / 1000; + /* milliseconds of the wall clock, as before, from the 64-bit time + * instead of the GTimeVal whose glong ends in 2038 on 32-bit systems */ + return (guint32) (g_get_real_time () / 1000); } void diff --git a/gdk/directfb/gdkscreen-directfb.c b/gdk/directfb/gdkscreen-directfb.c index 59079a5ef..c79f42c01 100644 --- a/gdk/directfb/gdkscreen-directfb.c +++ b/gdk/directfb/gdkscreen-directfb.c @@ -250,5 +250,20 @@ gdk_screen_is_composited (GdkScreen *screen) return FALSE; } + +/* HiDPI: not scaled by this backend (yet) */ +gint +_gdk_windowing_drawable_get_scale (GdkDrawable *drawable) +{ + return 1; +} + +gint +_gdk_windowing_screen_get_monitor_scale (GdkScreen *screen, + gint monitor_num) +{ + return 1; +} + #define __GDK_SCREEN_X11_C__ #include "gdkaliasdef.c" diff --git a/gdk/gdk.h b/gdk/gdk.h index 9cb88e248..27bd7256a 100644 --- a/gdk/gdk.h +++ b/gdk/gdk.h @@ -155,7 +155,7 @@ void gdk_rectangle_union (const GdkRectangle *src1, const GdkRectangle *src2, GdkRectangle *dest); -GType gdk_rectangle_get_type (void) G_GNUC_CONST; +GType gdk_rectangle_get_type (void); #define GDK_TYPE_RECTANGLE (gdk_rectangle_get_type ()) diff --git a/gdk/gdk.symbols b/gdk/gdk.symbols index b48eac70b..01af090dd 100644 --- a/gdk/gdk.symbols +++ b/gdk/gdk.symbols @@ -44,11 +44,15 @@ gdk_event_free gdk_event_get gdk_event_get_axis gdk_event_get_coords +gdk_event_get_event_sequence gdk_event_get_root_coords +gdk_event_get_pointer_emulated +gdk_event_get_touchpad_emulated gdk_event_get_screen +gdk_event_get_scroll_deltas gdk_event_get_state gdk_event_get_time -gdk_event_get_type G_GNUC_CONST +gdk_event_get_type gdk_event_handler_set gdk_event_new gdk_event_peek @@ -186,7 +190,7 @@ gdk_utf8_to_compound_text #if IN_HEADER(__GDK_PROPERTY_H__) #if IN_FILE(__GDK_C__) -gdk_atom_get_type G_GNUC_CONST +gdk_atom_get_type #endif #endif @@ -229,54 +233,54 @@ gdk_x11_free_text_list #if IN_HEADER(__GDK_ENUM_TYPES_H__) #if IN_FILE(__GDK_ENUM_TYPES_C__) -gdk_rgb_dither_get_type G_GNUC_CONST -gdk_drag_protocol_get_type G_GNUC_CONST -gdk_input_source_get_type G_GNUC_CONST -gdk_input_condition_get_type G_GNUC_CONST -gdk_input_mode_get_type G_GNUC_CONST -gdk_axis_use_get_type G_GNUC_CONST -gdk_byte_order_get_type G_GNUC_CONST -gdk_cap_style_get_type G_GNUC_CONST -gdk_crossing_mode_get_type G_GNUC_CONST -gdk_extension_mode_get_type G_GNUC_CONST -gdk_event_mask_get_type G_GNUC_CONST -gdk_event_type_get_type G_GNUC_CONST -gdk_fill_get_type G_GNUC_CONST +gdk_rgb_dither_get_type +gdk_drag_protocol_get_type +gdk_input_source_get_type +gdk_input_condition_get_type +gdk_input_mode_get_type +gdk_axis_use_get_type +gdk_byte_order_get_type +gdk_cap_style_get_type +gdk_crossing_mode_get_type +gdk_extension_mode_get_type +gdk_event_mask_get_type +gdk_event_type_get_type +gdk_fill_get_type #ifndef GDK_DISABLE_DEPRECATED -gdk_fill_rule_get_type G_GNUC_CONST +gdk_fill_rule_get_type #endif -gdk_filter_return_get_type G_GNUC_CONST -gdk_function_get_type G_GNUC_CONST -gdk_grab_status_get_type G_GNUC_CONST -gdk_gravity_get_type G_GNUC_CONST -gdk_join_style_get_type G_GNUC_CONST -gdk_line_style_get_type G_GNUC_CONST -gdk_modifier_type_get_type G_GNUC_CONST -gdk_notify_type_get_type G_GNUC_CONST -gdk_overlap_type_get_type G_GNUC_CONST -gdk_owner_change_get_type G_GNUC_CONST -gdk_property_state_get_type G_GNUC_CONST -gdk_prop_mode_get_type G_GNUC_CONST -gdk_scroll_direction_get_type G_GNUC_CONST -gdk_setting_action_get_type G_GNUC_CONST -gdk_status_get_type G_GNUC_CONST -gdk_subwindow_mode_get_type G_GNUC_CONST -gdk_visibility_state_get_type G_GNUC_CONST -gdk_wm_decoration_get_type G_GNUC_CONST -gdk_wm_function_get_type G_GNUC_CONST -gdk_font_type_get_type G_GNUC_CONST -gdk_cursor_type_get_type G_GNUC_CONST -gdk_drag_action_get_type G_GNUC_CONST -gdk_gc_values_mask_get_type G_GNUC_CONST -gdk_window_attributes_type_get_type G_GNUC_CONST -gdk_window_class_get_type G_GNUC_CONST -gdk_window_edge_get_type G_GNUC_CONST -gdk_window_hints_get_type G_GNUC_CONST -gdk_window_state_get_type G_GNUC_CONST -gdk_window_type_get_type G_GNUC_CONST -gdk_window_type_hint_get_type G_GNUC_CONST -gdk_image_type_get_type G_GNUC_CONST -gdk_visual_type_get_type G_GNUC_CONST +gdk_filter_return_get_type +gdk_function_get_type +gdk_grab_status_get_type +gdk_gravity_get_type +gdk_join_style_get_type +gdk_line_style_get_type +gdk_modifier_type_get_type +gdk_notify_type_get_type +gdk_overlap_type_get_type +gdk_owner_change_get_type +gdk_property_state_get_type +gdk_prop_mode_get_type +gdk_scroll_direction_get_type +gdk_setting_action_get_type +gdk_status_get_type +gdk_subwindow_mode_get_type +gdk_visibility_state_get_type +gdk_wm_decoration_get_type +gdk_wm_function_get_type +gdk_font_type_get_type +gdk_cursor_type_get_type +gdk_drag_action_get_type +gdk_gc_values_mask_get_type +gdk_window_attributes_type_get_type +gdk_window_class_get_type +gdk_window_edge_get_type +gdk_window_hints_get_type +gdk_window_state_get_type +gdk_window_type_get_type +gdk_window_type_hint_get_type +gdk_image_type_get_type +gdk_visual_type_get_type #endif #endif @@ -285,7 +289,7 @@ gdk_visual_type_get_type G_GNUC_CONST #ifndef GDK_DISABLE_DEPRECATED gdk_font_from_description #endif -gdk_font_get_type G_GNUC_CONST +gdk_font_get_type gdk_font_ref gdk_font_unref #ifndef GDK_DISABLE_DEPRECATED @@ -325,6 +329,7 @@ gdk_fontset_load_for_display #if IN_HEADER(__GDK_CAIRO_H__) #if IN_FILE(__GDK_CAIRO_C__) gdk_cairo_create +gdk_cairo_create_in_area_libgtk_only gdk_cairo_reset_clip gdk_cairo_set_source_color gdk_cairo_set_source_pixbuf @@ -346,7 +351,7 @@ gdk_color_alloc gdk_color_copy gdk_color_equal gdk_color_free -gdk_color_get_type G_GNUC_CONST +gdk_color_get_type gdk_color_hash gdk_colormap_alloc_color gdk_colormap_get_system @@ -363,7 +368,7 @@ gdk_color_to_string #if IN_HEADER(__GDK_COLOR_H__) #if IN_FILE(__GDK_COLOR_X11_C__) gdk_colormap_new -gdk_colormap_get_type G_GNUC_CONST +gdk_colormap_get_type #ifndef GDK_DISABLE_DEPRECATED gdk_colormap_change gdk_colors_alloc @@ -380,7 +385,7 @@ gdk_colormap_get_screen #if IN_HEADER(__GDK_CURSOR_H__) #if IN_FILE(__GDK_CURSOR_C__) -gdk_cursor_get_type G_GNUC_CONST +gdk_cursor_get_type gdk_cursor_get_cursor_type gdk_cursor_new gdk_cursor_ref @@ -412,7 +417,7 @@ gdk_device_get_name gdk_device_get_n_axes gdk_device_get_n_keys gdk_device_get_source -gdk_device_get_type G_GNUC_CONST +gdk_device_get_type gdk_device_set_axis_use gdk_device_set_key gdk_device_set_source @@ -458,7 +463,7 @@ gdk_display_close gdk_display_get_core_pointer gdk_display_get_event gdk_display_get_pointer -gdk_display_get_type G_GNUC_CONST +gdk_display_get_type gdk_display_get_window_at_pointer gdk_display_is_closed gdk_display_peek_event @@ -533,7 +538,7 @@ gdk_display_set_double_click_time #if IN_HEADER(__GDK_DISPLAY_MANAGER_H__) #if IN_FILE(__GDK_DISPLAY_MANAGER_C__) gdk_display_manager_get -gdk_display_manager_get_type G_GNUC_CONST +gdk_display_manager_get_type gdk_display_manager_list_displays gdk_display_manager_set_default_display gdk_display_manager_get_default_display @@ -544,7 +549,7 @@ gdk_display_manager_get_default_display #if IN_FILE(__GDK_DND_X11_C__) gdk_drag_abort gdk_drag_begin -gdk_drag_context_get_type G_GNUC_CONST +gdk_drag_context_get_type #ifndef GDK_DISABLE_DEPRECATED gdk_drag_context_new gdk_drag_context_ref @@ -598,7 +603,7 @@ gdk_drawable_get_visual #endif gdk_drawable_get_depth gdk_drawable_get_image -gdk_drawable_get_type G_GNUC_CONST +gdk_drawable_get_type gdk_drawable_get_visible_region gdk_drawable_set_colormap gdk_draw_arc @@ -630,7 +635,7 @@ gdk_draw_layout_with_colors #if IN_HEADER(__GDK_GC_H__) #if IN_FILE(__GDK_GC_C__) gdk_gc_new -gdk_gc_get_type G_GNUC_CONST +gdk_gc_get_type gdk_gc_new_with_values #ifndef GDK_DISABLE_DEPRECATED gdk_gc_ref @@ -672,7 +677,7 @@ gdk_gc_get_screen #if IN_HEADER(__GDK_PIXMAP_X11_H__) #if IN_FILE(__GDK_PIXMAP_X11_C__) #ifdef GDK_WINDOWING_X11 -gdk_pixmap_impl_x11_get_type G_GNUC_CONST +gdk_pixmap_impl_x11_get_type #endif #endif #endif @@ -680,7 +685,7 @@ gdk_pixmap_impl_x11_get_type G_GNUC_CONST #if IN_HEADER(__GDK_WINDOW_X11_H__) #if IN_FILE(__GDK_WINDOW_X11_C__) #ifdef GDK_WINDOWING_X11 -gdk_window_impl_x11_get_type G_GNUC_CONST +gdk_window_impl_x11_get_type #endif #endif #endif @@ -767,7 +772,7 @@ gdk_window_is_input_only gdk_window_is_shaped gdk_window_is_viewable gdk_window_is_visible -gdk_window_object_get_type G_GNUC_CONST +gdk_window_object_get_type gdk_window_peek_children gdk_window_process_all_updates gdk_window_process_updates @@ -777,6 +782,7 @@ gdk_window_remove_redirection gdk_window_set_debug_updates gdk_window_set_user_data gdk_window_thaw_toplevel_updates_libgtk_only +gdk_window_set_touch_emulation_libgtk_only gdk_window_thaw_updates gdk_window_set_composited gdk_pointer_grab @@ -788,6 +794,7 @@ gdk_window_get_display gdk_window_get_visual gdk_window_get_width gdk_window_get_height +gdk_window_get_scale_factor #endif #endif @@ -801,7 +808,7 @@ gdk_offscreen_window_get_embedder #if IN_HEADER(__GDK_INTERNALS_H__) #if IN_FILE(__GDK_OFFSCREEN_WINDOW_C__) -gdk_offscreen_window_get_type G_GNUC_CONST +gdk_offscreen_window_get_type #endif #endif @@ -892,14 +899,14 @@ gdk_image_new_bitmap #endif gdk_image_get_pixel gdk_image_put_pixel -gdk_image_get_type G_GNUC_CONST +gdk_image_get_type #endif #endif #if IN_HEADER(__GDK_KEYS_H__) #if IN_FILE(__GDK_KEYS_C__) gdk_keymap_get_default -gdk_keymap_get_type G_GNUC_CONST +gdk_keymap_get_type gdk_keyval_is_lower G_GNUC_CONST gdk_keyval_is_upper G_GNUC_CONST gdk_keyval_to_lower G_GNUC_CONST @@ -974,7 +981,7 @@ gdk_visual_get_best_with_both gdk_visual_get_best_with_depth gdk_visual_get_best_with_type gdk_visual_get_screen -gdk_visual_get_type G_GNUC_CONST +gdk_visual_get_type #endif #endif @@ -999,7 +1006,7 @@ gdk_pango_context_set_colormap gdk_pango_layout_get_clip_region gdk_pango_layout_line_get_clip_region gdk_pango_renderer_get_default -gdk_pango_renderer_get_type G_GNUC_CONST +gdk_pango_renderer_get_type gdk_pango_renderer_new gdk_pango_renderer_set_drawable gdk_pango_renderer_set_gc @@ -1036,7 +1043,7 @@ gdk_pixmap_create_from_xpm gdk_pixmap_colormap_create_from_xpm_d gdk_pixmap_create_from_xpm_d gdk_pixmap_get_size -gdk_pixmap_get_type G_GNUC_CONST +gdk_pixmap_get_type gdk_pixmap_new #endif #endif @@ -1093,7 +1100,7 @@ gdk_region_polygon #if IN_FILE(__GDK_RGB_C__) gdk_rgb_cmap_free gdk_rgb_cmap_copy -gdk_rgb_cmap_get_type G_GNUC_CONST +gdk_rgb_cmap_get_type gdk_rgb_cmap_new gdk_rgb_colormap_ditherable gdk_rgb_ditherable @@ -1119,7 +1126,7 @@ gdk_draw_rgb_image_dithalign #endif #if IN_HEADER(__GDK_RGB_H__) -#if IN_FILE(__GDK_RGB16_C__) +#if IN_FILE(__GDK_RGB_C__) gdk_draw_rgb_48_image gdk_draw_rgb_48_image_dithalign gdk_draw_rgbx_64_image @@ -1129,13 +1136,14 @@ gdk_draw_rgbx_64_image_dithalign #if IN_HEADER(__GDK_SCREEN_H__) #if IN_FILE(__GDK_SCREEN_C__) -gdk_screen_get_type G_GNUC_CONST +gdk_screen_get_type gdk_screen_get_monitor_at_point gdk_screen_get_monitor_at_window gdk_screen_set_font_options gdk_screen_get_font_options gdk_screen_set_resolution gdk_screen_get_resolution +gdk_screen_get_monitor_scale_factor #endif #endif @@ -1302,7 +1310,7 @@ gdk_win32_selection_add_targets #if IN_HEADER(__GDK_WIN32_H__) #if IN_FILE(__GDK_KEYS_WIN32_C__) -gdk_win32_keymap_get_type G_GNUC_CONST +gdk_win32_keymap_get_type gdk_win32_keymap_check_compose #endif #endif @@ -1417,7 +1425,7 @@ gdk_xid_table_lookup_for_display #if IN_HEADER(__GDK_APP_LAUNCH_CONTEXT_H__) #if IN_FILE(__GDK_APP_LAUNCH_CONTEXT_C__) -gdk_app_launch_context_get_type G_GNUC_CONST +gdk_app_launch_context_get_type gdk_app_launch_context_new gdk_app_launch_context_set_display gdk_app_launch_context_set_screen @@ -1430,7 +1438,7 @@ gdk_app_launch_context_set_icon_name #if IN_HEADER(__GDK_WINDOW_IMPL_H__) #if IN_FILE(__GDK_WINDOW_IMPL_C__) -gdk_window_impl_get_type G_GNUC_CONST +gdk_window_impl_get_type #endif #endif diff --git a/gdk/gdkcairo.c b/gdk/gdkcairo.c index 7f5c42165..8ae088f30 100644 --- a/gdk/gdkcairo.c +++ b/gdk/gdkcairo.c @@ -17,7 +17,10 @@ * Boston, MA 02111-1307, USA. */ +#include + #include "gdkcairo.h" +#include "gdkrgbsimd.h" #include "gdkdrawable.h" #include "gdkinternals.h" #include "gdkregion-generic.h" @@ -30,6 +33,8 @@ gdk_ensure_surface_flush (gpointer surface) cairo_surface_destroy (surface); } +static const cairo_user_data_key_t surface_flush_key; + /** * gdk_cairo_create: * @drawable: a #GdkDrawable @@ -50,7 +55,6 @@ gdk_ensure_surface_flush (gpointer surface) cairo_t * gdk_cairo_create (GdkDrawable *drawable) { - static const cairo_user_data_key_t key; cairo_surface_t *surface; cairo_t *cr; @@ -67,11 +71,60 @@ gdk_cairo_create (GdkDrawable *drawable) * on X11 (where flushing is a no-op). For details, see * https://bugzilla.gnome.org/show_bug.cgi?id=628291 */ - cairo_set_user_data (cr, &key, surface, gdk_ensure_surface_flush); + cairo_set_user_data (cr, &surface_flush_key, surface, gdk_ensure_surface_flush); return cr; } +/* gdk_cairo_create() for drawing that stays within @area (in the + * coordinates of @drawable): for a window whose clip has many + * rectangles, only those parts of it within @area make the clip */ +cairo_t * +_gdk_cairo_create_in_area (GdkDrawable *drawable, + const GdkRectangle *area) +{ + cairo_surface_t *surface; + cairo_t *cr; + + if (!GDK_IS_WINDOW (drawable) || + _gdk_window_get_cairo_clip_n_rects ((GdkWindow *) drawable) <= 2) + return gdk_cairo_create (drawable); + + surface = _gdk_drawable_ref_cairo_surface (drawable); + cr = cairo_create (surface); + _gdk_window_set_cairo_clip_in_area ((GdkWindow *) drawable, cr, area); + cairo_set_user_data (cr, &surface_flush_key, surface, gdk_ensure_surface_flush); + + return cr; +} + +/** + * gdk_cairo_create_in_area_libgtk_only: + * @drawable: a #GdkDrawable + * @area: the area that will be drawn + * + * Like gdk_cairo_create(), for drawing that stays inside @area: of the + * clip of a window only the rectangles meeting @area are given to cairo, + * which within @area is the same clip. Theme engines that clip to the + * area they are given anyway spare cairo the whole clip of the window, + * which during an expose can be many rectangles, for each part they + * draw. Private to GTK+ and its modules. + * + * Return value: A newly created Cairo context. Free with + * cairo_destroy() when you are done drawing. + **/ +cairo_t * +gdk_cairo_create_in_area_libgtk_only (GdkDrawable *drawable, + const GdkRectangle *area) +{ + g_return_val_if_fail (GDK_IS_DRAWABLE (drawable), NULL); + + if (!area) + return gdk_cairo_create (drawable); + + return _gdk_cairo_create_in_area (drawable, area); +} + /** * gdk_cairo_reset_clip: * @cr: a #cairo_t @@ -173,24 +226,8 @@ gdk_cairo_region (cairo_t *cr, boxes[i].y2 - boxes[i].y1); } -/** - * gdk_cairo_set_source_pixbuf: - * @cr: a #Cairo context - * @pixbuf: a #GdkPixbuf - * @pixbuf_x: X coordinate of location to place upper left corner of @pixbuf - * @pixbuf_y: Y coordinate of location to place upper left corner of @pixbuf - * - * Sets the given pixbuf as the source pattern for the Cairo context. - * The pattern has an extend mode of %CAIRO_EXTEND_NONE and is aligned - * so that the origin of @pixbuf is @pixbuf_x, @pixbuf_y - * - * Since: 2.8 - **/ -void -gdk_cairo_set_source_pixbuf (cairo_t *cr, - const GdkPixbuf *pixbuf, - double pixbuf_x, - double pixbuf_y) +static cairo_surface_t * +gdk_cairo_surface_from_pixbuf (const GdkPixbuf *pixbuf) { gint width = gdk_pixbuf_get_width (pixbuf); gint height = gdk_pixbuf_get_height (pixbuf); @@ -202,6 +239,7 @@ gdk_cairo_set_source_pixbuf (cairo_t *cr, cairo_format_t format; cairo_surface_t *surface; static const cairo_user_data_key_t key; + const GdkRgbSimd *simd = _gdk_rgb_simd_get (); cairo_status_t status; int j; @@ -228,52 +266,60 @@ gdk_cairo_set_source_pixbuf (cairo_t *cr, { guchar *p = gdk_pixels; guchar *q = cairo_pixels; + gint done = 0; + /* vector code where there is some, C for the rest of the row */ + if (n_channels == 3 && simd->rgb_to_x888) + done = simd->rgb_to_x888 ((guint32 *) q, p, width); + else if (n_channels == 4 && simd->rgba_to_argb) + done = simd->rgba_to_argb ((guint32 *) q, p, width); + p += done * n_channels; + q += done * 4; + + /* One word out for each pixel, so that machines without vector + * units, the PowerPC G3 or ARMv5, store once, not three or four + * times; and the unused byte of RGB24 gets a value */ if (n_channels == 3) { - guchar *end = p + 3 * width; + guchar *end = gdk_pixels + 3 * width; + guint32 *q32 = (guint32 *) q; - while (p < end) - { -#if G_BYTE_ORDER == G_LITTLE_ENDIAN - q[0] = p[2]; - q[1] = p[1]; - q[2] = p[0]; -#else - q[1] = p[0]; - q[2] = p[1]; - q[3] = p[2]; -#endif - p += 3; - q += 4; - } + for (; p < end; p += 3) + *q32++ = 0xff000000 | ((guint32) p[0] << 16) | (p[1] << 8) | p[2]; } else { - guchar *end = p + 4 * width; - guint t1,t2,t3; + guchar *end = gdk_pixels + 4 * width; + guint32 *q32 = (guint32 *) q; -#define MULT(d,c,a,t) G_STMT_START { t = c * a + 0x80; d = ((t >> 8) + t) >> 8; } G_STMT_END - - while (p < end) + /* Red and blue 16 bits apart in one register, multiplied by + * alpha at once: c * a / 255 to the nearest, as + * ((t >> 8) + t) >> 8 with t = c * a + 0x80, which does not + * carry from one into the other. The pixel is read as one word + * as well. */ + for (; p < end; p += 4) { + guint32 w, a, rb, g; + + memcpy (&w, p, 4); #if G_BYTE_ORDER == G_LITTLE_ENDIAN - MULT(q[0], p[2], p[3], t1); - MULT(q[1], p[1], p[3], t2); - MULT(q[2], p[0], p[3], t3); - q[3] = p[3]; + a = w >> 24; + rb = w & 0x00ff00ff; /* B << 16 | R */ + g = (w >> 8) & 0xff; #else - q[0] = p[3]; - MULT(q[1], p[0], p[3], t1); - MULT(q[2], p[1], p[3], t2); - MULT(q[3], p[2], p[3], t3); + a = w & 0xff; + rb = (w >> 8) & 0x00ff00ff; /* R << 16 | B */ + g = (w >> 16) & 0xff; #endif - - p += 4; - q += 4; + rb = rb * a + 0x00800080; + rb = ((((rb >> 8) & 0x00ff00ff) + rb) >> 8) & 0x00ff00ff; + g = g * a + 0x80; + g = ((g >> 8) + g) >> 8; +#if G_BYTE_ORDER == G_LITTLE_ENDIAN + rb = (rb << 16) | (rb >> 16); /* R << 16 | B */ +#endif + *q32++ = (a << 24) | rb | (g << 8); } - -#undef MULT } gdk_pixels += gdk_rowstride; @@ -281,6 +327,104 @@ gdk_cairo_set_source_pixbuf (cairo_t *cr, } out: + return surface; +} + +/* GTK marks the pixbufs it renders for its icon caches with this, + * as no one may change them; their cairo surface is kept with them, + * so that a cached icon is neither converted nor uploaded again. */ +#define PIXBUF_SHARED_KEY "gdk-pixbuf-shared" + +static const cairo_user_data_key_t gdk_cairo_hidpi_key; + +void +_gdk_cairo_surface_set_hidpi_scale (cairo_surface_t *surface, + gint scale) +{ + cairo_surface_set_user_data (surface, &gdk_cairo_hidpi_key, + GINT_TO_POINTER (scale > 1 ? scale : 0), NULL); +} + +/** + * gdk_cairo_set_source_pixbuf: + * @cr: a #Cairo context + * @pixbuf: a #GdkPixbuf + * @pixbuf_x: X coordinate of location to place upper left corner of @pixbuf + * @pixbuf_y: Y coordinate of location to place upper left corner of @pixbuf + * + * Sets the given pixbuf as the source pattern for the Cairo context. + * The pattern has an extend mode of %CAIRO_EXTEND_NONE and is aligned + * so that the origin of @pixbuf is @pixbuf_x, @pixbuf_y + * + * Since: 2.8 + **/ +void +gdk_cairo_set_source_pixbuf (cairo_t *cr, + const GdkPixbuf *pixbuf, + double pixbuf_x, + double pixbuf_y) +{ + static GQuark quark_shared, quark_surface; + cairo_surface_t *surface; + + if (!quark_shared) + { + quark_shared = g_quark_from_static_string (PIXBUF_SHARED_KEY); + quark_surface = g_quark_from_static_string ("gdk-cairo-surface"); + } + +#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE (1, 14, 0) + { + /* HiDPI: on a surface of the window system with more pixels than + * GDK's, the pixbuf's own picture of that resolution, if it has + * one, else its pixels as sharp blocks (where it is not scaled) */ + gdouble sx = 1, sy = 1; + cairo_matrix_t m; + GdkPixbuf *hires; + + cairo_surface_get_device_scale (cairo_get_target (cr), &sx, &sy); + if (sx == 1 && sy == 1) + sx = sy = GPOINTER_TO_INT (cairo_surface_get_user_data (cairo_get_target (cr), + &gdk_cairo_hidpi_key)); + if (sx > 1 && sx == sy && sx == (gint) sx) + { + hires = _gdk_pixbuf_get_hires ((GdkPixbuf *) pixbuf, (gint) sx); + if (hires) + { + surface = gdk_cairo_surface_from_pixbuf (hires); + cairo_surface_set_device_scale (surface, sx, sy); + cairo_set_source_surface (cr, surface, pixbuf_x, pixbuf_y); + cairo_surface_destroy (surface); + return; + } + + cairo_get_matrix (cr, &m); + if (m.xx == 1 && m.yy == 1 && m.xy == 0 && m.yx == 0) + { + surface = gdk_cairo_surface_from_pixbuf (pixbuf); + cairo_set_source_surface (cr, surface, pixbuf_x, pixbuf_y); + cairo_pattern_set_filter (cairo_get_source (cr), CAIRO_FILTER_NEAREST); + cairo_surface_destroy (surface); + return; + } + } + } +#endif + + if (g_object_get_qdata (G_OBJECT (pixbuf), quark_shared)) + { + surface = g_object_get_qdata (G_OBJECT (pixbuf), quark_surface); + if (!surface) + { + surface = gdk_cairo_surface_from_pixbuf (pixbuf); + g_object_set_qdata_full (G_OBJECT (pixbuf), quark_surface, surface, + (GDestroyNotify) cairo_surface_destroy); + } + cairo_set_source_surface (cr, surface, pixbuf_x, pixbuf_y); + return; + } + + surface = gdk_cairo_surface_from_pixbuf (pixbuf); cairo_set_source_surface (cr, surface, pixbuf_x, pixbuf_y); cairo_surface_destroy (surface); } diff --git a/gdk/gdkcairo.h b/gdk/gdkcairo.h index 5bc952636..3d9822aef 100644 --- a/gdk/gdkcairo.h +++ b/gdk/gdkcairo.h @@ -31,6 +31,10 @@ G_BEGIN_DECLS cairo_t *gdk_cairo_create (GdkDrawable *drawable); + +/* private, for the theme engines of GTK+ */ +cairo_t *gdk_cairo_create_in_area_libgtk_only (GdkDrawable *drawable, + const GdkRectangle *area); void gdk_cairo_reset_clip (cairo_t *cr, GdkDrawable *drawable); diff --git a/gdk/gdkcolor.h b/gdk/gdkcolor.h index f2262bbeb..96ee023aa 100644 --- a/gdk/gdkcolor.h +++ b/gdk/gdkcolor.h @@ -86,7 +86,7 @@ struct _GdkColormapClass }; -GType gdk_colormap_get_type (void) G_GNUC_CONST; +GType gdk_colormap_get_type (void); GdkColormap* gdk_colormap_new (GdkVisual *visual, gboolean allocate); @@ -140,7 +140,7 @@ gboolean gdk_color_equal (const GdkColor *colora, const GdkColor *colorb); gchar * gdk_color_to_string (const GdkColor *color); -GType gdk_color_get_type (void) G_GNUC_CONST; +GType gdk_color_get_type (void); /* The following functions are deprecated */ #ifndef GDK_DISABLE_DEPRECATED diff --git a/gdk/gdkcursor.h b/gdk/gdkcursor.h index 5a9bbcb92..61c8db389 100644 --- a/gdk/gdkcursor.h +++ b/gdk/gdkcursor.h @@ -134,7 +134,7 @@ struct _GdkCursor /* Cursors */ -GType gdk_cursor_get_type (void) G_GNUC_CONST; +GType gdk_cursor_get_type (void); GdkCursor* gdk_cursor_new_for_display (GdkDisplay *display, GdkCursorType cursor_type); diff --git a/gdk/gdkdisplay.h b/gdk/gdkdisplay.h index fcc0ec9c4..1994b2691 100644 --- a/gdk/gdkdisplay.h +++ b/gdk/gdkdisplay.h @@ -138,7 +138,7 @@ struct _GdkDisplayPointerHooks gint *win_y); }; -GType gdk_display_get_type (void) G_GNUC_CONST; +GType gdk_display_get_type (void); GdkDisplay *gdk_display_open (const gchar *display_name); const gchar * gdk_display_get_name (GdkDisplay *display); diff --git a/gdk/gdkdisplaymanager.h b/gdk/gdkdisplaymanager.h index 02d1cf697..2d4cf99ee 100644 --- a/gdk/gdkdisplaymanager.h +++ b/gdk/gdkdisplaymanager.h @@ -54,7 +54,7 @@ struct _GdkDisplayManagerClass GdkDisplay *display); }; -GType gdk_display_manager_get_type (void) G_GNUC_CONST; +GType gdk_display_manager_get_type (void); GdkDisplayManager *gdk_display_manager_get (void); GdkDisplay * gdk_display_manager_get_default_display (GdkDisplayManager *display_manager); diff --git a/gdk/gdkdnd.h b/gdk/gdkdnd.h index 244169e68..f2fd1e3fe 100644 --- a/gdk/gdkdnd.h +++ b/gdk/gdkdnd.h @@ -103,7 +103,7 @@ struct _GdkDragContextClass { /* Drag and Drop */ -GType gdk_drag_context_get_type (void) G_GNUC_CONST; +GType gdk_drag_context_get_type (void); #if !defined (GDK_DISABLE_DEPRECATED) || defined (GDK_COMPILATION) GdkDragContext * gdk_drag_context_new (void); #endif diff --git a/gdk/gdkdraw.c b/gdk/gdkdraw.c index b6b0a5953..4d9073343 100644 --- a/gdk/gdkdraw.c +++ b/gdk/gdkdraw.c @@ -84,6 +84,13 @@ gdk_drawable_class_init (GdkDrawableClass *klass) klass->get_visible_region = gdk_drawable_real_get_visible_region; klass->draw_pixbuf = gdk_drawable_real_draw_pixbuf; klass->draw_drawable = gdk_drawable_real_draw_drawable; + + /* how theme engines built outside GTK+, which must load into other + * builds of GTK+ 2 too, find gdk_cairo_create_in_area_libgtk_only(): + * where this is not set they use gdk_cairo_create() */ + g_type_set_qdata (G_TYPE_FROM_CLASS (klass), + g_quark_from_static_string ("gdk-cairo-create-in-area"), + (gpointer) gdk_cairo_create_in_area_libgtk_only); } static void @@ -794,12 +801,6 @@ gdk_draw_image (GdkDrawable *drawable, * On older X servers, rendering pixbufs with an alpha channel involves round * trips to the X server, and may be somewhat slow. * - * If GDK is built with the Sun mediaLib library, the gdk_draw_pixbuf - * function is accelerated using mediaLib, which provides hardware - * acceleration on Intel, AMD, and Sparc chipsets. If desired, mediaLib - * support can be turned off by setting the GDK_DISABLE_MEDIALIB environment - * variable. - * * Since: 2.2 * * Deprecated: 2.22: Use gdk_cairo_set_source_pixbuf() and cairo_paint() or @@ -948,7 +949,7 @@ real_draw_glyphs (GdkDrawable *drawable, cairo_t *cr; cr = gdk_cairo_create (drawable); - _gdk_gc_update_context (gc, cr, NULL, NULL, TRUE, drawable); + _gdk_gc_update_context (gc, cr, NULL, NULL, TRUE, drawable, TRUE); if (matrix) { @@ -1078,7 +1079,7 @@ gdk_draw_trapezoids (GdkDrawable *drawable, g_return_if_fail (n_trapezoids == 0 || trapezoids != NULL); cr = gdk_cairo_create (drawable); - _gdk_gc_update_context (gc, cr, NULL, NULL, TRUE, drawable); + _gdk_gc_update_context (gc, cr, NULL, NULL, TRUE, drawable, TRUE); for (i = 0; i < n_trapezoids; i++) { @@ -1403,174 +1404,62 @@ composite (guchar *src_buf, } } -static void -composite_0888 (guchar *src_buf, - gint src_rowstride, - guchar *dest_buf, - gint dest_rowstride, - GdkByteOrder dest_byte_order, - gint width, - gint height) +/* Blends @pixbuf over the drawable piece by piece, in the drawable's + * own pixel format. Returns FALSE, having drawn nothing, where GdkRGB + * can't do that (palettes, gray levels, dithering). */ +static gboolean +composite_on_images (GdkDrawable *drawable, + GdkDrawable *real_drawable, + GdkGC *gc, + GdkPixbuf *pixbuf, + gint src_x, + gint src_y, + gint dest_x, + gint dest_y, + gint width, + gint height, + GdkRgbDither dither) { - guchar *src = src_buf; - guchar *dest = dest_buf; + GdkColormap *colormap = gdk_drawable_get_colormap (drawable); + guchar *pixels = gdk_pixbuf_get_pixels (pixbuf); + gint rowstride = gdk_pixbuf_get_rowstride (pixbuf); + gint x0, y0; - while (height--) + if (!colormap) + return FALSE; + + for (y0 = 0; y0 < height; y0 += GDK_SCRATCH_IMAGE_HEIGHT) { - gint twidth = width; - guchar *p = src; - guchar *q = dest; + gint height1 = MIN (height - y0, GDK_SCRATCH_IMAGE_HEIGHT); - if (dest_byte_order == GDK_LSB_FIRST) + for (x0 = 0; x0 < width; x0 += GDK_SCRATCH_IMAGE_WIDTH) { - while (twidth--) - { - guint t; + gint width1 = MIN (width - x0, GDK_SCRATCH_IMAGE_WIDTH); + gint xs0, ys0; + GdkImage *image; - t = p[3] * p[2] + (255 - p[3]) * q[0] + 0x80; - q[0] = (t + (t >> 8)) >> 8; - t = p[3] * p[1] + (255 - p[3]) * q[1] + 0x80; - q[1] = (t + (t >> 8)) >> 8; - t = p[3] * p[0] + (255 - p[3]) * q[2] + 0x80; - q[2] = (t + (t >> 8)) >> 8; - p += 4; - q += 4; - } + image = _gdk_image_get_scratch (gdk_drawable_get_screen (drawable), + width1, height1, + gdk_drawable_get_depth (drawable), &xs0, &ys0); + gdk_drawable_copy_to_image (drawable, image, + dest_x + x0, dest_y + y0, + xs0, ys0, + width1, height1); + + /* this fails for the first piece or for none */ + if (!_gdk_rgb_composite (colormap, image, xs0, ys0, width1, height1, + pixels + (src_y + y0) * rowstride + (src_x + x0) * 4, + rowstride, dither)) + return FALSE; + + gdk_draw_image (real_drawable, gc, image, + xs0, ys0, + dest_x + x0, dest_y + y0, + width1, height1); } - else - { - while (twidth--) - { - guint t; - - t = p[3] * p[0] + (255 - p[3]) * q[1] + 0x80; - q[1] = (t + (t >> 8)) >> 8; - t = p[3] * p[1] + (255 - p[3]) * q[2] + 0x80; - q[2] = (t + (t >> 8)) >> 8; - t = p[3] * p[2] + (255 - p[3]) * q[3] + 0x80; - q[3] = (t + (t >> 8)) >> 8; - p += 4; - q += 4; - } - } - - src += src_rowstride; - dest += dest_rowstride; } -} -#ifdef USE_MEDIALIB -static void -composite_0888_medialib (guchar *src_buf, - gint src_rowstride, - guchar *dest_buf, - gint dest_rowstride, - GdkByteOrder dest_byte_order, - gint width, - gint height) -{ - guchar *src = src_buf; - guchar *dest = dest_buf; - - mlib_image img_src, img_dst; - - mlib_ImageSetStruct (&img_dst, - MLIB_BYTE, - 4, - width, - height, - dest_rowstride, - dest_buf); - - mlib_ImageSetStruct (&img_src, - MLIB_BYTE, - 4, - width, - height, - src_rowstride, - src_buf); - - if (dest_byte_order == GDK_LSB_FIRST) - mlib_ImageBlendRGBA2BGRA (&img_dst, &img_src); - else - mlib_ImageBlendRGBA2ARGB (&img_dst, &img_src); -} -#endif - -static void -composite_565 (guchar *src_buf, - gint src_rowstride, - guchar *dest_buf, - gint dest_rowstride, - GdkByteOrder dest_byte_order, - gint width, - gint height) -{ - guchar *src = src_buf; - guchar *dest = dest_buf; - - while (height--) - { - gint twidth = width; - guchar *p = src; - gushort *q = (gushort *)dest; - - while (twidth--) - { - guchar a = p[3]; - guint tr, tg, tb; - guint tr1, tg1, tb1; - guint tmp = *q; - -#if 1 - /* This is fast, and corresponds to what composite() above does - * if we converted to 8-bit first. - */ - tr = (tmp & 0xf800); - tr1 = a * p[0] + (255 - a) * ((tr >> 8) + (tr >> 13)) + 0x80; - tg = (tmp & 0x07e0); - tg1 = a * p[1] + (255 - a) * ((tg >> 3) + (tg >> 9)) + 0x80; - tb = (tmp & 0x001f); - tb1 = a * p[2] + (255 - a) * ((tb << 3) + (tb >> 2)) + 0x80; - - *q = (((tr1 + (tr1 >> 8)) & 0xf800) | - (((tg1 + (tg1 >> 8)) & 0xfc00) >> 5) | - ((tb1 + (tb1 >> 8)) >> 11)); -#else - /* This version correspond to the result we get with XRENDER - - * a bit of precision is lost since we convert to 8 bit after premultiplying - * instead of at the end - */ - guint tr2, tg2, tb2; - guint tr3, tg3, tb3; - - tr = (tmp & 0xf800); - tr1 = (255 - a) * ((tr >> 8) + (tr >> 13)) + 0x80; - tr2 = a * p[0] + 0x80; - tr3 = ((tr1 + (tr1 >> 8)) >> 8) + ((tr2 + (tr2 >> 8)) >> 8); - - tg = (tmp & 0x07e0); - tg1 = (255 - a) * ((tg >> 3) + (tg >> 9)) + 0x80; - tg2 = a * p[0] + 0x80; - tg3 = ((tg1 + (tg1 >> 8)) >> 8) + ((tg2 + (tg2 >> 8)) >> 8); - - tb = (tmp & 0x001f); - tb1 = (255 - a) * ((tb << 3) + (tb >> 2)) + 0x80; - tb2 = a * p[0] + 0x80; - tb3 = ((tb1 + (tb1 >> 8)) >> 8) + ((tb2 + (tb2 >> 8)) >> 8); - - *q = (((tr3 & 0xf8) << 8) | - ((tg3 & 0xfc) << 3) | - ((tb3 >> 3))); -#endif - - p += 4; - q++; - } - - src += src_rowstride; - dest += dest_rowstride; - } + return TRUE; } /* Implementation of the old vfunc in terms of the new one @@ -1706,101 +1595,26 @@ gdk_drawable_real_draw_pixbuf (GdkDrawable *drawable, if (gdk_pixbuf_get_has_alpha (pixbuf)) { - GdkVisual *visual = gdk_drawable_get_visual (drawable); - void (*composite_func) (guchar *src_buf, - gint src_rowstride, - guchar *dest_buf, - gint dest_rowstride, - GdkByteOrder dest_byte_order, - gint width, - gint height) = NULL; + if (composite_on_images (drawable, real_drawable, gc, pixbuf, + src_x, src_y, dest_x, dest_y, width, height, dither)) + return; - /* First we see if we have a visual-specific composition function that can composite - * the pixbuf data directly onto the image + /* Palettes, gray levels, dithering: composite against the + * drawable as 24-bit RGB, and convert back. */ - if (visual) - { - gint bits_per_pixel = _gdk_windowing_get_bits_for_depth (gdk_drawable_get_display (drawable), - visual->depth); + composited = gdk_pixbuf_get_from_drawable (NULL, + drawable, + NULL, + dest_x, dest_y, + 0, 0, + width, height); - if (visual->byte_order == (G_BYTE_ORDER == G_BIG_ENDIAN ? GDK_MSB_FIRST : GDK_LSB_FIRST) && - visual->depth == 16 && - visual->red_mask == 0xf800 && - visual->green_mask == 0x07e0 && - visual->blue_mask == 0x001f) - composite_func = composite_565; - else if (visual->depth == 24 && bits_per_pixel == 32 && - visual->red_mask == 0xff0000 && - visual->green_mask == 0x00ff00 && - visual->blue_mask == 0x0000ff) - { -#ifdef USE_MEDIALIB - if (_gdk_use_medialib ()) - composite_func = composite_0888_medialib; - else - composite_func = composite_0888; -#else - composite_func = composite_0888; -#endif - } - } - - /* We can't use our composite func if we are required to dither - */ - if (composite_func && !(dither == GDK_RGB_DITHER_MAX && visual->depth != 24)) - { - gint x0, y0; - for (y0 = 0; y0 < height; y0 += GDK_SCRATCH_IMAGE_HEIGHT) - { - gint height1 = MIN (height - y0, GDK_SCRATCH_IMAGE_HEIGHT); - for (x0 = 0; x0 < width; x0 += GDK_SCRATCH_IMAGE_WIDTH) - { - gint xs0, ys0; - - gint width1 = MIN (width - x0, GDK_SCRATCH_IMAGE_WIDTH); - - GdkImage *image = _gdk_image_get_scratch (gdk_drawable_get_screen (drawable), - width1, height1, - gdk_drawable_get_depth (drawable), &xs0, &ys0); - - gdk_drawable_copy_to_image (drawable, image, - dest_x + x0, dest_y + y0, - xs0, ys0, - width1, height1); - (*composite_func) (gdk_pixbuf_get_pixels (pixbuf) + (src_y + y0) * gdk_pixbuf_get_rowstride (pixbuf) + (src_x + x0) * 4, - gdk_pixbuf_get_rowstride (pixbuf), - (guchar*)image->mem + ys0 * image->bpl + xs0 * image->bpp, - image->bpl, - visual->byte_order, - width1, height1); - gdk_draw_image (real_drawable, gc, image, - xs0, ys0, - dest_x + x0, dest_y + y0, - width1, height1); - } - } - - goto out; - } - else - { - /* No special composition func, convert dest to 24 bit RGB data, composite against - * that, and convert back. - */ - composited = gdk_pixbuf_get_from_drawable (NULL, - drawable, - NULL, - dest_x, dest_y, - 0, 0, - width, height); - - if (composited) - composite (gdk_pixbuf_get_pixels (pixbuf) + src_y * gdk_pixbuf_get_rowstride (pixbuf) + src_x * 4, - gdk_pixbuf_get_rowstride (pixbuf), - gdk_pixbuf_get_pixels (composited), - gdk_pixbuf_get_rowstride (composited), - width, height); - } + if (composited) + composite (gdk_pixbuf_get_pixels (pixbuf) + src_y * gdk_pixbuf_get_rowstride (pixbuf) + src_x * 4, + gdk_pixbuf_get_rowstride (pixbuf), + gdk_pixbuf_get_pixels (composited), + gdk_pixbuf_get_rowstride (composited), + width, height); } if (composited) @@ -1833,7 +1647,6 @@ gdk_drawable_real_draw_pixbuf (GdkDrawable *drawable, x_dither, y_dither); } - out: if (composited) g_object_unref (composited); } @@ -1975,5 +1788,30 @@ _gdk_drawable_create_cairo_surface (GdkDrawable *drawable, } +/* HiDPI: a pixbuf of GTK+ can carry one with as many more pixels as a + * scale (icons of the icon theme and the stock icons do); drawn on a + * drawable of that scale, its pixels are those of the X server */ +GdkPixbuf * +_gdk_pixbuf_get_hires (GdkPixbuf *pixbuf, + gint scale) +{ + gchar key[32]; + GdkPixbuf *hires; + + if (scale <= 1) + return NULL; + + g_snprintf (key, sizeof key, "gdk-pixbuf-hires-%d", scale); + hires = g_object_get_data (G_OBJECT (pixbuf), key); + if (hires && + gdk_pixbuf_get_width (hires) == gdk_pixbuf_get_width (pixbuf) * scale && + gdk_pixbuf_get_height (hires) == gdk_pixbuf_get_height (pixbuf) * scale && + gdk_pixbuf_get_n_channels (hires) == gdk_pixbuf_get_n_channels (pixbuf) && + gdk_pixbuf_get_has_alpha (hires) == gdk_pixbuf_get_has_alpha (pixbuf)) + return hires; + + return NULL; +} + #define __GDK_DRAW_C__ #include "gdkaliasdef.c" diff --git a/gdk/gdkdrawable.h b/gdk/gdkdrawable.h index 33bb95604..e06fd2751 100644 --- a/gdk/gdkdrawable.h +++ b/gdk/gdkdrawable.h @@ -236,7 +236,7 @@ struct _GdkTrapezoid double y1, x11, x21, y2, x12, x22; }; -GType gdk_drawable_get_type (void) G_GNUC_CONST; +GType gdk_drawable_get_type (void); /* Manipulation of drawables */ diff --git a/gdk/gdkenumtypes.h.template b/gdk/gdkenumtypes.h.template index 85487f47f..469b75147 100644 --- a/gdk/gdkenumtypes.h.template +++ b/gdk/gdkenumtypes.h.template @@ -17,7 +17,7 @@ G_BEGIN_DECLS /*** END file-production ***/ /*** BEGIN value-header ***/ -GType @enum_name@_get_type (void) G_GNUC_CONST; +GType @enum_name@_get_type (void); #define @ENUMPREFIX@_TYPE_@ENUMSHORT@ (@enum_name@_get_type ()) /*** END value-header ***/ diff --git a/gdk/gdkevents.c b/gdk/gdkevents.c index bd8598059..b47cc27e6 100644 --- a/gdk/gdkevents.c +++ b/gdk/gdkevents.c @@ -32,6 +32,10 @@ #include "gdkprivate.h" #include "gdkalias.h" +/* the touch event of GTK+ 3 fits in the GdkEvent of GTK+ 2, whose size + * is ABI: on LP64 88 bytes, on i386 68, on 32-bit Windows 72 */ +G_STATIC_ASSERT (sizeof (GdkEventTouch) <= sizeof (GdkEventCrossing)); + /* See gdkprivate.h for why this avoids g_memdup(). */ #if !GLIB_CHECK_VERSION (2, 68, 0) gpointer @@ -412,6 +416,15 @@ gdk_event_new (GdkEventType type) new_event->scroll.x_root = 0.; new_event->scroll.y_root = 0.; break; + case GDK_TOUCH_BEGIN: + case GDK_TOUCH_UPDATE: + case GDK_TOUCH_END: + case GDK_TOUCH_CANCEL: + new_event->touch.x = 0.; + new_event->touch.y = 0.; + new_event->touch.x_root = 0.; + new_event->touch.y_root = 0.; + break; case GDK_ENTER_NOTIFY: case GDK_LEAVE_NOTIFY: new_event->crossing.x = 0.; @@ -465,6 +478,11 @@ gdk_event_copy (const GdkEvent *event) GdkEventPrivate *private = (GdkEventPrivate *)event; new_private->screen = private->screen; + new_private->flags |= private->flags & (GDK_EVENT_POINTER_EMULATED | + GDK_EVENT_TOUCHPAD_EMULATED); + if (event->any.type == GDK_SCROLL && + event->scroll.direction == GDK_SCROLL_SMOOTH) + new_private->delta = private->delta; } switch (event->any.type) @@ -500,6 +518,8 @@ gdk_event_copy (const GdkEvent *event) break; case GDK_BUTTON_PRESS: + case GDK_2BUTTON_PRESS: + case GDK_3BUTTON_PRESS: case GDK_BUTTON_RELEASE: if (event->button.axes) new_event->button.axes = _gdk_memdup2 (event->button.axes, @@ -559,10 +579,13 @@ gdk_event_free (GdkEvent *event) case GDK_DRAG_STATUS: case GDK_DROP_START: case GDK_DROP_FINISHED: - g_object_unref (event->dnd.context); + if (event->dnd.context != NULL) + g_object_unref (event->dnd.context); break; case GDK_BUTTON_PRESS: + case GDK_2BUTTON_PRESS: + case GDK_3BUTTON_PRESS: case GDK_BUTTON_RELEASE: g_free (event->button.axes); break; @@ -615,6 +638,11 @@ gdk_event_get_time (const GdkEvent *event) return event->button.time; case GDK_SCROLL: return event->scroll.time; + case GDK_TOUCH_BEGIN: + case GDK_TOUCH_UPDATE: + case GDK_TOUCH_END: + case GDK_TOUCH_CANCEL: + return event->touch.time; case GDK_KEY_PRESS: case GDK_KEY_RELEASE: return event->key.time; @@ -694,6 +722,12 @@ gdk_event_get_state (const GdkEvent *event, case GDK_SCROLL: *state = event->scroll.state; return TRUE; + case GDK_TOUCH_BEGIN: + case GDK_TOUCH_UPDATE: + case GDK_TOUCH_END: + case GDK_TOUCH_CANCEL: + *state = event->touch.state; + return TRUE; case GDK_KEY_PRESS: case GDK_KEY_RELEASE: *state = event->key.state; @@ -703,8 +737,6 @@ gdk_event_get_state (const GdkEvent *event, *state = event->crossing.state; return TRUE; case GDK_PROPERTY_NOTIFY: - *state = event->property.state; - return TRUE; case GDK_VISIBILITY_NOTIFY: case GDK_CLIENT_EVENT: case GDK_NO_EXPOSE: @@ -776,6 +808,13 @@ gdk_event_get_coords (const GdkEvent *event, x = event->scroll.x; y = event->scroll.y; break; + case GDK_TOUCH_BEGIN: + case GDK_TOUCH_UPDATE: + case GDK_TOUCH_END: + case GDK_TOUCH_CANCEL: + x = event->touch.x; + y = event->touch.y; + break; case GDK_BUTTON_PRESS: case GDK_2BUTTON_PRESS: case GDK_3BUTTON_PRESS: @@ -830,6 +869,13 @@ gdk_event_get_root_coords (const GdkEvent *event, x = event->scroll.x_root; y = event->scroll.y_root; break; + case GDK_TOUCH_BEGIN: + case GDK_TOUCH_UPDATE: + case GDK_TOUCH_END: + case GDK_TOUCH_CANCEL: + x = event->touch.x_root; + y = event->touch.y_root; + break; case GDK_BUTTON_PRESS: case GDK_2BUTTON_PRESS: case GDK_3BUTTON_PRESS: @@ -1034,6 +1080,354 @@ gdk_event_get_screen (const GdkEvent *event) return NULL; } +/** + * gdk_event_get_scroll_deltas: + * @event: a #GdkEvent + * @delta_x: (out): return location for the steps to the right + * @delta_y: (out): return location for the steps down + * + * Gets how far a %GDK_SCROLL_SMOOTH event scrolls, in steps of a + * mouse wheel: high resolution wheels and touchpads give fractions. + * On Quartz, trackpads give pixels, as in GTK+ 3. + * The same movement also arrives as ordinary scroll events, one per + * whole step, which gdk_event_get_pointer_emulated() tells apart. + * + * Return value: %TRUE if @event is a smooth scroll event + * + * Since: 2.24 + **/ +gboolean +gdk_event_get_scroll_deltas (const GdkEvent *event, + gdouble *delta_x, + gdouble *delta_y) +{ + const GdkEventPrivate *private = (const GdkEventPrivate *) event; + + if (!event || event->type != GDK_SCROLL || + event->scroll.direction != GDK_SCROLL_SMOOTH || + !gdk_event_is_allocated (event)) + return FALSE; + + if (delta_x) + *delta_x = private->delta.x; + if (delta_y) + *delta_y = private->delta.y; + + return TRUE; +} + +/** + * gdk_event_get_event_sequence: + * @event: a #GdkEvent + * + * If @event is a touch event, returns the #GdkEventSequence to which + * the event belongs, as in GTK+ 3.4. Otherwise, return %NULL. + * + * Returns: (transfer none): the event sequence that the event belongs to + * + * Since: 2.24 + **/ +GdkEventSequence * +gdk_event_get_event_sequence (const GdkEvent *event) +{ + if (!event) + return NULL; + + if (event->type == GDK_TOUCH_BEGIN || + event->type == GDK_TOUCH_UPDATE || + event->type == GDK_TOUCH_END || + event->type == GDK_TOUCH_CANCEL) + return event->touch.sequence; + + return NULL; +} + +/** + * gdk_event_get_pointer_emulated: + * @event: a #GdkEvent + * + * Tells whether a scroll event of a whole wheel step repeats what a + * %GDK_SCROLL_SMOOTH event has already given; whoever handles the + * smooth events ignores these. + * + * Return value: %TRUE if the event is emulated + * + * Since: 2.24 + **/ +gboolean +gdk_event_get_pointer_emulated (GdkEvent *event) +{ + return event && gdk_event_is_allocated (event) && + (((GdkEventPrivate *) event)->flags & GDK_EVENT_POINTER_EMULATED) != 0; +} + +/** + * gdk_event_get_touchpad_emulated: + * @event: a #GdkEvent + * + * Tells whether @event was made of a gesture on a touchpad, for + * programs that know nothing of those: a pinch arrives as scroll + * events up (larger) and down (smaller) with %GDK_CONTROL_MASK, which + * most programs that zoom take for zooming; a swipe sideways arrives + * as a press and release of button 8 (back, swiping to the right) or + * 9 (forward). GTK+'s own widgets do not scroll on such a pinch. + * + * Return value: %TRUE if the event was made of a touchpad gesture + * + * Since: 2.24 + **/ +gboolean +gdk_event_get_touchpad_emulated (GdkEvent *event) +{ + return event && gdk_event_is_allocated (event) && + (((GdkEventPrivate *) event)->flags & GDK_EVENT_TOUCHPAD_EMULATED) != 0; +} + +/* Touchpad gestures, as Windows hands them to its old programs: a + * pinch is the wheel with Ctrl, one step for each 15 % the fingers + * spread or close (up for larger, as browsers and image programs zoom + * in then); a swipe sideways is the back or forward button. Nothing + * is made unless a gesture comes. */ +#define TOUCHPAD_PINCH_STEP 0.14 /* ln 1.15 */ + +static GdkEvent * +touchpad_event (const GdkEvent *template_event, + GdkEventType type) +{ + GdkEvent *event = gdk_event_new (type); + GdkEventPrivate *private = (GdkEventPrivate *) event; + + if (type == GDK_SCROLL) + { + event->scroll = template_event->scroll; + event->scroll.type = GDK_SCROLL; + event->scroll.state |= GDK_CONTROL_MASK; + } + else + { + event->button.type = type; + event->button.send_event = template_event->scroll.send_event; + event->button.time = template_event->scroll.time; + event->button.x = template_event->scroll.x; + event->button.y = template_event->scroll.y; + event->button.x_root = template_event->scroll.x_root; + event->button.y_root = template_event->scroll.y_root; + event->button.state = template_event->scroll.state; + event->button.device = template_event->scroll.device; + event->button.axes = NULL; + } + + event->any.window = template_event->any.window; + if (event->any.window) + g_object_ref (event->any.window); + if (gdk_event_is_allocated (template_event)) + gdk_event_set_screen (event, ((GdkEventPrivate *) template_event)->screen); + private->flags |= GDK_EVENT_TOUCHPAD_EMULATED; + + return event; +} + +/* The scroll steps of a pinch whose scale changed by @log_scale (its + * logarithm) since the last call; @rest keeps what makes no whole step + * yet, 0 when a pinch begins. @template_event is a scroll event with + * window, time, place, state and device. */ +GList * +_gdk_event_touchpad_pinch (const GdkEvent *template_event, + gdouble log_scale, + gdouble *rest) +{ + GList *events = NULL; + gint n; + + /* turning the other way starts afresh */ + if (log_scale * *rest < 0) + *rest = 0; + *rest += log_scale; + + n = (gint) CLAMP (*rest / TOUCHPAD_PINCH_STEP, -16, 16); + *rest -= n * TOUCHPAD_PINCH_STEP; + + for (; n != 0; n += n > 0 ? -1 : 1) + { + GdkEvent *event = touchpad_event (template_event, GDK_SCROLL); + + event->scroll.direction = n > 0 ? GDK_SCROLL_UP : GDK_SCROLL_DOWN; + events = g_list_prepend (events, event); + } + + return g_list_reverse (events); +} + +/* The press and release of the back button (8) for a swipe of @dx > 0 + * (to the right) or the forward button (9) for @dx < 0 */ +GList * +_gdk_event_touchpad_swipe (const GdkEvent *template_event, + gdouble dx) +{ + GdkEvent *press, *release; + guint button = dx > 0 ? 8 : 9; + + if (dx == 0) + return NULL; + + press = touchpad_event (template_event, GDK_BUTTON_PRESS); + press->button.button = button; + release = touchpad_event (template_event, GDK_BUTTON_RELEASE); + release->button.button = button; + /* buttons past 5 have no bit in the state */ + + return g_list_append (g_list_append (NULL, press), release); +} + +/* GDK makes smooth scroll events only for GTK+'s event handler, which + * knows who can take them; libgtk leaves it here when it sets it. A + * program with a handler of its own sees what it always saw. */ +gboolean +_gdk_event_handler_takes_smooth (void) +{ + static GQuark quark; + + if (!quark) + quark = g_quark_from_static_string ("gdk-smooth-scroll-handler"); + + return _gdk_event_func != NULL && + (gpointer) _gdk_event_func == g_object_get_qdata (G_OBJECT (gdk_display_manager_get ()), quark); +} + +/* Whether any window has asked for GDK_SMOOTH_SCROLL_MASK: then smooth + * scroll events are made for other event handlers than that of GTK+ + * as well, and gdk_window's event routing gives them only to those + * windows (see _gdk_event_scroll_for_window()) */ +static gboolean smooth_scroll_wanted; + +void +_gdk_event_note_event_mask (GdkEventMask mask) +{ + if (mask & GDK_SMOOTH_SCROLL_MASK) + smooth_scroll_wanted = TRUE; +} + +/* Whether smooth scroll events are to be made at all */ +gboolean +_gdk_event_smooth_scroll_wanted (void) +{ + return smooth_scroll_wanted || _gdk_event_handler_takes_smooth (); +} + +/* Whether the scroll event @event goes to @window: a window with + * GDK_SMOOTH_SCROLL_MASK takes the smooth events and not the whole + * steps made of them, others the other way round. The event handler + * of GTK+ gets them all and sorts them out per widget (gtkmain.c), + * as GTK+'s own scrolled windows take smooth events too. */ +gboolean +_gdk_event_scroll_for_window (GdkEvent *event, + GdkWindow *window) +{ + gboolean smooth_window; + + if (event->type != GDK_SCROLL || _gdk_event_handler_takes_smooth ()) + return TRUE; + + smooth_window = (gdk_window_get_events (window) & GDK_SMOOTH_SCROLL_MASK) != 0; + if (event->scroll.direction == GDK_SCROLL_SMOOTH) + return smooth_window; + return !(smooth_window && gdk_event_get_pointer_emulated (event)); +} + +void +_gdk_event_set_scroll_deltas (GdkEvent *event, + gdouble delta_x, + gdouble delta_y) +{ + GdkEventPrivate *private = (GdkEventPrivate *) event; + + event->scroll.direction = GDK_SCROLL_SMOOTH; + private->delta.x = delta_x; + private->delta.y = delta_y; +} + +static GdkEvent * +scroll_event_from (GdkEvent **first, + const GdkEvent *template_event) +{ + GdkEvent *event = *first ? *first : gdk_event_new (GDK_SCROLL); + + *first = NULL; + event->scroll = template_event->scroll; + event->scroll.type = GDK_SCROLL; + + return event; +} + +/* For backends whose system tells how far to scroll: makes of + * @template_event (a scroll event but for the direction) a smooth + * event of @delta_x, @delta_y if asked and GTK+ takes those, and the + * whole steps of the wheel that @steps_x, @steps_y complete in @rest, + * marked as emulated when the smooth event goes out as well. The + * first event made goes into @first if there is one, the others to + * @append, which takes their references. Returns whether any event + * was made. */ +gboolean +_gdk_event_emit_scroll (GdkEvent *first, + const GdkEvent *template_event, + gboolean smooth, + gdouble delta_x, + gdouble delta_y, + gdouble steps_x, + gdouble steps_y, + gdouble rest[2], + void (*append) (GdkEvent *event)) +{ + static const GdkScrollDirection direction[2][2] = { + { GDK_SCROLL_LEFT, GDK_SCROLL_RIGHT }, + { GDK_SCROLL_UP, GDK_SCROLL_DOWN } + }; + gdouble steps[2]; + gboolean made = FALSE; + gint a, n; + + steps[0] = steps_x; + steps[1] = steps_y; + + if (smooth && (delta_x != 0 || delta_y != 0) && _gdk_event_smooth_scroll_wanted ()) + { + gboolean into_first = first != NULL; + GdkEvent *event = scroll_event_from (&first, template_event); + + _gdk_event_set_scroll_deltas (event, delta_x, delta_y); + if (!into_first) + append (event); + made = TRUE; + } + else + smooth = FALSE; + + for (a = 0; a < 2; a++) + { + /* turning the other way starts afresh */ + if (steps[a] * rest[a] < 0) + rest[a] = 0; + rest[a] += steps[a]; + n = (gint) CLAMP (rest[a] + (rest[a] > 0 ? 1e-9 : -1e-9), -64, 64); + rest[a] -= n; + + for (; n != 0; n += n > 0 ? -1 : 1) + { + gboolean into_first = first != NULL; + GdkEvent *event = scroll_event_from (&first, template_event); + + event->scroll.direction = direction[a][n > 0]; + if (smooth) + ((GdkEventPrivate *) event)->flags |= GDK_EVENT_POINTER_EMULATED; + if (!into_first) + append (event); + made = TRUE; + } + } + + return made; +} + /** * gdk_set_show_events: * @show_events: %TRUE to output event debugging information. diff --git a/gdk/gdkevents.h b/gdk/gdkevents.h index 707700cbb..76320db02 100644 --- a/gdk/gdkevents.h +++ b/gdk/gdkevents.h @@ -64,6 +64,8 @@ typedef struct _GdkEventDND GdkEventDND; typedef struct _GdkEventWindowState GdkEventWindowState; typedef struct _GdkEventSetting GdkEventSetting; typedef struct _GdkEventGrabBroken GdkEventGrabBroken; +typedef struct _GdkEventTouch GdkEventTouch; +typedef struct _GdkEventSequence GdkEventSequence; typedef union _GdkEvent GdkEvent; @@ -152,6 +154,11 @@ typedef enum GDK_OWNER_CHANGE = 34, GDK_GRAB_BROKEN = 35, GDK_DAMAGE = 36, + /* as in GTK+ 3.4, for windows with GDK_TOUCH_MASK */ + GDK_TOUCH_BEGIN = 37, + GDK_TOUCH_UPDATE = 38, + GDK_TOUCH_END = 39, + GDK_TOUCH_CANCEL = 40, GDK_EVENT_LAST /* helper variable for decls */ } GdkEventType; @@ -181,9 +188,25 @@ typedef enum GDK_PROXIMITY_OUT_MASK = 1 << 19, GDK_SUBSTRUCTURE_MASK = 1 << 20, GDK_SCROLL_MASK = 1 << 21, + /* as in GTK+ 3.4: the events of the fingers on a touch screen, + * GDK_TOUCH_BEGIN to GDK_TOUCH_CANCEL; GDK makes pointer events of + * the first finger for the windows that did not ask (see + * gdk_event_get_pointer_emulated()). Not in GDK_ALL_EVENTS_MASK: a + * program that does not ask keeps getting a touch as the pointer. */ + GDK_TOUCH_MASK = 1 << 22, + /* as in GTK+ 3.4: %GDK_SCROLL_SMOOTH events with the distance (see + * gdk_event_get_scroll_deltas()), and none of the whole wheel steps + * made of them; not part of GDK_ALL_EVENTS_MASK, which old programs + * use and which keeps the steps for them */ + GDK_SMOOTH_SCROLL_MASK = 1 << 23, GDK_ALL_EVENTS_MASK = 0x3FFFFE } GdkEventMask; +/* so that programs can ask with #ifdef whether GDK has it (GTK+ 2 from + * gtk2-ng; GTK+ 3 has it from 3.4 on) */ +#define GDK_SMOOTH_SCROLL_MASK GDK_SMOOTH_SCROLL_MASK +#define GDK_TOUCH_MASK GDK_TOUCH_MASK + typedef enum { GDK_VISIBILITY_UNOBSCURED, @@ -196,7 +219,8 @@ typedef enum GDK_SCROLL_UP, GDK_SCROLL_DOWN, GDK_SCROLL_LEFT, - GDK_SCROLL_RIGHT + GDK_SCROLL_RIGHT, + GDK_SCROLL_SMOOTH } GdkScrollDirection; /* Types of enter/leave notifications. @@ -488,6 +512,47 @@ struct _GdkEventDND { gshort x_root, y_root; }; +/** + * GdkEventTouch: + * @type: the type of the event (%GDK_TOUCH_BEGIN, %GDK_TOUCH_UPDATE, + * %GDK_TOUCH_END, %GDK_TOUCH_CANCEL) + * @window: the window which received the event + * @send_event: %TRUE if the event was sent explicitly + * @time: the time of the event in milliseconds + * @x: the x coordinate of the touch relative to the window + * @y: the y coordinate of the touch relative to the window + * @axes: %NULL + * @state: the modifier keys + * @emulating_pointer: whether the event is the one of the finger that + * also moves the pointer (the first one) + * @sequence: what tells the touches of the fingers apart; the same + * for all events of one finger, from begin to end + * @device: the device where the event originated + * @x_root: the x coordinate of the touch relative to the root of the screen + * @y_root: the y coordinate of the touch relative to the root of the screen + * + * A touch on a touch screen, as in GTK+ 3.4, with the same fields; + * @emulating_pointer comes before @sequence here, so that the event + * fits in the GdkEvent of GTK+ 2. + * + * Since: 2.24 + */ +struct _GdkEventTouch +{ + GdkEventType type; + GdkWindow *window; + gint8 send_event; + guint32 time; + gdouble x; + gdouble y; + gdouble *axes; + guint state; + gboolean emulating_pointer; + GdkEventSequence *sequence; + GdkDevice *device; + gdouble x_root, y_root; +}; + union _GdkEvent { GdkEventType type; @@ -511,9 +576,10 @@ union _GdkEvent GdkEventWindowState window_state; GdkEventSetting setting; GdkEventGrabBroken grab_broken; + GdkEventTouch touch; }; -GType gdk_event_get_type (void) G_GNUC_CONST; +GType gdk_event_get_type (void); gboolean gdk_events_pending (void); GdkEvent* gdk_event_get (void); @@ -549,6 +615,13 @@ void gdk_event_set_screen (GdkEvent *event, GdkScreen *screen); GdkScreen *gdk_event_get_screen (const GdkEvent *event); +gboolean gdk_event_get_scroll_deltas (const GdkEvent *event, + gdouble *delta_x, + gdouble *delta_y); +gboolean gdk_event_get_pointer_emulated (GdkEvent *event); +gboolean gdk_event_get_touchpad_emulated (GdkEvent *event); +GdkEventSequence *gdk_event_get_event_sequence (const GdkEvent *event); + void gdk_set_show_events (gboolean show_events); gboolean gdk_get_show_events (void); diff --git a/gdk/gdkfont.h b/gdk/gdkfont.h index 71f1e9c77..26d4235e9 100644 --- a/gdk/gdkfont.h +++ b/gdk/gdkfont.h @@ -53,7 +53,7 @@ struct _GdkFont gint descent; }; -GType gdk_font_get_type (void) G_GNUC_CONST; +GType gdk_font_get_type (void); GdkFont* gdk_font_ref (GdkFont *font); void gdk_font_unref (GdkFont *font); diff --git a/gdk/gdkgc.c b/gdk/gdkgc.c index 3cb2a7b0e..5f78aaed7 100644 --- a/gdk/gdkgc.c +++ b/gdk/gdkgc.c @@ -61,6 +61,9 @@ struct _GdkGCPrivate guint subwindow_mode : 1; guint fill : 2; guint exposures : 2; + /* the clip of a window stays on after a drawing, see + * _gdk_gc_set_draw_origins() */ + guint drawable_clip_kept : 1; }; #define GDK_GC_GET_PRIVATE(o) ((GdkGCPrivate *) gdk_gc_get_instance_private (GDK_GC (o))) @@ -758,11 +761,66 @@ _gdk_gc_add_drawable_clip (GdkGC *gc, priv->region_tag_offset_y = offset_y; } +/* For drawing to a window inside the paint of a parent: moves the clip + * and tile origins of @gc there for the drawing, and back after it + * (@drawing_done), without taking off the clip of the window that + * _gdk_gc_add_drawable_clip() puts on, as setting the clip origin does. + * That clip is relative to the clip origin of the caller, which these + * moves keep, so the next drawing to the window finds it still in + * place, instead of making it anew and sending it to the X server. + * + * Where a GC is used for drawing directly by the caller, with + * gdk_x11_gc_get_xgc(), the clip of the window is taken off first, as + * it was before. Other backends set the clip of a GC for each drawing + * themselves, from the same region the raw drawing functions use, so + * the clip of the window is taken off after a drawing there. */ +void +_gdk_gc_set_draw_origins (GdkGC *gc, + gint clip_x, + gint clip_y, + gint ts_x, + gint ts_y, + gboolean drawing_done) +{ + GdkGCPrivate *priv = GDK_GC_GET_PRIVATE (gc); + GdkGCValues values; + +#ifndef GDK_WINDOWING_X11 + if (drawing_done) + { + gdk_gc_set_clip_origin (gc, clip_x, clip_y); + gdk_gc_set_ts_origin (gc, ts_x, ts_y); + return; + } +#endif + + priv->drawable_clip_kept = drawing_done && priv->region_tag_applied != 0; + + gc->clip_x_origin = values.clip_x_origin = clip_x; + gc->clip_y_origin = values.clip_y_origin = clip_y; + gc->ts_x_origin = values.ts_x_origin = ts_x; + gc->ts_y_origin = values.ts_y_origin = ts_y; + + GDK_GC_GET_CLASS (gc)->set_values (gc, &values, + GDK_GC_CLIP_X_ORIGIN | GDK_GC_CLIP_Y_ORIGIN | + GDK_GC_TS_X_ORIGIN | GDK_GC_TS_Y_ORIGIN); +} + +/* Takes off a clip of a window that _gdk_gc_set_draw_origins() left on */ +void +_gdk_gc_remove_kept_drawable_clip (GdkGC *gc) +{ + if (GDK_GC_GET_PRIVATE (gc)->drawable_clip_kept) + _gdk_gc_remove_drawable_clip (gc); +} + void _gdk_gc_remove_drawable_clip (GdkGC *gc) { GdkGCPrivate *priv = GDK_GC_GET_PRIVATE (gc); + priv->drawable_clip_kept = FALSE; + if (priv->region_tag_applied) { priv->region_tag_applied = 0; @@ -1194,6 +1252,7 @@ gdk_gc_copy (GdkGC *dst_gc, dst_priv->clip_region = NULL; dst_priv->region_tag_applied = src_priv->region_tag_applied; + dst_priv->drawable_clip_kept = src_priv->drawable_clip_kept; if (dst_priv->old_clip_region) gdk_region_destroy (dst_priv->old_clip_region); @@ -1453,6 +1512,8 @@ gc_get_background (GdkGC *gc, * last call to this function * @target_drawable: The drawable you're drawing in. If passed in * this is used for client side window clip emulation. + * @cr_is_new: %TRUE if @cr comes straight from gdk_cairo_create() + * on @target_drawable, which has set the window clip already * * Set the attributes of a cairo context to match those of a #GdkGC * as far as possible. Some aspects of a #GdkGC, such as clip masks @@ -1464,7 +1525,8 @@ _gdk_gc_update_context (GdkGC *gc, const GdkColor *override_foreground, GdkBitmap *override_stipple, gboolean gc_changed, - GdkDrawable *target_drawable) + GdkDrawable *target_drawable, + gboolean cr_is_new) { GdkGCPrivate *priv; GdkFill fill; @@ -1570,10 +1632,15 @@ _gdk_gc_update_context (GdkGC *gc, if (!gc_changed) return; - cairo_reset_clip (cr); - /* The reset above resets the window clip rect, so we want to re-set that */ - if (target_drawable && GDK_DRAWABLE_GET_CLASS (target_drawable)->set_cairo_clip) - GDK_DRAWABLE_GET_CLASS (target_drawable)->set_cairo_clip (target_drawable, cr); + /* a new context has the window clip and no other: building the + * window clip again from its region is work for nothing */ + if (!cr_is_new) + { + cairo_reset_clip (cr); + /* The reset above resets the window clip rect, so we want to re-set that */ + if (target_drawable && GDK_DRAWABLE_GET_CLASS (target_drawable)->set_cairo_clip) + GDK_DRAWABLE_GET_CLASS (target_drawable)->set_cairo_clip (target_drawable, cr); + } if (priv->clip_region) { diff --git a/gdk/gdkgc.h b/gdk/gdkgc.h index 360ae44f6..bb3e9dc6f 100644 --- a/gdk/gdkgc.h +++ b/gdk/gdkgc.h @@ -221,7 +221,7 @@ struct _GdkGCClass #ifndef GDK_DISABLE_DEPRECATED -GType gdk_gc_get_type (void) G_GNUC_CONST; +GType gdk_gc_get_type (void); GdkGC *gdk_gc_new (GdkDrawable *drawable); GdkGC *gdk_gc_new_with_values (GdkDrawable *drawable, GdkGCValues *values, diff --git a/gdk/gdkimage.c b/gdk/gdkimage.c index 0c46aa142..146da4e1c 100644 --- a/gdk/gdkimage.c +++ b/gdk/gdkimage.c @@ -655,5 +655,66 @@ gdk_image_new (GdkImageType type, visual, width, height, -1); } +/** + * _gdk_image_read_row: + * @image: a #GdkImage + * @x: the first pixel + * @y: the row + * @width: how many pixels + * @pixels: where to put the pixel values + * + * Reads pixel values of any number of bits per pixel and either byte + * order; for less than 8 bits, the byte order is the order of the + * pixels in a byte, too. + */ +void +_gdk_image_read_row (GdkImage *image, + gint x, + gint y, + gint width, + guint32 *pixels) +{ + const guchar *in = (const guchar *) image->mem + y * image->bpl; + const gboolean msb = image->byte_order == GDK_MSB_FIRST; + const gint bits = image->bits_per_pixel; + gint i; + + if (bits < 8) + { + const guint mask = (1 << bits) - 1; + + for (i = 0; i < width; i++) + { + const gint bit = (x + i) * bits; + + pixels[i] = (in[bit >> 3] >> (msb ? 8 - bits - (bit & 7) : bit & 7)) & mask; + } + return; + } + + in += x * (bits / 8); + switch (bits) + { + case 8: + for (i = 0; i < width; i++) + pixels[i] = in[i]; + break; + case 16: + for (i = 0; i < width; i++, in += 2) + pixels[i] = msb ? (in[0] << 8) | in[1] : in[0] | (in[1] << 8); + break; + case 24: + for (i = 0; i < width; i++, in += 3) + pixels[i] = msb ? (in[0] << 16) | (in[1] << 8) | in[2] + : in[0] | (in[1] << 8) | (in[2] << 16); + break; + case 32: + for (i = 0; i < width; i++, in += 4) + pixels[i] = msb ? ((guint32) in[0] << 24) | (in[1] << 16) | (in[2] << 8) | in[3] + : in[0] | (in[1] << 8) | (in[2] << 16) | ((guint32) in[3] << 24); + break; + } +} + #define __GDK_IMAGE_C__ #include "gdkaliasdef.c" diff --git a/gdk/gdkimage.h b/gdk/gdkimage.h index cd9631090..a6d2e7c72 100644 --- a/gdk/gdkimage.h +++ b/gdk/gdkimage.h @@ -90,7 +90,7 @@ struct _GdkImageClass GObjectClass parent_class; }; -GType gdk_image_get_type (void) G_GNUC_CONST; +GType gdk_image_get_type (void); #ifndef GDK_DISABLE_DEPRECATED GdkImage* gdk_image_new (GdkImageType type, diff --git a/gdk/gdkinput.h b/gdk/gdkinput.h index 41e348eac..3d2032cde 100644 --- a/gdk/gdkinput.h +++ b/gdk/gdkinput.h @@ -123,7 +123,7 @@ struct _GdkTimeCoord gdouble axes[GDK_MAX_TIMECOORD_AXES]; }; -GType gdk_device_get_type (void) G_GNUC_CONST; +GType gdk_device_get_type (void); #ifndef GDK_MULTIHEAD_SAFE /* Returns a list of GdkDevice * */ diff --git a/gdk/gdkinternals.h b/gdk/gdkinternals.h index 4f6ea7e5f..f3b234fe8 100644 --- a/gdk/gdkinternals.h +++ b/gdk/gdkinternals.h @@ -33,9 +33,6 @@ #include #include #include -#ifdef USE_MEDIALIB -#include -#endif G_BEGIN_DECLS @@ -166,7 +163,19 @@ typedef enum /* Following flag is set for events on the event queue during * translation and cleared afterwards. */ - GDK_EVENT_PENDING = 1 << 0 + GDK_EVENT_PENDING = 1 << 0, + + /* A scroll event from a wheel step that a smooth scroll event with + * the same time has already given */ + GDK_EVENT_POINTER_EMULATED = 1 << 1, + + /* A touch for which the window system sends the pointer events of + * the first finger itself (Windows), so GDK need not make them */ + GDK_EVENT_TOUCH_SYSTEM_POINTER = 1 << 2, + + /* A scroll or button event made of a touchpad gesture for programs + * that know nothing of those (gdk_event_get_touchpad_emulated()) */ + GDK_EVENT_TOUCHPAD_EMULATED = 1 << 3 } GdkEventFlags; struct _GdkEventPrivate @@ -174,7 +183,16 @@ struct _GdkEventPrivate GdkEvent event; guint flags; GdkScreen *screen; - gpointer windowing_data; +#ifdef GDK_WINDOWING_QUARTZ + gpointer windowing_data; /* the NSEvent */ +#endif + /* the steps of a GDK_SCROLL_SMOOTH event, where elsewhere a + * windowing_data pointer nobody used was */ + struct + { + gfloat x; + gfloat y; + } delta; }; /* Tracks information about the pointer grab on this display */ @@ -291,6 +309,30 @@ extern GdkEventFunc _gdk_event_func; /* Callback for events */ extern gpointer _gdk_event_data; extern GDestroyNotify _gdk_event_notify; +gboolean _gdk_event_handler_takes_smooth (void); +gboolean _gdk_event_smooth_scroll_wanted (void); + +GList *_gdk_event_touchpad_pinch (const GdkEvent *template_event, + gdouble log_scale, + gdouble *rest); +GList *_gdk_event_touchpad_swipe (const GdkEvent *template_event, + gdouble dx); +void _gdk_event_note_event_mask (GdkEventMask mask); +gboolean _gdk_event_scroll_for_window (GdkEvent *event, + GdkWindow *window); +void _gdk_event_set_scroll_deltas (GdkEvent *event, + gdouble delta_x, + gdouble delta_y); +gboolean _gdk_event_emit_scroll (GdkEvent *first, + const GdkEvent *template_event, + gboolean smooth, + gdouble delta_x, + gdouble delta_y, + gdouble steps_x, + gdouble steps_y, + gdouble rest[2], + void (*append) (GdkEvent *event)); + extern GSList *_gdk_displays; extern gchar *_gdk_display_name; extern gint _gdk_screen_number; @@ -335,6 +377,11 @@ GdkImage* _gdk_image_new_for_depth (GdkScreen *screen, gint width, gint height, gint depth); +void _gdk_image_read_row (GdkImage *image, + gint x, + gint y, + gint width, + guint32 *pixels); GdkImage *_gdk_image_get_scratch (GdkScreen *screen, gint width, gint height, @@ -361,14 +408,36 @@ cairo_surface_t * _gdk_drawable_create_cairo_surface (GdkDrawable *drawable, /* GC caching */ GdkGC *_gdk_drawable_get_scratch_gc (GdkDrawable *drawable, gboolean graphics_exposures); + GdkGC *_gdk_drawable_get_subwindow_scratch_gc (GdkDrawable *drawable); +/* GdkRGB */ +gboolean _gdk_rgb_composite (GdkColormap *colormap, + GdkImage *image, + gint x0, + gint y0, + gint width, + gint height, + const guchar *rgba, + gint rowstride, + GdkRgbDither dither); +gboolean _gdk_rgb_prefers_own_blending (GdkColormap *colormap, + GdkRgbDither dither); + +gint _gdk_window_get_cairo_clip_n_rects (GdkWindow *window); +void _gdk_window_set_cairo_clip_in_area (GdkWindow *window, + cairo_t *cr, + const GdkRectangle *area); +cairo_t *_gdk_cairo_create_in_area (GdkDrawable *drawable, + const GdkRectangle *area); + void _gdk_gc_update_context (GdkGC *gc, cairo_t *cr, const GdkColor *override_foreground, GdkBitmap *override_stipple, gboolean gc_changed, - GdkDrawable *target_drawable); + GdkDrawable *target_drawable, + gboolean cr_is_new); /************************************* * Interfaces used by windowing code * @@ -429,6 +498,13 @@ void _gdk_gc_add_drawable_clip (GdkGC *gc, int offset_x, int offset_y); void _gdk_gc_remove_drawable_clip (GdkGC *gc); +void _gdk_gc_set_draw_origins (GdkGC *gc, + gint clip_x, + gint clip_y, + gint ts_x, + gint ts_y, + gboolean drawing_done); +void _gdk_gc_remove_kept_drawable_clip (GdkGC *gc); void _gdk_gc_set_clip_region_internal (GdkGC *gc, GdkRegion *region, gboolean reset_origin); @@ -538,11 +614,11 @@ struct _GdkPaintableIface void (* end_paint) (GdkPaintable *paintable); }; -GType _gdk_paintable_get_type (void) G_GNUC_CONST; +GType _gdk_paintable_get_type (void); /* Implementation types */ -GType _gdk_window_impl_get_type (void) G_GNUC_CONST; -GType _gdk_pixmap_impl_get_type (void) G_GNUC_CONST; +GType _gdk_window_impl_get_type (void); +GType _gdk_pixmap_impl_get_type (void); /** @@ -630,6 +706,24 @@ void _gdk_display_enable_motion_hints (GdkDisplay *display); void _gdk_window_invalidate_for_expose (GdkWindow *window, GdkRegion *region); +void _gdk_window_reapply_shapes (GdkWindow *window); + +/* HiDPI: how many pixels of the window system make one of GDK in each + * direction, for a drawable (window, pixmap or their implementation) and + * for a monitor (-1: the screen's default); 1 where the backend does not + * scale */ +gint _gdk_windowing_drawable_get_scale (GdkDrawable *drawable); +GdkPixbuf *_gdk_pixbuf_get_hires (GdkPixbuf *pixbuf, + gint scale); +gint _gdk_windowing_screen_get_monitor_scale (GdkScreen *screen, + gint monitor_num); +void _gdk_cairo_surface_set_device_offset (cairo_surface_t *surface, + gdouble x, + gdouble y); +/* HiDPI: for surfaces whose window system scales by itself, without a + * device scale of cairo (Quartz): its pixels per pixel of GDK */ +void _gdk_cairo_surface_set_hidpi_scale (cairo_surface_t *surface, + gint scale); void _gdk_windowing_set_cairo_surface_size (cairo_surface_t *surface, int width, diff --git a/gdk/gdkkeys.h b/gdk/gdkkeys.h index 4a7528fe1..0738a78e5 100644 --- a/gdk/gdkkeys.h +++ b/gdk/gdkkeys.h @@ -78,7 +78,7 @@ struct _GdkKeymapClass void (*state_changed) (GdkKeymap *keymap); }; -GType gdk_keymap_get_type (void) G_GNUC_CONST; +GType gdk_keymap_get_type (void); #ifndef GDK_MULTIHEAD_SAFE GdkKeymap* gdk_keymap_get_default (void); diff --git a/gdk/gdkmedialib.c b/gdk/gdkmedialib.c deleted file mode 100644 index 8966a4e42..000000000 --- a/gdk/gdkmedialib.c +++ /dev/null @@ -1,120 +0,0 @@ -/* GDK - The GIMP Drawing Kit - * Copyright (C) 2001-2007 Sun Microsystems, Inc. All rights reserved. - * (Brian Cameron, Dmitriy Demin, James Cheng, Padraig O'Briain) - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -/* - * Modified by the GTK+ Team and others 1997-2007. See the AUTHORS - * file for a list of people on the GTK+ Team. See the ChangeLog - * files for a list of changes. These files are distributed with - * GTK+ at ftp://ftp.gtk.org/pub/gtk/. - */ - -#include "config.h" - -#include -#include - -#ifdef HAVE_STRINGS_H -#include -#endif - -#ifdef HAVE_STRING_H -#include -#endif - -#if defined(HAVE_SYS_SYSTEMINFO_H) -#include -#elif defined(HAVE_SYS_SYSINFO_H) -#include -#endif - -#include "gdkmedialib.h" - -typedef char * (*ml_version) (void); - -static ml_version medialib_version = mlib_version; - -gboolean -_gdk_use_medialib (void) -{ - char *mlib_version_string; - char sys_info[257]; - long count; - - /* - * Sun mediaLib(tm) support. - * - * http://www.sun.com/processors/vis/mlib.html - * - */ - if (getenv ("GDK_DISABLE_MEDIALIB")) - return FALSE; - - /* - * The imaging functions we want to use were added in mediaLib version 2. - * So turn off mediaLib support if the user has an older version. - * mlib_version returns a string in this format: - * - * mediaLib:0210:20011101:v8plusa - * ^^^^^^^^ ^^^^ ^^^^^^^^ ^^^^^^^ - * libname vers build ISALIST identifier - * date (in this case sparcv8plus+vis) - * - * The first 2 digits of the version are the major version. The 3rd digit - * is the minor version, and the 4th digit is the micro version. So the - * above string corresponds to version 2.1.0.In the following test we only - * care about the major version. - */ - mlib_version_string = medialib_version (); - - count = sysinfo (SI_ARCHITECTURE, &sys_info[0], 257); - - if (count != -1) - { - if (strcmp (sys_info, "i386") == 0) - { - char *mlib_target_isa = &mlib_version_string[23]; - - /* - * For x86 processors mediaLib generic C implementation - * does not give any performance advantage so disable it. - */ - if (strncmp (mlib_target_isa, "sse", 3) != 0) - { - return FALSE; - } - - /* - * For x86 processors use of libumem conflicts with - * mediaLib, so avoid using it. - */ - if (dlsym (RTLD_PROBE, "umem_alloc") != NULL) - { - return FALSE; - } - } - } - else - { - /* Failed to get system architecture, disable mediaLib */ - return FALSE; - } - - return TRUE; -} diff --git a/gdk/gdkpango.c b/gdk/gdkpango.c index c00949f1a..5b36602f7 100644 --- a/gdk/gdkpango.c +++ b/gdk/gdkpango.c @@ -59,6 +59,12 @@ struct _GdkPangoRendererPrivate GdkGC *base_gc; gboolean gc_changed; + + /* what gdk_draw_layout[_line]_with_colors() draws, where, for the + * clip (see get_cairo_context()) */ + PangoLayout *area_layout; + PangoLayoutLine *area_line; + gint area_x, area_y; }; static PangoAttrType gdk_pango_attr_stipple_type; @@ -155,18 +161,62 @@ color_equal (const PangoColor *c1, const PangoColor *c2) return FALSE; } +/* Where gdk_draw_layout[_line]_with_colors() draws: the ink and the + * logical extents, with room around for the emboss and for pixels of + * glyphs that antialiasing puts a little outside their ink. Only asked + * for when the clip of the window has more than a few rectangles. */ +#define DRAW_AREA_MARGIN 4 + +static gboolean +get_draw_area (GdkPangoRendererPrivate *priv, + GdkRectangle *area) +{ + PangoRectangle ink, logical; + + if (priv->area_layout) + pango_layout_get_pixel_extents (priv->area_layout, &ink, &logical); + else if (priv->area_line) + pango_layout_line_get_pixel_extents (priv->area_line, &ink, &logical); + else + return FALSE; + + if (ink.width <= 0 || ink.height <= 0) + ink = logical; + + area->x = MIN (ink.x, logical.x); + area->y = MIN (ink.y, logical.y); + area->width = MAX (ink.x + ink.width, logical.x + logical.width) - area->x; + area->height = MAX (ink.y + ink.height, logical.y + logical.height) - area->y; + + area->x += priv->area_x - DRAW_AREA_MARGIN; + area->y += priv->area_y - DRAW_AREA_MARGIN; + area->width += 2 * DRAW_AREA_MARGIN; + area->height += 2 * DRAW_AREA_MARGIN; + + return TRUE; +} + static cairo_t * get_cairo_context (GdkPangoRenderer *gdk_renderer, PangoRenderPart part) { PangoRenderer *renderer = PANGO_RENDERER (gdk_renderer); GdkPangoRendererPrivate *priv = gdk_renderer->priv; + gboolean cr_is_new = FALSE; if (!priv->cr) { const PangoMatrix *matrix; + GdkRectangle area; - priv->cr = gdk_cairo_create (priv->drawable); + if ((priv->area_layout || priv->area_line) && + GDK_IS_WINDOW (priv->drawable) && + _gdk_window_get_cairo_clip_n_rects ((GdkWindow *) priv->drawable) > 2 && + get_draw_area (priv, &area)) + priv->cr = _gdk_cairo_create_in_area (priv->drawable, &area); + else + priv->cr = gdk_cairo_create (priv->drawable); + cr_is_new = TRUE; matrix = pango_renderer_get_matrix (renderer); if (matrix) @@ -216,7 +266,8 @@ get_cairo_context (GdkPangoRenderer *gdk_renderer, color, priv->stipple[part], priv->gc_changed, - priv->drawable); + priv->drawable, + cr_is_new); } priv->last_part = part; @@ -839,6 +890,9 @@ release_renderer (PangoRenderer *renderer) gdk_pango_renderer_set_drawable (gdk_renderer, NULL); gdk_pango_renderer_set_gc (gdk_renderer, NULL); + + gdk_renderer->priv->area_layout = NULL; + gdk_renderer->priv->area_line = NULL; } /** @@ -911,7 +965,16 @@ gdk_draw_layout_line_with_colors (GdkDrawable *drawable, y = 0; } else - pango_renderer_set_matrix (renderer, NULL); + { + GdkPangoRendererPrivate *priv = GDK_PANGO_RENDERER (renderer)->priv; + + pango_renderer_set_matrix (renderer, NULL); + + /* without a matrix, the extents of the line say where it goes */ + priv->area_line = line; + priv->area_x = x; + priv->area_y = y; + } pango_renderer_draw_layout_line (renderer, line, x * PANGO_SCALE, y * PANGO_SCALE); @@ -991,7 +1054,16 @@ gdk_draw_layout_with_colors (GdkDrawable *drawable, y = 0; } else - pango_renderer_set_matrix (renderer, NULL); + { + GdkPangoRendererPrivate *priv = GDK_PANGO_RENDERER (renderer)->priv; + + pango_renderer_set_matrix (renderer, NULL); + + /* without a matrix, the extents of the layout say where it goes */ + priv->area_layout = layout; + priv->area_x = x; + priv->area_y = y; + } pango_renderer_draw_layout (renderer, layout, x * PANGO_SCALE, y * PANGO_SCALE); diff --git a/gdk/gdkpango.h b/gdk/gdkpango.h index 1b73a4b90..6dbed215a 100644 --- a/gdk/gdkpango.h +++ b/gdk/gdkpango.h @@ -86,7 +86,7 @@ struct _GdkPangoRendererClass PangoRendererClass parent_class; }; -GType gdk_pango_renderer_get_type (void) G_GNUC_CONST; +GType gdk_pango_renderer_get_type (void); PangoRenderer *gdk_pango_renderer_new (GdkScreen *screen); PangoRenderer *gdk_pango_renderer_get_default (GdkScreen *screen); diff --git a/gdk/gdkpixbuf-drawable.c b/gdk/gdkpixbuf-drawable.c index c710ab388..df099da25 100644 --- a/gdk/gdkpixbuf-drawable.c +++ b/gdk/gdkpixbuf-drawable.c @@ -36,1004 +36,30 @@ #include "gdkinternals.h" #include "gdkalias.h" -/* Some convenient names - */ -#if (G_BYTE_ORDER == G_LITTLE_ENDIAN) -#define LITTLE -#undef BIG -#else -#define BIG -#undef LITTLE -#endif -#define d(x) - -#define SWAP16(d) GUINT16_SWAP_LE_BE(d) - - - -static const guint32 mask_table[] = { - 0x00000000, 0x00000001, 0x00000003, 0x00000007, - 0x0000000f, 0x0000001f, 0x0000003f, 0x0000007f, - 0x000000ff, 0x000001ff, 0x000003ff, 0x000007ff, - 0x00000fff, 0x00001fff, 0x00003fff, 0x00007fff, - 0x0000ffff, 0x0001ffff, 0x0003ffff, 0x0007ffff, - 0x000fffff, 0x001fffff, 0x003fffff, 0x007fffff, - 0x00ffffff, 0x01ffffff, 0x03ffffff, 0x07ffffff, - 0x0fffffff, 0x1fffffff, 0x3fffffff, 0x7fffffff, - 0xffffffff -}; - - - -/* - * convert bitmap data to pixbuf without alpha, - * without using a colormap - */ -static void -bitmap1 (GdkImage *image, - guchar *pixels, - int rowstride, - int x1, - int y1, - int x2, - int y2) -{ - int xx, yy; - int bpl; - register guint8 data; - guint8 *o; - guint8 *srow = (guint8*)image->mem + y1 * image->bpl, *orow = pixels; - - d (printf ("bitmap, no alpha\n")); - - bpl = image->bpl; - - for (yy = y1; yy < y2; yy++) - { - o = orow; - - for (xx = x1; xx < x2; xx ++) - { - /* top 29 bits of xx (xx >> 3) indicate the byte the bit is inside, - * bottom 3 bits (xx & 7) indicate bit inside that byte, - * we don't bother to canonicalize data to 1 or 0, just - * leave the relevant bit in-place. - */ - data = srow[xx >> 3] & (image->byte_order == GDK_MSB_FIRST ? - (0x80 >> (xx & 7)) : - (1 << (xx & 7))); - - if (data) - { - *o++ = 255; - *o++ = 255; - *o++ = 255; - } - else - { - *o++ = 0; - *o++ = 0; - *o++ = 0; - } - } - srow += bpl; - orow += rowstride; - } -} - -/* - * convert bitmap data to pixbuf with alpha, - * without using a colormap - */ -static void -bitmap1a (GdkImage *image, - guchar *pixels, - int rowstride, - int x1, - int y1, - int x2, - int y2) -{ - int xx, yy; - int bpl; - register guint8 data; - guint8 *o; - guint8 *srow = (guint8*)image->mem + y1 * image->bpl, *orow = pixels; - - d (printf ("bitmap, with alpha\n")); - - bpl = image->bpl; - - for (yy = y1; yy < y2; yy++) - { - o = orow; - - for (xx = x1; xx < x2; xx ++) - { - /* see comment in bitmap1() */ - data = srow[xx >> 3] & (image->byte_order == GDK_MSB_FIRST ? - (0x80 >> (xx & 7)) : - (1 << (xx & 7))); - - if (data) - { - *o++ = 255; - *o++ = 255; - *o++ = 255; - *o++ = 255; - } - else - { - *o++ = 0; - *o++ = 0; - *o++ = 0; - *o++ = 0; - } - } - srow += bpl; - orow += rowstride; - } -} - -/* - * convert 1 bits-pixel data - * no alpha - */ -static void -rgb1 (GdkImage *image, - guchar *pixels, - int rowstride, - int x1, - int y1, - int x2, - int y2, - GdkColormap *colormap) -{ - int xx, yy; - int bpl; - register guint8 data; - guint8 *o; - guint8 *srow = (guint8*)image->mem + y1 * image->bpl, *orow = pixels; - - d (printf ("1 bits/pixel\n")); - - /* convert upto 8 pixels/time */ - /* its probably not worth trying to make this run very fast, who uses - * 1 bit displays anymore? - */ - bpl = image->bpl; - - for (yy = y1; yy < y2; yy++) - { - o = orow; - - for (xx = x1; xx < x2; xx ++) - { - /* see comment in bitmap1() */ - data = srow[xx >> 3] & (image->byte_order == GDK_MSB_FIRST ? - (0x80 >> (xx & 7)) : - (1 << (xx & 7))); - - *o++ = colormap->colors[data].red >> 8; - *o++ = colormap->colors[data].green >> 8; - *o++ = colormap->colors[data].blue >> 8; - } - srow += bpl; - orow += rowstride; - } -} - -/* - * convert 1 bits/pixel data - * with alpha - */ -static void -rgb1a (GdkImage *image, - guchar *pixels, - int rowstride, - int x1, - int y1, - int x2, - int y2, - GdkColormap *colormap) -{ - int xx, yy; - int bpl; - register guint8 data; - guint8 *o; - guint8 *srow = (guint8*)image->mem + y1 * image->bpl, *orow = pixels; - - d (printf ("1 bits/pixel\n")); - - /* convert upto 8 pixels/time */ - /* its probably not worth trying to make this run very fast, who uses - * 1 bit displays anymore? */ - bpl = image->bpl; - - for (yy = y1; yy < y2; yy++) - { - o = orow; - - for (xx = x1; xx < x2; xx ++) - { - /* see comment in bitmap1() */ - data = srow[xx >> 3] & (image->byte_order == GDK_MSB_FIRST ? - (0x80 >> (xx & 7)) : - (1 << (xx & 7))); - - *o++ = colormap->colors[data].red >> 8; - *o++ = colormap->colors[data].green >> 8; - *o++ = colormap->colors[data].blue >> 8; - *o++ = 255; - } - srow += bpl; - orow += rowstride; - } -} - -/* - * convert 8 bits/pixel data - * no alpha - */ -static void -rgb8 (GdkImage *image, - guchar *pixels, - int rowstride, - int x1, - int y1, - int x2, - int y2, - GdkColormap *colormap) -{ - int xx, yy; - int bpl; - guint32 mask; - register guint32 data; - guint8 *srow = (guint8*)image->mem + y1 * image->bpl + x1 * image->bpp, *orow = pixels; - register guint8 *s; - register guint8 *o; - - bpl = image->bpl; - - d (printf ("8 bit, no alpha output\n")); - - mask = mask_table[image->depth]; - - for (yy = y1; yy < y2; yy++) - { - s = srow; - o = orow; - for (xx = x1; xx < x2; xx++) - { - data = *s++ & mask; - *o++ = colormap->colors[data].red >> 8; - *o++ = colormap->colors[data].green >> 8; - *o++ = colormap->colors[data].blue >> 8; - } - srow += bpl; - orow += rowstride; - } -} - -/* - * convert 8 bits/pixel data - * with alpha - */ -static void -rgb8a (GdkImage *image, - guchar *pixels, - int rowstride, - int x1, - int y1, - int x2, - int y2, - GdkColormap *colormap) -{ - int xx, yy; - int bpl; - guint32 mask; - register guint32 data; - guint32 remap[256]; - register guint8 *s; /* read 2 pixels at once */ - register guint32 *o; - guint8 *srow = (guint8*)image->mem + y1 * image->bpl + x1 * image->bpp, *orow = pixels; - - bpl = image->bpl; - - d (printf ("8 bit, with alpha output\n")); - - mask = mask_table[image->depth]; - - for (xx = x1; xx < colormap->size; xx++) - { -#ifdef LITTLE - remap[xx] = 0xff000000 - | (colormap->colors[xx].blue & 0xff00) << 8 - | (colormap->colors[xx].green & 0xff00) - | (colormap->colors[xx].red >> 8); -#else - remap[xx] = 0xff - | (colormap->colors[xx].red & 0xff00) << 16 - | (colormap->colors[xx].green & 0xff00) << 8 - | (colormap->colors[xx].blue & 0xff00); -#endif - } - - for (yy = y1; yy < y2; yy++) - { - s = srow; - o = (guint32 *) orow; - for (xx = x1; xx < x2; xx ++) - { - data = *s++ & mask; - *o++ = remap[data]; - } - srow += bpl; - orow += rowstride; - } -} - -/* Bit shifting for 565 and 555 conversion routines - * - * RGB565 == rrrr rggg gggb bbbb, 16 bit native endian - * RGB555 == xrrr rrgg gggb bbbb - * ABGR8888: ARGB, 32-bit native endian - * RGBA8888: RGBA, 32-bit native endian - */ -#define R8fromRGB565(d) ((((d) >> 8) & 0xf8) | (((d) >> 13) & 0x7)) -#define G8fromRGB565(d) ((((d) >> 3) & 0xfc) | (((d) >> 9) & 0x3)) -#define B8fromRGB565(d) ((((d) << 3) & 0xf8) | (((d) >> 2) & 0x7)) - -#define ABGR8888fromRGB565(d) ( ((d) & 0xf800) >> 8 | ((d) & 0xe000) >> 13 \ - | ((d) & 0x07e0) << 5 | ((d) & 0x0600) >> 1 \ - | ((d) & 0x001f) << 19 | ((d) & 0x001c) << 14 \ - | 0xff000000) -#define RGBA8888fromRGB565(d) ( ((d) & 0xf800) << 16 | ((d) & 0xe000) << 11 \ - | ((d) & 0x07e0) << 13 | ((d) & 0x0600) << 7 \ - | ((d) & 0x001f) << 11 | ((d) & 0x001c) << 6 \ - | 0xff) - -#define R8fromRGB555(d) (((d) & 0x7c00) >> 7 | ((d) & 0x7000) >> 12) -#define G8fromRGB555(d) (((d) & 0x03e0) >> 2 | ((d) & 0x0380) >> 7) -#define B8fromRGB555(d) (((d) & 0x001f) << 3 | ((d) & 0x001c) >> 2) - -#define ABGR8888fromRGB555(d) ( ((d) & 0x7c00) >> 7 | ((d) & 0x7000) >> 12 \ - | ((d) & 0x03e0) << 6 | ((d) & 0x0380) << 1 \ - | ((d) & 0x001f) << 19 | ((d) & 0x001c) << 14 \ - | 0xff000000) -#define RGBA8888fromRGB555(d) ( ((d) & 0x7c00) << 17 | ((d) & 0x7000) << 12 \ - | ((d) & 0x03e0) << 14 | ((d) & 0x0380) << 9 \ - | ((d) & 0x001f) << 11 | ((d) & 0x001c) << 6 \ - | 0xff) - -/* - * convert 16 bits/pixel data - * no alpha - * data in lsb format - */ -static void -rgb565lsb (GdkImage *image, - guchar *pixels, - int rowstride, - int x1, - int y1, - int x2, - int y2, - GdkColormap *colormap) -{ - int xx, yy; - int bpl; - - register guint16 *s; - register guint8 *o; - - guint8 *srow = (guint8*)image->mem + y1 * image->bpl + x1 * image->bpp, *orow = pixels; - - bpl = image->bpl; - - for (yy = y1; yy < y2; yy++) - { - s = (guint16 *) srow; - o = (guint8 *) orow; - for (xx = x1; xx < x2; xx ++) - { - register guint32 data = *s++; -#ifdef BIG - data = SWAP16 (data); -#endif - *o++ = R8fromRGB565 (data); - *o++ = G8fromRGB565 (data); - *o++ = B8fromRGB565 (data); - } - srow += bpl; - orow += rowstride; - } -} - -/* - * convert 16 bits/pixel data - * no alpha - * data in msb format - */ -static void -rgb565msb (GdkImage *image, - guchar *pixels, - int rowstride, - int x1, - int y1, - int x2, - int y2, - GdkColormap *colormap) -{ - int xx, yy; - int bpl; - - register guint16 *s; - register guint8 *o; - - guint8 *srow = (guint8*)image->mem + y1 * image->bpl + x1 * image->bpp, *orow = pixels; - - bpl = image->bpl; - - for (yy = y1; yy < y2; yy++) - { - s = (guint16 *) srow; - o = (guint8 *) orow; - for (xx = x1; xx < x2; xx ++) - { - register guint32 data = *s++; -#ifdef LITTLE - data = SWAP16 (data); -#endif - *o++ = R8fromRGB565 (data); - *o++ = G8fromRGB565 (data); - *o++ = B8fromRGB565 (data); - } - srow += bpl; - orow += rowstride; - } -} - -/* - * convert 16 bits/pixel data - * with alpha - * data in lsb format - */ -static void -rgb565alsb (GdkImage *image, - guchar *pixels, - int rowstride, - int x1, - int y1, - int x2, - int y2, - GdkColormap *colormap) -{ - int xx, yy; - int bpl; - - register guint16 *s; - register guint32 *o; - - guint8 *srow = (guint8*)image->mem + y1 * image->bpl + x1 * image->bpp, *orow = pixels; - - bpl = image->bpl; - - for (yy = y1; yy < y2; yy++) - { - s = (guint16 *) srow; - o = (guint32 *) orow; - for (xx = x1; xx < x2; xx ++) - { - register guint32 data = *s++; -#ifdef LITTLE - *o++ = ABGR8888fromRGB565 (data); -#else - data = SWAP16 (data); - *o++ = RGBA8888fromRGB565 (data); -#endif - } - srow += bpl; - orow += rowstride; - } -} - -/* - * convert 16 bits/pixel data - * with alpha - * data in msb format - */ -static void -rgb565amsb (GdkImage *image, - guchar *pixels, - int rowstride, - int x1, - int y1, - int x2, - int y2, - GdkColormap *colormap) -{ - int xx, yy; - int bpl; - - register guint16 *s; - register guint32 *o; - - guint8 *srow = (guint8*)image->mem + y1 * image->bpl + x1 * image->bpp, *orow = pixels; - - bpl = image->bpl; - - for (yy = y1; yy < y2; yy++) - { - s = (guint16 *) srow; - o = (guint32 *) orow; - for (xx = x1; xx < x2; xx ++) - { - register guint32 data = *s++; -#ifdef LITTLE - data = SWAP16 (data); - *o++ = ABGR8888fromRGB565 (data); -#else - *o++ = RGBA8888fromRGB565 (data); -#endif - } - srow += bpl; - orow += rowstride; - } -} - -/* - * convert 15 bits/pixel data - * no alpha - * data in lsb format - */ -static void -rgb555lsb (GdkImage *image, - guchar *pixels, - int rowstride, - int x1, - int y1, - int x2, - int y2, - GdkColormap *colormap) -{ - int xx, yy; - int bpl; - - register guint16 *s; - register guint8 *o; - - guint8 *srow = (guint8*)image->mem + y1 * image->bpl + x1 * image->bpp, *orow = pixels; - - bpl = image->bpl; - - for (yy = y1; yy < y2; yy++) - { - s = (guint16 *) srow; - o = (guint8 *) orow; - for (xx = x1; xx < x2; xx ++) - { - register guint32 data = *s++; -#ifdef BIG - data = SWAP16 (data); -#endif - *o++ = R8fromRGB555 (data); - *o++ = G8fromRGB555 (data); - *o++ = B8fromRGB555 (data); - } - srow += bpl; - orow += rowstride; - } -} - -/* - * convert 15 bits/pixel data - * no alpha - * data in msb format - */ -static void -rgb555msb (GdkImage *image, - guchar *pixels, - int rowstride, - int x1, - int y1, - int x2, - int y2, - GdkColormap *colormap) -{ - int xx, yy; - int bpl; - - register guint16 *s; - register guint8 *o; - - guint8 *srow = (guint8*)image->mem + y1 * image->bpl + x1 * image->bpp, *orow = pixels; - - bpl = image->bpl; - - for (yy = y1; yy < y2; yy++) - { - s = (guint16 *) srow; - o = (guint8 *) orow; - for (xx = x1; xx < x2; xx ++) - { - register guint32 data = *s++; -#ifdef LITTLE - data = SWAP16 (data); -#endif - *o++ = R8fromRGB555 (data); - *o++ = G8fromRGB555 (data); - *o++ = B8fromRGB555 (data); - } - srow += bpl; - orow += rowstride; - } -} - -/* - * convert 15 bits/pixel data - * with alpha - * data in lsb format - */ -static void -rgb555alsb (GdkImage *image, - guchar *pixels, - int rowstride, - int x1, - int y1, - int x2, - int y2, - GdkColormap *colormap) -{ - int xx, yy; - int bpl; - - register guint16 *s; /* read 1 pixels at once */ - register guint32 *o; - - guint8 *srow = (guint8*)image->mem + y1 * image->bpl + x1 * image->bpp, *orow = pixels; - - bpl = image->bpl; - - for (yy = y1; yy < y2; yy++) - { - s = (guint16 *) srow; - o = (guint32 *) orow; - for (xx = x1; xx < x2; xx++) - { - register guint32 data = *s++; -#ifdef LITTLE - *o++ = ABGR8888fromRGB555 (data); -#else - data = SWAP16 (data); - *o++ = RGBA8888fromRGB555 (data); -#endif - } - srow += bpl; - orow += rowstride; - } -} - -/* - * convert 15 bits/pixel data - * with alpha - * data in msb format - */ -static void -rgb555amsb (GdkImage *image, - guchar *pixels, - int rowstride, - int x1, - int y1, - int x2, - int y2, - GdkColormap *colormap) -{ - int xx, yy; - int bpl; - - register guint16 *s; - register guint32 *o; - - guint8 *srow = (guint8*)image->mem + y1 * image->bpl + x1 * image->bpp, *orow = pixels; - - bpl = image->bpl; - - for (yy = y1; yy < y2; yy++) - { - s = (guint16 *) srow; - o = (guint32 *) orow; - for (xx = x1; xx < x2; xx++) - { - register guint32 data = *s++; -#ifdef LITTLE - data = SWAP16 (data); - *o++ = ABGR8888fromRGB555 (data); -#else - *o++ = RGBA8888fromRGB555 (data); -#endif - } - srow += bpl; - orow += rowstride; - } -} - - -static void -rgb888alsb (GdkImage *image, - guchar *pixels, - int rowstride, - int x1, - int y1, - int x2, - int y2, - GdkColormap *colormap) -{ - int xx, yy; - int bpl; - - guint8 *s; /* for byte order swapping */ - guint8 *o; - guint8 *srow = (guint8*)image->mem + y1 * image->bpl + x1 * image->bpp, *orow = pixels; - - bpl = image->bpl; - - d (printf ("32 bits/pixel with alpha\n")); - - /* lsb data */ - for (yy = y1; yy < y2; yy++) - { - s = srow; - o = orow; - for (xx = x1; xx < x2; xx++) - { - *o++ = s[2]; - *o++ = s[1]; - *o++ = s[0]; - *o++ = 0xff; - s += 4; - } - srow += bpl; - orow += rowstride; - } -} - -static void -rgb888lsb (GdkImage *image, - guchar *pixels, - int rowstride, - int x1, - int y1, - int x2, - int y2, - GdkColormap *colormap) -{ - int xx, yy; - int bpl; - - guint8 *srow = (guint8*)image->mem + y1 * image->bpl + x1 * image->bpp, *orow = pixels; - guint8 *o, *s; - - bpl = image->bpl; - - d (printf ("32 bit, lsb, no alpha\n")); - - for (yy = y1; yy < y2; yy++) - { - s = srow; - o = orow; - for (xx = x1; xx < x2; xx++) - { - *o++ = s[2]; - *o++ = s[1]; - *o++ = s[0]; - s += 4; - } - srow += bpl; - orow += rowstride; - } -} - -static void -rgb888amsb (GdkImage *image, - guchar *pixels, - int rowstride, - int x1, - int y1, - int x2, - int y2, - GdkColormap *colormap) -{ - int xx, yy; - int bpl; - - guint8 *srow = (guint8*)image->mem + y1 * image->bpl + x1 * image->bpp, *orow = pixels; - guint32 *o; - guint32 *s; - - d (printf ("32 bit, msb, with alpha\n")); - - bpl = image->bpl; - - /* msb data */ - for (yy = y1; yy < y2; yy++) - { - s = (guint32 *) srow; - o = (guint32 *) orow; - for (xx = x1; xx < x2; xx++) - { -#ifdef LITTLE - *o++ = (*s++ >> 8) | 0xff000000; -#else - *o++ = (*s++ << 8) | 0xff; -#endif - } - srow += bpl; - orow += rowstride; - } -} - -static void -rgb888msb (GdkImage *image, - guchar *pixels, - int rowstride, - int x1, - int y1, - int x2, - int y2, - GdkColormap *colormap) -{ - int xx, yy; - int bpl; - - guint8 *srow = (guint8*)image->mem + y1 * image->bpl + x1 * image->bpp, *orow = pixels; - guint8 *s; - guint8 *o; - - d (printf ("32 bit, msb, no alpha\n")); - - bpl = image->bpl; - - for (yy = y1; yy < y2; yy++) - { - s = srow; - o = orow; - for (xx = x1; xx < x2; xx++) - { - *o++ = s[1]; - *o++ = s[2]; - *o++ = s[3]; - s += 4; - } - srow += bpl; - orow += rowstride; - } -} - -/* - * This should work correctly with any display/any endianness, but will probably - * run quite slow - */ -static void -convert_real_slow (GdkImage *image, - guchar *pixels, - int rowstride, - int x1, - int y1, - int x2, - int y2, - GdkColormap *cmap, - gboolean alpha) -{ - int xx, yy; - guint8 *orow = pixels; - guint8 *o; - guint32 pixel; - GdkVisual *v; - guint8 component; - int i; - - v = gdk_colormap_get_visual (cmap); - - if (image->depth != v->depth) - { - g_warning ("%s: The depth of the source image (%d) doesn't " - "match the depth of the colormap passed in (%d).", - G_STRLOC, image->depth, v->depth); - return; - } - - d(printf("rgb mask/shift/prec = %x:%x:%x %d:%d:%d %d:%d:%d\n", - v->red_mask, v->green_mask, v->blue_mask, - v->red_shift, v->green_shift, v->blue_shift, - v->red_prec, v->green_prec, v->blue_prec)); - - for (yy = y1; yy < y2; yy++) - { - o = orow; - for (xx = x1; xx < x2; xx++) - { - pixel = gdk_image_get_pixel (image, xx, yy); - switch (v->type) - { - /* I assume this is right for static & greyscale's too? */ - case GDK_VISUAL_STATIC_GRAY: - case GDK_VISUAL_GRAYSCALE: - case GDK_VISUAL_STATIC_COLOR: - case GDK_VISUAL_PSEUDO_COLOR: - *o++ = cmap->colors[pixel].red >> 8; - *o++ = cmap->colors[pixel].green >> 8; - *o++ = cmap->colors[pixel].blue >> 8; - break; - case GDK_VISUAL_TRUE_COLOR: - /* This is odd because it must sometimes shift left (otherwise - * I'd just shift >> (*_shift - 8 + *_prec + <0-7>). This logic - * should work for all bit sizes/shifts/etc. - */ - component = 0; - for (i = 24; i < 32; i += v->red_prec) - component |= ((pixel & v->red_mask) << (32 - v->red_shift - v->red_prec)) >> i; - *o++ = component; - component = 0; - for (i = 24; i < 32; i += v->green_prec) - component |= ((pixel & v->green_mask) << (32 - v->green_shift - v->green_prec)) >> i; - *o++ = component; - component = 0; - for (i = 24; i < 32; i += v->blue_prec) - component |= ((pixel & v->blue_mask) << (32 - v->blue_shift - v->blue_prec)) >> i; - *o++ = component; - break; - case GDK_VISUAL_DIRECT_COLOR: - *o++ = cmap->colors[((pixel & v->red_mask) << (32 - v->red_shift - v->red_prec)) >> 24].red >> 8; - *o++ = cmap->colors[((pixel & v->green_mask) << (32 - v->green_shift - v->green_prec)) >> 24].green >> 8; - *o++ = cmap->colors[((pixel & v->blue_mask) << (32 - v->blue_shift - v->blue_prec)) >> 24].blue >> 8; - break; - } - if (alpha) - *o++ = 0xff; - } - orow += rowstride; - } -} - -typedef void (* cfunc) (GdkImage *image, - guchar *pixels, - int rowstride, - int x1, - int y1, - int x2, - int y2, - GdkColormap *cmap); - -static const cfunc convert_map[] = { - rgb1,rgb1,rgb1a,rgb1a, - rgb8,rgb8,rgb8a,rgb8a, - rgb555lsb,rgb555msb,rgb555alsb,rgb555amsb, - rgb565lsb,rgb565msb,rgb565alsb,rgb565amsb, - rgb888lsb,rgb888msb,rgb888alsb,rgb888amsb -}; - -/* - * perform actual conversion - * - * If we can, try and use the optimised code versions, but as a default - * fallback, and always for direct colour, use the generic/slow but complete - * conversion function. +/* Converts @width x @height pixels of @image at @x, @y to RGB or RGBA + * at @pixels, for any visual and any number of bits per pixel. Without + * a colormap, the image is a bitmap: 0 is black, 1 is white. */ static void rgbconvert (GdkImage *image, guchar *pixels, int rowstride, gboolean alpha, - int x, - int y, - int width, - int height, + int x, + int y, + int width, + int height, GdkColormap *cmap) { - int index; - int bank; - GdkVisual *v; + static const GdkColor bitmap_colors[2] = { { 0, 0, 0, 0 }, { 1, 0xffff, 0xffff, 0xffff } }; + const GdkColor *colors = bitmap_colors; + gint n_colors = 2; + GdkVisual *v = NULL; + guint32 mask[3] = { 0, }, row[GDK_SCRATCH_IMAGE_WIDTH]; + gint shift[3] = { 0, }, down[3] = { 0, }; + guchar chan[3][256]; + gboolean palette = TRUE, direct = FALSE, bytes = FALSE; + gint ri = 0, gi = 0, bi = 0, i, j, c; g_assert ((x + width) <= image->width); g_assert ((y + height) <= image->height); @@ -1042,92 +68,113 @@ rgbconvert (GdkImage *image, { /* Only allowed for bitmaps */ g_return_if_fail (image->depth == 1); - - if (alpha) - bitmap1a (image, pixels, rowstride, - x, y, x + width, y + height); - else - bitmap1 (image, pixels, rowstride, - x, y, x + width, y + height); - - return; - } - - v = gdk_colormap_get_visual (cmap); - - if (image->depth != v->depth) - { - g_warning ("%s: The depth of the source image (%d) doesn't " - "match the depth of the colormap passed in (%d).", - G_STRLOC, image->depth, v->depth); - return; - } - - bank = 5; /* default fallback converter */ - index = (image->byte_order == GDK_MSB_FIRST) | (alpha != 0) << 1; - - d(printf("masks = %x:%x:%x\n", v->red_mask, v->green_mask, v->blue_mask)); - d(printf("image depth = %d, bits per pixel = %d\n", image->depth, image->bits_per_pixel)); - - switch (v->type) - { - /* I assume this is right for static & greyscale's too? */ - case GDK_VISUAL_STATIC_GRAY: - case GDK_VISUAL_GRAYSCALE: - case GDK_VISUAL_STATIC_COLOR: - case GDK_VISUAL_PSEUDO_COLOR: - switch (image->bits_per_pixel) - { - case 1: - bank = 0; - break; - case 8: - if (image->depth == 8) - bank = 1; - break; - } - break; - case GDK_VISUAL_TRUE_COLOR: - switch (image->depth) - { - case 15: - if (v->red_mask == 0x7c00 && v->green_mask == 0x3e0 && v->blue_mask == 0x1f - && image->bits_per_pixel == 16) - bank = 2; - break; - case 16: - if (v->red_mask == 0xf800 && v->green_mask == 0x7e0 && v->blue_mask == 0x1f - && image->bits_per_pixel == 16) - bank = 3; - break; - case 24: - case 32: - if (v->red_mask == 0xff0000 && v->green_mask == 0xff00 && v->blue_mask == 0xff - && image->bits_per_pixel == 32) - bank = 4; - break; - } - break; - case GDK_VISUAL_DIRECT_COLOR: - /* always use the slow version */ - break; - } - - d (g_print ("converting using conversion function in bank %d\n", bank)); - - if (bank == 5) - { - convert_real_slow (image, pixels, rowstride, - x, y, x + width, y + height, - cmap, alpha); } else { - index |= bank << 2; - d (g_print ("converting with index %d\n", index)); - (* convert_map[index]) (image, pixels, rowstride, - x, y, x + width, y + height, - cmap); + v = gdk_colormap_get_visual (cmap); + + if (image->depth != v->depth) + { + g_warning ("%s: The depth of the source image (%d) doesn't " + "match the depth of the colormap passed in (%d).", + G_STRLOC, image->depth, v->depth); + return; + } + + colors = cmap->colors; + n_colors = cmap->size; + direct = v->type == GDK_VISUAL_DIRECT_COLOR; + palette = v->type != GDK_VISUAL_TRUE_COLOR && !direct; + } + + if (!palette) + { + const gint prec[3] = { v->red_prec, v->green_prec, v->blue_prec }; + + mask[0] = v->red_mask, mask[1] = v->green_mask, mask[2] = v->blue_mask; + shift[0] = v->red_shift, shift[1] = v->green_shift, shift[2] = v->blue_shift; + + /* TrueColor: 8 bits of each channel are its top 8 bits, or its + * bits repeated up to 8 */ + bytes = !direct && (image->bits_per_pixel == 24 || image->bits_per_pixel == 32); + for (c = 0; c < 3; c++) + { + bytes &= prec[c] == 8 && shift[c] % 8 == 0; + down[c] = MAX (prec[c] - 8, 0); + for (i = 0; i < 256; i++) + { + gint value = 0; + + for (j = 0; prec[c] > 0 && j < 8; j += prec[c]) + value |= ((i << 8) >> MIN (prec[c], 8)) >> j; + chan[c][i] = value; + } + } + + if (bytes) + { + gint n = image->bits_per_pixel / 8; + + ri = shift[0] / 8, gi = shift[1] / 8, bi = shift[2] / 8; + if (image->byte_order == GDK_MSB_FIRST) + ri = n - 1 - ri, gi = n - 1 - gi, bi = n - 1 - bi; + } + } + + for (j = 0; j < height; j++, pixels += rowstride) + { + guchar *o = pixels; + + if (bytes) + { + const guchar *in = (guchar *) image->mem + (y + j) * image->bpl + x * (image->bits_per_pixel / 8); + const gint step = image->bits_per_pixel / 8; + + for (i = 0; i < width; i++, in += step) + { + *o++ = in[ri]; + *o++ = in[gi]; + *o++ = in[bi]; + if (alpha) + *o++ = 0xff; + } + continue; + } + + for (i = 0; i < width; i++) + { + const gint k = i % GDK_SCRATCH_IMAGE_WIDTH; + + if (k == 0) + _gdk_image_read_row (image, x + i, y + j, + MIN (width - i, GDK_SCRATCH_IMAGE_WIDTH), row); + + if (palette) + { + if (row[k] < (guint32) n_colors) + { + *o++ = colors[row[k]].red >> 8; + *o++ = colors[row[k]].green >> 8; + *o++ = colors[row[k]].blue >> 8; + } + else + *o++ = 0, *o++ = 0, *o++ = 0; + } + else if (direct) + /* each channel looks its value up in the colormap */ + for (c = 0; c < 3; c++) + { + const guint32 index = (row[k] & mask[c]) >> shift[c]; + const GdkColor *color = &colors[MIN (index, (guint32) n_colors - 1)]; + + *o++ = (c == 0 ? color->red : c == 1 ? color->green : color->blue) >> 8; + } + else + for (c = 0; c < 3; c++) + *o++ = chan[c][(row[k] & mask[c]) >> shift[c] >> down[c]]; + if (alpha) + *o++ = 0xff; + } } } diff --git a/gdk/gdkpixmap.c b/gdk/gdkpixmap.c index 5bda8dd63..3241a9c89 100644 --- a/gdk/gdkpixmap.c +++ b/gdk/gdkpixmap.c @@ -740,6 +740,12 @@ gdk_pixmap_colormap_create_from_xpm (GdkDrawable *drawable, if (colormap == NULL) colormap = gdk_drawable_get_colormap (drawable); + /* no mask either if the image cannot be read (gdk-pixbuf may come + * without its XPM loader): callers use it without looking at the + * pixmap first */ + if (mask) + *mask = NULL; + pixbuf = gdk_pixbuf_new_from_file (filename, NULL); if (!pixbuf) return NULL; @@ -823,6 +829,12 @@ gdk_pixmap_colormap_create_from_xpm_d (GdkDrawable *drawable, if (colormap == NULL) colormap = gdk_drawable_get_colormap (drawable); + /* no mask either if the image cannot be read (gdk-pixbuf may come + * without its XPM loader): callers use it without looking at the + * pixmap first */ + if (mask) + *mask = NULL; + pixbuf = gdk_pixbuf_new_from_xpm_data ((const char **)data); if (!pixbuf) return NULL; diff --git a/gdk/gdkpixmap.h b/gdk/gdkpixmap.h index 230329e8c..c844987e4 100644 --- a/gdk/gdkpixmap.h +++ b/gdk/gdkpixmap.h @@ -62,7 +62,7 @@ struct _GdkPixmapObjectClass }; -GType gdk_pixmap_get_type (void) G_GNUC_CONST; +GType gdk_pixmap_get_type (void); /* Pixmaps */ diff --git a/gdk/gdkproperty.h b/gdk/gdkproperty.h index 6f2a68970..5ef52ac62 100644 --- a/gdk/gdkproperty.h +++ b/gdk/gdkproperty.h @@ -42,7 +42,7 @@ typedef enum GDK_PROP_MODE_APPEND } GdkPropMode; -GType gdk_atom_get_type (void) G_GNUC_CONST; +GType gdk_atom_get_type (void); GdkAtom gdk_atom_intern (const gchar *atom_name, gboolean only_if_exists); GdkAtom gdk_atom_intern_static_string (const gchar *atom_name); diff --git a/gdk/gdkregion-generic.c b/gdk/gdkregion-generic.c index c921142e4..f58a29a0f 100644 --- a/gdk/gdkregion-generic.c +++ b/gdk/gdkregion-generic.c @@ -611,6 +611,36 @@ gdk_region_intersect (GdkRegion *source1, if ((!(source1->numRects)) || (!(source2->numRects)) || (!EXTENTCHECK(&source1->extents, &source2->extents))) source1->numRects = 0; + /* Mostly one of the two is a rectangle: an expose area, a window, + * a clip rectangle. Then a rectangle around the other is the other, + * and two rectangles meet in one. */ + else if (source2->numRects == 1 && + source2->extents.x1 <= source1->extents.x1 && + source2->extents.y1 <= source1->extents.y1 && + source2->extents.x2 >= source1->extents.x2 && + source2->extents.y2 >= source1->extents.y2) + return; + else if (source1->numRects == 1 && + source1->extents.x1 <= source2->extents.x1 && + source1->extents.y1 <= source2->extents.y1 && + source1->extents.x2 >= source2->extents.x2 && + source1->extents.y2 >= source2->extents.y2) + { + miRegionCopy (source1, source2); + return; + } + else if (source1->numRects == 1 && source2->numRects == 1) + { + GdkRegionBox box; + + box.x1 = MAX (source1->extents.x1, source2->extents.x1); + box.y1 = MAX (source1->extents.y1, source2->extents.y1); + box.x2 = MIN (source1->extents.x2, source2->extents.x2); + box.y2 = MIN (source1->extents.y2, source2->extents.y2); + source1->rects[0] = box; + source1->extents = box; + return; + } else miRegionOp (source1, source1, source2, miIntersectO, (nonOverlapFunc) NULL, (nonOverlapFunc) NULL); diff --git a/gdk/gdkrgb-altivec.c b/gdk/gdkrgb-altivec.c new file mode 100644 index 000000000..8e3a3d1a0 --- /dev/null +++ b/gdk/gdkrgb-altivec.c @@ -0,0 +1,433 @@ +/* GDK - The GIMP Drawing Kit + * GdkRGB loops for AltiVec (PowerPC G4 and G5) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + */ + +#include "config.h" + +#include "gdkrgbsimd.h" + +#if defined(__ALTIVEC__) && defined(__BIG_ENDIAN__) + +#include + +/* An x888 pixel is the bytes 0xff, R, G, B; a 565 pixel is a big + * endian 16-bit word. Vector loads and stores need 16-byte aligned + * addresses: loads are put together from two, and each loop starts + * with single pixels until the output is aligned. */ + +typedef vector unsigned char vu8; +typedef vector unsigned short vu16; +typedef vector unsigned int vu32; + +#define VU8(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) \ + ((vu8) { a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p }) + +/* Reads 16 bytes after 16 bytes from any address, one aligned load + * each; never reads a block that holds none of the bytes asked for. + * Set up only when at least 16 bytes will be read. */ +typedef struct +{ + const guchar *p; + vu8 perm, last; + gboolean aligned; +} Reader; + +static inline void +reader_init (Reader *r, const guchar *p) +{ + r->p = p; + r->aligned = ((gsize) p & 15) == 0; + r->perm = vec_lvsl (0, p); + r->last = vec_ld (0, p); +} + +static inline vu8 +reader_next (Reader *r) +{ + vu8 v; + + if (r->aligned) + v = vec_ld (0, r->p); + else + { + /* the block of the 16th byte follows the block of the first */ + vu8 next = vec_ld (15, r->p); + + v = vec_perm (r->last, next, r->perm); + r->last = next; + } + r->p += 16; + + return v; +} + +static inline gboolean +aligned (const void *p) +{ + return ((gsize) p & 15) == 0; +} + +static inline guint32 +x888 (const guchar *p) +{ + return 0xff000000 | (p[0] << 16) | (p[1] << 8) | p[2]; +} + +static inline guint16 +rgb565 (const guchar *p) +{ + return ((p[0] & 0xf8) << 8) | ((p[1] & 0xfc) << 3) | (p[2] >> 3); +} + +/* with the unused bit set, as all of GdkRGB does */ +static inline guint16 +rgb555 (const guchar *p) +{ + return 0x8000 | ((p[0] & 0xf8) << 7) | ((p[1] & 0xf8) << 2) | (p[2] >> 3); +} + +static inline guint +blend8 (guint a, guint s, guint d) +{ + guint t = a * s + (255 - a) * d + 0x80; + + return (t + (t >> 8)) >> 8; +} + +static inline void +composite1_x888 (guint32 *pixel, const guchar *s) +{ + guint32 d = *pixel; + + if (s[3] != 0) + *pixel = 0xff000000 | + (blend8 (s[3], s[0], (d >> 16) & 0xff) << 16) | + (blend8 (s[3], s[1], (d >> 8) & 0xff) << 8) | + blend8 (s[3], s[2], d & 0xff); +} + +static inline void +composite1_565 (guint16 *pixel, const guchar *s) +{ + guint d = *pixel, r = d >> 11, g = (d >> 5) & 0x3f, b = d & 0x1f; + + r = blend8 (s[3], s[0], (r << 3) | (r >> 2)); + g = blend8 (s[3], s[1], (g << 2) | (g >> 4)); + b = blend8 (s[3], s[2], (b << 3) | (b >> 2)); + *pixel = ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | (b >> 3); +} + +static inline void +composite1_555 (guint16 *pixel, const guchar *s) +{ + guint d = *pixel, r = (d >> 10) & 0x1f, g = (d >> 5) & 0x1f, b = d & 0x1f; + + r = blend8 (s[3], s[0], (r << 3) | (r >> 2)); + g = blend8 (s[3], s[1], (g << 3) | (g >> 2)); + b = blend8 (s[3], s[2], (b << 3) | (b >> 2)); + *pixel = 0x8000 | ((r & 0xf8) << 7) | ((g & 0xf8) << 2) | (b >> 3); +} + +/* 0xff in the first byte of each pixel */ +static inline vu8 +fill_x888 (void) +{ + /* -8 shifts by 24 */ + return (vu8) vec_sl (vec_splat_u32 (-1), vec_splat_u32 (-8)); +} + +static gint +rgb_to_x888 (guint32 *out, const guchar *rgb, gint n) +{ + const vu8 fill = fill_x888 (); + const vu8 p0 = VU8 (0, 0, 1, 2, 0, 3, 4, 5, 0, 6, 7, 8, 0, 9, 10, 11); + const vu8 p1 = VU8 (0, 12, 13, 14, 0, 15, 16, 17, 0, 18, 19, 20, 0, 21, 22, 23); + const vu8 p2 = VU8 (0, 8, 9, 10, 0, 11, 12, 13, 0, 14, 15, 16, 0, 17, 18, 19); + const vu8 p3 = VU8 (0, 4, 5, 6, 0, 7, 8, 9, 0, 10, 11, 12, 0, 13, 14, 15); + Reader r; + gint i; + + for (i = 0; i < n && !aligned (out + i); i++, rgb += 3) + out[i] = x888 (rgb); + + if (i + 16 <= n) + reader_init (&r, rgb); + for (; i + 16 <= n; i += 16) + { + vu8 a = reader_next (&r), b = reader_next (&r), c = reader_next (&r); + + vec_st (vec_or (vec_perm (a, a, p0), fill), 0, (guchar *) (out + i)); + vec_st (vec_or (vec_perm (a, b, p1), fill), 16, (guchar *) (out + i)); + vec_st (vec_or (vec_perm (b, c, p2), fill), 32, (guchar *) (out + i)); + vec_st (vec_or (vec_perm (c, c, p3), fill), 48, (guchar *) (out + i)); + } + + return i; +} + +static gint +rgbx_to_x888 (guint32 *out, const guchar *rgbx, gint n) +{ + const vu8 fill = fill_x888 (); + const vu8 p = VU8 (0, 0, 1, 2, 0, 4, 5, 6, 0, 8, 9, 10, 0, 12, 13, 14); + Reader r; + gint i; + + for (i = 0; i < n && !aligned (out + i); i++, rgbx += 4) + out[i] = x888 (rgbx); + + if (i + 4 <= n) + reader_init (&r, rgbx); + for (; i + 4 <= n; i += 4) + { + vu8 a = reader_next (&r); + + vec_st (vec_or (vec_perm (a, a, p), fill), 0, (guchar *) (out + i)); + } + + return i; +} + +/* Bytes of eight RGB pixels as 16-bit lanes, for one channel */ +static inline vu16 +channel (vu8 a, vu8 b, vu8 p) +{ + return vec_and ((vu16) vec_perm (a, b, p), vec_splats ((unsigned short) 0xff)); +} + +static inline vu16 +pack565 (vu16 r, vu16 g, vu16 b) +{ + return vec_or (vec_or (vec_sl (vec_and (r, vec_splats ((unsigned short) 0xf8)), vec_splats ((unsigned short) 8)), + vec_sl (vec_and (g, vec_splats ((unsigned short) 0xfc)), vec_splats ((unsigned short) 3))), + vec_sr (b, vec_splats ((unsigned short) 3))); +} + +static inline vu16 +pack555 (vu16 r, vu16 g, vu16 b) +{ + return vec_or (vec_or (vec_sl (vec_and (r, vec_splats ((unsigned short) 0xf8)), vec_splats ((unsigned short) 7)), + vec_sl (vec_and (g, vec_splats ((unsigned short) 0xf8)), vec_splats ((unsigned short) 2))), + vec_or (vec_sr (b, vec_splats ((unsigned short) 3)), vec_splats ((unsigned short) 0x8000))); +} + +static inline vu16 +pack16 (vu16 r, vu16 g, vu16 b, const gint green_bits) +{ + return green_bits == 6 ? pack565 (r, g, b) : pack555 (r, g, b); +} + +static inline gint +rgb_to_16 (guint16 *out, const guchar *rgb, gint n, const gint green_bits) +{ + /* the channel byte of pixel k in both bytes of lane k */ + const vu8 r0 = VU8 (0, 0, 3, 3, 6, 6, 9, 9, 12, 12, 15, 15, 18, 18, 21, 21); + const vu8 g0 = VU8 (1, 1, 4, 4, 7, 7, 10, 10, 13, 13, 16, 16, 19, 19, 22, 22); + const vu8 b0 = VU8 (2, 2, 5, 5, 8, 8, 11, 11, 14, 14, 17, 17, 20, 20, 23, 23); + const vu8 r1 = VU8 (8, 8, 11, 11, 14, 14, 17, 17, 20, 20, 23, 23, 26, 26, 29, 29); + const vu8 g1 = VU8 (9, 9, 12, 12, 15, 15, 18, 18, 21, 21, 24, 24, 27, 27, 30, 30); + const vu8 b1 = VU8 (10, 10, 13, 13, 16, 16, 19, 19, 22, 22, 25, 25, 28, 28, 31, 31); + Reader r; + gint i; + + for (i = 0; i < n && !aligned (out + i); i++, rgb += 3) + out[i] = green_bits == 6 ? rgb565 (rgb) : rgb555 (rgb); + + if (i + 16 <= n) + reader_init (&r, rgb); + for (; i + 16 <= n; i += 16) + { + vu8 a = reader_next (&r), b = reader_next (&r), c = reader_next (&r); + + vec_st (pack16 (channel (a, b, r0), channel (a, b, g0), channel (a, b, b0), green_bits), 0, out + i); + vec_st (pack16 (channel (b, c, r1), channel (b, c, g1), channel (b, c, b1), green_bits), 0, out + i + 8); + } + + return i; +} + +static gint +rgb_to_565 (guint16 *out, const guchar *rgb, gint n) +{ + return rgb_to_16 (out, rgb, n, 6); +} + +static gint +rgb_to_555 (guint16 *out, const guchar *rgb, gint n) +{ + return rgb_to_16 (out, rgb, n, 5); +} + +/* (a * s + (255 - a) * d) / 255, rounded, in 16-bit lanes */ +static inline vu16 +blend (vu16 t) +{ + t = vec_add (t, vec_splats ((unsigned short) 0x80)); + + return vec_sr (vec_add (t, vec_sr (t, vec_splats ((unsigned short) 8))), + vec_splats ((unsigned short) 8)); +} + +static gint +composite_x888 (guint32 *pixels, const guchar *rgba, gint n) +{ + const vu8 fill = fill_x888 (); + const vu8 argb = VU8 (3, 0, 1, 2, 7, 4, 5, 6, 11, 8, 9, 10, 15, 12, 13, 14); + const vu8 alpha = VU8 (3, 3, 3, 3, 7, 7, 7, 7, 11, 11, 11, 11, 15, 15, 15, 15); + const vu8 merge = VU8 (1, 17, 3, 19, 5, 21, 7, 23, 9, 25, 11, 27, 13, 29, 15, 31); + Reader r; + gint i; + + for (i = 0; i < n && !aligned (pixels + i); i++, rgba += 4) + composite1_x888 (pixels + i, rgba); + + if (i + 4 <= n) + reader_init (&r, rgba); + for (; i + 4 <= n; i += 4) + { + vu8 s = reader_next (&r); + vu8 d = vec_ld (0, (guchar *) (pixels + i)); + vu8 a = vec_perm (s, s, alpha); + vu8 inv = vec_nor (a, a); + vu16 even, odd; + vu8 v; + + s = vec_perm (s, s, argb); + even = blend (vec_add (vec_mule (s, a), vec_mule (d, inv))); + odd = blend (vec_add (vec_mulo (s, a), vec_mulo (d, inv))); + v = vec_or (vec_perm ((vu8) even, (vu8) odd, merge), fill); + + /* fully transparent pixels stay as they are */ + vec_st (vec_sel (v, d, vec_cmpeq (a, vec_splat_u8 (0))), 0, (guchar *) (pixels + i)); + } + + return i; +} + +static inline gint +composite_16 (guint16 *pixels, const guchar *rgba, gint n, const gint green_bits) +{ + const vu8 pr = VU8 (0, 0, 4, 4, 8, 8, 12, 12, 16, 16, 20, 20, 24, 24, 28, 28); + const vu8 pg = VU8 (1, 1, 5, 5, 9, 9, 13, 13, 17, 17, 21, 21, 25, 25, 29, 29); + const vu8 pb = VU8 (2, 2, 6, 6, 10, 10, 14, 14, 18, 18, 22, 22, 26, 26, 30, 30); + const vu8 pa = VU8 (3, 3, 7, 7, 11, 11, 15, 15, 19, 19, 23, 23, 27, 27, 31, 31); + const vu16 c255 = vec_splats ((unsigned short) 255); + Reader r; + gint i; + + for (i = 0; i < n && !aligned (pixels + i); i++, rgba += 4) + if (rgba[3] != 0) + { + if (green_bits == 6) + composite1_565 (pixels + i, rgba); + else + composite1_555 (pixels + i, rgba); + } + + if (i + 8 <= n) + reader_init (&r, rgba); + for (; i + 8 <= n; i += 8) + { + vu8 s0 = reader_next (&r), s1 = reader_next (&r); + vu16 d = vec_ld (0, pixels + i); + vu16 a = channel (s0, s1, pa), inv = vec_sub (c255, a); + vu16 dr = vec_and (vec_sr (d, vec_splats ((unsigned short) (5 + green_bits))), vec_splats ((unsigned short) 0x1f)); + vu16 dg = vec_and (vec_sr (d, vec_splats ((unsigned short) 5)), vec_splats ((unsigned short) ((1 << green_bits) - 1))); + vu16 db = vec_and (d, vec_splats ((unsigned short) 0x1f)); + vu16 v; + + /* the bits of the pixel repeated up to 8 */ + dr = vec_or (vec_sl (dr, vec_splats ((unsigned short) 3)), vec_sr (dr, vec_splats ((unsigned short) 2))); + if (green_bits == 6) + dg = vec_or (vec_sl (dg, vec_splats ((unsigned short) 2)), vec_sr (dg, vec_splats ((unsigned short) 4))); + else + dg = vec_or (vec_sl (dg, vec_splats ((unsigned short) 3)), vec_sr (dg, vec_splats ((unsigned short) 2))); + db = vec_or (vec_sl (db, vec_splats ((unsigned short) 3)), vec_sr (db, vec_splats ((unsigned short) 2))); + + v = pack16 (blend (vec_mladd (channel (s0, s1, pr), a, vec_mladd (dr, inv, vec_splats ((unsigned short) 0)))), + blend (vec_mladd (channel (s0, s1, pg), a, vec_mladd (dg, inv, vec_splats ((unsigned short) 0)))), + blend (vec_mladd (channel (s0, s1, pb), a, vec_mladd (db, inv, vec_splats ((unsigned short) 0)))), + green_bits); + + /* where nothing is drawn the unused bit of 555 stays as it was */ + if (green_bits == 5) + v = vec_sel (v, d, vec_cmpeq (a, vec_splats ((unsigned short) 0))); + vec_st (v, 0, pixels + i); + } + + return i; +} + +static gint +rgba_to_argb (guint32 *out, const guchar *rgba, gint n) +{ + const vu8 argb = VU8 (3, 0, 1, 2, 7, 4, 5, 6, 11, 8, 9, 10, 15, 12, 13, 14); + /* a for R, G and B; 255 for the alpha, which a * 255 / 255 keeps */ + const vu8 factors = VU8 (16, 3, 3, 3, 16, 7, 7, 7, 16, 11, 11, 11, 16, 15, 15, 15); + const vu8 merge = VU8 (1, 17, 3, 19, 5, 21, 7, 23, 9, 25, 11, 27, 13, 29, 15, 31); + const vu8 ones = vec_splat_u8 (-1); + Reader r; + gint i; + + for (i = 0; i < n && !aligned (out + i); i++, rgba += 4) + { + guint a = rgba[3]; + + out[i] = (a << 24) | (blend8 (a, rgba[0], 0) << 16) | + (blend8 (a, rgba[1], 0) << 8) | blend8 (a, rgba[2], 0); + } + + if (i + 4 <= n) + reader_init (&r, rgba); + for (; i + 4 <= n; i += 4) + { + vu8 s = reader_next (&r); + vu8 m = vec_perm (s, ones, factors); + + s = vec_perm (s, s, argb); + vec_st (vec_perm ((vu8) blend (vec_mule (s, m)), (vu8) blend (vec_mulo (s, m)), merge), + 0, (guchar *) (out + i)); + } + + return i; +} + +static gint +composite_565 (guint16 *pixels, const guchar *rgba, gint n) +{ + return composite_16 (pixels, rgba, n, 6); +} + +static gint +composite_555 (guint16 *pixels, const guchar *rgba, gint n) +{ + return composite_16 (pixels, rgba, n, 5); +} + +void +_gdk_rgb_simd_init_altivec (GdkRgbSimd *simd) +{ + simd->name = "altivec"; + simd->rgb_to_x888 = rgb_to_x888; + simd->rgbx_to_x888 = rgbx_to_x888; + simd->rgb_to_565 = rgb_to_565; + simd->rgb_to_555 = rgb_to_555; + simd->composite_x888 = composite_x888; + simd->composite_565 = composite_565; + simd->composite_555 = composite_555; + simd->rgba_to_argb = rgba_to_argb; +} + +#else + +void +_gdk_rgb_simd_init_altivec (GdkRgbSimd *simd) +{ +} + +#endif diff --git a/gdk/gdkrgb-armv6.c b/gdk/gdkrgb-armv6.c new file mode 100644 index 000000000..5c32b4f4e --- /dev/null +++ b/gdk/gdkrgb-armv6.c @@ -0,0 +1,318 @@ +/* GDK - The GIMP Drawing Kit + * GdkRGB loops for the media instructions of ARMv6 (the ARM11 of the + * Raspberry Pi 1 and Zero), which has no NEON: two channels of a pixel + * 16 bits apart in one register, multiplied at once, with UXTB16 and + * UXTAB16 taking bytes apart and adding them in both halves; REV puts + * the bytes of a pixel in the other order. A pixel goes in and out as + * one word, not byte by byte. + * + * GDK_RGB_ARMV6_C builds the same loops with C for the instructions, + * to check them on other machines. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + */ + +#include "config.h" + +#include "gdkrgbsimd.h" + +/* ARMv6 or later in ARM or Thumb-2 code, little endian */ +#if defined(__arm__) && !defined(__ARMEB__) && \ + (!defined(__thumb__) || defined(__thumb2__)) && \ + (defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) || defined(__ARM_ARCH_6K__) || \ + defined(__ARM_ARCH_6Z__) || defined(__ARM_ARCH_6ZK__) || defined(__ARM_ARCH_6T2__) || \ + (defined(__ARM_ARCH) && __ARM_ARCH >= 6)) +#define ARMV6_ASM 1 +#endif + +#if defined(ARMV6_ASM) || defined(GDK_RGB_ARMV6_C) + +#ifdef ARMV6_ASM + +/* bytes 0 and 2 in the two halves */ +static inline guint32 +uxtb16 (guint32 x) +{ + guint32 r; + __asm__ ("uxtb16 %0, %1" : "=r" (r) : "r" (x)); + return r; +} + +/* bytes 1 and 3 */ +static inline guint32 +uxtb16_ror8 (guint32 x) +{ + guint32 r; + __asm__ ("uxtb16 %0, %1, ror #8" : "=r" (r) : "r" (x)); + return r; +} + +/* @acc plus bytes 1 and 3 of @x, in each half */ +static inline guint32 +uxtab16_ror8 (guint32 acc, guint32 x) +{ + guint32 r; + __asm__ ("uxtab16 %0, %1, %2, ror #8" : "=r" (r) : "r" (acc), "r" (x)); + return r; +} + +static inline guint32 +rev (guint32 x) +{ + guint32 r; + __asm__ ("rev %0, %1" : "=r" (r) : "r" (x)); + return r; +} + +#else + +static inline guint32 uxtb16 (guint32 x) { return x & 0x00ff00ff; } +static inline guint32 uxtb16_ror8 (guint32 x) { return (x >> 8 | x << 24) & 0x00ff00ff; } +static inline guint32 +uxtab16_ror8 (guint32 acc, guint32 x) +{ + guint32 b = uxtb16_ror8 (x); + + return ((acc + b) & 0xffff) | ((acc & 0xffff0000) + (b & 0xffff0000)); +} +static inline guint32 +rev (guint32 x) +{ + return x >> 24 | (x >> 8 & 0xff00) | (x << 8 & 0xff0000) | x << 24; +} + +#endif + +/* A word of pixels, at an address of a whole word: rows of pixbufs + * start there, and the loops take words from the start. Rows that do + * not are left to the C code, as ARMv6 compilers read words byte by + * byte where they are not sure. */ +typedef guint32 __attribute__ ((may_alias)) word; + +#define ALIGNED(p) (((gsize) (p) & 3) == 0) + +static inline guint32 +load32 (const guchar *p) +{ + return *(const word *) p; +} + +/* t / 255 rounded, in both halves, for t = c * a + 0x80 (no carries + * between the halves: t stays below 65536) */ +static inline guint32 +div255 (guint32 t) +{ + return uxtb16_ror8 (uxtab16_ror8 (t, t)); +} + +/* Of each three RGB pixels: R G B R | G B R G | B R G B in three words */ + +static gint +rgb_to_x888 (guint32 *out, const guchar *rgb, gint n) +{ + gint i; + + if (!ALIGNED (rgb)) + return 0; + + for (i = 0; i + 4 <= n; i += 4, rgb += 12) + { + guint32 w0 = load32 (rgb), w1 = load32 (rgb + 4), w2 = load32 (rgb + 8); + + /* B G R x, reversed and moved down, is R << 16 | G << 8 | B */ + out[i] = (rev (w0) >> 8) | 0xff000000; + out[i + 1] = (rev ((w0 >> 24) | (w1 << 8)) >> 8) | 0xff000000; + out[i + 2] = (rev ((w1 >> 16) | (w2 << 16)) >> 8) | 0xff000000; + out[i + 3] = (rev (w2) & 0xffffff) | 0xff000000; + } + + return i; +} + +/* Lanes R | G << 8 | B << 16 to 565 or 555 */ +static inline guint32 +rgb16_of (guint32 v, const gint green_bits) +{ + if (green_bits == 6) + return ((v & 0xf8) << 8) | ((v >> 5) & 0x7e0) | ((v >> 19) & 0x1f); + else + return ((v & 0xf8) << 7) | ((v >> 6) & 0x3e0) | ((v >> 19) & 0x1f) | 0x8000; +} + +static inline gint +rgb_to_16 (guint16 *out, const guchar *rgb, gint n, const gint green_bits) +{ + guint32 *out32 = (guint32 *) out; + gint i; + + /* two pixels to a word of the output; the words of both at their + * places, or the C code does the row */ + if (!ALIGNED (rgb) || !ALIGNED (out)) + return 0; + + for (i = 0; i + 4 <= n; i += 4, rgb += 12, out32 += 2) + { + guint32 w0 = load32 (rgb), w1 = load32 (rgb + 4), w2 = load32 (rgb + 8); + + out32[0] = rgb16_of (w0, green_bits) | + (rgb16_of ((w0 >> 24) | (w1 << 8), green_bits) << 16); + out32[1] = rgb16_of ((w1 >> 16) | (w2 << 16), green_bits) | + (rgb16_of (w2 >> 8, green_bits) << 16); + } + + return i; +} + +static gint +rgb_to_565 (guint16 *out, const guchar *rgb, gint n) +{ + return rgb_to_16 (out, rgb, n, 6); +} + +static gint +rgb_to_555 (guint16 *out, const guchar *rgb, gint n) +{ + return rgb_to_16 (out, rgb, n, 5); +} + +/* c * a / 255 to the nearest for the channels of the RGBA word @w: + * red and blue together, green and alpha together */ +static gint +rgba_to_argb (guint32 *out, const guchar *rgba, gint n) +{ + gint i; + + if (!ALIGNED (rgba)) + return 0; + + for (i = 0; i < n; i++, rgba += 4) + { + guint32 w = load32 (rgba); + guint32 a = w >> 24; + guint32 rb = div255 (uxtb16 (w) * a + 0x00800080); /* R | B << 16 */ + guint32 g = div255 (uxtb16_ror8 (w) * a + 0x80) & 0xff; + + /* B | R << 16, which a rotation is */ + out[i] = (a << 24) | (g << 8) | (rb >> 16) | (rb << 16); + } + + return i; +} + +/* a * s + (255 - a) * d, rounded, for two channels at once */ +static inline guint32 +blend2 (guint32 s, guint32 d, guint32 a) +{ + return div255 (s * a + d * (255 - a) + 0x00800080); +} + +static gint +composite_x888 (guint32 *pixels, const guchar *rgba, gint n) +{ + gint i; + + if (!ALIGNED (rgba)) + return 0; + + for (i = 0; i < n; i++, rgba += 4) + { + guint32 w = load32 (rgba); + guint32 a = w >> 24; + guint32 d, rb, g; + + if (a == 0) + continue; + if (a == 255) + { + pixels[i] = (rev (w) >> 8) | 0xff000000; + continue; + } + + /* the pixel is B | G << 8 | R << 16: blue and red as in @w swapped */ + d = pixels[i]; + rb = blend2 (uxtb16 (w), ((d >> 16) & 0xff) | ((d & 0xff) << 16), a); + g = blend2 ((w >> 8) & 0xff, (d >> 8) & 0xff, a) & 0xff; + pixels[i] = 0xff000000 | ((rb & 0xff) << 16) | (g << 8) | (rb >> 16); + } + + return i; +} + +/* The bits of a channel repeated up to 8, as GdkRGB unpacks them */ +#define WIDEN5(c) (((c) << 3) | ((c) >> 2)) +#define WIDEN6(c) (((c) << 2) | ((c) >> 4)) + +static inline gint +composite_16 (guint16 *pixels, const guchar *rgba, gint n, const gint green_bits) +{ + const gint red_shift = 5 + green_bits; + gint i; + + if (!ALIGNED (rgba)) + return 0; + + for (i = 0; i < n; i++, rgba += 4) + { + guint32 w = load32 (rgba); + guint32 a = w >> 24; + guint32 d, dr, dg, db, rb, g, v; + + if (a == 0) + continue; + + d = pixels[i]; + dr = (d >> red_shift) & 0x1f; + dg = (d >> 5) & ((1 << green_bits) - 1); + db = d & 0x1f; + dr = WIDEN5 (dr); + dg = green_bits == 6 ? WIDEN6 (dg) : WIDEN5 (dg); + db = WIDEN5 (db); + + rb = blend2 (uxtb16 (w), dr | (db << 16), a); /* R | B << 16 */ + g = blend2 ((w >> 8) & 0xff, dg, a) & 0xff; + + v = (((rb & 0xff) >> 3) << red_shift) | ((g >> (8 - green_bits)) << 5) | (rb >> 19); + if (green_bits == 5) + v |= 0x8000; + pixels[i] = v; + } + + return i; +} + +static gint +composite_565 (guint16 *pixels, const guchar *rgba, gint n) +{ + return composite_16 (pixels, rgba, n, 6); +} + +static gint +composite_555 (guint16 *pixels, const guchar *rgba, gint n) +{ + return composite_16 (pixels, rgba, n, 5); +} + +void +_gdk_rgb_simd_init_armv6 (GdkRgbSimd *simd) +{ + simd->name = "armv6"; + simd->rgb_to_x888 = rgb_to_x888; + simd->rgb_to_565 = rgb_to_565; + simd->rgb_to_555 = rgb_to_555; + simd->composite_x888 = composite_x888; + simd->composite_565 = composite_565; + simd->composite_555 = composite_555; + simd->rgba_to_argb = rgba_to_argb; +} + +#else + +void +_gdk_rgb_simd_init_armv6 (GdkRgbSimd *simd) +{ +} + +#endif diff --git a/gdk/gdkrgb-avx2.c b/gdk/gdkrgb-avx2.c new file mode 100644 index 000000000..3ee7d6a5d --- /dev/null +++ b/gdk/gdkrgb-avx2.c @@ -0,0 +1,136 @@ +/* GDK - The GIMP Drawing Kit + * GdkRGB loops for AVX2 (Haswell, Zen and later): the SSSE3 loops eight + * pixels at a time, for the pixels of four bytes, where the lanes of 128 + * bits do not mix. Pixels of three bytes would cross the two halves of + * a register and need permutes; those stay with SSSE3. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + */ + +#include "config.h" + +#include "gdkrgbsimd.h" + +#if defined(__AVX2__) + +#include + +/* x86 is little endian: an x888 pixel is the bytes B, G, R, 0xff */ + +#define SPLAT(v) _mm256_set1_epi32 ((gint) (v)) + +/* the same order of bytes in both halves */ +#define BYTES(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) \ + _mm256_setr_epi8 (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, \ + a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) + +static gint +rgbx_to_x888 (guint32 *out, const guchar *rgbx, gint n) +{ + const __m256i order = BYTES (2, 1, 0, -1, 6, 5, 4, -1, 10, 9, 8, -1, 14, 13, 12, -1); + gint i; + + for (i = 0; i + 8 <= n; i += 8, rgbx += 32) + _mm256_storeu_si256 ((__m256i *) (out + i), + _mm256_or_si256 (_mm256_shuffle_epi8 (_mm256_loadu_si256 ((const __m256i *) rgbx), order), + SPLAT (0xff000000))); + + return i; +} + +/* The alpha of each pixel in its four 16-bit lanes */ +static inline __m256i +alpha_of (__m256i v) +{ + return _mm256_shuffle_epi8 (v, BYTES (6, 7, 6, 7, 6, 7, 6, 7, 14, 15, 14, 15, 14, 15, 14, 15)); +} + +/* (a * s + (255 - a) * d) / 255, rounded as GdkRGB's C code does */ +static inline __m256i +blend (__m256i s, __m256i d, __m256i a) +{ + __m256i t = _mm256_add_epi16 (_mm256_add_epi16 (_mm256_mullo_epi16 (s, a), + _mm256_mullo_epi16 (d, _mm256_sub_epi16 (_mm256_set1_epi16 (255), a))), + _mm256_set1_epi16 (0x80)); + + return _mm256_mulhi_epu16 (t, _mm256_set1_epi16 (257)); +} + +static gint +composite_x888 (guint32 *pixels, const guchar *rgba, gint n) +{ + const __m256i zero = _mm256_setzero_si256 (); + const __m256i order = BYTES (2, 1, 0, 3, 6, 5, 4, 7, 10, 9, 8, 11, 14, 13, 12, 15); + gint i; + + for (i = 0; i + 8 <= n; i += 8, rgba += 32) + { + __m256i s = _mm256_loadu_si256 ((const __m256i *) rgba); + __m256i d = _mm256_loadu_si256 ((const __m256i *) (pixels + i)); + __m256i transparent = _mm256_cmpeq_epi32 (_mm256_srli_epi32 (s, 24), zero); + __m256i lo, hi, v; + + /* RGBA to BGRA, the order of the pixels */ + s = _mm256_shuffle_epi8 (s, order); + lo = _mm256_unpacklo_epi8 (s, zero); + hi = _mm256_unpackhi_epi8 (s, zero); + lo = blend (lo, _mm256_unpacklo_epi8 (d, zero), alpha_of (lo)); + hi = blend (hi, _mm256_unpackhi_epi8 (d, zero), alpha_of (hi)); + v = _mm256_or_si256 (_mm256_packus_epi16 (lo, hi), SPLAT (0xff000000)); + + /* fully transparent pixels stay as they are */ + v = _mm256_blendv_epi8 (v, d, transparent); + _mm256_storeu_si256 ((__m256i *) (pixels + i), v); + } + + return i; +} + +/* c * a / 255 to the nearest, which (c * a + 0x80) * 257 >> 16 is */ +static gint +rgba_to_argb (guint32 *out, const guchar *rgba, gint n) +{ + const __m256i zero = _mm256_setzero_si256 (); + const __m256i order = BYTES (2, 1, 0, -1, 6, 5, 4, -1, 10, 9, 8, -1, 14, 13, 12, -1); + gint i; + + for (i = 0; i + 8 <= n; i += 8, rgba += 32) + { + __m256i s = _mm256_loadu_si256 ((const __m256i *) rgba); + __m256i lo = _mm256_unpacklo_epi8 (s, zero); + __m256i hi = _mm256_unpackhi_epi8 (s, zero); + + lo = _mm256_mulhi_epu16 (_mm256_add_epi16 (_mm256_mullo_epi16 (lo, alpha_of (lo)), _mm256_set1_epi16 (0x80)), + _mm256_set1_epi16 (257)); + hi = _mm256_mulhi_epu16 (_mm256_add_epi16 (_mm256_mullo_epi16 (hi, alpha_of (hi)), _mm256_set1_epi16 (0x80)), + _mm256_set1_epi16 (257)); + + /* R, G, B to B, G, R, and the alpha byte as it was */ + _mm256_storeu_si256 ((__m256i *) (out + i), + _mm256_or_si256 (_mm256_shuffle_epi8 (_mm256_packus_epi16 (lo, hi), order), + _mm256_and_si256 (s, SPLAT (0xff000000)))); + } + + return i; +} + +void +_gdk_rgb_simd_init_avx2 (GdkRgbSimd *simd) +{ + simd->name = "avx2"; + simd->rgbx_to_x888 = rgbx_to_x888; + simd->composite_x888 = composite_x888; + simd->rgba_to_argb = rgba_to_argb; +} + +#else + +void +_gdk_rgb_simd_init_avx2 (GdkRgbSimd *simd) +{ +} + +#endif diff --git a/gdk/gdkrgb-mmx.c b/gdk/gdkrgb-mmx.c new file mode 100644 index 000000000..56d5ba372 --- /dev/null +++ b/gdk/gdkrgb-mmx.c @@ -0,0 +1,480 @@ +/* GDK - The GIMP Drawing Kit + * GdkRGB loops for MMX, and for what came later on the same registers: + * the integer SSE instructions of the Pentium III and Athlon (pshufw, + * pmulhuw), and 3DNow! of the K6-2, Athlon and Geode LX (pmulhrw) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + */ + +#include "config.h" + +#include + +#include "gdkrgbsimd.h" + +/* x86-64 always has SSE2, which does all of this better */ +#if defined(__MMX__) && !defined(__x86_64__) + +#include + +/* The file is compiled for plain MMX. The later instructions are + * written as assembler, so the compiler uses them nowhere else, and + * the kernels with them are only called on CPUs that have them. */ + +#if defined(__GNUC__) +#define KERNEL static inline __attribute__ ((always_inline)) +#else +#define KERNEL static inline +#endif + +/* How a kernel does what MMX has no instruction for */ +enum +{ + PLAIN, /* MMX only */ + EXT, /* pshufw and pmulhuw */ + AMD3D, /* pmulhrw */ + AMD3D_EXT /* all three */ +}; + +#define SPLAT(v) _mm_set1_pi32 ((gint) (v)) + +static inline __m64 +load8 (const void *p) +{ + __m64 v; + + memcpy (&v, p, 8); + return v; +} + +static inline void +store8 (void *p, __m64 v) +{ + memcpy (p, &v, 8); +} + +static inline __m64 +load4 (const void *p) +{ + gint32 v; + + memcpy (&v, p, 4); + return _mm_cvtsi32_si64 (v); +} + +#if defined(__i386__) && defined(__GNUC__) + +#define HAVE_LATER_MMX 1 + +#define PSHUFW(v, imm) G_STMT_START { \ + __asm__ ("pshufw $" #imm ", %0, %0" : "+y" (v)); \ + } G_STMT_END + +static inline __m64 +pmulhuw (__m64 a, __m64 b) +{ + __asm__ ("pmulhuw %1, %0" : "+y" (a) : "y" (b)); + return a; +} + +static inline __m64 +pmulhrw (__m64 a, __m64 b) +{ + __asm__ ("pmulhrw %1, %0" : "+y" (a) : "y" (b)); + return a; +} + +#else + +/* never used: only plain kernels are made here */ +#define PSHUFW(v, imm) G_STMT_START { } G_STMT_END +#define pmulhuw(a, b) ((void) (b), (a)) +#define pmulhrw(a, b) ((void) (b), (a)) + +#endif + +/* The 6 bytes of two RGB pixels as lanes R | G << 8 | B << 16 */ +static inline __m64 +rgb_lanes (__m64 v) +{ + return _mm_unpacklo_pi32 (v, _mm_srli_si64 (v, 24)); +} + +static inline __m64 +x888_of (__m64 v) +{ + return _mm_or_si64 (_mm_or_si64 (_mm_slli_pi32 (_mm_and_si64 (v, SPLAT (0xff)), 16), + _mm_and_si64 (v, SPLAT (0xff00))), + _mm_or_si64 (_mm_and_si64 (_mm_srli_pi32 (v, 16), SPLAT (0xff)), + SPLAT (0xff000000))); +} + +/* Lanes R | G << 8 | B << 16 to 565 or 555, sign extended for packing. + * The bit 555 has no use for is set, as in all of GdkRGB's pixels. */ +static inline __m64 +rgb565_of (__m64 v) +{ + v = _mm_or_si64 (_mm_or_si64 (_mm_slli_pi32 (_mm_and_si64 (v, SPLAT (0xf8)), 8), + _mm_srli_pi32 (_mm_and_si64 (v, SPLAT (0xfc00)), 5)), + _mm_and_si64 (_mm_srli_pi32 (v, 19), SPLAT (0x1f))); + + return _mm_srai_pi32 (_mm_slli_pi32 (v, 16), 16); +} + +static inline __m64 +rgb555_of (__m64 v) +{ + v = _mm_or_si64 (_mm_or_si64 (_mm_slli_pi32 (_mm_and_si64 (v, SPLAT (0xf8)), 7), + _mm_srli_pi32 (_mm_and_si64 (v, SPLAT (0xf800)), 6)), + _mm_or_si64 (_mm_and_si64 (_mm_srli_pi32 (v, 19), SPLAT (0x1f)), + SPLAT (0x8000))); + + return _mm_srai_pi32 (_mm_slli_pi32 (v, 16), 16); +} + +static gint +rgb_to_x888 (guint32 *out, const guchar *rgb, gint n) +{ + gint i; + + for (i = 0; i + 4 <= n; i += 4, rgb += 12) + { + __m64 a = load8 (rgb); + __m64 b = _mm_or_si64 (_mm_srli_si64 (a, 48), _mm_slli_si64 (load4 (rgb + 8), 16)); + + store8 (out + i, x888_of (rgb_lanes (a))); + store8 (out + i + 2, x888_of (rgb_lanes (b))); + } + _mm_empty (); + + return i; +} + +static gint +rgbx_to_x888 (guint32 *out, const guchar *rgbx, gint n) +{ + gint i; + + for (i = 0; i + 2 <= n; i += 2, rgbx += 8) + store8 (out + i, x888_of (load8 (rgbx))); + _mm_empty (); + + return i; +} + +static gint +rgb_to_565 (guint16 *out, const guchar *rgb, gint n) +{ + gint i; + + for (i = 0; i + 4 <= n; i += 4, rgb += 12) + { + __m64 a = load8 (rgb); + __m64 b = _mm_or_si64 (_mm_srli_si64 (a, 48), _mm_slli_si64 (load4 (rgb + 8), 16)); + + store8 (out + i, _mm_packs_pi32 (rgb565_of (rgb_lanes (a)), rgb565_of (rgb_lanes (b)))); + } + _mm_empty (); + + return i; +} + +static gint +rgb_to_555 (guint16 *out, const guchar *rgb, gint n) +{ + gint i; + + for (i = 0; i + 4 <= n; i += 4, rgb += 12) + { + __m64 a = load8 (rgb); + __m64 b = _mm_or_si64 (_mm_srli_si64 (a, 48), _mm_slli_si64 (load4 (rgb + 8), 16)); + + store8 (out + i, _mm_packs_pi32 (rgb555_of (rgb_lanes (a)), rgb555_of (rgb_lanes (b)))); + } + _mm_empty (); + + return i; +} + +/* (a * s + (255 - a) * d) / 255, rounded as GdkRGB's C code does, in + * 16-bit lanes. 3DNow! does it as d + (s - d) * a / 255: pmulhrw + * rounds the signed difference times a * 257, a correction makes up + * for a * 257 not fitting a signed lane from a = 128 on. That is the + * same in all 16777216 cases. */ +KERNEL __m64 +blend (__m64 s, __m64 d, __m64 a, const gint how) +{ + if (how == AMD3D || how == AMD3D_EXT) + { + __m64 scaled = _mm_slli_pi16 (a, 8); + __m64 mask = _mm_srai_pi16 (scaled, 15); + __m64 coeff = _mm_sub_pi16 (_mm_add_pi16 (a, scaled), mask); + __m64 delta = _mm_sub_pi16 (s, d); + + return _mm_add_pi16 (_mm_add_pi16 (pmulhrw (delta, coeff), _mm_and_si64 (delta, mask)), d); + } + else + { + __m64 t = _mm_add_pi16 (_mm_add_pi16 (_mm_mullo_pi16 (s, a), + _mm_mullo_pi16 (d, _mm_sub_pi16 (_mm_set1_pi16 (255), a))), + _mm_set1_pi16 (0x80)); + + /* t * 257 >> 16 is (t + (t >> 8)) >> 8 */ + if (how == EXT) + return pmulhuw (t, _mm_set1_pi16 (257)); + return _mm_srli_pi16 (_mm_add_pi16 (t, _mm_srli_pi16 (t, 8)), 8); + } +} + +/* c * a / 255, rounded the same way */ +KERNEL __m64 +premultiply (__m64 c, __m64 a, const gint how) +{ + if (how == AMD3D || how == AMD3D_EXT) + return blend (c, _mm_setzero_si64 (), a, how); + else + { + __m64 t = _mm_add_pi16 (_mm_mullo_pi16 (c, a), _mm_set1_pi16 (0x80)); + + if (how == EXT) + return pmulhuw (t, _mm_set1_pi16 (257)); + return _mm_srli_pi16 (_mm_add_pi16 (t, _mm_srli_pi16 (t, 8)), 8); + } +} + +/* The alpha of a pixel in 16-bit lanes in all four lanes */ +KERNEL __m64 +alpha_of (__m64 v, const gint how) +{ + if (how == EXT || how == AMD3D_EXT) + { + PSHUFW (v, 0xff); + return v; + } + v = _mm_srli_si64 (v, 48); + v = _mm_unpacklo_pi16 (v, v); + + return _mm_unpacklo_pi32 (v, v); +} + +/* Two RGBA pixels as 16-bit lanes B, G, R, A each: the order of the + * bytes of 0xAARRGGBB */ +KERNEL void +unpack_bgra (__m64 s, __m64 *lo, __m64 *hi, const gint how) +{ + const __m64 zero = _mm_setzero_si64 (); + + if (how == EXT || how == AMD3D_EXT) + { + __m64 l = _mm_unpacklo_pi8 (s, zero); + __m64 h = _mm_unpackhi_pi8 (s, zero); + + PSHUFW (l, 0xc6); + PSHUFW (h, 0xc6); + *lo = l; + *hi = h; + } + else + { + s = _mm_or_si64 (_mm_and_si64 (s, SPLAT (0xff00ff00)), + _mm_or_si64 (_mm_slli_pi32 (_mm_and_si64 (s, SPLAT (0xff)), 16), + _mm_and_si64 (_mm_srli_pi32 (s, 16), SPLAT (0xff)))); + *lo = _mm_unpacklo_pi8 (s, zero); + *hi = _mm_unpackhi_pi8 (s, zero); + } +} + +KERNEL gint +composite_x888_k (guint32 *pixels, const guchar *rgba, gint n, const gint how) +{ + const __m64 zero = _mm_setzero_si64 (); + gint i; + + for (i = 0; i + 2 <= n; i += 2, rgba += 8) + { + __m64 s = load8 (rgba); + __m64 d = load8 (pixels + i); + __m64 transparent = _mm_cmpeq_pi32 (_mm_srli_pi32 (s, 24), zero); + __m64 lo, hi, v; + + unpack_bgra (s, &lo, &hi, how); + lo = blend (lo, _mm_unpacklo_pi8 (d, zero), alpha_of (lo, how), how); + hi = blend (hi, _mm_unpackhi_pi8 (d, zero), alpha_of (hi, how), how); + v = _mm_or_si64 (_mm_packs_pu16 (lo, hi), SPLAT (0xff000000)); + + /* fully transparent pixels stay as they are */ + store8 (pixels + i, _mm_or_si64 (_mm_and_si64 (transparent, d), + _mm_andnot_si64 (transparent, v))); + } + _mm_empty (); + + return i; +} + +/* Four 565 or 555 pixels at a time, each channel in a register */ +KERNEL gint +composite_16_k (guint16 *pixels, const guchar *rgba, gint n, const gint green_bits, const gint how) +{ + const gint red_shift = 5 + green_bits; + const __m64 zero = _mm_setzero_si64 (); + gint i; + + for (i = 0; i + 4 <= n; i += 4, rgba += 16) + { + __m64 s0 = load8 (rgba); + __m64 s1 = load8 (rgba + 8); + __m64 d = load8 (pixels + i); + __m64 r = _mm_packs_pi32 (_mm_and_si64 (s0, SPLAT (0xff)), _mm_and_si64 (s1, SPLAT (0xff))); + __m64 g = _mm_packs_pi32 (_mm_and_si64 (_mm_srli_pi32 (s0, 8), SPLAT (0xff)), + _mm_and_si64 (_mm_srli_pi32 (s1, 8), SPLAT (0xff))); + __m64 b = _mm_packs_pi32 (_mm_and_si64 (_mm_srli_pi32 (s0, 16), SPLAT (0xff)), + _mm_and_si64 (_mm_srli_pi32 (s1, 16), SPLAT (0xff))); + __m64 a = _mm_packs_pi32 (_mm_srli_pi32 (s0, 24), _mm_srli_pi32 (s1, 24)); + __m64 dr = _mm_and_si64 (_mm_srli_pi16 (d, red_shift), _mm_set1_pi16 (0x1f)); + __m64 dg = _mm_and_si64 (_mm_srli_pi16 (d, 5), _mm_set1_pi16 ((1 << green_bits) - 1)); + __m64 db = _mm_and_si64 (d, _mm_set1_pi16 (0x1f)); + __m64 v; + + /* the bits of the pixel repeated up to 8 */ + dr = _mm_or_si64 (_mm_slli_pi16 (dr, 3), _mm_srli_pi16 (dr, 2)); + if (green_bits == 6) + dg = _mm_or_si64 (_mm_slli_pi16 (dg, 2), _mm_srli_pi16 (dg, 4)); + else + dg = _mm_or_si64 (_mm_slli_pi16 (dg, 3), _mm_srli_pi16 (dg, 2)); + db = _mm_or_si64 (_mm_slli_pi16 (db, 3), _mm_srli_pi16 (db, 2)); + + r = blend (r, dr, a, how); + g = blend (g, dg, a, how); + b = blend (b, db, a, how); + v = _mm_or_si64 (_mm_or_si64 (_mm_slli_pi16 (_mm_srli_pi16 (r, 3), red_shift), + _mm_slli_pi16 (_mm_srli_pi16 (g, 8 - green_bits), 5)), + _mm_srli_pi16 (b, 3)); + + if (green_bits == 5) + { + /* the unused bit is set, except where nothing is drawn */ + __m64 transparent = _mm_cmpeq_pi16 (a, zero); + + v = _mm_or_si64 (_mm_and_si64 (transparent, d), + _mm_andnot_si64 (transparent, _mm_or_si64 (v, _mm_set1_pi16 ((gshort) 0x8000)))); + } + store8 (pixels + i, v); + } + _mm_empty (); + + return i; +} + +KERNEL gint +rgba_to_argb_k (guint32 *out, const guchar *rgba, gint n, const gint how) +{ + gint i; + + for (i = 0; i + 2 <= n; i += 2, rgba += 8) + { + __m64 s = load8 (rgba); + __m64 lo, hi; + + unpack_bgra (s, &lo, &hi, how); + lo = premultiply (lo, alpha_of (lo, how), how); + hi = premultiply (hi, alpha_of (hi, how), how); + + /* the alpha byte as it was */ + store8 (out + i, _mm_or_si64 (_mm_and_si64 (_mm_packs_pu16 (lo, hi), SPLAT (0x00ffffff)), + _mm_and_si64 (s, SPLAT (0xff000000)))); + } + _mm_empty (); + + return i; +} + +#define DEFINE_KERNELS(suffix, how) \ +static gint \ +composite_x888_##suffix (guint32 *pixels, const guchar *rgba, gint n) \ +{ \ + return composite_x888_k (pixels, rgba, n, how); \ +} \ + \ +static gint \ +composite_565_##suffix (guint16 *pixels, const guchar *rgba, gint n) \ +{ \ + return composite_16_k (pixels, rgba, n, 6, how); \ +} \ + \ +static gint \ +composite_555_##suffix (guint16 *pixels, const guchar *rgba, gint n) \ +{ \ + return composite_16_k (pixels, rgba, n, 5, how); \ +} \ + \ +static gint \ +rgba_to_argb_##suffix (guint32 *out, const guchar *rgba, gint n) \ +{ \ + return rgba_to_argb_k (out, rgba, n, how); \ +} \ + \ +static void \ +init_##suffix (GdkRgbSimd *simd, const gchar *name) \ +{ \ + simd->name = name; \ + simd->rgb_to_x888 = rgb_to_x888; \ + simd->rgbx_to_x888 = rgbx_to_x888; \ + simd->rgb_to_565 = rgb_to_565; \ + simd->rgb_to_555 = rgb_to_555; \ + simd->composite_x888 = composite_x888_##suffix; \ + simd->composite_565 = composite_565_##suffix; \ + simd->composite_555 = composite_555_##suffix; \ + simd->rgba_to_argb = rgba_to_argb_##suffix; \ +} + +DEFINE_KERNELS (mmx, PLAIN) + +void +_gdk_rgb_simd_init_mmx (GdkRgbSimd *simd) +{ + init_mmx (simd, "mmx"); +} + +#if defined(HAVE_LATER_MMX) + +DEFINE_KERNELS (ext, EXT) +DEFINE_KERNELS (3dnow, AMD3D) +DEFINE_KERNELS (3dnowext, AMD3D_EXT) + +void +_gdk_rgb_simd_init_mmxext (GdkRgbSimd *simd) +{ + init_ext (simd, "mmxext"); +} + +void +_gdk_rgb_simd_init_3dnow (GdkRgbSimd *simd) +{ + init_3dnow (simd, "3dnow"); +} + +void +_gdk_rgb_simd_init_3dnowext (GdkRgbSimd *simd) +{ + init_3dnowext (simd, "3dnowext"); +} + +#else + +void _gdk_rgb_simd_init_mmxext (GdkRgbSimd *simd) { } +void _gdk_rgb_simd_init_3dnow (GdkRgbSimd *simd) { } +void _gdk_rgb_simd_init_3dnowext (GdkRgbSimd *simd) { } + +#endif + +#else + +void _gdk_rgb_simd_init_mmx (GdkRgbSimd *simd) { } +void _gdk_rgb_simd_init_mmxext (GdkRgbSimd *simd) { } +void _gdk_rgb_simd_init_3dnow (GdkRgbSimd *simd) { } +void _gdk_rgb_simd_init_3dnowext (GdkRgbSimd *simd) { } + +#endif diff --git a/gdk/gdkrgb-neon.c b/gdk/gdkrgb-neon.c new file mode 100644 index 000000000..1e90e8705 --- /dev/null +++ b/gdk/gdkrgb-neon.c @@ -0,0 +1,251 @@ +/* GDK - The GIMP Drawing Kit + * GdkRGB loops for NEON (ARMv7 with NEON, AArch64) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + */ + +#include "config.h" + +#include "gdkrgbsimd.h" + +#if (defined(__ARM_NEON) || defined(__ARM_NEON__)) && !defined(__ARM_BIG_ENDIAN) + +#include + +/* An x888 pixel is the bytes B, G, R, 0xff. The structure loads and + * stores take the channels apart and put them together. */ + +/* (a * s + (255 - a) * d) / 255, rounded */ +static inline uint8x8_t +blend (uint8x8_t s, uint8x8_t d, uint8x8_t a, uint8x8_t inv) +{ + uint16x8_t t = vmlal_u8 (vmull_u8 (s, a), d, inv); + + return vrshrn_n_u16 (vrsraq_n_u16 (t, t, 8), 8); +} + +static inline uint16x8_t +pack565 (uint8x8_t r, uint8x8_t g, uint8x8_t b) +{ + uint16x8_t v = vshll_n_u8 (r, 8); + + v = vsriq_n_u16 (v, vshll_n_u8 (g, 8), 5); + + return vsriq_n_u16 (v, vshll_n_u8 (b, 8), 11); +} + +/* with the unused bit set, as all of GdkRGB does */ +static inline uint16x8_t +pack555 (uint8x8_t r, uint8x8_t g, uint8x8_t b) +{ + uint16x8_t v = vshll_n_u8 (r, 7); + + v = vsriq_n_u16 (v, vshll_n_u8 (g, 8), 6); + v = vsriq_n_u16 (v, vshll_n_u8 (b, 8), 11); + + return vorrq_u16 (v, vdupq_n_u16 (0x8000)); +} + +static gint +rgb_to_x888 (guint32 *out, const guchar *rgb, gint n) +{ + gint i; + + for (i = 0; i + 16 <= n; i += 16, rgb += 48) + { + uint8x16x3_t s = vld3q_u8 (rgb); + uint8x16x4_t d; + + d.val[0] = s.val[2]; + d.val[1] = s.val[1]; + d.val[2] = s.val[0]; + d.val[3] = vdupq_n_u8 (0xff); + vst4q_u8 ((guchar *) (out + i), d); + } + + return i; +} + +static gint +rgbx_to_x888 (guint32 *out, const guchar *rgbx, gint n) +{ + gint i; + + for (i = 0; i + 16 <= n; i += 16, rgbx += 64) + { + uint8x16x4_t s = vld4q_u8 (rgbx); + uint8x16x4_t d; + + d.val[0] = s.val[2]; + d.val[1] = s.val[1]; + d.val[2] = s.val[0]; + d.val[3] = vdupq_n_u8 (0xff); + vst4q_u8 ((guchar *) (out + i), d); + } + + return i; +} + +static gint +rgb_to_565 (guint16 *out, const guchar *rgb, gint n) +{ + gint i; + + for (i = 0; i + 8 <= n; i += 8, rgb += 24) + { + uint8x8x3_t s = vld3_u8 (rgb); + + vst1q_u16 (out + i, pack565 (s.val[0], s.val[1], s.val[2])); + } + + return i; +} + +static gint +rgb_to_555 (guint16 *out, const guchar *rgb, gint n) +{ + gint i; + + for (i = 0; i + 8 <= n; i += 8, rgb += 24) + { + uint8x8x3_t s = vld3_u8 (rgb); + + vst1q_u16 (out + i, pack555 (s.val[0], s.val[1], s.val[2])); + } + + return i; +} + +static gint +composite_x888 (guint32 *pixels, const guchar *rgba, gint n) +{ + gint i; + + for (i = 0; i + 8 <= n; i += 8, rgba += 32) + { + uint8x8x4_t s = vld4_u8 (rgba); + uint8x8x4_t d = vld4_u8 ((const guchar *) (pixels + i)); + uint8x8_t a = s.val[3], inv = vmvn_u8 (a); + uint8x8_t transparent = vceq_u8 (a, vdup_n_u8 (0)); + uint8x8x4_t v; + + v.val[0] = vbsl_u8 (transparent, d.val[0], blend (s.val[2], d.val[0], a, inv)); + v.val[1] = vbsl_u8 (transparent, d.val[1], blend (s.val[1], d.val[1], a, inv)); + v.val[2] = vbsl_u8 (transparent, d.val[2], blend (s.val[0], d.val[2], a, inv)); + v.val[3] = vbsl_u8 (transparent, d.val[3], vdup_n_u8 (0xff)); + vst4_u8 ((guchar *) (pixels + i), v); + } + + return i; +} + +static gint +composite_565 (guint16 *pixels, const guchar *rgba, gint n) +{ + gint i; + + for (i = 0; i + 8 <= n; i += 8, rgba += 32) + { + uint8x8x4_t s = vld4_u8 (rgba); + uint16x8_t d = vld1q_u16 (pixels + i); + uint8x8_t a = s.val[3], inv = vmvn_u8 (a); + uint8x8_t r = vmovn_u16 (vshrq_n_u16 (d, 8)); + uint8x8_t g = vmovn_u16 (vshrq_n_u16 (d, 3)); + uint8x8_t b = vmovn_u16 (vshlq_n_u16 (d, 3)); + + /* the bits of the pixel repeated up to 8 */ + r = vsri_n_u8 (r, r, 5); + g = vsri_n_u8 (vand_u8 (g, vdup_n_u8 (0xfc)), g, 6); + b = vsri_n_u8 (b, b, 5); + + vst1q_u16 (pixels + i, pack565 (blend (s.val[0], r, a, inv), + blend (s.val[1], g, a, inv), + blend (s.val[2], b, a, inv))); + } + + return i; +} + +/* c * a / 255 to the nearest */ +static gint +rgba_to_argb (guint32 *out, const guchar *rgba, gint n) +{ + gint i; + + for (i = 0; i + 8 <= n; i += 8, rgba += 32) + { + uint8x8x4_t s = vld4_u8 (rgba); + uint8x8x4_t v; + uint16x8_t t; + + t = vmull_u8 (s.val[2], s.val[3]); + v.val[0] = vrshrn_n_u16 (vrsraq_n_u16 (t, t, 8), 8); + t = vmull_u8 (s.val[1], s.val[3]); + v.val[1] = vrshrn_n_u16 (vrsraq_n_u16 (t, t, 8), 8); + t = vmull_u8 (s.val[0], s.val[3]); + v.val[2] = vrshrn_n_u16 (vrsraq_n_u16 (t, t, 8), 8); + v.val[3] = s.val[3]; + vst4_u8 ((guchar *) (out + i), v); + } + + return i; +} + +static gint +composite_555 (guint16 *pixels, const guchar *rgba, gint n) +{ + gint i; + + for (i = 0; i + 8 <= n; i += 8, rgba += 32) + { + uint8x8x4_t s = vld4_u8 (rgba); + uint16x8_t d = vld1q_u16 (pixels + i); + uint8x8_t a = s.val[3], inv = vmvn_u8 (a); + uint8x8_t r = vmovn_u16 (vshrq_n_u16 (d, 7)); + uint8x8_t g = vmovn_u16 (vshrq_n_u16 (d, 2)); + uint8x8_t b = vmovn_u16 (vshlq_n_u16 (d, 3)); + uint16x8_t v; + + /* the bits of the pixel repeated up to 8 */ + r = vsri_n_u8 (r, r, 5); + g = vsri_n_u8 (g, g, 5); + b = vsri_n_u8 (b, b, 5); + + v = pack555 (blend (s.val[0], r, a, inv), + blend (s.val[1], g, a, inv), + blend (s.val[2], b, a, inv)); + + /* where nothing is drawn the unused bit stays as it was */ + vst1q_u16 (pixels + i, + vbslq_u16 (vreinterpretq_u16_s16 (vmovl_s8 (vreinterpret_s8_u8 (vceq_u8 (a, vdup_n_u8 (0))))), + d, v)); + } + + return i; +} + +void +_gdk_rgb_simd_init_neon (GdkRgbSimd *simd) +{ + simd->name = "neon"; + simd->rgb_to_x888 = rgb_to_x888; + simd->rgbx_to_x888 = rgbx_to_x888; + simd->rgb_to_565 = rgb_to_565; + simd->rgb_to_555 = rgb_to_555; + simd->composite_x888 = composite_x888; + simd->composite_565 = composite_565; + simd->composite_555 = composite_555; + simd->rgba_to_argb = rgba_to_argb; +} + +#else + +void +_gdk_rgb_simd_init_neon (GdkRgbSimd *simd) +{ +} + +#endif diff --git a/gdk/gdkrgb-sse2.c b/gdk/gdkrgb-sse2.c new file mode 100644 index 000000000..8662c6f96 --- /dev/null +++ b/gdk/gdkrgb-sse2.c @@ -0,0 +1,300 @@ +/* GDK - The GIMP Drawing Kit + * GdkRGB loops for SSE2 + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + */ + +#include "config.h" + +#include "gdkrgbsimd.h" + +#if defined(__SSE2__) + +#include + +/* x86 is little endian: an x888 pixel is the bytes B, G, R, 0xff */ + +#define SPLAT(v) _mm_set1_epi32 ((gint) (v)) + +/* The 12 bytes of four RGB pixels as lanes R | G << 8 | B << 16 */ +static inline __m128i +rgb_lanes (__m128i v) +{ + __m128i lo = _mm_unpacklo_epi32 (v, _mm_srli_si128 (v, 3)); + __m128i hi = _mm_unpacklo_epi32 (_mm_srli_si128 (v, 6), _mm_srli_si128 (v, 9)); + + return _mm_unpacklo_epi64 (lo, hi); +} + +/* Lanes R | G << 8 | B << 16 to x888 */ +static inline __m128i +x888_of (__m128i v) +{ + return _mm_or_si128 (_mm_or_si128 (_mm_slli_epi32 (_mm_and_si128 (v, SPLAT (0xff)), 16), + _mm_and_si128 (v, SPLAT (0xff00))), + _mm_or_si128 (_mm_and_si128 (_mm_srli_epi32 (v, 16), SPLAT (0xff)), + SPLAT (0xff000000))); +} + +/* Lanes R | G << 8 | B << 16 to 565, sign extended for packing */ +static inline __m128i +rgb565_of (__m128i v) +{ + v = _mm_or_si128 (_mm_or_si128 (_mm_slli_epi32 (_mm_and_si128 (v, SPLAT (0xf8)), 8), + _mm_srli_epi32 (_mm_and_si128 (v, SPLAT (0xfc00)), 5)), + _mm_and_si128 (_mm_srli_epi32 (v, 19), SPLAT (0x1f))); + + return _mm_srai_epi32 (_mm_slli_epi32 (v, 16), 16); +} + +/* The same to 555, with the unused bit set as all of GdkRGB does */ +static inline __m128i +rgb555_of (__m128i v) +{ + v = _mm_or_si128 (_mm_or_si128 (_mm_slli_epi32 (_mm_and_si128 (v, SPLAT (0xf8)), 7), + _mm_srli_epi32 (_mm_and_si128 (v, SPLAT (0xf800)), 6)), + _mm_or_si128 (_mm_and_si128 (_mm_srli_epi32 (v, 19), SPLAT (0x1f)), + SPLAT (0x8000))); + + return _mm_srai_epi32 (_mm_slli_epi32 (v, 16), 16); +} + +static gint +rgb_to_x888 (guint32 *out, const guchar *rgb, gint n) +{ + gint i; + + for (i = 0; i + 8 <= n; i += 8, rgb += 24) + { + __m128i a = _mm_loadu_si128 ((const __m128i *) rgb); + __m128i b = _mm_loadl_epi64 ((const __m128i *) (rgb + 16)); + __m128i c = _mm_or_si128 (_mm_srli_si128 (a, 12), _mm_slli_si128 (b, 4)); + + _mm_storeu_si128 ((__m128i *) (out + i), x888_of (rgb_lanes (a))); + _mm_storeu_si128 ((__m128i *) (out + i + 4), x888_of (rgb_lanes (c))); + } + + return i; +} + +static gint +rgbx_to_x888 (guint32 *out, const guchar *rgbx, gint n) +{ + gint i; + + for (i = 0; i + 4 <= n; i += 4, rgbx += 16) + _mm_storeu_si128 ((__m128i *) (out + i), + x888_of (_mm_loadu_si128 ((const __m128i *) rgbx))); + + return i; +} + +static gint +rgb_to_565 (guint16 *out, const guchar *rgb, gint n) +{ + gint i; + + for (i = 0; i + 8 <= n; i += 8, rgb += 24) + { + __m128i a = _mm_loadu_si128 ((const __m128i *) rgb); + __m128i b = _mm_loadl_epi64 ((const __m128i *) (rgb + 16)); + __m128i c = _mm_or_si128 (_mm_srli_si128 (a, 12), _mm_slli_si128 (b, 4)); + + _mm_storeu_si128 ((__m128i *) (out + i), + _mm_packs_epi32 (rgb565_of (rgb_lanes (a)), + rgb565_of (rgb_lanes (c)))); + } + + return i; +} + +static gint +rgb_to_555 (guint16 *out, const guchar *rgb, gint n) +{ + gint i; + + for (i = 0; i + 8 <= n; i += 8, rgb += 24) + { + __m128i a = _mm_loadu_si128 ((const __m128i *) rgb); + __m128i b = _mm_loadl_epi64 ((const __m128i *) (rgb + 16)); + __m128i c = _mm_or_si128 (_mm_srli_si128 (a, 12), _mm_slli_si128 (b, 4)); + + _mm_storeu_si128 ((__m128i *) (out + i), + _mm_packs_epi32 (rgb555_of (rgb_lanes (a)), + rgb555_of (rgb_lanes (c)))); + } + + return i; +} + +/* (a * s + (255 - a) * d) / 255, rounded, in 16-bit lanes */ +static inline __m128i +blend (__m128i s, __m128i d, __m128i a) +{ + __m128i t = _mm_add_epi16 (_mm_add_epi16 (_mm_mullo_epi16 (s, a), + _mm_mullo_epi16 (d, _mm_sub_epi16 (_mm_set1_epi16 (255), a))), + _mm_set1_epi16 (0x80)); + + return _mm_srli_epi16 (_mm_add_epi16 (t, _mm_srli_epi16 (t, 8)), 8); +} + +/* Alpha of each pixel in all four 16-bit lanes of the pixel */ +static inline __m128i +alpha_of (__m128i v) +{ + return _mm_shufflehi_epi16 (_mm_shufflelo_epi16 (v, 0xff), 0xff); +} + +static gint +composite_x888 (guint32 *pixels, const guchar *rgba, gint n) +{ + const __m128i zero = _mm_setzero_si128 (); + gint i; + + for (i = 0; i + 4 <= n; i += 4, rgba += 16) + { + __m128i s = _mm_loadu_si128 ((const __m128i *) rgba); + __m128i d = _mm_loadu_si128 ((const __m128i *) (pixels + i)); + __m128i transparent = _mm_cmpeq_epi32 (_mm_srli_epi32 (s, 24), zero); + __m128i lo, hi, v; + + /* RGBA to BGRA, the order of the pixels */ + s = _mm_or_si128 (_mm_and_si128 (s, SPLAT (0xff00ff00)), + _mm_or_si128 (_mm_slli_epi32 (_mm_and_si128 (s, SPLAT (0xff)), 16), + _mm_and_si128 (_mm_srli_epi32 (s, 16), SPLAT (0xff)))); + + lo = _mm_unpacklo_epi8 (s, zero); + hi = _mm_unpackhi_epi8 (s, zero); + lo = blend (lo, _mm_unpacklo_epi8 (d, zero), alpha_of (lo)); + hi = blend (hi, _mm_unpackhi_epi8 (d, zero), alpha_of (hi)); + v = _mm_or_si128 (_mm_packus_epi16 (lo, hi), SPLAT (0xff000000)); + + /* fully transparent pixels stay as they are */ + v = _mm_or_si128 (_mm_and_si128 (transparent, d), _mm_andnot_si128 (transparent, v)); + _mm_storeu_si128 ((__m128i *) (pixels + i), v); + } + + return i; +} + +/* Eight 565 or 555 pixels at a time, each channel in a register */ +static inline gint +composite_16 (guint16 *pixels, const guchar *rgba, gint n, const gint green_bits) +{ + const gint red_shift = 5 + green_bits; + gint i; + + for (i = 0; i + 8 <= n; i += 8, rgba += 32) + { + __m128i s0 = _mm_loadu_si128 ((const __m128i *) rgba); + __m128i s1 = _mm_loadu_si128 ((const __m128i *) (rgba + 16)); + __m128i d = _mm_loadu_si128 ((const __m128i *) (pixels + i)); + __m128i r = _mm_packs_epi32 (_mm_and_si128 (s0, SPLAT (0xff)), + _mm_and_si128 (s1, SPLAT (0xff))); + __m128i g = _mm_packs_epi32 (_mm_and_si128 (_mm_srli_epi32 (s0, 8), SPLAT (0xff)), + _mm_and_si128 (_mm_srli_epi32 (s1, 8), SPLAT (0xff))); + __m128i b = _mm_packs_epi32 (_mm_and_si128 (_mm_srli_epi32 (s0, 16), SPLAT (0xff)), + _mm_and_si128 (_mm_srli_epi32 (s1, 16), SPLAT (0xff))); + __m128i a = _mm_packs_epi32 (_mm_srli_epi32 (s0, 24), _mm_srli_epi32 (s1, 24)); + __m128i dr = _mm_and_si128 (_mm_srli_epi16 (d, red_shift), _mm_set1_epi16 (0x1f)); + __m128i dg = _mm_and_si128 (_mm_srli_epi16 (d, 5), _mm_set1_epi16 ((1 << green_bits) - 1)); + __m128i db = _mm_and_si128 (d, _mm_set1_epi16 (0x1f)); + __m128i v; + + /* the bits of the pixel repeated up to 8 */ + dr = _mm_or_si128 (_mm_slli_epi16 (dr, 3), _mm_srli_epi16 (dr, 2)); + if (green_bits == 6) + dg = _mm_or_si128 (_mm_slli_epi16 (dg, 2), _mm_srli_epi16 (dg, 4)); + else + dg = _mm_or_si128 (_mm_slli_epi16 (dg, 3), _mm_srli_epi16 (dg, 2)); + db = _mm_or_si128 (_mm_slli_epi16 (db, 3), _mm_srli_epi16 (db, 2)); + + r = blend (r, dr, a); + g = blend (g, dg, a); + b = blend (b, db, a); + v = _mm_or_si128 (_mm_or_si128 (_mm_slli_epi16 (_mm_srli_epi16 (r, 3), red_shift), + _mm_slli_epi16 (_mm_srli_epi16 (g, 8 - green_bits), 5)), + _mm_srli_epi16 (b, 3)); + + if (green_bits == 5) + { + /* the unused bit is set, except where nothing is drawn */ + __m128i transparent = _mm_cmpeq_epi16 (a, _mm_setzero_si128 ()); + + v = _mm_or_si128 (_mm_and_si128 (transparent, d), + _mm_andnot_si128 (transparent, _mm_or_si128 (v, _mm_set1_epi16 ((gshort) 0x8000)))); + } + _mm_storeu_si128 ((__m128i *) (pixels + i), v); + } + + return i; +} + +static gint +composite_565 (guint16 *pixels, const guchar *rgba, gint n) +{ + return composite_16 (pixels, rgba, n, 6); +} + +static gint +composite_555 (guint16 *pixels, const guchar *rgba, gint n) +{ + return composite_16 (pixels, rgba, n, 5); +} + +/* c * a / 255 to the nearest, which (c * a + 0x80) * 257 >> 16 is */ +static gint +rgba_to_argb (guint32 *out, const guchar *rgba, gint n) +{ + const __m128i zero = _mm_setzero_si128 (); + gint i; + + for (i = 0; i + 4 <= n; i += 4, rgba += 16) + { + __m128i s = _mm_loadu_si128 ((const __m128i *) rgba); + __m128i lo = _mm_unpacklo_epi8 (s, zero); + __m128i hi = _mm_unpackhi_epi8 (s, zero); + + lo = _mm_mulhi_epu16 (_mm_add_epi16 (_mm_mullo_epi16 (lo, alpha_of (lo)), _mm_set1_epi16 (0x80)), + _mm_set1_epi16 (257)); + hi = _mm_mulhi_epu16 (_mm_add_epi16 (_mm_mullo_epi16 (hi, alpha_of (hi)), _mm_set1_epi16 (0x80)), + _mm_set1_epi16 (257)); + + /* R, G, B to B, G, R: the bytes of 0xAARRGGBB */ + lo = _mm_shufflehi_epi16 (_mm_shufflelo_epi16 (lo, 0xc6), 0xc6); + hi = _mm_shufflehi_epi16 (_mm_shufflelo_epi16 (hi, 0xc6), 0xc6); + + /* the alpha byte as it was */ + _mm_storeu_si128 ((__m128i *) (out + i), + _mm_or_si128 (_mm_and_si128 (_mm_packus_epi16 (lo, hi), SPLAT (0x00ffffff)), + _mm_and_si128 (s, SPLAT (0xff000000)))); + } + + return i; +} + +void +_gdk_rgb_simd_init_sse2 (GdkRgbSimd *simd) +{ + simd->name = "sse2"; + simd->rgb_to_x888 = rgb_to_x888; + simd->rgbx_to_x888 = rgbx_to_x888; + simd->rgb_to_565 = rgb_to_565; + simd->rgb_to_555 = rgb_to_555; + simd->composite_x888 = composite_x888; + simd->composite_565 = composite_565; + simd->composite_555 = composite_555; + simd->rgba_to_argb = rgba_to_argb; +} + +#else + +void +_gdk_rgb_simd_init_sse2 (GdkRgbSimd *simd) +{ +} + +#endif diff --git a/gdk/gdkrgb-ssse3.c b/gdk/gdkrgb-ssse3.c new file mode 100644 index 000000000..f2157955c --- /dev/null +++ b/gdk/gdkrgb-ssse3.c @@ -0,0 +1,224 @@ +/* GDK - The GIMP Drawing Kit + * GdkRGB loops for SSSE3 (Atom, Core 2 and later): pshufb moves the + * bytes of pixels where SSE2 takes a row of shifts and masks + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + */ + +#include "config.h" + +#include "gdkrgbsimd.h" + +#if defined(__SSSE3__) + +#include + +/* x86 is little endian: an x888 pixel is the bytes B, G, R, 0xff */ + +#define SPLAT(v) _mm_set1_epi32 ((gint) (v)) +#define BYTES(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) \ + _mm_setr_epi8 (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) + +/* The first 12 bytes of four RGB pixels to B, G, R, 0 each */ +static inline __m128i +bgr0_of_rgb (__m128i v) +{ + return _mm_shuffle_epi8 (v, BYTES (2, 1, 0, -1, 5, 4, 3, -1, 8, 7, 6, -1, 11, 10, 9, -1)); +} + +/* ... and to lanes R | G << 8 | B << 16, which SSE2 calls them */ +static inline __m128i +rgb0_of_rgb (__m128i v) +{ + return _mm_shuffle_epi8 (v, BYTES (0, 1, 2, -1, 3, 4, 5, -1, 6, 7, 8, -1, 9, 10, 11, -1)); +} + +static gint +rgb_to_x888 (guint32 *out, const guchar *rgb, gint n) +{ + const __m128i fill = SPLAT (0xff000000); + gint i; + + for (i = 0; i + 16 <= n; i += 16, rgb += 48) + { + __m128i a = _mm_loadu_si128 ((const __m128i *) rgb); + __m128i b = _mm_loadu_si128 ((const __m128i *) (rgb + 16)); + __m128i c = _mm_loadu_si128 ((const __m128i *) (rgb + 32)); + + _mm_storeu_si128 ((__m128i *) (out + i), _mm_or_si128 (bgr0_of_rgb (a), fill)); + _mm_storeu_si128 ((__m128i *) (out + i + 4), + _mm_or_si128 (bgr0_of_rgb (_mm_alignr_epi8 (b, a, 12)), fill)); + _mm_storeu_si128 ((__m128i *) (out + i + 8), + _mm_or_si128 (bgr0_of_rgb (_mm_alignr_epi8 (c, b, 8)), fill)); + _mm_storeu_si128 ((__m128i *) (out + i + 12), + _mm_or_si128 (bgr0_of_rgb (_mm_srli_si128 (c, 4)), fill)); + } + + return i; +} + +static gint +rgbx_to_x888 (guint32 *out, const guchar *rgbx, gint n) +{ + const __m128i order = BYTES (2, 1, 0, -1, 6, 5, 4, -1, 10, 9, 8, -1, 14, 13, 12, -1); + gint i; + + for (i = 0; i + 4 <= n; i += 4, rgbx += 16) + _mm_storeu_si128 ((__m128i *) (out + i), + _mm_or_si128 (_mm_shuffle_epi8 (_mm_loadu_si128 ((const __m128i *) rgbx), order), + SPLAT (0xff000000))); + + return i; +} + +/* Lanes R | G << 8 | B << 16 to 565 or 555, sign extended for packing. + * The bit 555 has no use for is set, as in all of GdkRGB's pixels. */ +static inline __m128i +rgb16_of (__m128i v, const gint green_bits) +{ + if (green_bits == 6) + v = _mm_or_si128 (_mm_or_si128 (_mm_slli_epi32 (_mm_and_si128 (v, SPLAT (0xf8)), 8), + _mm_srli_epi32 (_mm_and_si128 (v, SPLAT (0xfc00)), 5)), + _mm_and_si128 (_mm_srli_epi32 (v, 19), SPLAT (0x1f))); + else + v = _mm_or_si128 (_mm_or_si128 (_mm_slli_epi32 (_mm_and_si128 (v, SPLAT (0xf8)), 7), + _mm_srli_epi32 (_mm_and_si128 (v, SPLAT (0xf800)), 6)), + _mm_or_si128 (_mm_and_si128 (_mm_srli_epi32 (v, 19), SPLAT (0x1f)), + SPLAT (0x8000))); + + return _mm_srai_epi32 (_mm_slli_epi32 (v, 16), 16); +} + +static inline gint +rgb_to_16 (guint16 *out, const guchar *rgb, gint n, const gint green_bits) +{ + gint i; + + for (i = 0; i + 16 <= n; i += 16, rgb += 48) + { + __m128i a = _mm_loadu_si128 ((const __m128i *) rgb); + __m128i b = _mm_loadu_si128 ((const __m128i *) (rgb + 16)); + __m128i c = _mm_loadu_si128 ((const __m128i *) (rgb + 32)); + + _mm_storeu_si128 ((__m128i *) (out + i), + _mm_packs_epi32 (rgb16_of (rgb0_of_rgb (a), green_bits), + rgb16_of (rgb0_of_rgb (_mm_alignr_epi8 (b, a, 12)), green_bits))); + _mm_storeu_si128 ((__m128i *) (out + i + 8), + _mm_packs_epi32 (rgb16_of (rgb0_of_rgb (_mm_alignr_epi8 (c, b, 8)), green_bits), + rgb16_of (rgb0_of_rgb (_mm_srli_si128 (c, 4)), green_bits))); + } + + return i; +} + +static gint +rgb_to_565 (guint16 *out, const guchar *rgb, gint n) +{ + return rgb_to_16 (out, rgb, n, 6); +} + +static gint +rgb_to_555 (guint16 *out, const guchar *rgb, gint n) +{ + return rgb_to_16 (out, rgb, n, 5); +} + +/* The alpha of each pixel in its four 16-bit lanes */ +static inline __m128i +alpha_of (__m128i v) +{ + return _mm_shuffle_epi8 (v, BYTES (6, 7, 6, 7, 6, 7, 6, 7, 14, 15, 14, 15, 14, 15, 14, 15)); +} + +/* (a * s + (255 - a) * d) / 255, rounded as GdkRGB's C code does */ +static inline __m128i +blend (__m128i s, __m128i d, __m128i a) +{ + __m128i t = _mm_add_epi16 (_mm_add_epi16 (_mm_mullo_epi16 (s, a), + _mm_mullo_epi16 (d, _mm_sub_epi16 (_mm_set1_epi16 (255), a))), + _mm_set1_epi16 (0x80)); + + return _mm_mulhi_epu16 (t, _mm_set1_epi16 (257)); +} + +static gint +composite_x888 (guint32 *pixels, const guchar *rgba, gint n) +{ + const __m128i zero = _mm_setzero_si128 (); + const __m128i order = BYTES (2, 1, 0, 3, 6, 5, 4, 7, 10, 9, 8, 11, 14, 13, 12, 15); + gint i; + + for (i = 0; i + 4 <= n; i += 4, rgba += 16) + { + __m128i s = _mm_loadu_si128 ((const __m128i *) rgba); + __m128i d = _mm_loadu_si128 ((const __m128i *) (pixels + i)); + __m128i transparent = _mm_cmpeq_epi32 (_mm_srli_epi32 (s, 24), zero); + __m128i lo, hi, v; + + /* RGBA to BGRA, the order of the pixels */ + s = _mm_shuffle_epi8 (s, order); + lo = _mm_unpacklo_epi8 (s, zero); + hi = _mm_unpackhi_epi8 (s, zero); + lo = blend (lo, _mm_unpacklo_epi8 (d, zero), alpha_of (lo)); + hi = blend (hi, _mm_unpackhi_epi8 (d, zero), alpha_of (hi)); + v = _mm_or_si128 (_mm_packus_epi16 (lo, hi), SPLAT (0xff000000)); + + /* fully transparent pixels stay as they are */ + v = _mm_or_si128 (_mm_and_si128 (transparent, d), _mm_andnot_si128 (transparent, v)); + _mm_storeu_si128 ((__m128i *) (pixels + i), v); + } + + return i; +} + +/* c * a / 255 to the nearest, which (c * a + 0x80) * 257 >> 16 is */ +static gint +rgba_to_argb (guint32 *out, const guchar *rgba, gint n) +{ + const __m128i zero = _mm_setzero_si128 (); + const __m128i order = BYTES (2, 1, 0, -1, 6, 5, 4, -1, 10, 9, 8, -1, 14, 13, 12, -1); + gint i; + + for (i = 0; i + 4 <= n; i += 4, rgba += 16) + { + __m128i s = _mm_loadu_si128 ((const __m128i *) rgba); + __m128i lo = _mm_unpacklo_epi8 (s, zero); + __m128i hi = _mm_unpackhi_epi8 (s, zero); + + lo = _mm_mulhi_epu16 (_mm_add_epi16 (_mm_mullo_epi16 (lo, alpha_of (lo)), _mm_set1_epi16 (0x80)), + _mm_set1_epi16 (257)); + hi = _mm_mulhi_epu16 (_mm_add_epi16 (_mm_mullo_epi16 (hi, alpha_of (hi)), _mm_set1_epi16 (0x80)), + _mm_set1_epi16 (257)); + + /* R, G, B to B, G, R, and the alpha byte as it was */ + _mm_storeu_si128 ((__m128i *) (out + i), + _mm_or_si128 (_mm_shuffle_epi8 (_mm_packus_epi16 (lo, hi), order), + _mm_and_si128 (s, SPLAT (0xff000000)))); + } + + return i; +} + +void +_gdk_rgb_simd_init_ssse3 (GdkRgbSimd *simd) +{ + simd->name = "ssse3"; + simd->rgb_to_x888 = rgb_to_x888; + simd->rgbx_to_x888 = rgbx_to_x888; + simd->rgb_to_565 = rgb_to_565; + simd->rgb_to_555 = rgb_to_555; + simd->composite_x888 = composite_x888; + simd->rgba_to_argb = rgba_to_argb; +} + +#else + +void +_gdk_rgb_simd_init_ssse3 (GdkRgbSimd *simd) +{ +} + +#endif diff --git a/gdk/gdkrgb.c b/gdk/gdkrgb.c index e4f63ddaf..8f7a66b12 100644 --- a/gdk/gdkrgb.c +++ b/gdk/gdkrgb.c @@ -39,6 +39,7 @@ #include "gdkinternals.h" /* _gdk_windowing_get_bits_for_depth() */ #include "gdkrgb.h" +#include "gdkrgbsimd.h" #include "gdkscreen.h" #include "gdkalias.h" #include @@ -46,14 +47,12 @@ typedef struct _GdkRgbInfo GdkRgbInfo; typedef struct _GdkRgbCmapInfo GdkRgbCmapInfo; -typedef void (*GdkRgbConvFunc) (GdkRgbInfo *image_info, GdkImage *image, - gint x0, gint y0, - gint width, gint height, - const guchar *buf, int rowstride, - gint x_align, gint y_align, - GdkRgbCmap *cmap); - -#define STAGE_ROWSTRIDE (GDK_SCRATCH_IMAGE_WIDTH * 3) +typedef void (*GdkRgbIndexRowFunc) (GdkRgbInfo *info, + guchar *out, + const guchar *in, + gint width, + const guchar *dm, + gint x_dith); /* Some of these fields should go, as they're not being used at all. (?) */ @@ -69,13 +68,10 @@ struct _GdkRgbInfo guint nreserved; guint bpp; + guint bits_per_pixel; gint cmap_alloced; gdouble gamma; - /* Generally, the stage buffer is used to convert 32bit RGB, gray, - and indexed images into 24 bit packed RGB. */ - guchar *stage_buf; - GdkRgbCmap *gray_cmap; gboolean dith_default; @@ -83,18 +79,18 @@ struct _GdkRgbInfo gboolean bitmap; /* set true if in 1 bit per pixel mode */ GdkGC *own_gc; - /* Convert functions */ - GdkRgbConvFunc conv; - GdkRgbConvFunc conv_d; + /* TrueColor: red, green and blue table (see gdk_rgb_init_truecolor()) */ + guint32 *tables; + guint32 fill; + guint8 shift16[3][2]; + guint32 dither_pack[64]; + guint8 unpack[3][256]; /* channel values of up to 8 bits to 8 bits */ + guint8 layout; + gboolean ditherable; - GdkRgbConvFunc conv_32; - GdkRgbConvFunc conv_32_d; - - GdkRgbConvFunc conv_gray; - GdkRgbConvFunc conv_gray_d; - - GdkRgbConvFunc conv_indexed; - GdkRgbConvFunc conv_indexed_d; + /* Palettes and gray levels */ + GdkRgbIndexRowFunc index_row; + GdkRgbIndexRowFunc index_row_dither; guchar *colorcube; guchar *colorcube_d; @@ -390,17 +386,25 @@ gdk_rgb_score_visual (GdkVisual *visual) if (visual->type == GDK_VISUAL_TRUE_COLOR || visual->type == GDK_VISUAL_DIRECT_COLOR) { - if (visual->depth == 24) - { - quality = 9; - /* Should test for MSB visual here, and set speed if so. */ - } - else if (visual->depth == 16) + /* Visuals with alpha (depth 32 with 24 color bits) are skipped */ + gint bits = visual->red_prec + visual->green_prec + visual->blue_prec; + + if (bits != visual->depth) + quality = 0; + else if (bits > 24) + quality = 10; + else if (bits == 24) + quality = 9; + else if (bits == 16) quality = 8; - else if (visual->depth == 15) + else if (bits == 15) quality = 7; - else if (visual->depth == 8) + else if (bits > 8) + quality = 5; + else if (bits == 8) quality = 4; + else if (bits >= 3) + quality = 2; } else if (visual->type == GDK_VISUAL_PSEUDO_COLOR || visual->type == GDK_VISUAL_STATIC_COLOR) @@ -525,7 +529,7 @@ gdk_rgb_free_info (GdkRgbInfo *image_info) { GSList *tmp_list; - g_free (image_info->stage_buf); + g_free (image_info->tables); if (image_info->gray_cmap) gdk_rgb_cmap_free (image_info->gray_cmap); @@ -543,6 +547,7 @@ gdk_rgb_free_info (GdkRgbInfo *image_info) GdkRgbCmapInfo *cmap_info = tmp_list->data; cmap_info->cmap->info_list = g_slist_remove (cmap_info->cmap->info_list, cmap_info); g_free (cmap_info); + tmp_list = tmp_list->next; } g_slist_free (image_info->cmap_info_list); @@ -575,8 +580,6 @@ gdk_rgb_create_info (GdkVisual *visual, GdkColormap *colormap) image_info->cmap_alloced = FALSE; image_info->gamma = 1.0; - image_info->stage_buf = NULL; - image_info->own_gc = NULL; image_info->cmap = colormap; @@ -661,7 +664,8 @@ gdk_rgb_create_info (GdkVisual *visual, GdkColormap *colormap) image_info->bitmap = (image_info->visual->depth == 1); - image_info->bpp = (_gdk_windowing_get_bits_for_depth (gdk_screen_get_display (screen), image_info->visual->depth) + 7) / 8; + image_info->bits_per_pixel = _gdk_windowing_get_bits_for_depth (gdk_screen_get_display (screen), image_info->visual->depth); + image_info->bpp = (image_info->bits_per_pixel + 7) / 8; gdk_rgb_select_conv (image_info); if (!gdk_rgb_quark) @@ -838,141 +842,28 @@ gdk_rgb_find_color (GdkColormap *colormap, GdkColor *color) color->red, color->green, color->blue); } -#if G_BYTE_ORDER == G_LITTLE_ENDIAN -#define HAIRY_CONVERT_8 -#endif - -#ifdef HAIRY_CONVERT_8 -static void -gdk_rgb_convert_8 (GdkRgbInfo *image_info, GdkImage *image, - gint x0, gint y0, gint width, gint height, - const guchar *buf, int rowstride, - gint x_align, gint y_align, GdkRgbCmap *cmap) -{ - int x, y; - gint bpl; - guchar *obuf, *obptr; - const guchar *bptr, *bp2; - gint r, g, b; - guchar *colorcube = image_info->colorcube; - - bptr = buf; - bpl = image->bpl; - obuf = ((guchar *)image->mem) + y0 * bpl + x0; - for (y = 0; y < height; y++) - { - bp2 = bptr; - obptr = obuf; - if (((guintptr)obuf | (guintptr) bp2) & 3) - { - for (x = 0; x < width; x++) - { - r = *bp2++; - g = *bp2++; - b = *bp2++; - obptr[0] = colorcube[((r & 0xf0) << 4) | - (g & 0xf0) | - (b >> 4)]; - obptr++; - } - } - else - { - for (x = 0; x < width - 3; x += 4) - { - guint32 r1b0g0r0; - guint32 g2r2b1g1; - guint32 b3g3r3b2; - - r1b0g0r0 = ((guint32 *)bp2)[0]; - g2r2b1g1 = ((guint32 *)bp2)[1]; - b3g3r3b2 = ((guint32 *)bp2)[2]; - ((guint32 *)obptr)[0] = - colorcube[((r1b0g0r0 & 0xf0) << 4) | - ((r1b0g0r0 & 0xf000) >> 8) | - ((r1b0g0r0 & 0xf00000) >> 20)] | - (colorcube[((r1b0g0r0 & 0xf0000000) >> 20) | - (g2r2b1g1 & 0xf0) | - ((g2r2b1g1 & 0xf000) >> 12)] << 8) | - (colorcube[((g2r2b1g1 & 0xf00000) >> 12) | - ((g2r2b1g1 & 0xf0000000) >> 24) | - ((b3g3r3b2 & 0xf0) >> 4)] << 16) | - (colorcube[((b3g3r3b2 & 0xf000) >> 4) | - ((b3g3r3b2 & 0xf00000) >> 16) | - (b3g3r3b2 >> 28)] << 24); - bp2 += 12; - obptr += 4; - } - for (; x < width; x++) - { - r = *bp2++; - g = *bp2++; - b = *bp2++; - obptr[0] = colorcube[((r & 0xf0) << 4) | - (g & 0xf0) | - (b >> 4)]; - obptr++; - } - } - bptr += rowstride; - obuf += bpl; - } -} -#else -static void -gdk_rgb_convert_8 (GdkRgbInfo *image_info, GdkImage *image, - gint x0, gint y0, gint width, gint height, - const guchar *buf, int rowstride, - gint x_align, gint y_align, GdkRgbCmap *cmap) -{ - int x, y; - gint bpl; - guchar *obuf, *obptr; - const guchar *bptr, *bp2; - gint r, g, b; - guchar *colorcube = image_info->colorcube; - - bptr = buf; - bpl = image->bpl; - obuf = ((guchar *)image->mem) + y0 * bpl + x0; - for (y = 0; y < height; y++) - { - bp2 = bptr; - obptr = obuf; - for (x = 0; x < width; x++) - { - r = *bp2++; - g = *bp2++; - b = *bp2++; - obptr[0] = colorcube[((r & 0xf0) << 4) | - (g & 0xf0) | - (b >> 4)]; - obptr++; - } - bptr += rowstride; - obuf += bpl; - } -} -#endif - - - -/* Dither matrices - * --------------- +/*** Pixel conversion * - * The original matrices are called "DM" below. The preprocessed matrices for - * 5-6-5 RGB displays are called "DM_565". These preprocessed tables can be - * generated with the gdk_rgb_preprocess_dm_565() function below. + * Images are converted row by row into scratch images. The source is + * 8-bit RGB, RGBX, gray or indexed, or 16-bit RGB or RGBX; the target + * is described by the visual: + * + * - TrueColor and DirectColor with any size and position of the + * channels, 8, 16, 24 or 32 bits per pixel, in either byte order. + * A table per channel holds its bits already in place, so all of + * these cost the same. Bits outside the channels are set. + * - Palettes and gray levels with 1 to 8 bits per pixel: a row of + * pixel values is made and packed if pixels are smaller than bytes. + * + * Nothing depends on the byte order of the machine: pixels are always + * stored in the byte order of the image. */ -#if 1 - /* This dither table was generated by Raph Levien using patented technology (US Patent 5,276,535). The dither table itself is in the public domain. */ #define DM_WIDTH 128 -#define DM_WIDTH_SHIFT 7 #define DM_HEIGHT 128 static const guchar DM[128][128] = { @@ -1106,2416 +997,1033 @@ static const guchar DM[128][128] = { 51, 14, 61, 29, 59, 20, 55, 31, 0, 49, 11, 60, 3, 26, 22, 56, 0, 40, 12, 43, 41, 8, 36, 0, 17, 57, 24, 2, 46, 26, 61, 18, 0, 38, 12, 59, 6, 49, 3, 57, 19, 63, 5, 33, 18, 54, 28, 56, 0, 43, 26, 46, 63, 27, 56, 22, 27, 54, 38, 28, 63, 24, 10, 45, 0, 31, 42, 21, 12, 25, 44, 49, 59, 6, 26, 50, 3, 34, 27, 59, 0, 35, 62, 16, 4, 58, 47, 0, 43, 24, 37, 2, 54, 20, 46, 31, 0, 56, 34, 5, 55, 45, 60, 37, 0, 40, 10, 38, 63, 46, 15, 20, 0, 53, 21, 62, 30, 11, 24, 27, 40, 0, 57, 26, 3, 45, 27, 35 }, }; -static const guint32 DM_565[128 * 128] = +typedef enum { - 3072, 5243909, 2099202, 3072, 2099202, 4195332, 3072, 1051649, 7340039, 2099202, 5243909, 6291462, 3147779, 5243909, 1051649, 4195332, 6291462, 3147779, 7340039, 3147779, 3072, 7340039, 3147779, 6291462, 4195332, 3072, 5243909, 7340039, 2099202, 4195332, 1051649, 5243909, 3147779, 7340039, 5243909, 4195332, 2099202, 5243909, 4195332, 1051649, 4195332, 3147779, 6291462, 1051649, 7340039, 3072, 5243909, 1051649, 4195332, 1051649, 7340039, 2099202, 3072, 5243909, 1051649, 4195332, 3072, 7340039, 1051649, 5243909, 3072, 6291462, 4195332, 2099202, 4195332, 7340039, 1051649, 6291462, 4195332, 7340039, 1051649, 3147779, 2099202, 1051649, 7340039, 2099202, 5243909, 6291462, 3072, 2099202, 6291462, 1051649, 2099202, 6291462, 4195332, 2099202, 2099202, 4195332, 1051649, 6291462, 2099202, 7340039, 3147779, 1051649, 4195332, 3147779, 6291462, 1051649, 2099202, 5243909, 2099202, 3147779, 3072, 2099202, 6291462, 3147779, 6291462, 2099202, 3072, 4195332, 7340039, 5243909, 3147779, 4195332, 1051649, 6291462, 2099202, 5243909, 3072, 6291462, 1051649, 5243909, 4195332, 6291462, 2099202, 5243909, 1051649, 7340039, - 3147779, 7340039, 4195332, 6291462, 5243909, 4195332, 6291462, 3147779, 5243909, 3072, 3147779, 3072, 2099202, 4195332, 7340039, 1051649, 5243909, 3072, 2099202, 6291462, 4195332, 2099202, 5243909, 1051649, 3147779, 5243909, 1051649, 4195332, 3072, 6291462, 3147779, 7340039, 1051649, 3147779, 3072, 2099202, 6291462, 1051649, 7340039, 3147779, 5243909, 3072, 4195332, 3147779, 5243909, 2099202, 5243909, 3147779, 7340039, 4195332, 1051649, 4195332, 6291462, 2099202, 7340039, 3147779, 6291462, 2099202, 4195332, 3147779, 6291462, 2099202, 3072, 6291462, 2099202, 1051649, 3147779, 5243909, 3072, 4195332, 5243909, 2099202, 6291462, 5243909, 4195332, 2099202, 3147779, 1051649, 5243909, 3147779, 4195332, 7340039, 3072, 4195332, 1051649, 5243909, 7340039, 3147779, 7340039, 1051649, 5243909, 1051649, 5243909, 3072, 7340039, 3072, 2099202, 6291462, 7340039, 1051649, 6291462, 1051649, 5243909, 7340039, 1051649, 3147779, 3072, 6291462, 5243909, 3147779, 1051649, 6291462, 2099202, 7340039, 5243909, 3072, 4195332, 7340039, 4195332, 2099202, 7340039, 3147779, 2099202, 3072, 7340039, 4195332, 3147779, 4195332, - 2099202, 1051649, 2099202, 4195332, 3072, 3147779, 1051649, 7340039, 2099202, 5243909, 7340039, 4195332, 6291462, 2099202, 3072, 5243909, 2099202, 4195332, 7340039, 3072, 6291462, 1051649, 7340039, 3072, 7340039, 2099202, 6291462, 3147779, 5243909, 2099202, 3072, 6291462, 1051649, 6291462, 5243909, 6291462, 3147779, 4195332, 3072, 6291462, 2099202, 7340039, 1051649, 6291462, 3072, 4195332, 1051649, 6291462, 2099202, 3147779, 6291462, 1051649, 3147779, 6291462, 3072, 4195332, 1051649, 5243909, 3072, 6291462, 1051649, 4195332, 7340039, 3147779, 7340039, 4195332, 6291462, 1051649, 7340039, 2099202, 3072, 7340039, 3072, 3147779, 3072, 6291462, 7340039, 4195332, 1051649, 7340039, 3072, 3147779, 5243909, 3147779, 6291462, 1051649, 3072, 5243909, 3072, 4195332, 4195332, 6291462, 3147779, 6291462, 4195332, 5243909, 7340039, 3072, 3147779, 4195332, 2099202, 7340039, 3072, 4195332, 5243909, 7340039, 4195332, 2099202, 7340039, 3072, 6291462, 3147779, 3072, 4195332, 2099202, 6291462, 3147779, 1051649, 5243909, 6291462, 1051649, 3072, 7340039, 4195332, 2099202, 6291462, 3072, 5243909, - 6291462, 6291462, 5243909, 1051649, 5243909, 7340039, 3147779, 4195332, 1051649, 4195332, 2099202, 3072, 3147779, 5243909, 3147779, 7340039, 3072, 6291462, 1051649, 4195332, 3147779, 2099202, 4195332, 4195332, 2099202, 5243909, 3072, 6291462, 1051649, 7340039, 3147779, 4195332, 2099202, 4195332, 2099202, 2099202, 3072, 5243909, 4195332, 2099202, 1051649, 5243909, 3147779, 3147779, 7340039, 2099202, 7340039, 3072, 5243909, 3072, 5243909, 7340039, 3072, 3147779, 5243909, 2099202, 7340039, 3147779, 7340039, 2099202, 4195332, 5243909, 1051649, 5243909, 3072, 4195332, 3072, 4195332, 1051649, 5243909, 6291462, 4195332, 2099202, 6291462, 5243909, 1051649, 2099202, 3072, 6291462, 2099202, 6291462, 5243909, 1051649, 7340039, 2099202, 6291462, 3147779, 6291462, 2099202, 7340039, 1051649, 3072, 7340039, 2099202, 1051649, 2099202, 4195332, 4195332, 2099202, 5243909, 3072, 6291462, 3147779, 4195332, 2099202, 3072, 6291462, 1051649, 3147779, 5243909, 4195332, 2099202, 7340039, 1051649, 5243909, 1051649, 6291462, 2099202, 3072, 4195332, 3147779, 5243909, 3147779, 3072, 6291462, 1051649, 7340039, 3072, - 2099202, 3147779, 3072, 7340039, 2099202, 1051649, 6291462, 3072, 5243909, 6291462, 1051649, 7340039, 1051649, 6291462, 1051649, 4195332, 2099202, 3147779, 5243909, 1051649, 6291462, 3147779, 5243909, 3072, 6291462, 1051649, 7340039, 1051649, 4195332, 1051649, 6291462, 1051649, 7340039, 3072, 7340039, 5243909, 7340039, 1051649, 6291462, 3147779, 7340039, 4195332, 1051649, 6291462, 3072, 5243909, 3147779, 4195332, 6291462, 2099202, 4195332, 1051649, 6291462, 4195332, 1051649, 6291462, 3072, 2099202, 1051649, 5243909, 3072, 7340039, 1051649, 2099202, 6291462, 2099202, 6291462, 3147779, 7340039, 2099202, 3147779, 1051649, 5243909, 1051649, 3147779, 7340039, 5243909, 4195332, 3147779, 4195332, 1051649, 3147779, 2099202, 4195332, 3072, 5243909, 4195332, 1051649, 6291462, 4195332, 2099202, 5243909, 3147779, 5243909, 3147779, 6291462, 3072, 5243909, 6291462, 1051649, 7340039, 3147779, 1051649, 6291462, 2099202, 5243909, 4195332, 2099202, 4195332, 3072, 6291462, 1051649, 5243909, 4195332, 3072, 7340039, 3147779, 5243909, 7340039, 2099202, 1051649, 7340039, 4195332, 5243909, 1051649, 4195332, 3147779, 4195332, - 6291462, 4195332, 7340039, 3147779, 4195332, 5243909, 2099202, 7340039, 3072, 4195332, 5243909, 3147779, 5243909, 4195332, 3072, 6291462, 6291462, 1051649, 7340039, 2099202, 5243909, 3072, 7340039, 3147779, 2099202, 5243909, 4195332, 3147779, 7340039, 5243909, 2099202, 4195332, 4195332, 3147779, 5243909, 1051649, 3147779, 2099202, 3072, 5243909, 1051649, 6291462, 3072, 4195332, 2099202, 6291462, 1051649, 2099202, 3072, 7340039, 2099202, 3147779, 6291462, 2099202, 7340039, 3147779, 5243909, 4195332, 7340039, 1051649, 6291462, 4195332, 3147779, 5243909, 2099202, 7340039, 3147779, 1051649, 5243909, 3072, 4195332, 7340039, 1051649, 7340039, 3147779, 3072, 6291462, 1051649, 7340039, 3072, 5243909, 7340039, 3072, 7340039, 3147779, 2099202, 3072, 7340039, 3147779, 1051649, 7340039, 2099202, 5243909, 3072, 7340039, 4195332, 3147779, 1051649, 3147779, 4195332, 1051649, 5243909, 6291462, 3072, 6291462, 1051649, 7340039, 3072, 7340039, 1051649, 3147779, 7340039, 2099202, 6291462, 4195332, 2099202, 4195332, 1051649, 3147779, 6291462, 5243909, 2099202, 3072, 3147779, 7340039, 2099202, 6291462, 1051649, - 3147779, 3072, 3147779, 1051649, 6291462, 3072, 4195332, 3147779, 2099202, 6291462, 2099202, 7340039, 3072, 7340039, 3147779, 2099202, 3072, 4195332, 3147779, 3072, 6291462, 4195332, 1051649, 6291462, 3147779, 6291462, 2099202, 5243909, 3072, 3147779, 7340039, 3072, 6291462, 1051649, 3147779, 3072, 6291462, 5243909, 7340039, 3147779, 4195332, 1051649, 7340039, 2099202, 5243909, 1051649, 7340039, 4195332, 5243909, 3147779, 5243909, 5243909, 3072, 4195332, 1051649, 5243909, 2099202, 3072, 5243909, 3147779, 3147779, 2099202, 7340039, 3072, 4195332, 3072, 5243909, 4195332, 3147779, 6291462, 2099202, 3147779, 6291462, 3072, 4195332, 7340039, 2099202, 4195332, 2099202, 6291462, 1051649, 5243909, 3147779, 4195332, 1051649, 6291462, 5243909, 3147779, 2099202, 5243909, 4195332, 3072, 6291462, 2099202, 1051649, 1051649, 6291462, 7340039, 3072, 7340039, 5243909, 2099202, 1051649, 3147779, 7340039, 3147779, 3147779, 5243909, 3147779, 6291462, 4195332, 2099202, 5243909, 3072, 3147779, 6291462, 3072, 7340039, 3072, 4195332, 3072, 7340039, 6291462, 5243909, 1051649, 5243909, 3072, 5243909, - 2099202, 7340039, 5243909, 3072, 7340039, 3147779, 7340039, 1051649, 6291462, 1051649, 4195332, 1051649, 3147779, 5243909, 2099202, 5243909, 7340039, 3147779, 6291462, 4195332, 1051649, 7340039, 2099202, 4195332, 3072, 5243909, 3072, 7340039, 4195332, 2099202, 5243909, 1051649, 5243909, 2099202, 7340039, 5243909, 2099202, 1051649, 4195332, 2099202, 6291462, 4195332, 2099202, 7340039, 3147779, 6291462, 3147779, 3072, 2099202, 6291462, 3072, 7340039, 2099202, 7340039, 3147779, 3072, 7340039, 4195332, 2099202, 7340039, 3072, 6291462, 3072, 5243909, 3147779, 7340039, 1051649, 6291462, 1051649, 7340039, 3072, 2099202, 4195332, 2099202, 5243909, 1051649, 5243909, 3072, 5243909, 3147779, 4195332, 2099202, 6291462, 2099202, 6291462, 5243909, 1051649, 7340039, 3072, 6291462, 1051649, 6291462, 3147779, 4195332, 7340039, 2099202, 5243909, 2099202, 4195332, 3147779, 3072, 6291462, 4195332, 4195332, 3072, 5243909, 1051649, 5243909, 1051649, 2099202, 3072, 6291462, 1051649, 4195332, 7340039, 1051649, 5243909, 2099202, 6291462, 3147779, 5243909, 2099202, 3147779, 1051649, 7340039, 2099202, 4195332, 7340039, - 6291462, 4195332, 1051649, 5243909, 3147779, 2099202, 5243909, 3072, 4195332, 7340039, 3147779, 5243909, 6291462, 3072, 7340039, 1051649, 5243909, 2099202, 3072, 7340039, 2099202, 1051649, 5243909, 1051649, 7340039, 4195332, 1051649, 3147779, 3072, 6291462, 2099202, 7340039, 4195332, 6291462, 3072, 4195332, 6291462, 3147779, 7340039, 3072, 5243909, 3072, 5243909, 3072, 5243909, 3072, 6291462, 4195332, 7340039, 1051649, 4195332, 1051649, 5243909, 1051649, 4195332, 6291462, 3147779, 6291462, 1051649, 5243909, 2099202, 4195332, 7340039, 1051649, 2099202, 6291462, 4195332, 3072, 5243909, 3147779, 5243909, 6291462, 3072, 6291462, 1051649, 7340039, 3147779, 6291462, 1051649, 7340039, 3072, 6291462, 3072, 7340039, 3072, 4195332, 2099202, 4195332, 5243909, 3147779, 3147779, 7340039, 3072, 1051649, 5243909, 4195332, 3072, 6291462, 1051649, 7340039, 2099202, 5243909, 1051649, 7340039, 2099202, 7340039, 3072, 6291462, 3147779, 7340039, 5243909, 3147779, 6291462, 2099202, 5243909, 3147779, 7340039, 4195332, 2099202, 5243909, 1051649, 4195332, 3072, 6291462, 4195332, 6291462, 2099202, 1051649, - 3072, 2099202, 5243909, 2099202, 6291462, 1051649, 4195332, 6291462, 2099202, 5243909, 3072, 2099202, 3147779, 4195332, 4195332, 2099202, 3147779, 7340039, 1051649, 4195332, 5243909, 3147779, 7340039, 5243909, 3147779, 2099202, 7340039, 6291462, 5243909, 3147779, 3072, 4195332, 3072, 3147779, 2099202, 7340039, 3072, 1051649, 5243909, 3147779, 6291462, 2099202, 3147779, 6291462, 1051649, 4195332, 2099202, 1051649, 5243909, 3147779, 2099202, 6291462, 3147779, 5243909, 6291462, 1051649, 4195332, 3072, 6291462, 3147779, 6291462, 1051649, 4195332, 3147779, 5243909, 1051649, 2099202, 3147779, 7340039, 1051649, 4195332, 6291462, 2099202, 4195332, 3147779, 3072, 5243909, 2099202, 4195332, 2099202, 3147779, 5243909, 3147779, 4195332, 2099202, 6291462, 3147779, 3072, 7340039, 1051649, 5243909, 2099202, 3147779, 6291462, 2099202, 7340039, 3147779, 4195332, 5243909, 2099202, 6291462, 3147779, 3147779, 1051649, 5243909, 2099202, 4195332, 2099202, 4195332, 3072, 4195332, 1051649, 1051649, 7340039, 3072, 2099202, 1051649, 3072, 7340039, 1051649, 6291462, 3147779, 5243909, 3147779, 1051649, 3072, 3147779, 6291462, - 5243909, 3147779, 7340039, 3072, 4195332, 7340039, 3147779, 1051649, 7340039, 1051649, 6291462, 7340039, 1051649, 6291462, 1051649, 6291462, 3072, 5243909, 3147779, 6291462, 3072, 4195332, 2099202, 3072, 6291462, 4195332, 3072, 2099202, 1051649, 7340039, 6291462, 1051649, 6291462, 6291462, 5243909, 3147779, 4195332, 7340039, 1051649, 4195332, 1051649, 7340039, 4195332, 1051649, 7340039, 3147779, 7340039, 5243909, 1051649, 6291462, 5243909, 3072, 4195332, 2099202, 3072, 2099202, 7340039, 3147779, 1051649, 5243909, 3072, 6291462, 5243909, 3072, 6291462, 4195332, 6291462, 7340039, 3072, 5243909, 2099202, 3072, 7340039, 3147779, 6291462, 4195332, 7340039, 1051649, 7340039, 3147779, 5243909, 1051649, 7340039, 3072, 5243909, 1051649, 7340039, 5243909, 3147779, 4195332, 3072, 7340039, 5243909, 1051649, 4195332, 3072, 6291462, 1051649, 7340039, 3072, 4195332, 1051649, 5243909, 6291462, 3072, 6291462, 3147779, 3072, 7340039, 6291462, 3147779, 7340039, 5243909, 3147779, 4195332, 5243909, 6291462, 3147779, 5243909, 4195332, 2099202, 7340039, 3072, 7340039, 5243909, 4195332, 7340039, 2099202, - 3072, 6291462, 1051649, 6291462, 2099202, 5243909, 3072, 5243909, 3147779, 2099202, 5243909, 4195332, 3072, 5243909, 2099202, 3147779, 7340039, 1051649, 4195332, 2099202, 5243909, 6291462, 3147779, 7340039, 1051649, 6291462, 3147779, 5243909, 4195332, 2099202, 2099202, 4195332, 3147779, 1051649, 2099202, 3072, 6291462, 2099202, 4195332, 2099202, 6291462, 3072, 3147779, 5243909, 2099202, 4195332, 3072, 3147779, 4195332, 3072, 7340039, 1051649, 7340039, 4195332, 7340039, 3147779, 5243909, 2099202, 4195332, 7340039, 3147779, 2099202, 1051649, 7340039, 2099202, 3072, 2099202, 2099202, 4195332, 1051649, 7340039, 3147779, 5243909, 1051649, 1051649, 5243909, 2099202, 4195332, 3072, 6291462, 3072, 4195332, 1051649, 6291462, 3147779, 4195332, 2099202, 3072, 6291462, 1051649, 6291462, 4195332, 3147779, 3072, 7340039, 5243909, 1051649, 4195332, 2099202, 6291462, 2099202, 7340039, 3072, 4195332, 4195332, 1051649, 7340039, 5243909, 2099202, 1051649, 5243909, 3072, 4195332, 3072, 6291462, 1051649, 2099202, 6291462, 1051649, 5243909, 3072, 4195332, 2099202, 4195332, 3072, 3147779, 1051649, 4195332, - 6291462, 4195332, 3147779, 1051649, 6291462, 1051649, 4195332, 6291462, 3072, 7340039, 3072, 2099202, 6291462, 4195332, 7340039, 1051649, 5243909, 3147779, 7340039, 1051649, 6291462, 3072, 3147779, 4195332, 2099202, 5243909, 3072, 7340039, 3072, 4195332, 7340039, 3072, 5243909, 7340039, 4195332, 5243909, 3147779, 5243909, 3072, 7340039, 2099202, 5243909, 6291462, 3072, 4195332, 7340039, 6291462, 2099202, 7340039, 2099202, 5243909, 3147779, 4195332, 3072, 2099202, 5243909, 3072, 6291462, 2099202, 3072, 5243909, 4195332, 6291462, 3147779, 4195332, 7340039, 5243909, 3147779, 6291462, 4195332, 3072, 6291462, 3147779, 5243909, 7340039, 3072, 6291462, 2099202, 5243909, 3147779, 7340039, 2099202, 6291462, 2099202, 7340039, 1051649, 4195332, 7340039, 2099202, 4195332, 2099202, 3072, 6291462, 5243909, 3147779, 2099202, 3147779, 6291462, 3072, 3147779, 5243909, 2099202, 4195332, 7340039, 2099202, 5243909, 3147779, 1051649, 6291462, 4195332, 2099202, 6291462, 3147779, 7340039, 3147779, 7340039, 4195332, 3072, 7340039, 2099202, 6291462, 7340039, 1051649, 6291462, 2099202, 7340039, 5243909, 2099202, - 2099202, 3072, 7340039, 5243909, 3147779, 7340039, 3072, 2099202, 5243909, 3147779, 4195332, 7340039, 1051649, 3147779, 3072, 6291462, 1051649, 6291462, 3072, 4195332, 2099202, 7340039, 1051649, 5243909, 1051649, 6291462, 2099202, 3147779, 6291462, 3147779, 1051649, 6291462, 2099202, 3072, 6291462, 1051649, 7340039, 1051649, 6291462, 3147779, 4195332, 3072, 3147779, 7340039, 1051649, 2099202, 1051649, 5243909, 3147779, 3072, 4195332, 1051649, 6291462, 6291462, 1051649, 7340039, 1051649, 4195332, 7340039, 4195332, 1051649, 7340039, 3072, 3147779, 2099202, 3072, 5243909, 1051649, 1051649, 5243909, 2099202, 4195332, 1051649, 2099202, 3147779, 4195332, 1051649, 6291462, 3147779, 1051649, 2099202, 5243909, 3072, 4195332, 3072, 5243909, 3147779, 1051649, 6291462, 3072, 7340039, 5243909, 2099202, 4195332, 3072, 7340039, 5243909, 1051649, 4195332, 7340039, 3072, 6291462, 3147779, 3072, 2099202, 6291462, 3072, 7340039, 4195332, 3072, 7340039, 1051649, 2099202, 1051649, 1051649, 4195332, 3147779, 5243909, 4195332, 3072, 3147779, 1051649, 5243909, 3147779, 6291462, 1051649, 3147779, 7340039, - 6291462, 4195332, 2099202, 4195332, 3072, 5243909, 6291462, 4195332, 6291462, 1051649, 3147779, 6291462, 3147779, 7340039, 4195332, 2099202, 5243909, 2099202, 4195332, 7340039, 2099202, 5243909, 3147779, 3072, 7340039, 4195332, 3147779, 5243909, 1051649, 2099202, 6291462, 4195332, 5243909, 1051649, 3147779, 4195332, 1051649, 3147779, 5243909, 3072, 5243909, 6291462, 2099202, 5243909, 3147779, 5243909, 6291462, 1051649, 7340039, 6291462, 2099202, 7340039, 3072, 3147779, 5243909, 2099202, 4195332, 3147779, 1051649, 6291462, 2099202, 5243909, 1051649, 6291462, 6291462, 4195332, 7340039, 3147779, 7340039, 3147779, 7340039, 3072, 5243909, 7340039, 4195332, 7340039, 2099202, 5243909, 3072, 7340039, 6291462, 1051649, 7340039, 4195332, 6291462, 2099202, 6291462, 3147779, 4195332, 5243909, 1051649, 3147779, 6291462, 1051649, 6291462, 4195332, 2099202, 7340039, 3147779, 1051649, 5243909, 4195332, 2099202, 6291462, 4195332, 3147779, 5243909, 1051649, 3147779, 6291462, 3147779, 4195332, 5243909, 6291462, 7340039, 3072, 6291462, 1051649, 7340039, 2099202, 6291462, 6291462, 3072, 4195332, 1051649, 5243909, 3147779, 3072, - 5243909, 1051649, 7340039, 3147779, 2099202, 3147779, 2099202, 1051649, 4195332, 3072, 5243909, 1051649, 3072, 5243909, 1051649, 5243909, 3072, 6291462, 3147779, 3072, 4195332, 1051649, 6291462, 4195332, 2099202, 1051649, 6291462, 3072, 5243909, 7340039, 1051649, 3147779, 3072, 7340039, 2099202, 5243909, 3147779, 6291462, 2099202, 7340039, 2099202, 1051649, 7340039, 3072, 6291462, 3072, 4195332, 3147779, 3072, 2099202, 4195332, 5243909, 2099202, 6291462, 3147779, 3072, 6291462, 7340039, 3147779, 4195332, 3072, 7340039, 3147779, 5243909, 3072, 2099202, 1051649, 4195332, 3072, 6291462, 1051649, 5243909, 2099202, 1051649, 3072, 3147779, 6291462, 2099202, 4195332, 4195332, 3072, 5243909, 3147779, 1051649, 1051649, 5243909, 3072, 5243909, 3072, 3147779, 7340039, 3072, 3147779, 7340039, 2099202, 1051649, 3072, 5243909, 2099202, 6291462, 3147779, 3072, 7340039, 1051649, 5243909, 3072, 3147779, 7340039, 3072, 5243909, 2099202, 7340039, 3072, 4195332, 2099202, 3147779, 5243909, 2099202, 3147779, 5243909, 1051649, 3147779, 7340039, 2099202, 6291462, 1051649, 7340039, 3147779, - 2099202, 6291462, 1051649, 5243909, 7340039, 3072, 7340039, 6291462, 2099202, 7340039, 2099202, 4195332, 7340039, 2099202, 6291462, 3147779, 4195332, 7340039, 1051649, 6291462, 7340039, 5243909, 3147779, 3072, 6291462, 3147779, 7340039, 2099202, 4195332, 3072, 4195332, 7340039, 6291462, 4195332, 5243909, 3072, 7340039, 3072, 4195332, 1051649, 5243909, 4195332, 2099202, 4195332, 3147779, 1051649, 7340039, 3147779, 5243909, 4195332, 1051649, 6291462, 3072, 4195332, 1051649, 7340039, 2099202, 3072, 5243909, 2099202, 5243909, 1051649, 4195332, 2099202, 7340039, 5243909, 3147779, 6291462, 5243909, 1051649, 4195332, 3147779, 7340039, 4195332, 6291462, 3072, 5243909, 1051649, 3147779, 6291462, 3147779, 2099202, 7340039, 5243909, 3147779, 4195332, 7340039, 2099202, 7340039, 2099202, 2099202, 6291462, 4195332, 1051649, 5243909, 7340039, 3147779, 4195332, 6291462, 3072, 4195332, 7340039, 1051649, 6291462, 2099202, 7340039, 1051649, 4195332, 6291462, 3147779, 1051649, 5243909, 1051649, 3147779, 3072, 7340039, 1051649, 6291462, 3072, 7340039, 4195332, 4195332, 2099202, 5243909, 3072, 4195332, 3072, 5243909, - 3072, 7340039, 2099202, 4195332, 1051649, 5243909, 1051649, 4195332, 3072, 3147779, 6291462, 3147779, 3072, 4195332, 1051649, 7340039, 2099202, 3072, 4195332, 3147779, 2099202, 3072, 6291462, 4195332, 5243909, 1051649, 4195332, 2099202, 7340039, 5243909, 3147779, 1051649, 2099202, 1051649, 7340039, 3147779, 2099202, 6291462, 4195332, 7340039, 3072, 7340039, 1051649, 5243909, 7340039, 5243909, 1051649, 2099202, 6291462, 3072, 7340039, 1051649, 7340039, 3147779, 5243909, 2099202, 4195332, 6291462, 1051649, 7340039, 3147779, 3147779, 6291462, 3072, 4195332, 1051649, 7340039, 3072, 2099202, 7340039, 3072, 6291462, 3072, 2099202, 5243909, 3147779, 7340039, 4195332, 7340039, 1051649, 4195332, 6291462, 2099202, 3072, 7340039, 1051649, 4195332, 3147779, 1051649, 6291462, 5243909, 1051649, 5243909, 2099202, 3147779, 6291462, 3072, 4195332, 1051649, 7340039, 2099202, 5243909, 3147779, 1051649, 5243909, 3147779, 6291462, 2099202, 1051649, 4195332, 6291462, 2099202, 4195332, 6291462, 5243909, 2099202, 4195332, 3147779, 6291462, 2099202, 3072, 5243909, 3072, 6291462, 4195332, 7340039, 3147779, 4195332, - 5243909, 3147779, 3072, 4195332, 6291462, 3147779, 4195332, 7340039, 3147779, 5243909, 1051649, 5243909, 6291462, 3147779, 6291462, 3072, 5243909, 4195332, 7340039, 1051649, 3147779, 7340039, 2099202, 5243909, 1051649, 7340039, 3072, 5243909, 3072, 2099202, 5243909, 3072, 7340039, 4195332, 1051649, 6291462, 4195332, 3072, 1051649, 3147779, 2099202, 6291462, 3147779, 2099202, 3072, 3147779, 6291462, 5243909, 3147779, 2099202, 5243909, 3147779, 3147779, 5243909, 1051649, 6291462, 4195332, 3072, 5243909, 2099202, 3072, 5243909, 1051649, 6291462, 3147779, 5243909, 2099202, 4195332, 5243909, 3147779, 5243909, 2099202, 3147779, 7340039, 1051649, 6291462, 3072, 1051649, 5243909, 3072, 7340039, 3072, 5243909, 3147779, 6291462, 3072, 6291462, 2099202, 5243909, 4195332, 3072, 3147779, 6291462, 3072, 7340039, 1051649, 5243909, 2099202, 5243909, 3147779, 5243909, 3072, 4195332, 6291462, 3072, 6291462, 3072, 4195332, 5243909, 2099202, 3072, 7340039, 5243909, 3072, 2099202, 7340039, 3072, 5243909, 1051649, 4195332, 6291462, 2099202, 7340039, 1051649, 3147779, 2099202, 6291462, 1051649, - 7340039, 3147779, 6291462, 2099202, 3072, 7340039, 2099202, 3072, 6291462, 1051649, 6291462, 2099202, 4195332, 1051649, 2099202, 6291462, 3147779, 2099202, 3072, 5243909, 5243909, 3147779, 1051649, 7340039, 2099202, 3147779, 6291462, 4195332, 3147779, 6291462, 3147779, 6291462, 2099202, 3147779, 5243909, 3072, 3147779, 7340039, 5243909, 6291462, 5243909, 3072, 4195332, 7340039, 6291462, 2099202, 4195332, 3072, 6291462, 4195332, 6291462, 1051649, 6291462, 3072, 7340039, 3072, 3147779, 7340039, 3147779, 4195332, 6291462, 3147779, 7340039, 2099202, 6291462, 3072, 4195332, 7340039, 1051649, 6291462, 3072, 7340039, 1051649, 5243909, 4195332, 2099202, 4195332, 6291462, 2099202, 6291462, 3147779, 2099202, 7340039, 4195332, 1051649, 4195332, 5243909, 3072, 7340039, 1051649, 6291462, 7340039, 2099202, 5243909, 3147779, 4195332, 2099202, 7340039, 3072, 6291462, 1051649, 3147779, 7340039, 2099202, 3147779, 5243909, 2099202, 7340039, 3147779, 6291462, 3147779, 4195332, 1051649, 7340039, 1051649, 4195332, 6291462, 3147779, 7340039, 3147779, 1051649, 5243909, 3147779, 4195332, 6291462, 1051649, 5243909, 2099202, - 1051649, 5243909, 1051649, 6291462, 3147779, 5243909, 1051649, 5243909, 3147779, 3072, 4195332, 7340039, 3072, 7340039, 5243909, 3072, 7340039, 3147779, 6291462, 2099202, 1051649, 6291462, 4195332, 4195332, 3072, 5243909, 1051649, 1051649, 7340039, 3072, 1051649, 4195332, 7340039, 1051649, 2099202, 6291462, 2099202, 1051649, 3147779, 3072, 1051649, 6291462, 2099202, 1051649, 4195332, 1051649, 5243909, 7340039, 1051649, 2099202, 3072, 7340039, 4195332, 2099202, 3147779, 4195332, 5243909, 1051649, 3072, 7340039, 1051649, 4195332, 3072, 4195332, 2099202, 7340039, 3147779, 1051649, 2099202, 6291462, 4195332, 2099202, 5243909, 3147779, 3072, 7340039, 3147779, 1051649, 3147779, 5243909, 1051649, 4195332, 3072, 6291462, 2099202, 7340039, 2099202, 4195332, 1051649, 5243909, 3147779, 3072, 4195332, 1051649, 7340039, 3072, 6291462, 4195332, 3147779, 2099202, 7340039, 6291462, 1051649, 4195332, 7340039, 2099202, 4195332, 3072, 5243909, 3072, 7340039, 1051649, 4195332, 3147779, 5243909, 2099202, 3072, 2099202, 3072, 6291462, 3147779, 7340039, 2099202, 3072, 7340039, 3147779, 3072, 6291462, - 4195332, 3072, 4195332, 1051649, 3147779, 4195332, 6291462, 2099202, 7340039, 5243909, 3147779, 1051649, 3147779, 5243909, 2099202, 4195332, 1051649, 5243909, 1051649, 4195332, 6291462, 3072, 2099202, 6291462, 2099202, 3147779, 6291462, 4195332, 2099202, 5243909, 6291462, 3147779, 3072, 5243909, 5243909, 4195332, 7340039, 4195332, 6291462, 4195332, 7340039, 3147779, 4195332, 5243909, 3147779, 7340039, 3072, 3147779, 4195332, 7340039, 2099202, 5243909, 1051649, 5243909, 7340039, 1051649, 6291462, 3147779, 5243909, 2099202, 1051649, 6291462, 5243909, 1051649, 3147779, 6291462, 3072, 5243909, 4195332, 3072, 3147779, 6291462, 1051649, 6291462, 2099202, 5243909, 3072, 7340039, 5243909, 3072, 7340039, 3147779, 5243909, 1051649, 4195332, 3072, 6291462, 3147779, 7340039, 2099202, 4195332, 6291462, 3147779, 5243909, 2099202, 4195332, 1051649, 1051649, 5243909, 4195332, 3072, 4195332, 3147779, 5243909, 3072, 6291462, 1051649, 7340039, 3147779, 2099202, 5243909, 2099202, 5243909, 6291462, 3072, 7340039, 5243909, 7340039, 4195332, 5243909, 1051649, 3072, 6291462, 4195332, 1051649, 7340039, 5243909, 2099202, - 7340039, 5243909, 4195332, 7340039, 6291462, 3072, 1051649, 4195332, 1051649, 5243909, 2099202, 6291462, 4195332, 1051649, 7340039, 3147779, 6291462, 3147779, 7340039, 3072, 3147779, 5243909, 7340039, 1051649, 5243909, 7340039, 3072, 7340039, 3147779, 1051649, 4195332, 6291462, 2099202, 7340039, 2099202, 3072, 3147779, 3072, 2099202, 5243909, 1051649, 5243909, 3072, 7340039, 3072, 3147779, 6291462, 1051649, 6291462, 1051649, 3147779, 4195332, 6291462, 3072, 2099202, 4195332, 2099202, 6291462, 3072, 5243909, 7340039, 2099202, 3147779, 7340039, 5243909, 1051649, 3147779, 6291462, 2099202, 7340039, 1051649, 3147779, 4195332, 1051649, 7340039, 1051649, 5243909, 2099202, 2099202, 5243909, 4195332, 1051649, 3147779, 7340039, 5243909, 3147779, 6291462, 3072, 3147779, 7340039, 3072, 1051649, 6291462, 3072, 7340039, 3147779, 6291462, 3147779, 7340039, 1051649, 7340039, 3072, 6291462, 1051649, 5243909, 2099202, 3147779, 5243909, 1051649, 7340039, 1051649, 6291462, 3072, 2099202, 4195332, 4195332, 1051649, 1051649, 3147779, 2099202, 5243909, 4195332, 2099202, 5243909, 3147779, 1051649, 4195332, 2099202, - 3072, 3147779, 2099202, 3072, 2099202, 6291462, 5243909, 7340039, 2099202, 3072, 7340039, 1051649, 6291462, 2099202, 4195332, 3072, 2099202, 3072, 5243909, 2099202, 6291462, 1051649, 3147779, 4195332, 3072, 2099202, 5243909, 1051649, 5243909, 7340039, 2099202, 3072, 5243909, 1051649, 4195332, 6291462, 3147779, 5243909, 7340039, 2099202, 6291462, 3147779, 2099202, 5243909, 2099202, 5243909, 4195332, 3072, 5243909, 3147779, 7340039, 3072, 2099202, 5243909, 7340039, 3072, 5243909, 1051649, 6291462, 4195332, 3072, 4195332, 5243909, 3072, 2099202, 6291462, 4195332, 3072, 5243909, 4195332, 5243909, 7340039, 3072, 6291462, 4195332, 3147779, 6291462, 4195332, 6291462, 1051649, 6291462, 2099202, 6291462, 3072, 2099202, 3147779, 1051649, 4195332, 6291462, 2099202, 5243909, 3147779, 5243909, 2099202, 4195332, 3072, 2099202, 5243909, 1051649, 4195332, 2099202, 6291462, 2099202, 4195332, 3072, 7340039, 4195332, 3072, 6291462, 4195332, 6291462, 4195332, 3147779, 7340039, 1051649, 6291462, 3147779, 6291462, 7340039, 3072, 7340039, 3147779, 6291462, 3072, 7340039, 3072, 5243909, 7340039, - 1051649, 6291462, 5243909, 5243909, 7340039, 3147779, 3072, 2099202, 4195332, 6291462, 4195332, 3147779, 5243909, 3072, 5243909, 7340039, 5243909, 6291462, 4195332, 7340039, 3147779, 3072, 5243909, 5243909, 7340039, 4195332, 2099202, 6291462, 3147779, 3072, 4195332, 7340039, 3147779, 6291462, 2099202, 1051649, 5243909, 1051649, 3072, 4195332, 3072, 6291462, 1051649, 7340039, 3147779, 1051649, 6291462, 2099202, 7340039, 1051649, 2099202, 4195332, 6291462, 1051649, 3147779, 4195332, 7340039, 3147779, 2099202, 7340039, 1051649, 7340039, 1051649, 6291462, 3147779, 7340039, 1051649, 7340039, 3147779, 1051649, 5243909, 2099202, 2099202, 4195332, 6291462, 3072, 3147779, 3072, 3147779, 3072, 3147779, 5243909, 4195332, 2099202, 6291462, 7340039, 5243909, 3072, 4195332, 1051649, 3147779, 7340039, 1051649, 6291462, 2099202, 6291462, 5243909, 3072, 6291462, 5243909, 3072, 3147779, 5243909, 7340039, 3147779, 2099202, 6291462, 2099202, 3147779, 1051649, 2099202, 3072, 7340039, 3147779, 5243909, 2099202, 3072, 4195332, 2099202, 4195332, 3147779, 1051649, 5243909, 2099202, 4195332, 6291462, 2099202, 2099202, - 6291462, 4195332, 3072, 3147779, 1051649, 4195332, 7340039, 5243909, 3147779, 3072, 7340039, 3072, 3147779, 6291462, 2099202, 1051649, 1051649, 4195332, 2099202, 1051649, 4195332, 7340039, 2099202, 1051649, 1051649, 3147779, 6291462, 3072, 5243909, 6291462, 2099202, 1051649, 4195332, 3072, 6291462, 7340039, 3147779, 6291462, 4195332, 7340039, 3147779, 2099202, 6291462, 3072, 4195332, 7340039, 3147779, 3072, 4195332, 6291462, 5243909, 3072, 7340039, 4195332, 6291462, 1051649, 2099202, 6291462, 3072, 3147779, 5243909, 3147779, 4195332, 2099202, 3072, 4195332, 2099202, 5243909, 1051649, 7340039, 3072, 4195332, 7340039, 1051649, 1051649, 7340039, 2099202, 6291462, 7340039, 4195332, 7340039, 1051649, 3072, 7340039, 1051649, 4195332, 2099202, 7340039, 5243909, 3147779, 6291462, 1051649, 4195332, 3072, 7340039, 3147779, 1051649, 4195332, 3147779, 2099202, 7340039, 5243909, 1051649, 1051649, 6291462, 4195332, 3072, 5243909, 7340039, 3147779, 5243909, 4195332, 1051649, 5243909, 3072, 6291462, 3147779, 5243909, 1051649, 6291462, 1051649, 7340039, 3147779, 5243909, 4195332, 3072, 6291462, 3147779, - 1051649, 4195332, 1051649, 7340039, 6291462, 4195332, 3072, 2099202, 6291462, 1051649, 5243909, 2099202, 5243909, 2099202, 4195332, 7340039, 3147779, 7340039, 3072, 5243909, 6291462, 3072, 4195332, 6291462, 6291462, 3072, 7340039, 4195332, 2099202, 1051649, 7340039, 3147779, 7340039, 2099202, 4195332, 3072, 5243909, 2099202, 3147779, 1051649, 5243909, 4195332, 3147779, 6291462, 2099202, 1051649, 5243909, 7340039, 3147779, 3072, 2099202, 5243909, 2099202, 3147779, 3072, 5243909, 2099202, 4195332, 5243909, 1051649, 6291462, 1051649, 6291462, 3147779, 7340039, 4195332, 6291462, 3072, 4195332, 3147779, 6291462, 2099202, 3147779, 5243909, 2099202, 4195332, 5243909, 2099202, 1051649, 4195332, 2099202, 6291462, 5243909, 3147779, 5243909, 3072, 5243909, 2099202, 1051649, 6291462, 3072, 5243909, 3147779, 5243909, 2099202, 5243909, 7340039, 2099202, 6291462, 1051649, 3147779, 3072, 7340039, 4195332, 5243909, 2099202, 7340039, 4195332, 1051649, 6291462, 3072, 6291462, 3147779, 2099202, 7340039, 2099202, 6291462, 1051649, 7340039, 3072, 4195332, 5243909, 2099202, 3072, 7340039, 3147779, 1051649, 5243909, - 7340039, 3147779, 5243909, 3147779, 1051649, 2099202, 6291462, 1051649, 7340039, 3147779, 4195332, 7340039, 3072, 6291462, 3147779, 3072, 6291462, 2099202, 4195332, 1051649, 3147779, 3147779, 5243909, 2099202, 3147779, 4195332, 1051649, 3147779, 7340039, 5243909, 1051649, 4195332, 3072, 5243909, 1051649, 4195332, 7340039, 3072, 6291462, 7340039, 3072, 7340039, 1051649, 4195332, 7340039, 2099202, 4195332, 1051649, 6291462, 3147779, 7340039, 1051649, 6291462, 6291462, 4195332, 3147779, 7340039, 3072, 7340039, 3147779, 2099202, 7340039, 4195332, 3072, 5243909, 1051649, 2099202, 5243909, 3072, 7340039, 1051649, 5243909, 3072, 6291462, 4195332, 3072, 7340039, 3147779, 5243909, 6291462, 3072, 4195332, 2099202, 1051649, 7340039, 2099202, 4195332, 7340039, 3072, 3147779, 4195332, 2099202, 7340039, 1051649, 4195332, 3072, 6291462, 3072, 7340039, 4195332, 6291462, 2099202, 4195332, 2099202, 3072, 6291462, 1051649, 5243909, 3072, 2099202, 5243909, 1051649, 7340039, 4195332, 1051649, 5243909, 3072, 4195332, 3147779, 3147779, 7340039, 3072, 4195332, 6291462, 2099202, 5243909, 7340039, 2099202, - 3072, 6291462, 3072, 4195332, 5243909, 7340039, 2099202, 5243909, 4195332, 1051649, 6291462, 1051649, 4195332, 1051649, 2099202, 5243909, 2099202, 5243909, 3147779, 7340039, 6291462, 1051649, 7340039, 3072, 6291462, 2099202, 5243909, 6291462, 3072, 3147779, 5243909, 2099202, 6291462, 3147779, 7340039, 1051649, 6291462, 2099202, 4195332, 3147779, 2099202, 5243909, 1051649, 5243909, 3072, 5243909, 4195332, 3072, 5243909, 2099202, 4195332, 3147779, 2099202, 3072, 1051649, 6291462, 3147779, 4195332, 2099202, 5243909, 3072, 5243909, 1051649, 7340039, 2099202, 6291462, 3147779, 2099202, 6291462, 3147779, 3147779, 4195332, 7340039, 1051649, 6291462, 3147779, 1051649, 6291462, 3072, 2099202, 4195332, 7340039, 3072, 6291462, 3147779, 5243909, 1051649, 4195332, 6291462, 2099202, 7340039, 4195332, 3072, 7340039, 6291462, 2099202, 4195332, 3147779, 1051649, 4195332, 3072, 3147779, 6291462, 1051649, 6291462, 3147779, 3147779, 7340039, 4195332, 5243909, 1051649, 6291462, 4195332, 3072, 5243909, 3147779, 7340039, 2099202, 6291462, 1051649, 5243909, 2099202, 6291462, 1051649, 4195332, 3072, 3147779, 4195332, - 5243909, 2099202, 7340039, 2099202, 1051649, 4195332, 3147779, 3072, 3147779, 7340039, 3072, 5243909, 3147779, 7340039, 6291462, 3072, 7340039, 4195332, 3072, 2099202, 4195332, 2099202, 4195332, 5243909, 7340039, 3072, 4195332, 2099202, 5243909, 2099202, 7340039, 3072, 3147779, 5243909, 3072, 4195332, 3147779, 5243909, 1051649, 5243909, 1051649, 3147779, 6291462, 2099202, 6291462, 3147779, 3147779, 6291462, 1051649, 7340039, 3072, 6291462, 3147779, 7340039, 5243909, 3072, 6291462, 1051649, 4195332, 1051649, 6291462, 4195332, 2099202, 3147779, 5243909, 3072, 7340039, 5243909, 1051649, 6291462, 3072, 6291462, 3072, 4195332, 2099202, 5243909, 7340039, 4195332, 2099202, 7340039, 1051649, 2099202, 5243909, 4195332, 3072, 2099202, 7340039, 3072, 5243909, 1051649, 1051649, 3147779, 5243909, 1051649, 3147779, 5243909, 1051649, 6291462, 5243909, 2099202, 5243909, 7340039, 1051649, 5243909, 4195332, 1051649, 5243909, 3072, 2099202, 7340039, 2099202, 3147779, 3072, 6291462, 3147779, 6291462, 1051649, 5243909, 3072, 6291462, 2099202, 7340039, 1051649, 3147779, 6291462, 3147779, 7340039, 2099202, - 1051649, 4195332, 3147779, 6291462, 4195332, 3072, 7340039, 5243909, 2099202, 6291462, 2099202, 5243909, 1051649, 4195332, 1051649, 5243909, 3147779, 1051649, 7340039, 6291462, 3072, 7340039, 3072, 1051649, 3147779, 3147779, 6291462, 1051649, 7340039, 4195332, 4195332, 2099202, 6291462, 1051649, 7340039, 4195332, 3072, 7340039, 2099202, 4195332, 7340039, 5243909, 3072, 4195332, 1051649, 7340039, 3072, 7340039, 4195332, 2099202, 5243909, 1051649, 4195332, 3072, 4195332, 3147779, 1051649, 7340039, 2099202, 7340039, 3147779, 3072, 6291462, 1051649, 6291462, 2099202, 4195332, 3072, 4195332, 2099202, 5243909, 2099202, 5243909, 3147779, 7340039, 3072, 3147779, 1051649, 4195332, 5243909, 3147779, 6291462, 3147779, 1051649, 7340039, 5243909, 3147779, 6291462, 3147779, 6291462, 5243909, 2099202, 6291462, 2099202, 4195332, 3072, 7340039, 3147779, 1051649, 7340039, 3072, 3147779, 4195332, 3072, 3147779, 7340039, 2099202, 6291462, 3147779, 3072, 7340039, 4195332, 3147779, 7340039, 1051649, 2099202, 4195332, 2099202, 7340039, 1051649, 4195332, 3072, 4195332, 6291462, 1051649, 5243909, 3072, 6291462, - 5243909, 1051649, 6291462, 3072, 3147779, 7340039, 1051649, 4195332, 1051649, 3147779, 6291462, 2099202, 7340039, 3072, 3147779, 6291462, 3072, 6291462, 3147779, 2099202, 3147779, 4195332, 6291462, 5243909, 3072, 7340039, 1051649, 4195332, 3072, 6291462, 1051649, 5243909, 3072, 5243909, 2099202, 3147779, 6291462, 2099202, 6291462, 3072, 2099202, 3147779, 7340039, 4195332, 1051649, 5243909, 2099202, 4195332, 3072, 6291462, 1051649, 7340039, 2099202, 5243909, 2099202, 7340039, 5243909, 3147779, 4195332, 3072, 6291462, 1051649, 4195332, 5243909, 3072, 6291462, 3147779, 7340039, 1051649, 7340039, 2099202, 7340039, 1051649, 2099202, 5243909, 1051649, 6291462, 6291462, 3072, 5243909, 3072, 7340039, 3072, 6291462, 3147779, 6291462, 1051649, 2099202, 4195332, 3072, 4195332, 7340039, 3072, 5243909, 7340039, 3147779, 3072, 5243909, 3147779, 2099202, 6291462, 4195332, 7340039, 2099202, 6291462, 3072, 5243909, 1051649, 6291462, 4195332, 2099202, 5243909, 3072, 5243909, 4195332, 7340039, 3072, 6291462, 3147779, 3147779, 7340039, 5243909, 3147779, 3072, 7340039, 1051649, 4195332, 3147779, - 3072, 7340039, 2099202, 5243909, 5243909, 2099202, 6291462, 2099202, 7340039, 4195332, 3072, 5243909, 3147779, 4195332, 6291462, 2099202, 5243909, 4195332, 1051649, 5243909, 6291462, 1051649, 2099202, 4195332, 4195332, 2099202, 6291462, 3147779, 6291462, 3147779, 2099202, 7340039, 3147779, 4195332, 1051649, 6291462, 3072, 4195332, 3147779, 5243909, 6291462, 3072, 2099202, 6291462, 3147779, 7340039, 1051649, 5243909, 3147779, 5243909, 4195332, 3147779, 7340039, 3072, 6291462, 2099202, 3072, 6291462, 2099202, 5243909, 4195332, 3147779, 7340039, 2099202, 7340039, 2099202, 5243909, 1051649, 4195332, 5243909, 3072, 3147779, 4195332, 7340039, 3072, 3147779, 4195332, 2099202, 7340039, 3147779, 1051649, 5243909, 2099202, 4195332, 1051649, 3072, 4195332, 7340039, 2099202, 7340039, 3147779, 1051649, 6291462, 3147779, 1051649, 7340039, 5243909, 2099202, 4195332, 7340039, 4195332, 3072, 2099202, 5243909, 1051649, 4195332, 7340039, 3147779, 3072, 6291462, 3147779, 1051649, 7340039, 2099202, 3072, 5243909, 4195332, 1051649, 5243909, 3072, 3147779, 2099202, 5243909, 4195332, 2099202, 6291462, 2099202, 7340039, - 5243909, 3147779, 1051649, 7340039, 3072, 4195332, 3072, 5243909, 3072, 5243909, 1051649, 7340039, 3072, 5243909, 1051649, 2099202, 7340039, 1051649, 7340039, 3147779, 3072, 5243909, 7340039, 3072, 7340039, 1051649, 5243909, 2099202, 1051649, 5243909, 1051649, 3072, 6291462, 2099202, 7340039, 3147779, 6291462, 1051649, 7340039, 1051649, 1051649, 7340039, 5243909, 3072, 2099202, 4195332, 6291462, 1051649, 6291462, 3072, 2099202, 6291462, 1051649, 4195332, 1051649, 4195332, 7340039, 1051649, 2099202, 7340039, 1051649, 5243909, 3072, 3147779, 4195332, 1051649, 3147779, 6291462, 2099202, 4195332, 3147779, 6291462, 3072, 3147779, 6291462, 5243909, 3072, 4195332, 1051649, 6291462, 4195332, 6291462, 1051649, 3147779, 5243909, 7340039, 3147779, 3072, 5243909, 1051649, 4195332, 6291462, 2099202, 4195332, 3072, 2099202, 4195332, 1051649, 6291462, 3072, 1051649, 5243909, 6291462, 3147779, 7340039, 3147779, 2099202, 6291462, 4195332, 2099202, 7340039, 3147779, 4195332, 6291462, 4195332, 2099202, 3147779, 6291462, 3072, 6291462, 4195332, 7340039, 1051649, 6291462, 3072, 5243909, 2099202, 4195332, - 3147779, 3072, 6291462, 1051649, 3147779, 5243909, 6291462, 3147779, 7340039, 3147779, 6291462, 2099202, 4195332, 2099202, 7340039, 3147779, 3072, 5243909, 3147779, 6291462, 2099202, 4195332, 1051649, 3147779, 5243909, 4195332, 3072, 6291462, 3147779, 7340039, 4195332, 6291462, 3147779, 5243909, 3072, 5243909, 1051649, 4195332, 2099202, 4195332, 5243909, 3147779, 1051649, 6291462, 6291462, 3072, 2099202, 5243909, 3147779, 7340039, 4195332, 3072, 7340039, 3147779, 2099202, 5243909, 3147779, 5243909, 6291462, 3072, 3147779, 5243909, 6291462, 1051649, 5243909, 3147779, 7340039, 3072, 6291462, 2099202, 7340039, 1051649, 5243909, 2099202, 1051649, 7340039, 2099202, 7340039, 2099202, 5243909, 3072, 3147779, 7340039, 6291462, 3072, 2099202, 5243909, 6291462, 2099202, 4195332, 5243909, 3072, 3147779, 7340039, 5243909, 6291462, 1051649, 7340039, 2099202, 5243909, 7340039, 3147779, 3072, 6291462, 3072, 5243909, 1051649, 5243909, 3072, 6291462, 1051649, 6291462, 1051649, 3072, 6291462, 1051649, 7340039, 4195332, 2099202, 5243909, 1051649, 3072, 5243909, 2099202, 6291462, 3147779, 7340039, 1051649, - 5243909, 7340039, 3147779, 4195332, 6291462, 2099202, 1051649, 4195332, 2099202, 5243909, 3072, 4195332, 6291462, 6291462, 1051649, 4195332, 6291462, 2099202, 1051649, 3072, 7340039, 3147779, 5243909, 7340039, 2099202, 2099202, 6291462, 1051649, 5243909, 3072, 3147779, 1051649, 6291462, 2099202, 2099202, 7340039, 3147779, 3072, 5243909, 6291462, 3072, 7340039, 4195332, 2099202, 4195332, 3147779, 7340039, 2099202, 6291462, 1051649, 3147779, 5243909, 1051649, 5243909, 6291462, 3072, 7340039, 3072, 4195332, 6291462, 4195332, 2099202, 2099202, 7340039, 3072, 6291462, 1051649, 4195332, 5243909, 3072, 5243909, 1051649, 4195332, 6291462, 4195332, 2099202, 3147779, 5243909, 3072, 3147779, 7340039, 2099202, 4195332, 2099202, 6291462, 4195332, 1051649, 1051649, 7340039, 3072, 6291462, 2099202, 6291462, 1051649, 2099202, 3072, 6291462, 4195332, 3147779, 1051649, 4195332, 2099202, 4195332, 2099202, 4195332, 2099202, 7340039, 1051649, 3147779, 5243909, 4195332, 2099202, 5243909, 5243909, 3147779, 5243909, 2099202, 3072, 7340039, 3147779, 6291462, 4195332, 3147779, 7340039, 1051649, 4195332, 3072, 6291462, - 2099202, 4195332, 1051649, 7340039, 3072, 6291462, 3147779, 7340039, 3072, 3147779, 7340039, 1051649, 3072, 3147779, 5243909, 3072, 4195332, 6291462, 7340039, 4195332, 5243909, 1051649, 4195332, 3072, 3147779, 7340039, 4195332, 7340039, 2099202, 7340039, 4195332, 5243909, 3072, 7340039, 4195332, 3072, 5243909, 7340039, 3147779, 2099202, 5243909, 3147779, 1051649, 6291462, 3072, 4195332, 3072, 5243909, 3072, 4195332, 6291462, 2099202, 7340039, 2099202, 1051649, 5243909, 3147779, 2099202, 5243909, 1051649, 3072, 7340039, 1051649, 4195332, 4195332, 2099202, 7340039, 3147779, 1051649, 6291462, 3147779, 7340039, 3147779, 3072, 7340039, 1051649, 6291462, 4195332, 1051649, 6291462, 1051649, 5243909, 3072, 5243909, 1051649, 3147779, 7340039, 5243909, 3147779, 4195332, 2099202, 5243909, 1051649, 7340039, 4195332, 5243909, 3147779, 3072, 5243909, 6291462, 3072, 7340039, 1051649, 6291462, 7340039, 1051649, 3147779, 7340039, 4195332, 2099202, 3072, 7340039, 3147779, 2099202, 7340039, 1051649, 5243909, 3147779, 5243909, 1051649, 2099202, 6291462, 2099202, 3072, 4195332, 3147779, 7340039, 2099202, - 1051649, 5243909, 3147779, 2099202, 5243909, 4195332, 3072, 6291462, 2099202, 5243909, 1051649, 5243909, 3147779, 7340039, 2099202, 7340039, 3147779, 1051649, 3072, 3147779, 6291462, 1051649, 2099202, 6291462, 5243909, 3072, 3147779, 3072, 5243909, 1051649, 6291462, 1051649, 4195332, 3147779, 2099202, 6291462, 1051649, 4195332, 3072, 7340039, 1051649, 2099202, 5243909, 3147779, 7340039, 1051649, 6291462, 3147779, 7340039, 1051649, 2099202, 3072, 4195332, 6291462, 3147779, 4195332, 3072, 7340039, 1051649, 3147779, 6291462, 5243909, 3147779, 6291462, 1051649, 6291462, 3072, 4195332, 7340039, 4195332, 1051649, 4195332, 6291462, 2099202, 5243909, 3147779, 3072, 4195332, 7340039, 3147779, 6291462, 4195332, 7340039, 2099202, 4195332, 6291462, 3072, 2099202, 6291462, 3072, 7340039, 3147779, 5243909, 2099202, 4195332, 1051649, 6291462, 2099202, 7340039, 2099202, 5243909, 4195332, 3147779, 5243909, 3072, 4195332, 6291462, 3072, 1051649, 5243909, 7340039, 3147779, 3072, 6291462, 3072, 4195332, 6291462, 2099202, 7340039, 4195332, 7340039, 3072, 5243909, 7340039, 1051649, 6291462, 3072, 5243909, - 4195332, 3072, 6291462, 2099202, 7340039, 1051649, 2099202, 6291462, 3147779, 1051649, 7340039, 3147779, 6291462, 1051649, 5243909, 1051649, 6291462, 5243909, 5243909, 2099202, 3072, 4195332, 7340039, 1051649, 6291462, 2099202, 6291462, 4195332, 3147779, 3072, 3147779, 5243909, 2099202, 7340039, 1051649, 3147779, 6291462, 2099202, 6291462, 3147779, 4195332, 7340039, 4195332, 1051649, 5243909, 3147779, 5243909, 1051649, 4195332, 5243909, 7340039, 3147779, 5243909, 3072, 7340039, 2099202, 6291462, 3147779, 6291462, 4195332, 3147779, 3072, 7340039, 2099202, 5243909, 3147779, 2099202, 5243909, 3072, 2099202, 6291462, 3072, 1051649, 6291462, 2099202, 7340039, 5243909, 2099202, 3072, 5243909, 1051649, 3072, 3147779, 6291462, 1051649, 3147779, 5243909, 3147779, 5243909, 3147779, 1051649, 6291462, 3072, 5243909, 3072, 7340039, 3147779, 5243909, 1051649, 3147779, 1051649, 3072, 6291462, 2099202, 3147779, 5243909, 2099202, 4195332, 6291462, 4195332, 1051649, 5243909, 6291462, 1051649, 7340039, 2099202, 3072, 4195332, 3072, 1051649, 5243909, 3147779, 1051649, 4195332, 5243909, 2099202, 3147779, 6291462, - 7340039, 4195332, 1051649, 4195332, 3072, 5243909, 4195332, 1051649, 7340039, 4195332, 4195332, 3072, 4195332, 2099202, 6291462, 3072, 3147779, 2099202, 4195332, 7340039, 4195332, 6291462, 3072, 3147779, 4195332, 3072, 5243909, 1051649, 2099202, 6291462, 7340039, 3072, 6291462, 3072, 4195332, 6291462, 3072, 5243909, 1051649, 5243909, 3072, 5243909, 2099202, 6291462, 3072, 7340039, 2099202, 7340039, 2099202, 3072, 4195332, 2099202, 6291462, 1051649, 4195332, 1051649, 5243909, 2099202, 3072, 7340039, 2099202, 5243909, 1051649, 4195332, 3072, 7340039, 1051649, 6291462, 3147779, 7340039, 2099202, 5243909, 7340039, 3147779, 3072, 4195332, 1051649, 6291462, 7340039, 3147779, 5243909, 4195332, 5243909, 1051649, 7340039, 2099202, 7340039, 3072, 4195332, 1051649, 7340039, 4195332, 2099202, 6291462, 4195332, 2099202, 3072, 7340039, 2099202, 6291462, 4195332, 7340039, 3147779, 6291462, 3072, 1051649, 7340039, 3147779, 3072, 7340039, 2099202, 1051649, 4195332, 3147779, 4195332, 6291462, 3147779, 6291462, 2099202, 6291462, 3147779, 4195332, 1051649, 7340039, 3072, 4195332, 7340039, 1051649, - 2099202, 3147779, 5243909, 6291462, 3147779, 7340039, 1051649, 6291462, 3072, 2099202, 1051649, 5243909, 7340039, 4195332, 2099202, 4195332, 7340039, 3072, 6291462, 1051649, 2099202, 3147779, 7340039, 5243909, 2099202, 7340039, 3147779, 7340039, 5243909, 1051649, 4195332, 2099202, 4195332, 5243909, 2099202, 7340039, 3147779, 4195332, 1051649, 6291462, 3147779, 3072, 7340039, 2099202, 4195332, 3072, 5243909, 1051649, 6291462, 3147779, 6291462, 1051649, 4195332, 3147779, 6291462, 7340039, 2099202, 6291462, 5243909, 1051649, 4195332, 7340039, 2099202, 6291462, 3147779, 4195332, 5243909, 2099202, 4195332, 3072, 5243909, 3147779, 3072, 4195332, 3147779, 6291462, 2099202, 4195332, 2099202, 3072, 7340039, 1051649, 2099202, 6291462, 3147779, 3072, 4195332, 1051649, 7340039, 5243909, 2099202, 1051649, 7340039, 1051649, 7340039, 3147779, 6291462, 4195332, 4195332, 3072, 6291462, 3072, 5243909, 1051649, 7340039, 4195332, 1051649, 6291462, 3147779, 2099202, 6291462, 3147779, 5243909, 3072, 5243909, 1051649, 3072, 7340039, 3147779, 6291462, 3072, 7340039, 5243909, 2099202, 6291462, 3147779, 1051649, 5243909, - 3072, 7340039, 2099202, 3072, 3147779, 2099202, 4195332, 3147779, 6291462, 5243909, 6291462, 3147779, 2099202, 3072, 7340039, 3147779, 1051649, 5243909, 3147779, 5243909, 6291462, 2099202, 1051649, 5243909, 1051649, 4195332, 1051649, 4195332, 2099202, 7340039, 3147779, 7340039, 1051649, 3147779, 5243909, 1051649, 2099202, 7340039, 3147779, 2099202, 7340039, 4195332, 1051649, 5243909, 6291462, 3147779, 4195332, 4195332, 3072, 3147779, 7340039, 2099202, 7340039, 3072, 2099202, 4195332, 1051649, 4195332, 3072, 6291462, 3147779, 3072, 3147779, 5243909, 1051649, 7340039, 3072, 3147779, 6291462, 2099202, 1051649, 5243909, 7340039, 2099202, 5243909, 3072, 6291462, 3072, 5243909, 3147779, 2099202, 7340039, 5243909, 3072, 4195332, 6291462, 3147779, 6291462, 2099202, 3072, 6291462, 4195332, 3147779, 3147779, 3072, 5243909, 1051649, 1051649, 5243909, 2099202, 3147779, 5243909, 2099202, 3147779, 5243909, 2099202, 5243909, 3072, 4195332, 5243909, 3072, 7340039, 1051649, 6291462, 2099202, 7340039, 2099202, 5243909, 1051649, 1051649, 5243909, 2099202, 1051649, 4195332, 3072, 5243909, 3147779, 6291462, - 4195332, 1051649, 6291462, 4195332, 5243909, 6291462, 3072, 5243909, 2099202, 1051649, 4195332, 3072, 6291462, 5243909, 1051649, 4195332, 7340039, 2099202, 4195332, 3072, 4195332, 3072, 7340039, 3147779, 6291462, 2099202, 6291462, 3072, 6291462, 4195332, 3072, 5243909, 6291462, 3072, 5243909, 3147779, 5243909, 3072, 6291462, 5243909, 1051649, 6291462, 3147779, 2099202, 3072, 7340039, 1051649, 3147779, 6291462, 4195332, 3072, 5243909, 3147779, 5243909, 1051649, 7340039, 3147779, 6291462, 3147779, 4195332, 1051649, 7340039, 5243909, 3072, 4195332, 1051649, 5243909, 7340039, 3072, 4195332, 6291462, 3147779, 1051649, 3147779, 7340039, 2099202, 5243909, 7340039, 1051649, 6291462, 4195332, 3072, 4195332, 1051649, 7340039, 2099202, 3072, 3147779, 5243909, 4195332, 3147779, 1051649, 6291462, 5243909, 2099202, 7340039, 3147779, 6291462, 2099202, 7340039, 4195332, 3072, 7340039, 6291462, 3072, 7340039, 2099202, 3147779, 7340039, 1051649, 6291462, 2099202, 4195332, 2099202, 5243909, 1051649, 4195332, 3147779, 7340039, 5243909, 3147779, 3147779, 6291462, 2099202, 6291462, 1051649, 7340039, 2099202, - 3147779, 7340039, 2099202, 7340039, 3072, 2099202, 4195332, 1051649, 7340039, 3072, 7340039, 5243909, 1051649, 3147779, 6291462, 3072, 4195332, 6291462, 1051649, 7340039, 2099202, 5243909, 4195332, 3147779, 3072, 6291462, 3147779, 5243909, 1051649, 2099202, 5243909, 1051649, 2099202, 6291462, 1051649, 7340039, 2099202, 4195332, 1051649, 4195332, 2099202, 3072, 5243909, 7340039, 3147779, 5243909, 2099202, 6291462, 2099202, 5243909, 2099202, 6291462, 1051649, 4195332, 5243909, 3072, 5243909, 2099202, 3072, 6291462, 2099202, 5243909, 2099202, 7340039, 3147779, 6291462, 1051649, 4195332, 5243909, 1051649, 6291462, 3072, 7340039, 4195332, 1051649, 4195332, 1051649, 3147779, 4195332, 2099202, 3147779, 7340039, 3147779, 6291462, 2099202, 5243909, 7340039, 1051649, 6291462, 3072, 7340039, 6291462, 3072, 1051649, 5243909, 3072, 4195332, 3072, 5243909, 1051649, 6291462, 3147779, 4195332, 1051649, 4195332, 1051649, 6291462, 5243909, 3072, 4195332, 3147779, 5243909, 3072, 4195332, 7340039, 3147779, 5243909, 3072, 4195332, 1051649, 7340039, 5243909, 3072, 7340039, 3147779, 5243909, 3072, 4195332, - 3072, 5243909, 1051649, 3147779, 4195332, 7340039, 3147779, 5243909, 2099202, 6291462, 3147779, 2099202, 7340039, 2099202, 2099202, 5243909, 3147779, 3072, 5243909, 2099202, 6291462, 1051649, 1051649, 6291462, 5243909, 1051649, 7340039, 3072, 4195332, 7340039, 2099202, 7340039, 3147779, 6291462, 4195332, 3072, 6291462, 2099202, 7340039, 3072, 7340039, 4195332, 2099202, 4195332, 1051649, 3147779, 6291462, 3072, 4195332, 7340039, 3072, 3147779, 7340039, 3072, 3147779, 6291462, 1051649, 7340039, 5243909, 2099202, 7340039, 3072, 4195332, 2099202, 6291462, 3072, 7340039, 2099202, 2099202, 7340039, 2099202, 3147779, 5243909, 1051649, 6291462, 5243909, 3147779, 6291462, 3072, 6291462, 5243909, 3072, 4195332, 1051649, 4195332, 3072, 4195332, 7340039, 2099202, 5243909, 2099202, 4195332, 3147779, 7340039, 3147779, 6291462, 2099202, 7340039, 4195332, 3147779, 1051649, 3072, 6291462, 2099202, 7340039, 5243909, 3147779, 1051649, 3147779, 7340039, 1051649, 7340039, 6291462, 2099202, 3072, 6291462, 1051649, 6291462, 2099202, 6291462, 3072, 2099202, 4195332, 1051649, 4195332, 7340039, 2099202, 6291462, - 6291462, 3147779, 5243909, 6291462, 1051649, 6291462, 1051649, 7340039, 4195332, 3072, 4195332, 5243909, 3072, 4195332, 6291462, 1051649, 7340039, 3147779, 7340039, 3072, 3147779, 7340039, 6291462, 1051649, 3147779, 4195332, 2099202, 5243909, 3147779, 4195332, 1051649, 4195332, 3072, 2099202, 3147779, 7340039, 1051649, 4195332, 3147779, 5243909, 2099202, 6291462, 3072, 7340039, 1051649, 7340039, 3072, 5243909, 1051649, 4195332, 1051649, 6291462, 5243909, 2099202, 7340039, 4195332, 3147779, 4195332, 1051649, 6291462, 3147779, 1051649, 6291462, 1051649, 3147779, 5243909, 2099202, 4195332, 6291462, 1051649, 4195332, 7340039, 3072, 4195332, 2099202, 3072, 7340039, 1051649, 5243909, 2099202, 1051649, 5243909, 6291462, 2099202, 7340039, 3147779, 5243909, 3072, 4195332, 3147779, 1051649, 7340039, 5243909, 3072, 4195332, 1051649, 4195332, 2099202, 3072, 6291462, 5243909, 7340039, 2099202, 4195332, 2099202, 3072, 3147779, 7340039, 5243909, 2099202, 5243909, 3147779, 1051649, 7340039, 4195332, 3147779, 2099202, 4195332, 3147779, 4195332, 2099202, 6291462, 5243909, 2099202, 6291462, 3072, 4195332, 1051649, - 1051649, 4195332, 3072, 2099202, 5243909, 3072, 3147779, 3072, 4195332, 7340039, 3147779, 1051649, 7340039, 3147779, 5243909, 2099202, 5243909, 1051649, 4195332, 5243909, 4195332, 3072, 2099202, 7340039, 5243909, 3072, 6291462, 1051649, 7340039, 3072, 6291462, 3147779, 5243909, 3147779, 5243909, 3072, 5243909, 6291462, 3072, 6291462, 1051649, 3147779, 5243909, 3147779, 6291462, 2099202, 5243909, 4195332, 7340039, 2099202, 5243909, 3147779, 1051649, 5243909, 3072, 2099202, 6291462, 3072, 7340039, 3072, 4195332, 5243909, 3147779, 5243909, 1051649, 6291462, 3072, 6291462, 3072, 5243909, 3072, 3147779, 6291462, 2099202, 7340039, 4195332, 2099202, 7340039, 4195332, 2099202, 7340039, 3147779, 1051649, 6291462, 1051649, 5243909, 1051649, 6291462, 2099202, 6291462, 4195332, 1051649, 2099202, 6291462, 2099202, 7340039, 5243909, 3147779, 5243909, 2099202, 4195332, 1051649, 5243909, 3072, 6291462, 4195332, 6291462, 3072, 2099202, 6291462, 3072, 4195332, 4195332, 1051649, 5243909, 3072, 7340039, 1051649, 7340039, 3072, 7340039, 3147779, 3072, 7340039, 1051649, 5243909, 2099202, 7340039, - 1051649, 5243909, 7340039, 2099202, 6291462, 3147779, 6291462, 5243909, 2099202, 5243909, 3072, 6291462, 3147779, 3072, 1051649, 6291462, 3072, 6291462, 3147779, 1051649, 7340039, 2099202, 4195332, 3072, 2099202, 7340039, 4195332, 3147779, 1051649, 6291462, 2099202, 7340039, 3072, 7340039, 1051649, 6291462, 3147779, 2099202, 4195332, 3147779, 6291462, 1051649, 1051649, 4195332, 1051649, 3147779, 7340039, 2099202, 3072, 6291462, 1051649, 7340039, 2099202, 7340039, 3147779, 5243909, 2099202, 5243909, 3147779, 2099202, 7340039, 3072, 4195332, 7340039, 3072, 4195332, 3147779, 4195332, 2099202, 7340039, 5243909, 1051649, 6291462, 3147779, 1051649, 5243909, 3147779, 3072, 3147779, 6291462, 3072, 6291462, 5243909, 3147779, 4195332, 3072, 7340039, 3147779, 6291462, 3072, 3147779, 6291462, 4195332, 3072, 5243909, 1051649, 3072, 7340039, 1051649, 7340039, 3072, 6291462, 3147779, 4195332, 7340039, 1051649, 2099202, 6291462, 4195332, 4195332, 2099202, 6291462, 3072, 7340039, 3147779, 6291462, 4195332, 5243909, 2099202, 4195332, 5243909, 1051649, 3147779, 4195332, 6291462, 3147779, 3147779, 5243909, - 7340039, 3147779, 3072, 4195332, 1051649, 4195332, 2099202, 1051649, 6291462, 1051649, 4195332, 2099202, 4195332, 7340039, 5243909, 4195332, 3147779, 2099202, 7340039, 3147779, 2099202, 5243909, 6291462, 3147779, 5243909, 1051649, 3072, 6291462, 5243909, 2099202, 4195332, 1051649, 5243909, 2099202, 4195332, 4195332, 1051649, 7340039, 3072, 7340039, 4195332, 5243909, 7340039, 3072, 6291462, 5243909, 1051649, 3147779, 6291462, 2099202, 4195332, 3072, 4195332, 1051649, 4195332, 3072, 7340039, 1051649, 4195332, 6291462, 1051649, 5243909, 1051649, 2099202, 4195332, 7340039, 2099202, 7340039, 3147779, 1051649, 4195332, 4195332, 3072, 5243909, 1051649, 6291462, 5243909, 6291462, 5243909, 1051649, 4195332, 2099202, 3072, 2099202, 7340039, 4195332, 2099202, 3072, 5243909, 2099202, 7340039, 1051649, 3147779, 7340039, 3147779, 6291462, 3147779, 6291462, 4195332, 3147779, 6291462, 2099202, 7340039, 1051649, 2099202, 5243909, 3147779, 1051649, 7340039, 1051649, 5243909, 2099202, 4195332, 5243909, 3072, 2099202, 3072, 2099202, 6291462, 1051649, 3072, 6291462, 7340039, 3072, 2099202, 6291462, 3072, 3147779, - 3072, 5243909, 2099202, 6291462, 7340039, 3072, 7340039, 5243909, 3147779, 6291462, 2099202, 7340039, 5243909, 1051649, 2099202, 3072, 7340039, 4195332, 3072, 6291462, 3072, 5243909, 1051649, 7340039, 3147779, 6291462, 5243909, 2099202, 3072, 5243909, 3072, 7340039, 4195332, 6291462, 3072, 7340039, 2099202, 4195332, 5243909, 2099202, 3072, 2099202, 6291462, 4195332, 2099202, 3072, 6291462, 4195332, 1051649, 5243909, 3147779, 6291462, 3147779, 7340039, 2099202, 6291462, 3147779, 5243909, 3072, 4195332, 3147779, 7340039, 3147779, 6291462, 3147779, 1051649, 6291462, 3072, 5243909, 3147779, 6291462, 2099202, 7340039, 3147779, 7340039, 3072, 3147779, 2099202, 1051649, 7340039, 3147779, 7340039, 4195332, 5243909, 1051649, 3147779, 6291462, 3147779, 4195332, 5243909, 2099202, 5243909, 3072, 6291462, 1051649, 5243909, 1051649, 2099202, 3072, 5243909, 1051649, 5243909, 3072, 3147779, 6291462, 3072, 7340039, 5243909, 3072, 6291462, 3147779, 7340039, 1051649, 6291462, 3147779, 7340039, 5243909, 6291462, 3147779, 5243909, 7340039, 2099202, 4195332, 3147779, 5243909, 1051649, 7340039, 4195332, - 2099202, 6291462, 3147779, 1051649, 3147779, 2099202, 5243909, 2099202, 3072, 7340039, 1051649, 3147779, 3072, 6291462, 4195332, 6291462, 3147779, 1051649, 5243909, 2099202, 7340039, 1051649, 4195332, 3072, 4195332, 1051649, 3147779, 7340039, 4195332, 3147779, 6291462, 2099202, 3147779, 1051649, 3147779, 5243909, 3072, 6291462, 1051649, 7340039, 3147779, 5243909, 3072, 3147779, 7340039, 5243909, 2099202, 3147779, 7340039, 3072, 5243909, 1051649, 6291462, 1051649, 5243909, 3072, 2099202, 4195332, 7340039, 1051649, 6291462, 3072, 5243909, 1051649, 5243909, 4195332, 2099202, 4195332, 1051649, 7340039, 3072, 2099202, 5243909, 3072, 2099202, 4195332, 1051649, 7340039, 6291462, 1051649, 4195332, 2099202, 1051649, 6291462, 3072, 7340039, 1051649, 7340039, 1051649, 3072, 7340039, 3147779, 4195332, 2099202, 7340039, 3147779, 7340039, 4195332, 2099202, 7340039, 3147779, 4195332, 6291462, 1051649, 5243909, 3147779, 2099202, 4195332, 3147779, 4195332, 3072, 5243909, 1051649, 3147779, 2099202, 4195332, 1051649, 3147779, 3072, 2099202, 3147779, 5243909, 1051649, 7340039, 2099202, 5243909, 1051649, 4195332, - 6291462, 3072, 7340039, 4195332, 6291462, 4195332, 3072, 7340039, 4195332, 4195332, 1051649, 6291462, 3147779, 7340039, 2099202, 1051649, 6291462, 5243909, 3147779, 4195332, 3147779, 6291462, 3147779, 6291462, 2099202, 7340039, 4195332, 3072, 7340039, 1051649, 5243909, 3072, 6291462, 7340039, 4195332, 2099202, 7340039, 3147779, 5243909, 6291462, 1051649, 2099202, 6291462, 4195332, 1051649, 3147779, 7340039, 3072, 4195332, 5243909, 2099202, 6291462, 3072, 3147779, 4195332, 7340039, 6291462, 1051649, 4195332, 2099202, 5243909, 2099202, 6291462, 3072, 7340039, 3072, 6291462, 2099202, 5243909, 4195332, 6291462, 3147779, 6291462, 4195332, 6291462, 5243909, 3072, 3147779, 4195332, 5243909, 3072, 6291462, 4195332, 5243909, 3147779, 4195332, 5243909, 2099202, 4195332, 6291462, 2099202, 5243909, 1051649, 6291462, 2099202, 3072, 5243909, 2099202, 6291462, 3147779, 1051649, 5243909, 2099202, 7340039, 1051649, 6291462, 4195332, 1051649, 6291462, 1051649, 7340039, 2099202, 7340039, 5243909, 6291462, 3072, 6291462, 7340039, 4195332, 7340039, 3072, 4195332, 1051649, 6291462, 3072, 4195332, 7340039, 2099202, - 4195332, 5243909, 1051649, 5243909, 3072, 3147779, 5243909, 1051649, 6291462, 2099202, 5243909, 2099202, 5243909, 3072, 4195332, 5243909, 2099202, 3072, 7340039, 1051649, 6291462, 3072, 5243909, 1051649, 2099202, 5243909, 1051649, 5243909, 2099202, 4195332, 3147779, 7340039, 2099202, 3072, 3147779, 5243909, 1051649, 4195332, 2099202, 3072, 4195332, 7340039, 4195332, 1051649, 5243909, 3072, 4195332, 6291462, 2099202, 7340039, 1051649, 4195332, 5243909, 7340039, 2099202, 3072, 5243909, 3147779, 6291462, 1051649, 7340039, 4195332, 3147779, 3147779, 2099202, 5243909, 3147779, 7340039, 3072, 3147779, 1051649, 5243909, 3072, 2099202, 1051649, 6291462, 2099202, 7340039, 3072, 3147779, 7340039, 3072, 3147779, 2099202, 6291462, 3072, 1051649, 7340039, 3072, 3147779, 1051649, 7340039, 3072, 5243909, 3147779, 5243909, 3072, 7340039, 3072, 4195332, 7340039, 3072, 4195332, 3147779, 4195332, 3072, 3147779, 7340039, 3072, 5243909, 3147779, 3072, 4195332, 3072, 3147779, 7340039, 2099202, 1051649, 4195332, 1051649, 6291462, 3147779, 6291462, 3147779, 2099202, 6291462, 1051649, 3147779, - 3072, 3147779, 2099202, 7340039, 2099202, 6291462, 3072, 4195332, 1051649, 7340039, 3072, 3147779, 7340039, 3147779, 7340039, 3072, 3147779, 5243909, 2099202, 4195332, 2099202, 3147779, 7340039, 4195332, 6291462, 3072, 7340039, 3147779, 3072, 6291462, 1051649, 1051649, 5243909, 4195332, 1051649, 6291462, 6291462, 3072, 7340039, 3147779, 5243909, 1051649, 3072, 7340039, 3147779, 6291462, 3147779, 1051649, 5243909, 3147779, 6291462, 2099202, 1051649, 3147779, 4195332, 6291462, 2099202, 1051649, 6291462, 3072, 3147779, 3072, 6291462, 7340039, 1051649, 6291462, 1051649, 2099202, 6291462, 1051649, 7340039, 4195332, 5243909, 7340039, 4195332, 3072, 5243909, 2099202, 6291462, 4195332, 2099202, 5243909, 7340039, 3072, 4195332, 7340039, 5243909, 3147779, 4195332, 6291462, 2099202, 4195332, 4195332, 1051649, 7340039, 2099202, 4195332, 5243909, 3147779, 1051649, 6291462, 2099202, 5243909, 3072, 6291462, 2099202, 5243909, 2099202, 4195332, 2099202, 6291462, 2099202, 6291462, 3147779, 5243909, 1051649, 4195332, 5243909, 6291462, 5243909, 3072, 4195332, 1051649, 5243909, 7340039, 3072, 5243909, 6291462, - 7340039, 5243909, 4195332, 1051649, 5243909, 3147779, 7340039, 3147779, 5243909, 3147779, 4195332, 6291462, 1051649, 4195332, 1051649, 5243909, 6291462, 1051649, 7340039, 3072, 6291462, 5243909, 3072, 2099202, 3147779, 4195332, 2099202, 6291462, 3147779, 4195332, 7340039, 5243909, 2099202, 7340039, 4195332, 2099202, 2099202, 4195332, 1051649, 6291462, 3147779, 5243909, 2099202, 5243909, 2099202, 1051649, 5243909, 7340039, 3072, 4195332, 3072, 7340039, 3147779, 6291462, 3072, 3147779, 7340039, 4195332, 5243909, 2099202, 7340039, 4195332, 1051649, 3147779, 4195332, 2099202, 4195332, 5243909, 3147779, 5243909, 2099202, 3072, 3147779, 1051649, 3147779, 7340039, 3147779, 5243909, 1051649, 5243909, 1051649, 6291462, 2099202, 5243909, 2099202, 3147779, 1051649, 5243909, 1051649, 6291462, 3072, 7340039, 3147779, 6291462, 3147779, 3072, 6291462, 2099202, 6291462, 1051649, 4195332, 5243909, 2099202, 7340039, 1051649, 7340039, 3147779, 3072, 7340039, 5243909, 1051649, 5243909, 1051649, 7340039, 2099202, 6291462, 3072, 3147779, 1051649, 2099202, 7340039, 5243909, 3072, 3147779, 1051649, 5243909, 3147779, 2099202, - 3072, 6291462, 1051649, 6291462, 4195332, 2099202, 1051649, 6291462, 3072, 6291462, 2099202, 3072, 5243909, 6291462, 2099202, 7340039, 3072, 3147779, 4195332, 5243909, 1051649, 3147779, 5243909, 7340039, 1051649, 6291462, 4195332, 3072, 7340039, 1051649, 3147779, 3072, 3147779, 1051649, 6291462, 3072, 5243909, 3147779, 5243909, 2099202, 3072, 7340039, 1051649, 6291462, 4195332, 6291462, 2099202, 1051649, 4195332, 7340039, 2099202, 5243909, 3072, 5243909, 2099202, 5243909, 3072, 6291462, 1051649, 3147779, 5243909, 2099202, 6291462, 3072, 7340039, 3147779, 7340039, 3072, 7340039, 3072, 4195332, 7340039, 6291462, 6291462, 1051649, 4195332, 3072, 2099202, 3147779, 7340039, 3072, 4195332, 1051649, 4195332, 3072, 6291462, 6291462, 3072, 7340039, 1051649, 3147779, 5243909, 2099202, 1051649, 4195332, 7340039, 1051649, 7340039, 3072, 3147779, 7340039, 3072, 6291462, 3147779, 4195332, 1051649, 5243909, 6291462, 3147779, 1051649, 7340039, 4195332, 4195332, 3072, 4195332, 3147779, 7340039, 4195332, 7340039, 3072, 3147779, 2099202, 6291462, 4195332, 7340039, 3147779, 1051649, 5243909, - 2099202, 3147779, 7340039, 2099202, 3072, 6291462, 4195332, 3147779, 5243909, 1051649, 4195332, 7340039, 2099202, 4195332, 3072, 3147779, 4195332, 7340039, 1051649, 2099202, 6291462, 2099202, 3072, 5243909, 3147779, 1051649, 6291462, 5243909, 2099202, 5243909, 6291462, 3147779, 6291462, 5243909, 3147779, 7340039, 3072, 7340039, 1051649, 6291462, 3147779, 4195332, 3147779, 7340039, 3072, 3147779, 5243909, 3147779, 6291462, 2099202, 5243909, 1051649, 4195332, 1051649, 7340039, 3147779, 1051649, 2099202, 7340039, 4195332, 3072, 7340039, 1051649, 4195332, 5243909, 3072, 5243909, 1051649, 3147779, 5243909, 2099202, 1051649, 3072, 4195332, 2099202, 5243909, 7340039, 6291462, 4195332, 3147779, 6291462, 2099202, 7340039, 3147779, 7340039, 1051649, 3147779, 4195332, 2099202, 6291462, 4195332, 3072, 5243909, 6291462, 3072, 4195332, 2099202, 4195332, 3147779, 5243909, 2099202, 4195332, 3147779, 1051649, 6291462, 5243909, 2099202, 4195332, 3072, 6291462, 3147779, 3072, 7340039, 2099202, 6291462, 1051649, 2099202, 3072, 5243909, 3147779, 7340039, 5243909, 1051649, 6291462, 2099202, 3072, 4195332, 7340039, - 6291462, 3072, 4195332, 3147779, 5243909, 1051649, 7340039, 3072, 7340039, 5243909, 3147779, 3072, 5243909, 1051649, 6291462, 5243909, 1051649, 3147779, 6291462, 5243909, 4195332, 7340039, 4195332, 2099202, 4195332, 7340039, 3072, 2099202, 4195332, 3072, 4195332, 1051649, 5243909, 3072, 2099202, 5243909, 2099202, 3147779, 4195332, 2099202, 7340039, 3072, 5243909, 2099202, 4195332, 7340039, 3072, 4195332, 1051649, 3072, 6291462, 3147779, 7340039, 4195332, 1051649, 6291462, 5243909, 4195332, 2099202, 6291462, 1051649, 4195332, 5243909, 2099202, 6291462, 1051649, 4195332, 6291462, 2099202, 4195332, 6291462, 7340039, 4195332, 3147779, 7340039, 3072, 3147779, 1051649, 3072, 6291462, 1051649, 5243909, 3072, 6291462, 2099202, 5243909, 6291462, 2099202, 5243909, 3072, 3147779, 7340039, 2099202, 4195332, 6291462, 2099202, 5243909, 1051649, 6291462, 1051649, 7340039, 5243909, 3072, 7340039, 3147779, 3072, 7340039, 1051649, 5243909, 4195332, 2099202, 5243909, 1051649, 5243909, 2099202, 5243909, 4195332, 6291462, 4195332, 1051649, 2099202, 4195332, 2099202, 3072, 5243909, 6291462, 4195332, 1051649, - 4195332, 1051649, 5243909, 1051649, 7340039, 4195332, 2099202, 3147779, 2099202, 4195332, 2099202, 7340039, 3147779, 5243909, 2099202, 7340039, 2099202, 6291462, 3072, 2099202, 3072, 3147779, 1051649, 7340039, 3072, 5243909, 3147779, 7340039, 1051649, 6291462, 2099202, 7340039, 1051649, 7340039, 4195332, 7340039, 1051649, 6291462, 3072, 5243909, 4195332, 1051649, 6291462, 3072, 3147779, 1051649, 6291462, 2099202, 7340039, 5243909, 3147779, 3072, 3147779, 6291462, 2099202, 4195332, 3072, 7340039, 3072, 3147779, 3147779, 1051649, 7340039, 3072, 3147779, 7340039, 3147779, 2099202, 6291462, 3072, 3147779, 1051649, 2099202, 5243909, 1051649, 5243909, 2099202, 4195332, 5243909, 2099202, 7340039, 3147779, 5243909, 1051649, 4195332, 3072, 3147779, 5243909, 3072, 7340039, 4195332, 1051649, 5243909, 1051649, 3147779, 7340039, 3072, 6291462, 2099202, 4195332, 3072, 3147779, 5243909, 4195332, 2099202, 5243909, 3147779, 6291462, 2099202, 1051649, 6291462, 3147779, 7340039, 3072, 6291462, 3072, 7340039, 2099202, 1051649, 5243909, 6291462, 3072, 7340039, 4195332, 3147779, 1051649, 7340039, 3147779, - 7340039, 6291462, 3147779, 7340039, 2099202, 3072, 5243909, 6291462, 3072, 6291462, 1051649, 6291462, 3072, 2099202, 4195332, 3072, 4195332, 1051649, 7340039, 4195332, 7340039, 6291462, 5243909, 1051649, 6291462, 2099202, 6291462, 1051649, 5243909, 4195332, 3072, 3147779, 6291462, 2099202, 4195332, 3072, 4195332, 4195332, 2099202, 6291462, 1051649, 4195332, 3147779, 6291462, 7340039, 4195332, 2099202, 6291462, 3072, 6291462, 1051649, 7340039, 4195332, 3072, 5243909, 7340039, 1051649, 3147779, 5243909, 6291462, 5243909, 4195332, 2099202, 6291462, 1051649, 5243909, 3072, 7340039, 1051649, 5243909, 6291462, 5243909, 6291462, 1051649, 7340039, 3147779, 6291462, 3072, 7340039, 2099202, 4195332, 1051649, 6291462, 3147779, 7340039, 5243909, 1051649, 7340039, 2099202, 5243909, 2099202, 6291462, 3072, 7340039, 4195332, 3147779, 5243909, 3147779, 1051649, 7340039, 6291462, 2099202, 7340039, 1051649, 7340039, 4195332, 1051649, 3072, 4195332, 7340039, 5243909, 3072, 3147779, 2099202, 4195332, 5243909, 1051649, 3147779, 7340039, 3072, 3147779, 6291462, 4195332, 3072, 7340039, 2099202, 5243909, 3072, - 2099202, 3072, 5243909, 1051649, 4195332, 6291462, 3147779, 1051649, 7340039, 3147779, 5243909, 3147779, 1051649, 7340039, 6291462, 3147779, 6291462, 5243909, 1051649, 4195332, 2099202, 3072, 3147779, 7340039, 4195332, 3072, 3147779, 5243909, 2099202, 7340039, 3147779, 6291462, 1051649, 5243909, 2099202, 6291462, 1051649, 7340039, 3072, 3147779, 7340039, 5243909, 3072, 5243909, 2099202, 3072, 5243909, 3147779, 4195332, 4195332, 2099202, 5243909, 2099202, 6291462, 1051649, 2099202, 4195332, 6291462, 1051649, 2099202, 3072, 7340039, 2099202, 3147779, 6291462, 2099202, 5243909, 4195332, 4195332, 1051649, 2099202, 3072, 7340039, 4195332, 3072, 6291462, 3147779, 4195332, 1051649, 5243909, 3072, 7340039, 1051649, 4195332, 3072, 3147779, 2099202, 6291462, 4195332, 1051649, 7340039, 3147779, 4195332, 2099202, 3072, 6291462, 1051649, 6291462, 3072, 4195332, 1051649, 5243909, 2099202, 4195332, 3072, 2099202, 6291462, 3147779, 6291462, 3072, 2099202, 7340039, 4195332, 6291462, 2099202, 7340039, 3147779, 5243909, 2099202, 6291462, 5243909, 1051649, 2099202, 5243909, 4195332, 2099202, 6291462, 3147779, - 7340039, 2099202, 4195332, 6291462, 2099202, 3072, 6291462, 4195332, 2099202, 5243909, 3072, 7340039, 4195332, 3147779, 1051649, 4195332, 3072, 5243909, 1051649, 3147779, 6291462, 2099202, 5243909, 1051649, 3147779, 4195332, 7340039, 3072, 4195332, 1051649, 5243909, 1051649, 4195332, 6291462, 3072, 1051649, 5243909, 3147779, 6291462, 5243909, 2099202, 1051649, 7340039, 1051649, 6291462, 3147779, 7340039, 1051649, 7340039, 1051649, 6291462, 3072, 7340039, 4195332, 3147779, 7340039, 3072, 3147779, 5243909, 7340039, 4195332, 1051649, 5243909, 3072, 4195332, 7340039, 3072, 2099202, 7340039, 3147779, 6291462, 3147779, 2099202, 3147779, 5243909, 2099202, 1051649, 7340039, 3147779, 4195332, 2099202, 5243909, 3147779, 7340039, 2099202, 6291462, 4195332, 3072, 3147779, 5243909, 3072, 5243909, 1051649, 6291462, 5243909, 2099202, 7340039, 2099202, 4195332, 7340039, 3147779, 6291462, 3072, 6291462, 3147779, 7340039, 1051649, 5243909, 2099202, 4195332, 5243909, 3147779, 1051649, 3072, 5243909, 1051649, 6291462, 3072, 4195332, 3147779, 3072, 7340039, 6291462, 3147779, 1051649, 6291462, 3072, 5243909, - 1051649, 3147779, 7340039, 3072, 5243909, 7340039, 2099202, 4195332, 1051649, 7340039, 4195332, 1051649, 6291462, 3072, 6291462, 2099202, 7340039, 3147779, 7340039, 3072, 5243909, 4195332, 1051649, 7340039, 5243909, 1051649, 6291462, 3147779, 6291462, 2099202, 4195332, 3147779, 7340039, 2099202, 7340039, 3147779, 6291462, 3072, 3147779, 2099202, 4195332, 6291462, 3147779, 4195332, 3072, 5243909, 1051649, 5243909, 3147779, 7340039, 2099202, 4195332, 3147779, 3072, 6291462, 1051649, 3147779, 5243909, 3072, 2099202, 3147779, 6291462, 2099202, 7340039, 3147779, 1051649, 4195332, 6291462, 3072, 5243909, 1051649, 7340039, 5243909, 3072, 6291462, 4195332, 5243909, 3072, 6291462, 1051649, 7340039, 2099202, 3072, 6291462, 1051649, 5243909, 2099202, 7340039, 4195332, 3147779, 6291462, 2099202, 7340039, 3072, 3147779, 4195332, 1051649, 5243909, 3072, 5243909, 3072, 3147779, 5243909, 1051649, 5243909, 4195332, 2099202, 6291462, 3072, 7340039, 1051649, 3147779, 7340039, 4195332, 3147779, 6291462, 2099202, 4195332, 1051649, 6291462, 2099202, 4195332, 1051649, 3072, 5243909, 3147779, 1051649, 5243909, - 4195332, 1051649, 4195332, 2099202, 3147779, 1051649, 7340039, 3072, 3147779, 6291462, 2099202, 5243909, 2099202, 5243909, 1051649, 5243909, 3072, 6291462, 2099202, 4195332, 2099202, 6291462, 3147779, 4195332, 3072, 6291462, 2099202, 2099202, 3072, 7340039, 3072, 6291462, 3072, 3147779, 4195332, 5243909, 1051649, 4195332, 7340039, 3072, 7340039, 3072, 2099202, 7340039, 2099202, 4195332, 6291462, 2099202, 3072, 5243909, 1051649, 1051649, 6291462, 2099202, 5243909, 4195332, 6291462, 2099202, 7340039, 4195332, 6291462, 3072, 4195332, 5243909, 3072, 6291462, 5243909, 3147779, 2099202, 6291462, 4195332, 2099202, 4195332, 3147779, 1051649, 7340039, 2099202, 4195332, 3147779, 5243909, 3072, 5243909, 6291462, 2099202, 4195332, 3072, 6291462, 1051649, 1051649, 6291462, 1051649, 4195332, 3147779, 5243909, 1051649, 7340039, 3072, 6291462, 3147779, 2099202, 6291462, 6291462, 1051649, 3147779, 7340039, 3072, 6291462, 4195332, 2099202, 5243909, 1051649, 5243909, 3072, 6291462, 2099202, 3072, 6291462, 1051649, 7340039, 5243909, 3072, 5243909, 7340039, 4195332, 7340039, 2099202, 6291462, 3147779, - 3072, 6291462, 2099202, 5243909, 6291462, 4195332, 3147779, 5243909, 6291462, 3072, 4195332, 1051649, 7340039, 3147779, 4195332, 7340039, 2099202, 3147779, 3072, 7340039, 3147779, 3072, 6291462, 2099202, 7340039, 3147779, 4195332, 7340039, 5243909, 3147779, 4195332, 1051649, 5243909, 7340039, 2099202, 3072, 5243909, 2099202, 6291462, 2099202, 3147779, 5243909, 6291462, 1051649, 5243909, 3072, 7340039, 2099202, 4195332, 7340039, 3147779, 5243909, 3147779, 7340039, 3072, 2099202, 1051649, 5243909, 3072, 4195332, 1051649, 7340039, 3147779, 6291462, 1051649, 3147779, 1051649, 7340039, 4195332, 2099202, 3072, 7340039, 3072, 5243909, 6291462, 3072, 3147779, 1051649, 7340039, 2099202, 6291462, 3147779, 1051649, 5243909, 7340039, 3147779, 4195332, 7340039, 5243909, 2099202, 7340039, 3072, 7340039, 4195332, 6291462, 3147779, 2099202, 4195332, 2099202, 7340039, 3147779, 3072, 4195332, 5243909, 1051649, 4195332, 3147779, 1051649, 7340039, 3147779, 6291462, 2099202, 4195332, 3147779, 7340039, 4195332, 3147779, 4195332, 3147779, 3147779, 7340039, 2099202, 1051649, 3147779, 3072, 4195332, 1051649, 7340039, - 5243909, 4195332, 7340039, 3072, 2099202, 1051649, 5243909, 3072, 3147779, 7340039, 5243909, 1051649, 4195332, 3072, 4195332, 1051649, 3147779, 6291462, 5243909, 1051649, 4195332, 7340039, 3072, 5243909, 1051649, 6291462, 3072, 5243909, 1051649, 2099202, 6291462, 2099202, 5243909, 1051649, 4195332, 6291462, 3147779, 7340039, 1051649, 5243909, 1051649, 5243909, 1051649, 4195332, 4195332, 3147779, 1051649, 5243909, 3072, 4195332, 3072, 6291462, 1051649, 2099202, 5243909, 6291462, 7340039, 3147779, 7340039, 2099202, 3147779, 5243909, 1051649, 2099202, 5243909, 7340039, 2099202, 4195332, 3072, 6291462, 5243909, 2099202, 6291462, 1051649, 2099202, 5243909, 6291462, 5243909, 3072, 4195332, 1051649, 4195332, 7340039, 3072, 3147779, 1051649, 5243909, 3072, 3147779, 1051649, 5243909, 3147779, 2099202, 3072, 2099202, 6291462, 5243909, 7340039, 3072, 4195332, 1051649, 7340039, 1051649, 6291462, 3147779, 7340039, 2099202, 5243909, 3072, 4195332, 3072, 7340039, 5243909, 1051649, 5243909, 2099202, 7340039, 3072, 6291462, 1051649, 3072, 6291462, 4195332, 6291462, 2099202, 7340039, 5243909, 2099202, - 1051649, 3072, 3147779, 4195332, 7340039, 6291462, 2099202, 7340039, 2099202, 1051649, 2099202, 6291462, 3147779, 7340039, 2099202, 6291462, 5243909, 1051649, 4195332, 6291462, 2099202, 3147779, 5243909, 2099202, 4195332, 1051649, 7340039, 2099202, 4195332, 5243909, 3072, 7340039, 2099202, 3147779, 7340039, 1051649, 5243909, 3147779, 1051649, 7340039, 4195332, 2099202, 3147779, 7340039, 2099202, 6291462, 3147779, 4195332, 6291462, 2099202, 5243909, 2099202, 4195332, 7340039, 3147779, 3072, 1051649, 4195332, 1051649, 6291462, 3072, 4195332, 7340039, 4195332, 3072, 6291462, 3072, 7340039, 3147779, 4195332, 1051649, 3147779, 4195332, 3147779, 7340039, 1051649, 3147779, 2099202, 7340039, 4195332, 6291462, 3072, 2099202, 4195332, 6291462, 2099202, 7340039, 2099202, 6291462, 4195332, 3072, 5243909, 6291462, 2099202, 5243909, 3072, 3147779, 1051649, 5243909, 3147779, 5243909, 2099202, 6291462, 2099202, 2099202, 3072, 6291462, 3147779, 7340039, 1051649, 5243909, 3147779, 3072, 7340039, 1051649, 6291462, 3072, 5243909, 2099202, 5243909, 4195332, 2099202, 1051649, 3147779, 5243909, 3147779, 3072, 6291462, - 3147779, 7340039, 5243909, 3072, 3147779, 1051649, 4195332, 3072, 5243909, 6291462, 4195332, 3072, 7340039, 1051649, 5243909, 3147779, 3072, 7340039, 2099202, 3072, 7340039, 1051649, 7340039, 3072, 6291462, 4195332, 3147779, 6291462, 3072, 7340039, 3147779, 5243909, 3072, 6291462, 2099202, 4195332, 3072, 6291462, 3147779, 3072, 6291462, 3072, 6291462, 3147779, 3072, 6291462, 3072, 7340039, 1051649, 3147779, 6291462, 3072, 6291462, 1051649, 5243909, 4195332, 6291462, 3147779, 5243909, 2099202, 6291462, 3147779, 3072, 6291462, 3147779, 4195332, 2099202, 5243909, 1051649, 7340039, 6291462, 1051649, 7340039, 3072, 4195332, 3147779, 7340039, 3072, 4195332, 1051649, 2099202, 7340039, 3147779, 6291462, 3072, 2099202, 4195332, 3072, 7340039, 1051649, 6291462, 3147779, 1051649, 6291462, 4195332, 7340039, 3147779, 6291462, 1051649, 7340039, 1051649, 4195332, 3072, 4195332, 7340039, 4195332, 5243909, 1051649, 4195332, 6291462, 2099202, 2099202, 6291462, 4195332, 3147779, 4195332, 2099202, 7340039, 4195332, 1051649, 7340039, 3147779, 7340039, 3072, 6291462, 1051649, 7340039, 4195332, - 1051649, 4195332, 2099202, 6291462, 3147779, 5243909, 6291462, 4195332, 3147779, 1051649, 6291462, 4195332, 2099202, 5243909, 3072, 4195332, 6291462, 2099202, 4195332, 3147779, 5243909, 1051649, 3147779, 5243909, 2099202, 3072, 5243909, 1051649, 5243909, 3147779, 1051649, 6291462, 4195332, 3072, 7340039, 2099202, 6291462, 2099202, 7340039, 4195332, 3147779, 5243909, 1051649, 6291462, 5243909, 2099202, 3147779, 1051649, 4195332, 7340039, 3147779, 4195332, 3147779, 3072, 7340039, 2099202, 3072, 7340039, 3072, 5243909, 1051649, 5243909, 2099202, 6291462, 1051649, 7340039, 3147779, 1051649, 5243909, 3072, 2099202, 5243909, 2099202, 5243909, 1051649, 5243909, 1051649, 6291462, 3147779, 6291462, 5243909, 3147779, 1051649, 5243909, 4195332, 7340039, 3147779, 5243909, 3147779, 4195332, 2099202, 7340039, 4195332, 3072, 2099202, 1051649, 5243909, 3072, 4195332, 2099202, 5243909, 6291462, 3147779, 7340039, 1051649, 3072, 6291462, 2099202, 7340039, 3072, 4195332, 6291462, 1051649, 2099202, 7340039, 3072, 5243909, 1051649, 3147779, 6291462, 3072, 3147779, 5243909, 4195332, 2099202, 5243909, 2099202, 6291462, - 7340039, 2099202, 6291462, 1051649, 1051649, 7340039, 2099202, 1051649, 7340039, 5243909, 3072, 3147779, 6291462, 2099202, 6291462, 3147779, 1051649, 5243909, 3072, 7340039, 2099202, 5243909, 6291462, 1051649, 7340039, 4195332, 3147779, 6291462, 2099202, 7340039, 2099202, 4195332, 1051649, 3147779, 5243909, 1051649, 4195332, 5243909, 3072, 2099202, 1051649, 7340039, 4195332, 3072, 4195332, 1051649, 7340039, 5243909, 3072, 5243909, 1051649, 7340039, 6291462, 2099202, 5243909, 3147779, 4195332, 2099202, 5243909, 2099202, 4195332, 7340039, 2099202, 4195332, 5243909, 3072, 5243909, 2099202, 6291462, 4195332, 3147779, 7340039, 4195332, 3072, 6291462, 2099202, 7340039, 2099202, 5243909, 1051649, 3072, 5243909, 7340039, 1051649, 6291462, 3072, 5243909, 1051649, 6291462, 3072, 5243909, 1051649, 4195332, 6291462, 7340039, 3147779, 4195332, 2099202, 7340039, 5243909, 3072, 3147779, 1051649, 5243909, 3147779, 3147779, 7340039, 1051649, 3147779, 5243909, 1051649, 3147779, 5243909, 6291462, 1051649, 5243909, 2099202, 7340039, 5243909, 2099202, 5243909, 6291462, 1051649, 2099202, 7340039, 3147779, 4195332, 3072, - 4195332, 3072, 3147779, 5243909, 5243909, 3072, 3147779, 6291462, 3072, 2099202, 7340039, 3147779, 1051649, 7340039, 1051649, 3147779, 7340039, 3147779, 6291462, 2099202, 4195332, 3072, 4195332, 4195332, 2099202, 1051649, 7340039, 3072, 4195332, 1051649, 5243909, 3072, 7340039, 6291462, 3147779, 7340039, 3072, 3147779, 4195332, 6291462, 5243909, 3147779, 1051649, 7340039, 3147779, 5243909, 3147779, 2099202, 6291462, 1051649, 5243909, 3072, 2099202, 4195332, 6291462, 3072, 6291462, 1051649, 3147779, 7340039, 3147779, 3072, 6291462, 3072, 7340039, 3147779, 2099202, 7340039, 3147779, 1051649, 7340039, 1051649, 4195332, 7340039, 3147779, 5243909, 3072, 4195332, 3072, 6291462, 3147779, 4195332, 2099202, 4195332, 1051649, 2099202, 7340039, 2099202, 4195332, 6291462, 1051649, 7340039, 2099202, 3147779, 1051649, 5243909, 7340039, 3072, 3147779, 1051649, 7340039, 2099202, 6291462, 2099202, 6291462, 5243909, 3072, 4195332, 5243909, 2099202, 7340039, 4195332, 3072, 4195332, 3147779, 6291462, 3147779, 3072, 4195332, 1051649, 7340039, 3072, 4195332, 5243909, 3072, 6291462, 1051649, 5243909, - 2099202, 7340039, 6291462, 3072, 3147779, 7340039, 5243909, 2099202, 4195332, 6291462, 1051649, 5243909, 5243909, 3072, 4195332, 5243909, 3072, 4195332, 1051649, 6291462, 3147779, 6291462, 1051649, 7340039, 3072, 5243909, 2099202, 4195332, 6291462, 1051649, 6291462, 3147779, 5243909, 2099202, 1051649, 4195332, 6291462, 1051649, 5243909, 2099202, 3072, 7340039, 2099202, 4195332, 3072, 6291462, 1051649, 7340039, 3147779, 4195332, 3147779, 7340039, 5243909, 3147779, 1051649, 5243909, 1051649, 7340039, 4195332, 3072, 6291462, 1051649, 4195332, 3147779, 1051649, 6291462, 4195332, 3072, 4195332, 6291462, 3072, 5243909, 2099202, 3072, 4195332, 1051649, 6291462, 4195332, 7340039, 2099202, 7340039, 3072, 6291462, 3147779, 6291462, 4195332, 3147779, 3072, 5243909, 2099202, 3147779, 5243909, 3072, 6291462, 4195332, 3072, 2099202, 3147779, 6291462, 4195332, 2099202, 6291462, 3072, 4195332, 3072, 4195332, 2099202, 6291462, 3072, 6291462, 3147779, 1051649, 7340039, 1051649, 6291462, 3072, 7340039, 4195332, 6291462, 3072, 3147779, 6291462, 3147779, 1051649, 7340039, 2099202, 6291462, 3147779, - 5243909, 2099202, 1051649, 6291462, 4195332, 2099202, 3072, 7340039, 1051649, 4195332, 3072, 4195332, 2099202, 7340039, 4195332, 2099202, 7340039, 2099202, 5243909, 3072, 4195332, 1051649, 5243909, 3147779, 5243909, 3147779, 6291462, 3147779, 3072, 4195332, 3147779, 6291462, 3072, 7340039, 1051649, 6291462, 2099202, 7340039, 3072, 7340039, 4195332, 1051649, 5243909, 6291462, 2099202, 4195332, 2099202, 5243909, 3072, 7340039, 1051649, 2099202, 3072, 7340039, 2099202, 4195332, 6291462, 3147779, 1051649, 5243909, 2099202, 7340039, 2099202, 6291462, 3147779, 3072, 5243909, 6291462, 1051649, 2099202, 5243909, 3147779, 6291462, 3147779, 6291462, 4195332, 2099202, 3147779, 1051649, 5243909, 1051649, 5243909, 3147779, 5243909, 3072, 1051649, 7340039, 3147779, 6291462, 3072, 7340039, 3147779, 5243909, 2099202, 7340039, 4195332, 7340039, 6291462, 1051649, 5243909, 3072, 4195332, 5243909, 3147779, 7340039, 1051649, 7340039, 2099202, 7340039, 2099202, 3072, 5243909, 2099202, 4195332, 2099202, 5243909, 1051649, 2099202, 3147779, 6291462, 2099202, 3072, 7340039, 4195332, 5243909, 3072, 3147779, 1051649, - 3072, 7340039, 4195332, 3147779, 1051649, 6291462, 3147779, 5243909, 3147779, 5243909, 7340039, 1051649, 6291462, 3147779, 1051649, 6291462, 3072, 6291462, 4195332, 7340039, 6291462, 2099202, 7340039, 2099202, 1051649, 7340039, 3072, 2099202, 5243909, 7340039, 1051649, 2099202, 4195332, 4195332, 5243909, 3072, 4195332, 2099202, 5243909, 3147779, 3147779, 6291462, 3072, 2099202, 7340039, 3147779, 6291462, 1051649, 4195332, 2099202, 5243909, 6291462, 4195332, 6291462, 3072, 7340039, 2099202, 3072, 7340039, 5243909, 1051649, 4195332, 5243909, 1051649, 7340039, 4195332, 3147779, 1051649, 6291462, 4195332, 1051649, 7340039, 3072, 5243909, 1051649, 7340039, 3072, 6291462, 3147779, 6291462, 2099202, 4195332, 1051649, 2099202, 7340039, 5243909, 4195332, 3072, 6291462, 4195332, 1051649, 6291462, 3072, 4195332, 1051649, 3147779, 3072, 2099202, 4195332, 1051649, 3147779, 7340039, 2099202, 1051649, 2099202, 5243909, 4195332, 1051649, 3147779, 4195332, 5243909, 3147779, 6291462, 3072, 7340039, 3147779, 4195332, 7340039, 3072, 5243909, 4195332, 3147779, 5243909, 1051649, 2099202, 6291462, 4195332, 7340039, - 5243909, 3147779, 1051649, 7340039, 5243909, 2099202, 4195332, 3072, 7340039, 2099202, 1051649, 6291462, 3147779, 3072, 7340039, 3147779, 2099202, 5243909, 1051649, 3147779, 2099202, 5243909, 3072, 4195332, 6291462, 2099202, 4195332, 7340039, 1051649, 3147779, 6291462, 3072, 7340039, 2099202, 1051649, 6291462, 3147779, 1051649, 6291462, 3072, 6291462, 2099202, 4195332, 5243909, 1051649, 5243909, 3072, 3147779, 6291462, 7340039, 1051649, 3147779, 2099202, 1051649, 4195332, 1051649, 4195332, 5243909, 3147779, 2099202, 6291462, 3147779, 3072, 4195332, 2099202, 5243909, 2099202, 7340039, 3072, 6291462, 2099202, 4195332, 3147779, 2099202, 5243909, 1051649, 2099202, 5243909, 3072, 7340039, 3072, 4195332, 7340039, 5243909, 3147779, 1051649, 2099202, 5243909, 1051649, 2099202, 5243909, 2099202, 7340039, 5243909, 3147779, 6291462, 5243909, 1051649, 7340039, 6291462, 5243909, 1051649, 6291462, 4195332, 7340039, 3072, 3147779, 5243909, 6291462, 3072, 7340039, 1051649, 2099202, 5243909, 3147779, 1051649, 6291462, 4195332, 1051649, 7340039, 1051649, 6291462, 2099202, 7340039, 4195332, 3072, 3147779, 2099202, - 6291462, 3072, 5243909, 2099202, 3072, 6291462, 1051649, 6291462, 2099202, 4195332, 5243909, 2099202, 4195332, 5243909, 2099202, 5243909, 3072, 7340039, 1051649, 5243909, 3072, 3147779, 7340039, 4195332, 3072, 5243909, 1051649, 5243909, 3147779, 5243909, 1051649, 4195332, 5243909, 3147779, 6291462, 3147779, 7340039, 4195332, 2099202, 5243909, 1051649, 5243909, 3147779, 3072, 6291462, 1051649, 7340039, 4195332, 3072, 4195332, 3072, 5243909, 4195332, 7340039, 3147779, 6291462, 3072, 7340039, 3072, 4195332, 1051649, 5243909, 7340039, 3147779, 6291462, 3072, 3147779, 2099202, 5243909, 1051649, 7340039, 3072, 7340039, 1051649, 4195332, 7340039, 4195332, 6291462, 3147779, 1051649, 3147779, 6291462, 2099202, 3072, 7340039, 5243909, 6291462, 3147779, 4195332, 7340039, 3072, 6291462, 1051649, 3072, 6291462, 2099202, 4195332, 5243909, 3072, 3147779, 3072, 5243909, 3147779, 3072, 4195332, 6291462, 2099202, 7340039, 1051649, 4195332, 2099202, 5243909, 6291462, 3147779, 1051649, 7340039, 3072, 2099202, 5243909, 2099202, 4195332, 3147779, 6291462, 3072, 3147779, 6291462, 5243909, 1051649, - 4195332, 3147779, 4195332, 7340039, 4195332, 2099202, 5243909, 3072, 7340039, 3147779, 6291462, 3072, 7340039, 1051649, 6291462, 3147779, 4195332, 2099202, 6291462, 4195332, 7340039, 6291462, 1051649, 2099202, 6291462, 3147779, 7340039, 2099202, 3072, 7340039, 3147779, 7340039, 3072, 4195332, 3072, 5243909, 3072, 2099202, 6291462, 3147779, 7340039, 1051649, 7340039, 4195332, 2099202, 4195332, 5243909, 2099202, 6291462, 3147779, 7340039, 1051649, 6291462, 3072, 2099202, 5243909, 2099202, 3147779, 6291462, 2099202, 7340039, 4195332, 1051649, 3072, 5243909, 7340039, 5243909, 1051649, 6291462, 4195332, 3147779, 5243909, 2099202, 6291462, 3147779, 3072, 4195332, 1051649, 5243909, 4195332, 7340039, 1051649, 6291462, 4195332, 2099202, 3147779, 3072, 7340039, 1051649, 4195332, 2099202, 3147779, 4195332, 6291462, 2099202, 1051649, 7340039, 3147779, 6291462, 2099202, 7340039, 2099202, 6291462, 3147779, 5243909, 1051649, 4195332, 3072, 5243909, 3147779, 7340039, 3072, 4195332, 3072, 5243909, 4195332, 6291462, 3147779, 7340039, 3147779, 3072, 7340039, 2099202, 4195332, 7340039, 1051649, 2099202, 7340039, - 3072, 6291462, 1051649, 1051649, 3147779, 7340039, 3147779, 5243909, 3147779, 3072, 1051649, 5243909, 3147779, 4195332, 2099202, 7340039, 3072, 6291462, 3147779, 3072, 1051649, 3147779, 5243909, 6291462, 1051649, 4195332, 3072, 6291462, 4195332, 2099202, 5243909, 1051649, 4195332, 2099202, 7340039, 1051649, 4195332, 7340039, 1051649, 4195332, 3072, 5243909, 2099202, 5243909, 6291462, 3072, 3147779, 7340039, 1051649, 2099202, 4195332, 3147779, 5243909, 2099202, 6291462, 1051649, 7340039, 4195332, 1051649, 6291462, 3072, 7340039, 3147779, 6291462, 2099202, 3147779, 3072, 4195332, 2099202, 7340039, 3072, 3147779, 5243909, 3072, 6291462, 2099202, 7340039, 2099202, 6291462, 3072, 3147779, 5243909, 2099202, 3072, 6291462, 1051649, 4195332, 6291462, 1051649, 6291462, 4195332, 7340039, 3072, 3147779, 4195332, 5243909, 3072, 3147779, 1051649, 5243909, 4195332, 7340039, 3072, 7340039, 2099202, 6291462, 3147779, 7340039, 2099202, 6291462, 1051649, 4195332, 6291462, 1051649, 7340039, 2099202, 3072, 5243909, 1051649, 5243909, 6291462, 1051649, 5243909, 1051649, 4195332, 4195332, 5243909, 2099202, - 6291462, 4195332, 2099202, 6291462, 5243909, 3072, 4195332, 1051649, 6291462, 2099202, 4195332, 7340039, 2099202, 3072, 5243909, 1051649, 3147779, 5243909, 1051649, 5243909, 7340039, 3147779, 3072, 4195332, 2099202, 6291462, 3147779, 2099202, 5243909, 3072, 6291462, 3147779, 6291462, 2099202, 5243909, 3147779, 5243909, 2099202, 6291462, 3147779, 7340039, 1051649, 6291462, 3072, 3147779, 7340039, 1051649, 4195332, 5243909, 6291462, 3072, 7340039, 3072, 5243909, 3147779, 3147779, 5243909, 3072, 5243909, 3147779, 4195332, 2099202, 4195332, 1051649, 6291462, 3147779, 4195332, 6291462, 3072, 3147779, 6291462, 1051649, 7340039, 4195332, 2099202, 5243909, 3147779, 3072, 2099202, 6291462, 4195332, 1051649, 7340039, 4195332, 5243909, 7340039, 2099202, 3147779, 3147779, 5243909, 3072, 5243909, 2099202, 7340039, 1051649, 4195332, 7340039, 4195332, 7340039, 3072, 2099202, 1051649, 5243909, 3147779, 1051649, 3072, 5243909, 1051649, 3072, 4195332, 7340039, 2099202, 3147779, 5243909, 1051649, 4195332, 6291462, 2099202, 6291462, 3072, 2099202, 6291462, 3147779, 7340039, 3072, 7340039, 3072, 3147779, - 1051649, 2099202, 7340039, 3072, 4195332, 7340039, 2099202, 7340039, 4195332, 1051649, 6291462, 3072, 3147779, 7340039, 4195332, 6291462, 3072, 7340039, 2099202, 4195332, 2099202, 5243909, 7340039, 3072, 7340039, 1051649, 6291462, 3072, 7340039, 3147779, 1051649, 5243909, 3072, 6291462, 3072, 7340039, 3072, 4195332, 1051649, 5243909, 3072, 4195332, 3147779, 7340039, 1051649, 4195332, 3147779, 6291462, 3072, 2099202, 5243909, 4195332, 2099202, 7340039, 1051649, 6291462, 1051649, 3147779, 7340039, 1051649, 6291462, 3072, 7340039, 5243909, 3072, 7340039, 1051649, 2099202, 7340039, 4195332, 5243909, 2099202, 4195332, 3072, 6291462, 1051649, 6291462, 3147779, 7340039, 4195332, 3072, 6291462, 1051649, 3147779, 3072, 2099202, 6291462, 3072, 7340039, 1051649, 7340039, 1051649, 5243909, 1051649, 6291462, 2099202, 3072, 2099202, 5243909, 3147779, 6291462, 4195332, 3072, 6291462, 4195332, 7340039, 3147779, 5243909, 6291462, 3147779, 1051649, 6291462, 3072, 7340039, 4195332, 3072, 2099202, 4195332, 3147779, 5243909, 4195332, 3072, 2099202, 5243909, 3147779, 1051649, 6291462, 5243909, - 7340039, 4195332, 1051649, 6291462, 3147779, 3072, 5243909, 1051649, 3147779, 7340039, 2099202, 5243909, 6291462, 1051649, 1051649, 4195332, 3147779, 6291462, 4195332, 3072, 6291462, 1051649, 3147779, 4195332, 5243909, 3147779, 5243909, 4195332, 3147779, 1051649, 7340039, 2099202, 7340039, 4195332, 3147779, 2099202, 6291462, 3147779, 2099202, 7340039, 3147779, 6291462, 3072, 5243909, 2099202, 5243909, 1051649, 2099202, 7340039, 5243909, 2099202, 3147779, 6291462, 2099202, 4195332, 3072, 6291462, 4195332, 2099202, 5243909, 2099202, 5243909, 2099202, 4195332, 3147779, 5243909, 1051649, 5243909, 1051649, 5243909, 3072, 6291462, 7340039, 2099202, 3147779, 7340039, 3072, 5243909, 1051649, 5243909, 3147779, 2099202, 5243909, 5243909, 7340039, 4195332, 1051649, 5243909, 4195332, 3147779, 2099202, 4195332, 6291462, 3072, 3147779, 5243909, 3147779, 6291462, 1051649, 4195332, 1051649, 7340039, 3147779, 1051649, 2099202, 4195332, 1051649, 7340039, 2099202, 1051649, 5243909, 3147779, 5243909, 2099202, 4195332, 6291462, 7340039, 3072, 7340039, 1051649, 7340039, 3147779, 5243909, 1051649, 4195332, 5243909, 2099202, 3147779, - 3072, 4195332, 5243909, 2099202, 5243909, 2099202, 4195332, 6291462, 3072, 4195332, 1051649, 3147779, 3072, 3147779, 7340039, 2099202, 6291462, 1051649, 2099202, 7340039, 4195332, 2099202, 6291462, 1051649, 7340039, 3072, 1051649, 2099202, 6291462, 4195332, 5243909, 3072, 4195332, 1051649, 4195332, 5243909, 1051649, 7340039, 5243909, 2099202, 1051649, 3147779, 6291462, 2099202, 7340039, 3072, 4195332, 7340039, 3147779, 1051649, 6291462, 1051649, 3072, 7340039, 4195332, 5243909, 2099202, 7340039, 4195332, 3072, 7340039, 3147779, 3072, 6291462, 1051649, 6291462, 4195332, 3147779, 2099202, 7340039, 2099202, 3147779, 1051649, 5243909, 4195332, 1051649, 5243909, 2099202, 7340039, 3147779, 1051649, 7340039, 3072, 3147779, 1051649, 4195332, 3072, 7340039, 3072, 6291462, 5243909, 3072, 4195332, 3147779, 6291462, 3072, 7340039, 2099202, 5243909, 3072, 5243909, 2099202, 6291462, 5243909, 6291462, 3072, 5243909, 2099202, 4195332, 6291462, 2099202, 7340039, 3072, 3147779, 6291462, 2099202, 1051649, 5243909, 3147779, 2099202, 3072, 6291462, 1051649, 7340039, 3072, 6291462, 1051649, 5243909, - 2099202, 3147779, 3072, 7340039, 1051649, 6291462, 3072, 2099202, 6291462, 5243909, 7340039, 5243909, 4195332, 6291462, 5243909, 3072, 3147779, 5243909, 3147779, 5243909, 1051649, 5243909, 3072, 6291462, 2099202, 4195332, 7340039, 3147779, 3072, 7340039, 2099202, 3147779, 6291462, 2099202, 7340039, 1051649, 3147779, 4195332, 3072, 5243909, 7340039, 4195332, 1051649, 4195332, 2099202, 6291462, 3147779, 3072, 1051649, 5243909, 3147779, 7340039, 4195332, 3147779, 2099202, 1051649, 6291462, 3072, 3147779, 6291462, 1051649, 5243909, 1051649, 7340039, 4195332, 2099202, 3072, 7340039, 3072, 4195332, 5243909, 7340039, 3147779, 3072, 7340039, 2099202, 4195332, 6291462, 3072, 6291462, 5243909, 4195332, 2099202, 6291462, 7340039, 3147779, 6291462, 2099202, 3147779, 5243909, 2099202, 6291462, 2099202, 7340039, 2099202, 4195332, 1051649, 6291462, 4195332, 7340039, 3147779, 4195332, 3072, 3147779, 2099202, 7340039, 4195332, 1051649, 7340039, 3072, 4195332, 1051649, 6291462, 5243909, 1051649, 3147779, 5243909, 3072, 6291462, 5243909, 6291462, 3147779, 4195332, 3147779, 7340039, 3147779, 4195332, 6291462, - 7340039, 5243909, 6291462, 1051649, 5243909, 3147779, 7340039, 4195332, 2099202, 2099202, 3147779, 1051649, 7340039, 1051649, 2099202, 7340039, 4195332, 1051649, 7340039, 3072, 7340039, 2099202, 5243909, 3147779, 3072, 5243909, 2099202, 4195332, 5243909, 1051649, 4195332, 6291462, 1051649, 5243909, 3072, 4195332, 6291462, 1051649, 7340039, 2099202, 3072, 5243909, 6291462, 3072, 6291462, 3147779, 4195332, 7340039, 4195332, 5243909, 3072, 1051649, 5243909, 3072, 7340039, 5243909, 3147779, 1051649, 5243909, 2099202, 4195332, 3147779, 6291462, 1051649, 3147779, 5243909, 6291462, 3147779, 6291462, 2099202, 3072, 1051649, 6291462, 4195332, 2099202, 7340039, 3072, 3147779, 1051649, 3147779, 3072, 7340039, 2099202, 4195332, 3072, 5243909, 2099202, 6291462, 1051649, 7340039, 1051649, 3147779, 7340039, 3072, 4195332, 3147779, 7340039, 2099202, 3072, 3147779, 1051649, 6291462, 4195332, 7340039, 1051649, 3147779, 3072, 6291462, 3147779, 3147779, 7340039, 3147779, 4195332, 3072, 7340039, 4195332, 7340039, 3147779, 4195332, 1051649, 2099202, 5243909, 3072, 6291462, 2099202, 3072, 5243909, 1051649, - 2099202, 3072, 3147779, 4195332, 7340039, 3072, 4195332, 1051649, 6291462, 3072, 5243909, 3072, 2099202, 5243909, 4195332, 3072, 3147779, 6291462, 2099202, 3147779, 4195332, 3147779, 7340039, 1051649, 6291462, 3147779, 6291462, 3072, 7340039, 2099202, 7340039, 3072, 6291462, 2099202, 7340039, 3147779, 3072, 5243909, 1051649, 4195332, 6291462, 1051649, 3147779, 5243909, 2099202, 3072, 5243909, 1051649, 2099202, 7340039, 3147779, 6291462, 2099202, 4195332, 6291462, 1051649, 6291462, 3147779, 5243909, 3072, 7340039, 3072, 7340039, 2099202, 4195332, 3072, 2099202, 1051649, 4195332, 5243909, 6291462, 5243909, 2099202, 3072, 6291462, 1051649, 5243909, 6291462, 4195332, 6291462, 4195332, 1051649, 5243909, 1051649, 3147779, 6291462, 3072, 5243909, 3147779, 3147779, 4195332, 6291462, 1051649, 5243909, 1051649, 5243909, 3072, 5243909, 6291462, 4195332, 7340039, 1051649, 5243909, 3072, 5243909, 6291462, 3147779, 5243909, 2099202, 6291462, 3072, 5243909, 2099202, 5243909, 2099202, 1051649, 3072, 5243909, 1051649, 7340039, 4195332, 2099202, 7340039, 1051649, 4195332, 7340039, 2099202, 6291462, - 5243909, 4195332, 7340039, 3072, 2099202, 5243909, 3147779, 6291462, 4195332, 3147779, 7340039, 4195332, 6291462, 3072, 6291462, 5243909, 6291462, 3072, 5243909, 1051649, 6291462, 3072, 2099202, 5243909, 4195332, 1051649, 2099202, 5243909, 3147779, 4195332, 1051649, 3147779, 5243909, 4195332, 1051649, 6291462, 4195332, 3147779, 7340039, 2099202, 3072, 7340039, 2099202, 7340039, 3147779, 6291462, 2099202, 4195332, 6291462, 3072, 5243909, 1051649, 6291462, 3072, 2099202, 4195332, 1051649, 7340039, 3072, 6291462, 5243909, 2099202, 4195332, 5243909, 1051649, 7340039, 5243909, 7340039, 1051649, 3147779, 3147779, 1051649, 7340039, 4195332, 3147779, 5243909, 3147779, 2099202, 1051649, 5243909, 2099202, 6291462, 3147779, 7340039, 4195332, 1051649, 4195332, 7340039, 3072, 7340039, 3072, 2099202, 6291462, 3147779, 7340039, 2099202, 4195332, 3147779, 2099202, 3072, 2099202, 5243909, 3147779, 2099202, 4195332, 1051649, 2099202, 6291462, 3072, 5243909, 2099202, 6291462, 1051649, 7340039, 3147779, 6291462, 4195332, 2099202, 7340039, 3147779, 3072, 6291462, 1051649, 5243909, 2099202, 4195332, 1051649, 3147779, - 1051649, 3072, 5243909, 3147779, 6291462, 1051649, 2099202, 1051649, 6291462, 1051649, 5243909, 2099202, 3147779, 7340039, 2099202, 1051649, 2099202, 4195332, 3147779, 7340039, 2099202, 4195332, 6291462, 1051649, 3147779, 7340039, 4195332, 6291462, 3072, 6291462, 2099202, 5243909, 3072, 3147779, 7340039, 3147779, 2099202, 6291462, 3072, 5243909, 3147779, 4195332, 5243909, 3072, 1051649, 6291462, 3072, 7340039, 2099202, 4195332, 3147779, 6291462, 2099202, 7340039, 5243909, 3147779, 5243909, 2099202, 4195332, 3147779, 1051649, 3147779, 6291462, 3072, 6291462, 3147779, 1051649, 4195332, 6291462, 3072, 4195332, 6291462, 2099202, 5243909, 1051649, 7340039, 1051649, 4195332, 7340039, 3072, 7340039, 1051649, 4195332, 2099202, 3072, 6291462, 1051649, 4195332, 2099202, 5243909, 3147779, 5243909, 1051649, 4195332, 3072, 6291462, 1051649, 7340039, 3147779, 7340039, 5243909, 3072, 6291462, 2099202, 7340039, 4195332, 7340039, 1051649, 4195332, 7340039, 1051649, 3147779, 4195332, 3072, 6291462, 1051649, 5243909, 3147779, 3072, 6291462, 5243909, 3147779, 4195332, 7340039, 3072, 6291462, 3147779, 7340039, - 7340039, 4195332, 1051649, 7340039, 3072, 4195332, 7340039, 5243909, 3147779, 3072, 5243909, 1051649, 5243909, 3072, 4195332, 7340039, 3147779, 5243909, 1051649, 4195332, 3072, 7340039, 3147779, 7340039, 3072, 6291462, 3072, 5243909, 1051649, 2099202, 7340039, 4195332, 6291462, 1051649, 5243909, 3072, 6291462, 1051649, 5243909, 1051649, 6291462, 3072, 3147779, 6291462, 4195332, 3147779, 5243909, 1051649, 5243909, 1051649, 7340039, 1051649, 4195332, 2099202, 3072, 6291462, 3072, 7340039, 2099202, 5243909, 7340039, 1051649, 2099202, 7340039, 3147779, 3072, 7340039, 3147779, 2099202, 5243909, 7340039, 1051649, 3147779, 3072, 6291462, 3072, 6291462, 3147779, 2099202, 5243909, 3147779, 3072, 5243909, 2099202, 7340039, 3147779, 5243909, 2099202, 6291462, 1051649, 7340039, 2099202, 6291462, 5243909, 2099202, 4195332, 5243909, 3072, 6291462, 1051649, 4195332, 7340039, 2099202, 6291462, 3072, 3147779, 3072, 5243909, 3147779, 2099202, 5243909, 3072, 7340039, 4195332, 2099202, 7340039, 1051649, 6291462, 4195332, 2099202, 1051649, 6291462, 3072, 2099202, 5243909, 1051649, 4195332, 2099202, - 3072, 3147779, 6291462, 2099202, 5243909, 3147779, 3072, 2099202, 4195332, 7340039, 3147779, 7340039, 2099202, 4195332, 1051649, 1051649, 6291462, 3072, 6291462, 2099202, 5243909, 2099202, 3072, 5243909, 2099202, 4195332, 2099202, 3147779, 7340039, 3147779, 5243909, 3072, 1051649, 6291462, 2099202, 7340039, 2099202, 4195332, 4195332, 7340039, 2099202, 6291462, 4195332, 1051649, 7340039, 2099202, 3072, 7340039, 3147779, 6291462, 3147779, 3072, 7340039, 4195332, 2099202, 5243909, 4195332, 4195332, 1051649, 6291462, 3072, 4195332, 5243909, 2099202, 4195332, 5243909, 2099202, 3072, 6291462, 3147779, 3072, 4195332, 7340039, 4195332, 2099202, 5243909, 4195332, 3072, 6291462, 2099202, 4195332, 6291462, 4195332, 6291462, 3072, 5243909, 1051649, 5243909, 3072, 4195332, 3147779, 3072, 1051649, 7340039, 1051649, 6291462, 1051649, 5243909, 2099202, 5243909, 3147779, 1051649, 4195332, 1051649, 5243909, 5243909, 6291462, 4195332, 3072, 6291462, 2099202, 7340039, 1051649, 3147779, 5243909, 3072, 4195332, 1051649, 7340039, 3147779, 7340039, 2099202, 5243909, 6291462, 2099202, 7340039, 3147779, 5243909, - 2099202, 6291462, 1051649, 7340039, 4195332, 1051649, 7340039, 3147779, 6291462, 1051649, 6291462, 3072, 7340039, 5243909, 6291462, 4195332, 2099202, 7340039, 3147779, 6291462, 1051649, 4195332, 5243909, 1051649, 6291462, 1051649, 7340039, 4195332, 3072, 5243909, 2099202, 6291462, 3147779, 4195332, 3072, 4195332, 3147779, 1051649, 6291462, 3072, 3147779, 4195332, 2099202, 7340039, 2099202, 5243909, 6291462, 4195332, 3072, 2099202, 5243909, 3147779, 5243909, 1051649, 7340039, 1051649, 3147779, 6291462, 3072, 4195332, 3147779, 6291462, 4195332, 3072, 6291462, 1051649, 5243909, 7340039, 4195332, 1051649, 7340039, 2099202, 5243909, 2099202, 6291462, 3147779, 2099202, 7340039, 5243909, 1051649, 7340039, 3072, 1051649, 3147779, 7340039, 2099202, 7340039, 3147779, 6291462, 2099202, 6291462, 7340039, 3147779, 5243909, 2099202, 3147779, 7340039, 3147779, 4195332, 3072, 6291462, 4195332, 3072, 7340039, 3147779, 2099202, 2099202, 1051649, 7340039, 4195332, 1051649, 3147779, 5243909, 3072, 6291462, 3147779, 7340039, 5243909, 2099202, 3072, 4195332, 5243909, 3072, 3147779, 1051649, 4195332, 3072, 6291462, - 5243909, 1051649, 4195332, 3147779, 2099202, 6291462, 5243909, 3072, 2099202, 4195332, 2099202, 4195332, 3147779, 3072, 2099202, 7340039, 4195332, 1051649, 4195332, 3072, 7340039, 3147779, 3147779, 7340039, 3072, 5243909, 3147779, 1051649, 7340039, 3072, 4195332, 5243909, 2099202, 7340039, 5243909, 1051649, 5243909, 7340039, 2099202, 3147779, 7340039, 1051649, 5243909, 3072, 4195332, 3147779, 1051649, 4195332, 7340039, 4195332, 1051649, 6291462, 2099202, 4195332, 5243909, 6291462, 1051649, 3147779, 7340039, 2099202, 5243909, 1051649, 3147779, 7340039, 2099202, 7340039, 1051649, 2099202, 4195332, 5243909, 1051649, 6291462, 3072, 5243909, 3072, 1051649, 5243909, 3072, 2099202, 3147779, 5243909, 3147779, 7340039, 5243909, 4195332, 1051649, 4195332, 1051649, 4195332, 3072, 4195332, 1051649, 4195332, 3072, 4195332, 6291462, 3072, 1051649, 7340039, 3147779, 6291462, 1051649, 6291462, 3147779, 3072, 4195332, 7340039, 3147779, 4195332, 2099202, 6291462, 2099202, 4195332, 7340039, 2099202, 4195332, 3072, 1051649, 6291462, 3147779, 6291462, 1051649, 7340039, 3147779, 6291462, 6291462, 1051649, 3147779, - 3072, 7340039, 5243909, 3072, 6291462, 1051649, 3147779, 5243909, 7340039, 3072, 6291462, 4195332, 6291462, 1051649, 5243909, 3072, 3147779, 6291462, 2099202, 5243909, 2099202, 6291462, 3072, 4195332, 3147779, 3072, 6291462, 5243909, 2099202, 6291462, 3147779, 1051649, 7340039, 3072, 3147779, 7340039, 3072, 2099202, 4195332, 6291462, 3072, 5243909, 3147779, 6291462, 5243909, 2099202, 6291462, 3072, 2099202, 7340039, 5243909, 3072, 7340039, 3072, 2099202, 3147779, 7340039, 3072, 5243909, 3147779, 3072, 6291462, 5243909, 3072, 3147779, 4195332, 3147779, 6291462, 3072, 2099202, 5243909, 3147779, 7340039, 3147779, 7340039, 6291462, 3147779, 7340039, 4195332, 7340039, 3072, 4195332, 2099202, 3072, 3147779, 6291462, 3072, 6291462, 7340039, 2099202, 7340039, 5243909, 2099202, 6291462, 1051649, 5243909, 3147779, 6291462, 2099202, 5243909, 1051649, 4195332, 2099202, 5243909, 7340039, 1051649, 6291462, 3072, 7340039, 3072, 5243909, 7340039, 3072, 3147779, 1051649, 6291462, 3147779, 5243909, 4195332, 5243909, 1051649, 4195332, 2099202, 4195332, 3072, 5243909, 3147779, 7340039, - 4195332, 3147779, 2099202, 5243909, 4195332, 7340039, 4195332, 1051649, 2099202, 5243909, 3072, 3147779, 1051649, 5243909, 3147779, 6291462, 1051649, 5243909, 4195332, 7340039, 1051649, 4195332, 1051649, 6291462, 4195332, 7340039, 2099202, 3147779, 5243909, 1051649, 3147779, 6291462, 2099202, 5243909, 1051649, 4195332, 6291462, 6291462, 1051649, 5243909, 2099202, 7340039, 1051649, 2099202, 1051649, 7340039, 1051649, 6291462, 5243909, 3072, 3147779, 4195332, 2099202, 5243909, 7340039, 3072, 4195332, 2099202, 6291462, 1051649, 7340039, 1051649, 2099202, 5243909, 7340039, 3072, 6291462, 1051649, 4195332, 7340039, 3147779, 3072, 4195332, 2099202, 4195332, 3072, 4195332, 1051649, 3147779, 1051649, 6291462, 2099202, 4195332, 6291462, 5243909, 2099202, 5243909, 3147779, 1051649, 5243909, 3072, 2099202, 7340039, 3147779, 6291462, 3072, 7340039, 4195332, 3072, 4195332, 7340039, 3072, 7340039, 1051649, 3147779, 6291462, 1051649, 5243909, 2099202, 5243909, 1051649, 3147779, 5243909, 4195332, 6291462, 2099202, 1051649, 7340039, 2099202, 3072, 7340039, 3147779, 6291462, 1051649, 7340039, 1051649, 5243909, 2099202, - 3072, 6291462, 1051649, 7340039, 2099202, 3072, 3147779, 6291462, 7340039, 2099202, 6291462, 2099202, 7340039, 3147779, 7340039, 1051649, 7340039, 3147779, 3072, 2099202, 4195332, 7340039, 5243909, 2099202, 1051649, 5243909, 1051649, 6291462, 3072, 4195332, 7340039, 3072, 6291462, 3147779, 6291462, 3072, 2099202, 3147779, 3072, 4195332, 6291462, 3072, 4195332, 6291462, 5243909, 3147779, 3072, 3147779, 4195332, 3147779, 6291462, 1051649, 6291462, 3147779, 1051649, 6291462, 3147779, 7340039, 2099202, 5243909, 4195332, 3147779, 6291462, 4195332, 1051649, 5243909, 2099202, 3147779, 6291462, 1051649, 5243909, 2099202, 6291462, 3072, 5243909, 2099202, 7340039, 6291462, 3072, 6291462, 3147779, 7340039, 1051649, 2099202, 3072, 7340039, 2099202, 3072, 6291462, 2099202, 5243909, 4195332, 3072, 4195332, 2099202, 3147779, 1051649, 2099202, 6291462, 2099202, 3147779, 5243909, 3147779, 5243909, 4195332, 3072, 5243909, 4195332, 6291462, 3147779, 6291462, 2099202, 1051649, 7340039, 3072, 4195332, 6291462, 3072, 4195332, 6291462, 3147779, 3072, 5243909, 2099202, 5243909, 4195332, 3072, 6291462, - 2099202, 5243909, 4195332, 3072, 3147779, 6291462, 4195332, 3072, 4195332, 1051649, 3147779, 5243909, 3072, 4195332, 3072, 2099202, 5243909, 2099202, 5243909, 7340039, 1051649, 3072, 3147779, 6291462, 2099202, 7340039, 4195332, 3147779, 7340039, 2099202, 1051649, 5243909, 2099202, 4195332, 1051649, 5243909, 7340039, 4195332, 7340039, 2099202, 1051649, 5243909, 3147779, 1051649, 3072, 4195332, 7340039, 2099202, 7340039, 1051649, 5243909, 3072, 7340039, 1051649, 6291462, 4195332, 3072, 4195332, 1051649, 5243909, 1051649, 7340039, 3072, 2099202, 6291462, 4195332, 7340039, 4195332, 3072, 7340039, 1051649, 6291462, 1051649, 7340039, 3147779, 5243909, 1051649, 3147779, 5243909, 2099202, 5243909, 1051649, 6291462, 4195332, 5243909, 1051649, 4195332, 6291462, 3147779, 3147779, 7340039, 1051649, 3147779, 5243909, 3147779, 7340039, 6291462, 5243909, 1051649, 7340039, 1051649, 6291462, 3072, 2099202, 6291462, 2099202, 7340039, 2099202, 3072, 1051649, 4195332, 6291462, 4195332, 2099202, 5243909, 3147779, 4195332, 7340039, 2099202, 1051649, 4195332, 6291462, 2099202, 6291462, 3072, 3147779, 7340039, 4195332, - 7340039, 1051649, 3147779, 6291462, 5243909, 1051649, 7340039, 2099202, 6291462, 5243909, 3072, 6291462, 3147779, 6291462, 4195332, 7340039, 3072, 6291462, 1051649, 3147779, 6291462, 3147779, 5243909, 3072, 4195332, 1051649, 3072, 6291462, 2099202, 5243909, 3147779, 7340039, 3072, 3147779, 6291462, 4195332, 2099202, 1051649, 3147779, 5243909, 7340039, 3147779, 7340039, 4195332, 6291462, 2099202, 3147779, 5243909, 3072, 6291462, 3147779, 2099202, 4195332, 4195332, 1051649, 5243909, 2099202, 6291462, 3147779, 7340039, 3072, 4195332, 3147779, 6291462, 3072, 2099202, 3072, 5243909, 3147779, 4195332, 2099202, 5243909, 4195332, 2099202, 4195332, 3072, 6291462, 4195332, 1051649, 7340039, 3072, 5243909, 3147779, 1051649, 7340039, 3147779, 7340039, 1051649, 5243909, 3072, 4195332, 6291462, 2099202, 7340039, 1051649, 4195332, 3072, 3147779, 5243909, 3072, 4195332, 2099202, 7340039, 4195332, 3072, 4195332, 1051649, 3147779, 7340039, 5243909, 3072, 7340039, 3072, 5243909, 1051649, 7340039, 1051649, 2099202, 5243909, 3147779, 7340039, 1051649, 4195332, 1051649, 7340039, 4195332, 1051649, 2099202, - 3072, 4195332, 1051649, 5243909, 2099202, 3072, 5243909, 3147779, 1051649, 3147779, 7340039, 2099202, 5243909, 1051649, 4195332, 2099202, 5243909, 4195332, 3072, 5243909, 2099202, 7340039, 1051649, 6291462, 4195332, 7340039, 5243909, 3147779, 4195332, 3072, 6291462, 1051649, 4195332, 7340039, 2099202, 3072, 6291462, 2099202, 7340039, 3072, 4195332, 1051649, 4195332, 3072, 2099202, 6291462, 1051649, 4195332, 5243909, 1051649, 4195332, 7340039, 3147779, 3072, 6291462, 2099202, 7340039, 4195332, 1051649, 3147779, 6291462, 2099202, 7340039, 1051649, 5243909, 3147779, 7340039, 1051649, 6291462, 1051649, 7340039, 3147779, 3072, 6291462, 1051649, 7340039, 1051649, 2099202, 5243909, 3147779, 4195332, 2099202, 6291462, 3072, 5243909, 3072, 4195332, 2099202, 7340039, 3147779, 7340039, 1051649, 5243909, 3072, 6291462, 2099202, 7340039, 4195332, 2099202, 7340039, 3147779, 5243909, 1051649, 5243909, 7340039, 3147779, 6291462, 5243909, 2099202, 4195332, 3147779, 1051649, 6291462, 2099202, 5243909, 3072, 3147779, 6291462, 3072, 6291462, 2099202, 3147779, 7340039, 4195332, 3072, 6291462, 3147779, 5243909, - 7340039, 5243909, 7340039, 3072, 3147779, 7340039, 2099202, 7340039, 4195332, 4195332, 1051649, 6291462, 3072, 7340039, 1051649, 6291462, 2099202, 7340039, 3147779, 6291462, 3072, 4195332, 3147779, 1051649, 3147779, 3072, 2099202, 7340039, 1051649, 6291462, 2099202, 4195332, 5243909, 3072, 5243909, 3147779, 6291462, 4195332, 1051649, 5243909, 2099202, 6291462, 2099202, 5243909, 7340039, 1051649, 4195332, 7340039, 2099202, 4195332, 3072, 6291462, 2099202, 7340039, 3147779, 5243909, 3072, 2099202, 6291462, 4195332, 1051649, 5243909, 3072, 4195332, 5243909, 1051649, 4195332, 6291462, 2099202, 5243909, 3072, 2099202, 7340039, 3147779, 6291462, 3147779, 4195332, 7340039, 2099202, 6291462, 1051649, 7340039, 2099202, 6291462, 3147779, 4195332, 2099202, 6291462, 1051649, 4195332, 3072, 5243909, 3147779, 4195332, 1051649, 5243909, 3147779, 3072, 6291462, 4195332, 3072, 6291462, 4195332, 2099202, 1051649, 5243909, 1051649, 3072, 7340039, 1051649, 5243909, 4195332, 3147779, 7340039, 1051649, 7340039, 2099202, 5243909, 2099202, 4195332, 3072, 5243909, 2099202, 5243909, 3147779, 2099202, 6291462, 1051649, - 3147779, 1051649, 2099202, 6291462, 4195332, 1051649, 5243909, 1051649, 3072, 6291462, 2099202, 3147779, 5243909, 1051649, 5243909, 3147779, 3072, 3147779, 1051649, 5243909, 2099202, 7340039, 2099202, 6291462, 6291462, 4195332, 5243909, 1051649, 5243909, 3147779, 7340039, 3072, 2099202, 4195332, 1051649, 7340039, 1051649, 3072, 6291462, 3147779, 5243909, 2099202, 6291462, 3072, 3147779, 5243909, 2099202, 3072, 7340039, 3147779, 6291462, 1051649, 5243909, 3147779, 3072, 7340039, 1051649, 6291462, 5243909, 3072, 7340039, 3147779, 3147779, 6291462, 2099202, 7340039, 2099202, 3072, 4195332, 3147779, 6291462, 5243909, 4195332, 1051649, 5243909, 3072, 5243909, 3072, 4195332, 3072, 4195332, 5243909, 3072, 4195332, 1051649, 7340039, 3072, 6291462, 5243909, 2099202, 7340039, 1051649, 6291462, 2099202, 7340039, 1051649, 6291462, 5243909, 1051649, 3147779, 2099202, 1051649, 7340039, 2099202, 6291462, 3147779, 7340039, 3147779, 6291462, 2099202, 4195332, 3072, 6291462, 3072, 3147779, 4195332, 3147779, 6291462, 1051649, 7340039, 5243909, 1051649, 6291462, 3072, 7340039, 5243909, 3072, 4195332, - 6291462, 3147779, 4195332, 2099202, 6291462, 2099202, 3147779, 6291462, 5243909, 2099202, 7340039, 4195332, 3147779, 7340039, 2099202, 6291462, 4195332, 7340039, 5243909, 4195332, 1051649, 5243909, 3072, 4195332, 3072, 3147779, 1051649, 7340039, 4195332, 3072, 3147779, 5243909, 7340039, 3147779, 6291462, 3147779, 5243909, 7340039, 4195332, 1051649, 7340039, 3072, 3147779, 7340039, 5243909, 3072, 6291462, 5243909, 1051649, 6291462, 2099202, 4195332, 1051649, 5243909, 2099202, 4195332, 5243909, 1051649, 3147779, 5243909, 2099202, 1051649, 7340039, 3072, 6291462, 3147779, 1051649, 5243909, 7340039, 1051649, 3147779, 3072, 2099202, 7340039, 2099202, 4195332, 3147779, 7340039, 2099202, 6291462, 1051649, 6291462, 3147779, 7340039, 4195332, 2099202, 5243909, 3147779, 3072, 5243909, 3147779, 4195332, 3072, 5243909, 2099202, 3147779, 4195332, 2099202, 1051649, 7340039, 5243909, 6291462, 3072, 5243909, 4195332, 3072, 5243909, 2099202, 3147779, 6291462, 1051649, 7340039, 2099202, 5243909, 1051649, 6291462, 3072, 7340039, 4195332, 1051649, 3147779, 7340039, 2099202, 4195332, 1051649, 3147779, 6291462, 2099202, - 5243909, 3072, 7340039, 1051649, 5243909, 3072, 6291462, 3072, 3147779, 5243909, 3072, 6291462, 3072, 4195332, 4195332, 3072, 1051649, 2099202, 4195332, 3072, 6291462, 3147779, 7340039, 2099202, 5243909, 7340039, 4195332, 2099202, 6291462, 2099202, 6291462, 2099202, 1051649, 5243909, 3072, 4195332, 3072, 3147779, 2099202, 6291462, 1051649, 5243909, 4195332, 1051649, 2099202, 7340039, 3147779, 1051649, 4195332, 3147779, 5243909, 3072, 7340039, 3147779, 6291462, 1051649, 4195332, 2099202, 7340039, 3072, 4195332, 5243909, 2099202, 4195332, 3147779, 3072, 6291462, 3147779, 2099202, 4195332, 7340039, 4195332, 6291462, 1051649, 6291462, 1051649, 5243909, 3072, 5243909, 3147779, 7340039, 3147779, 2099202, 4195332, 3072, 7340039, 2099202, 6291462, 4195332, 3072, 6291462, 1051649, 7340039, 4195332, 3072, 7340039, 3072, 3147779, 6291462, 3072, 2099202, 3147779, 4195332, 3147779, 2099202, 7340039, 4195332, 3072, 7340039, 3072, 5243909, 3147779, 7340039, 4195332, 5243909, 2099202, 4195332, 3072, 3147779, 6291462, 4195332, 3072, 3147779, 5243909, 6291462, 2099202, 7340039, 3072, - 2099202, 7340039, 3147779, 4195332, 2099202, 7340039, 4195332, 6291462, 1051649, 4195332, 1051649, 7340039, 5243909, 2099202, 6291462, 3147779, 7340039, 6291462, 1051649, 6291462, 2099202, 5243909, 1051649, 6291462, 1051649, 2099202, 6291462, 3072, 3147779, 5243909, 3072, 6291462, 1051649, 4195332, 6291462, 2099202, 5243909, 7340039, 3072, 4195332, 3147779, 1051649, 7340039, 3147779, 6291462, 1051649, 4195332, 6291462, 7340039, 3072, 3147779, 7340039, 2099202, 2099202, 3072, 5243909, 7340039, 3072, 6291462, 2099202, 7340039, 1051649, 6291462, 3072, 5243909, 7340039, 2099202, 6291462, 3072, 6291462, 3072, 2099202, 5243909, 3147779, 3072, 6291462, 2099202, 7340039, 1051649, 3147779, 3072, 5243909, 6291462, 3072, 5243909, 3147779, 1051649, 1051649, 2099202, 7340039, 4195332, 3147779, 5243909, 1051649, 6291462, 2099202, 5243909, 6291462, 4195332, 7340039, 5243909, 3072, 7340039, 1051649, 6291462, 3072, 3147779, 6291462, 2099202, 5243909, 6291462, 1051649, 3147779, 3072, 2099202, 7340039, 3147779, 6291462, 5243909, 3072, 2099202, 6291462, 7340039, 1051649, 4195332, 3072, 5243909, 3147779, - 4195332, 3072, 5243909, 1051649, 5243909, 3147779, 1051649, 4195332, 3147779, 7340039, 3147779, 2099202, 1051649, 6291462, 1051649, 5243909, 3072, 3147779, 4195332, 3147779, 7340039, 3072, 4195332, 3147779, 7340039, 5243909, 1051649, 7340039, 4195332, 1051649, 5243909, 3147779, 4195332, 7340039, 1051649, 7340039, 2099202, 5243909, 2099202, 7340039, 3147779, 6291462, 2099202, 4195332, 3072, 5243909, 2099202, 3072, 2099202, 6291462, 5243909, 1051649, 6291462, 4195332, 7340039, 2099202, 3147779, 5243909, 3147779, 4195332, 3072, 5243909, 3147779, 7340039, 2099202, 4195332, 1051649, 4195332, 5243909, 2099202, 4195332, 7340039, 1051649, 4195332, 7340039, 2099202, 4195332, 1051649, 6291462, 4195332, 7340039, 1051649, 2099202, 6291462, 1051649, 5243909, 7340039, 5243909, 6291462, 1051649, 6291462, 2099202, 3072, 3147779, 4195332, 7340039, 1051649, 3147779, 3072, 2099202, 6291462, 4195332, 1051649, 5243909, 2099202, 5243909, 4195332, 1051649, 4195332, 3147779, 1051649, 4195332, 7340039, 4195332, 6291462, 1051649, 5243909, 1051649, 2099202, 7340039, 4195332, 2099202, 3072, 5243909, 6291462, 3147779, 1051649, 7340039, - 6291462, 2099202, 3147779, 6291462, 1051649, 7340039, 3072, 7340039, 2099202, 5243909, 3072, 5243909, 7340039, 4195332, 1051649, 5243909, 2099202, 7340039, 2099202, 4195332, 1051649, 5243909, 2099202, 6291462, 3072, 3147779, 1051649, 5243909, 3147779, 7340039, 2099202, 7340039, 3072, 2099202, 3147779, 4195332, 1051649, 3147779, 4195332, 3072, 5243909, 3072, 5243909, 4195332, 7340039, 2099202, 7340039, 5243909, 3147779, 4195332, 3072, 4195332, 1051649, 5243909, 1051649, 3147779, 6291462, 1051649, 7340039, 1051649, 3147779, 6291462, 1051649, 4195332, 3072, 5243909, 1051649, 7340039, 2099202, 7340039, 1051649, 3147779, 6291462, 3147779, 3072, 3147779, 5243909, 6291462, 3147779, 3072, 2099202, 5243909, 3147779, 4195332, 7340039, 3072, 4195332, 3147779, 3072, 4195332, 2099202, 7340039, 5243909, 6291462, 2099202, 3072, 5243909, 5243909, 6291462, 3147779, 1051649, 7340039, 4195332, 3072, 7340039, 1051649, 6291462, 6291462, 3072, 7340039, 2099202, 5243909, 2099202, 3072, 6291462, 3147779, 3072, 7340039, 4195332, 1051649, 5243909, 3147779, 4195332, 2099202, 3072, 7340039, 4195332, 1051649, - 2099202, 4195332, 7340039, 3072, 4195332, 3147779, 6291462, 3147779, 3072, 4195332, 6291462, 2099202, 3072, 3147779, 7340039, 3072, 6291462, 1051649, 5243909, 3072, 7340039, 3147779, 6291462, 1051649, 4195332, 7340039, 2099202, 4195332, 3072, 6291462, 3072, 4195332, 5243909, 6291462, 3072, 4195332, 6291462, 1051649, 7340039, 6291462, 2099202, 6291462, 2099202, 3072, 1051649, 3147779, 4195332, 1051649, 6291462, 2099202, 7340039, 3147779, 6291462, 3072, 4195332, 6291462, 3072, 4195332, 2099202, 6291462, 4195332, 3072, 6291462, 3147779, 7340039, 3147779, 5243909, 3072, 5243909, 3147779, 6291462, 5243909, 3072, 7340039, 5243909, 1051649, 4195332, 3072, 2099202, 5243909, 6291462, 1051649, 7340039, 3072, 3147779, 4195332, 2099202, 5243909, 2099202, 7340039, 3147779, 3072, 4195332, 1051649, 5243909, 7340039, 3147779, 1051649, 3072, 4195332, 5243909, 2099202, 3147779, 5243909, 3147779, 4195332, 3072, 3147779, 5243909, 1051649, 6291462, 3072, 5243909, 3147779, 3147779, 4195332, 5243909, 2099202, 4195332, 7340039, 3072, 6291462, 7340039, 1051649, 5243909, 2099202, 3147779, 6291462, - 3072, 3147779, 1051649, 5243909, 6291462, 1051649, 2099202, 6291462, 2099202, 5243909, 1051649, 6291462, 3147779, 5243909, 2099202, 4195332, 4195332, 3147779, 7340039, 4195332, 1051649, 5243909, 3072, 3147779, 5243909, 3072, 6291462, 2099202, 7340039, 2099202, 3147779, 5243909, 1051649, 3147779, 5243909, 2099202, 6291462, 3072, 3147779, 4195332, 1051649, 3147779, 6291462, 4195332, 7340039, 5243909, 3072, 7340039, 3072, 5243909, 1051649, 5243909, 4195332, 3147779, 7340039, 2099202, 2099202, 5243909, 5243909, 3072, 7340039, 4195332, 2099202, 5243909, 2099202, 1051649, 7340039, 3147779, 1051649, 4195332, 3072, 2099202, 4195332, 2099202, 4195332, 7340039, 2099202, 3147779, 7340039, 1051649, 4195332, 5243909, 2099202, 5243909, 7340039, 1051649, 6291462, 1051649, 7340039, 1051649, 6291462, 3147779, 2099202, 7340039, 3147779, 1051649, 4195332, 6291462, 6291462, 2099202, 7340039, 3072, 2099202, 6291462, 1051649, 7340039, 5243909, 2099202, 7340039, 1051649, 4195332, 5243909, 2099202, 7340039, 3072, 7340039, 1051649, 6291462, 3072, 3147779, 5243909, 2099202, 1051649, 6291462, 4195332, 5243909, 3072, 5243909, - 7340039, 4195332, 7340039, 4195332, 2099202, 4195332, 5243909, 3072, 7340039, 1051649, 4195332, 3072, 6291462, 1051649, 7340039, 3072, 6291462, 2099202, 3072, 3147779, 6291462, 2099202, 7340039, 3147779, 6291462, 3147779, 5243909, 1051649, 5243909, 3072, 7340039, 1051649, 4195332, 6291462, 1051649, 7340039, 3147779, 5243909, 6291462, 1051649, 5243909, 7340039, 3072, 5243909, 2099202, 1051649, 6291462, 3147779, 4195332, 2099202, 7340039, 3072, 2099202, 5243909, 3072, 4195332, 7340039, 3147779, 1051649, 6291462, 2099202, 1051649, 7340039, 3072, 6291462, 4195332, 2099202, 6291462, 6291462, 1051649, 7340039, 5243909, 1051649, 6291462, 3072, 3147779, 5243909, 7340039, 1051649, 6291462, 3072, 3147779, 6291462, 3072, 2099202, 6291462, 4195332, 5243909, 2099202, 5243909, 3072, 5243909, 1051649, 4195332, 2099202, 7340039, 3072, 4195332, 2099202, 1051649, 5243909, 3147779, 7340039, 4195332, 3072, 2099202, 4195332, 1051649, 3147779, 6291462, 3147779, 7340039, 1051649, 6291462, 1051649, 6291462, 3147779, 2099202, 5243909, 3147779, 1051649, 6291462, 4195332, 3072, 3147779, 1051649, 7340039, 1051649, - 5243909, 2099202, 3072, 6291462, 3072, 7340039, 2099202, 6291462, 3147779, 4195332, 7340039, 3147779, 2099202, 5243909, 3147779, 1051649, 2099202, 5243909, 4195332, 6291462, 2099202, 5243909, 1051649, 4195332, 3072, 2099202, 4195332, 7340039, 2099202, 4195332, 3147779, 6291462, 3072, 2099202, 5243909, 3072, 2099202, 1051649, 7340039, 3147779, 2099202, 4195332, 3147779, 1051649, 6291462, 5243909, 2099202, 1051649, 6291462, 4195332, 1051649, 3147779, 6291462, 1051649, 6291462, 3147779, 3072, 5243909, 6291462, 2099202, 4195332, 5243909, 1051649, 3147779, 3147779, 5243909, 3072, 4195332, 3072, 4195332, 3147779, 3072, 5243909, 5243909, 3147779, 6291462, 3072, 2099202, 4195332, 6291462, 3147779, 7340039, 1051649, 3147779, 6291462, 2099202, 3072, 3147779, 6291462, 3147779, 3147779, 7340039, 2099202, 6291462, 3072, 4195332, 6291462, 1051649, 7340039, 4195332, 6291462, 3072, 2099202, 4195332, 6291462, 7340039, 2099202, 6291462, 4195332, 3072, 4195332, 3072, 4195332, 3147779, 5243909, 2099202, 3072, 7340039, 1051649, 6291462, 4195332, 2099202, 5243909, 7340039, 5243909, 6291462, 3147779, 2099202, - 3072, 4195332, 6291462, 3147779, 5243909, 1051649, 5243909, 3072, 5243909, 1051649, 2099202, 5243909, 7340039, 3072, 4195332, 5243909, 7340039, 3072, 7340039, 1051649, 6291462, 3072, 6291462, 1051649, 7340039, 5243909, 4195332, 3072, 6291462, 1051649, 7340039, 1051649, 5243909, 3147779, 6291462, 4195332, 7340039, 4195332, 3072, 5243909, 7340039, 3072, 5243909, 7340039, 3072, 3147779, 4195332, 7340039, 3072, 5243909, 3147779, 7340039, 5243909, 1051649, 4195332, 7340039, 2099202, 4195332, 1051649, 3147779, 7340039, 3072, 6291462, 5243909, 1051649, 7340039, 2099202, 7340039, 3147779, 5243909, 7340039, 3147779, 2099202, 1051649, 7340039, 1051649, 4195332, 6291462, 3072, 2099202, 4195332, 1051649, 5243909, 4195332, 1051649, 7340039, 3147779, 6291462, 3072, 7340039, 4195332, 3072, 5243909, 3147779, 6291462, 2099202, 5243909, 3147779, 3072, 3147779, 1051649, 5243909, 6291462, 3147779, 3072, 1051649, 5243909, 3072, 2099202, 6291462, 2099202, 6291462, 2099202, 7340039, 3072, 5243909, 4195332, 5243909, 3072, 4195332, 7340039, 3072, 3147779, 1051649, 2099202, 3072, 4195332, 6291462, - 3147779, 7340039, 2099202, 1051649, 3147779, 6291462, 3147779, 7340039, 2099202, 4195332, 6291462, 3072, 4195332, 3147779, 7340039, 3147779, 1051649, 4195332, 2099202, 4195332, 3147779, 7340039, 2099202, 5243909, 3147779, 2099202, 1051649, 7340039, 3147779, 2099202, 5243909, 4195332, 1051649, 7340039, 3072, 2099202, 1051649, 6291462, 3147779, 2099202, 1051649, 4195332, 1051649, 4195332, 2099202, 7340039, 3072, 3147779, 2099202, 3147779, 6291462, 3072, 2099202, 7340039, 3147779, 3072, 6291462, 5243909, 3072, 5243909, 2099202, 4195332, 3147779, 2099202, 6291462, 3072, 4195332, 2099202, 6291462, 1051649, 3072, 6291462, 7340039, 2099202, 4195332, 6291462, 1051649, 5243909, 3147779, 4195332, 7340039, 3072, 7340039, 3147779, 4195332, 2099202, 5243909, 1051649, 4195332, 1051649, 5243909, 2099202, 6291462, 3072, 4195332, 1051649, 7340039, 2099202, 6291462, 5243909, 7340039, 3147779, 1051649, 5243909, 7340039, 3147779, 5243909, 3147779, 7340039, 3147779, 5243909, 3147779, 1051649, 5243909, 2099202, 7340039, 1051649, 3147779, 6291462, 1051649, 2099202, 5243909, 3147779, 7340039, 4195332, 7340039, 1051649, 5243909, - 3147779, 3072, 5243909, 7340039, 4195332, 3072, 2099202, 4195332, 1051649, 7340039, 1051649, 3147779, 6291462, 1051649, 3072, 6291462, 5243909, 2099202, 6291462, 3072, 5243909, 1051649, 4195332, 3072, 6291462, 3147779, 6291462, 4195332, 3072, 6291462, 3072, 6291462, 3147779, 3147779, 4195332, 5243909, 7340039, 3072, 3147779, 7340039, 5243909, 6291462, 3147779, 7340039, 3147779, 5243909, 6291462, 1051649, 6291462, 4195332, 1051649, 4195332, 5243909, 3072, 4195332, 6291462, 1051649, 7340039, 3147779, 6291462, 1051649, 7340039, 3072, 7340039, 4195332, 3147779, 6291462, 3072, 4195332, 5243909, 2099202, 4195332, 1051649, 4195332, 3072, 7340039, 2099202, 5243909, 1051649, 7340039, 2099202, 5243909, 1051649, 6291462, 3072, 7340039, 1051649, 5243909, 2099202, 7340039, 3072, 5243909, 3147779, 1051649, 7340039, 2099202, 4195332, 1051649, 5243909, 2099202, 3072, 4195332, 7340039, 3072, 2099202, 4195332, 3072, 7340039, 1051649, 4195332, 3072, 7340039, 6291462, 4195332, 1051649, 4195332, 6291462, 2099202, 7340039, 3147779, 7340039, 3072, 6291462, 2099202, 3072, 3147779, 5243909, 2099202, - 4195332, 6291462, 1051649, 6291462, 3072, 5243909, 6291462, 3147779, 5243909, 2099202, 4195332, 7340039, 2099202, 6291462, 5243909, 2099202, 3072, 7340039, 3147779, 7340039, 2099202, 7340039, 3147779, 5243909, 1051649, 6291462, 3072, 2099202, 7340039, 4195332, 2099202, 5243909, 3072, 6291462, 4195332, 1051649, 3147779, 4195332, 6291462, 3072, 2099202, 4195332, 3072, 5243909, 1051649, 3072, 2099202, 5243909, 3072, 7340039, 2099202, 7340039, 2099202, 2099202, 6291462, 2099202, 4195332, 1051649, 3147779, 4195332, 2099202, 4195332, 5243909, 2099202, 3072, 6291462, 1051649, 6291462, 3147779, 1051649, 6291462, 2099202, 6291462, 3147779, 5243909, 2099202, 3072, 6291462, 3147779, 6291462, 3072, 3147779, 5243909, 2099202, 3147779, 6291462, 4195332, 3072, 6291462, 3147779, 4195332, 1051649, 7340039, 4195332, 3147779, 6291462, 3072, 7340039, 3147779, 3147779, 6291462, 2099202, 5243909, 3147779, 6291462, 1051649, 5243909, 2099202, 5243909, 1051649, 6291462, 2099202, 3072, 7340039, 3147779, 6291462, 3072, 5243909, 3072, 4195332, 1051649, 5243909, 2099202, 5243909, 4195332, 6291462, 3072, 7340039, - 5243909, 1051649, 4195332, 3147779, 2099202, 7340039, 1051649, 4195332, 3072, 6291462, 1051649, 5243909, 3072, 3147779, 1051649, 5243909, 4195332, 5243909, 1051649, 3147779, 3072, 4195332, 1051649, 7340039, 3147779, 2099202, 4195332, 5243909, 1051649, 5243909, 3147779, 7340039, 2099202, 7340039, 1051649, 5243909, 2099202, 7340039, 1051649, 4195332, 1051649, 6291462, 2099202, 3147779, 6291462, 4195332, 6291462, 2099202, 7340039, 3147779, 4195332, 1051649, 6291462, 5243909, 1051649, 3147779, 3072, 7340039, 5243909, 3072, 7340039, 1051649, 1051649, 5243909, 5243909, 3147779, 7340039, 1051649, 4195332, 7340039, 3147779, 5243909, 3072, 7340039, 1051649, 6291462, 4195332, 4195332, 1051649, 1051649, 4195332, 6291462, 3072, 7340039, 2099202, 3072, 3147779, 7340039, 2099202, 1051649, 5243909, 6291462, 2099202, 3072, 6291462, 4195332, 3147779, 5243909, 1051649, 7340039, 3072, 6291462, 1051649, 1051649, 4195332, 7340039, 3147779, 1051649, 7340039, 3147779, 4195332, 2099202, 5243909, 3147779, 1051649, 2099202, 4195332, 3147779, 7340039, 2099202, 6291462, 3147779, 1051649, 6291462, 1051649, 2099202, 5243909, 2099202, - 3072, 7340039, 1051649, 6291462, 1051649, 3147779, 7340039, 2099202, 6291462, 3147779, 7340039, 2099202, 4195332, 7340039, 3147779, 7340039, 3072, 2099202, 4195332, 6291462, 5243909, 2099202, 5243909, 3072, 5243909, 7340039, 3147779, 3072, 7340039, 1051649, 4195332, 3072, 5243909, 1051649, 3147779, 6291462, 3072, 2099202, 6291462, 5243909, 7340039, 3147779, 6291462, 3072, 7340039, 1051649, 4195332, 3072, 5243909, 1051649, 5243909, 4195332, 3072, 3147779, 5243909, 7340039, 6291462, 4195332, 3072, 6291462, 3147779, 6291462, 3147779, 7340039, 1051649, 2099202, 2099202, 4195332, 5243909, 3072, 3147779, 5243909, 2099202, 4195332, 3147779, 2099202, 7340039, 3072, 5243909, 7340039, 3147779, 2099202, 4195332, 4195332, 5243909, 6291462, 5243909, 2099202, 4195332, 7340039, 3147779, 3072, 4195332, 6291462, 1051649, 1051649, 5243909, 3072, 6291462, 2099202, 4195332, 3147779, 5243909, 6291462, 2099202, 3072, 5243909, 6291462, 3072, 6291462, 3072, 6291462, 1051649, 5243909, 7340039, 4195332, 6291462, 1051649, 3147779, 6291462, 3072, 7340039, 4195332, 2099202, 7340039, 4195332, 1051649, 7340039, - 4195332, 3147779, 7340039, 2099202, 4195332, 5243909, 3072, 5243909, 3147779, 3072, 4195332, 1051649, 5243909, 3072, 6291462, 2099202, 4195332, 6291462, 3072, 1051649, 3147779, 7340039, 3147779, 6291462, 2099202, 1051649, 4195332, 6291462, 3147779, 5243909, 2099202, 6291462, 3147779, 7340039, 3072, 4195332, 4195332, 5243909, 3072, 2099202, 3147779, 1051649, 4195332, 2099202, 5243909, 1051649, 7340039, 4195332, 3147779, 6291462, 3072, 7340039, 2099202, 7340039, 1051649, 3072, 2099202, 5243909, 2099202, 4195332, 2099202, 4195332, 3072, 3147779, 4195332, 5243909, 7340039, 3072, 6291462, 2099202, 7340039, 1051649, 6291462, 3072, 6291462, 1051649, 5243909, 2099202, 5243909, 3072, 6291462, 1051649, 7340039, 1051649, 3072, 4195332, 1051649, 6291462, 3072, 4195332, 1051649, 6291462, 2099202, 3147779, 5243909, 7340039, 2099202, 7340039, 4195332, 5243909, 2099202, 7340039, 1051649, 4195332, 7340039, 4195332, 1051649, 4195332, 3147779, 4195332, 2099202, 7340039, 4195332, 3072, 2099202, 3072, 3147779, 5243909, 1051649, 2099202, 5243909, 1051649, 6291462, 3072, 3147779, 5243909, 3072, 3147779, - 3147779, 2099202, 5243909, 3072, 6291462, 1051649, 6291462, 2099202, 4195332, 5243909, 3147779, 6291462, 2099202, 6291462, 3147779, 5243909, 1051649, 2099202, 7340039, 4195332, 6291462, 3072, 4195332, 1051649, 5243909, 6291462, 1051649, 2099202, 7340039, 3072, 6291462, 3147779, 1051649, 5243909, 2099202, 7340039, 1051649, 3147779, 7340039, 4195332, 6291462, 3072, 5243909, 2099202, 6291462, 3147779, 1051649, 5243909, 2099202, 3147779, 4195332, 3147779, 1051649, 6291462, 3147779, 6291462, 3147779, 7340039, 1051649, 5243909, 6291462, 1051649, 7340039, 2099202, 6291462, 3072, 4195332, 1051649, 5243909, 3147779, 4195332, 1051649, 4195332, 3147779, 5243909, 3072, 3147779, 7340039, 4195332, 2099202, 5243909, 3147779, 5243909, 3147779, 7340039, 2099202, 7340039, 1051649, 3147779, 6291462, 3072, 5243909, 7340039, 1051649, 4195332, 3072, 4195332, 1051649, 2099202, 3072, 4195332, 3072, 6291462, 2099202, 3072, 3147779, 7340039, 2099202, 5243909, 1051649, 6291462, 3147779, 1051649, 4195332, 6291462, 4195332, 6291462, 3072, 7340039, 4195332, 2099202, 5243909, 3147779, 4195332, 6291462, 1051649, 6291462, 5243909, - 6291462, 3072, 5243909, 4195332, 3147779, 7340039, 1051649, 7340039, 3072, 6291462, 3072, 7340039, 1051649, 4195332, 1051649, 3072, 7340039, 3147779, 2099202, 5243909, 1051649, 2099202, 6291462, 7340039, 3072, 3147779, 6291462, 4195332, 2099202, 2099202, 4195332, 3072, 7340039, 3147779, 6291462, 1051649, 6291462, 2099202, 5243909, 3072, 2099202, 7340039, 3147779, 7340039, 3072, 4195332, 6291462, 3072, 7340039, 3072, 7340039, 5243909, 5243909, 2099202, 4195332, 1051649, 5243909, 3072, 4195332, 3147779, 3072, 5243909, 4195332, 6291462, 1051649, 3147779, 7340039, 2099202, 6291462, 3072, 7340039, 6291462, 2099202, 7340039, 1051649, 4195332, 7340039, 3072, 3147779, 7340039, 1051649, 6291462, 3072, 5243909, 2099202, 3147779, 5243909, 2099202, 5243909, 2099202, 7340039, 3147779, 2099202, 5243909, 2099202, 6291462, 3147779, 5243909, 6291462, 7340039, 3147779, 6291462, 3147779, 1051649, 5243909, 6291462, 2099202, 6291462, 3072, 7340039, 3072, 5243909, 1051649, 7340039, 2099202, 5243909, 1051649, 3147779, 6291462, 4195332, 3072, 6291462, 3072, 7340039, 2099202, 5243909, 2099202, 1051649, - 3147779, 7340039, 2099202, 6291462, 3072, 2099202, 4195332, 3147779, 6291462, 3147779, 1051649, 4195332, 3147779, 5243909, 7340039, 3147779, 4195332, 5243909, 3072, 4195332, 7340039, 5243909, 1051649, 3147779, 4195332, 5243909, 1051649, 3072, 6291462, 4195332, 7340039, 5243909, 2099202, 4195332, 3072, 5243909, 3147779, 3072, 4195332, 6291462, 5243909, 3147779, 1051649, 2099202, 4195332, 7340039, 2099202, 3147779, 4195332, 2099202, 2099202, 1051649, 1051649, 6291462, 3072, 7340039, 2099202, 4195332, 7340039, 2099202, 7340039, 2099202, 3072, 5243909, 2099202, 6291462, 3072, 5243909, 1051649, 3147779, 5243909, 2099202, 3072, 3147779, 6291462, 2099202, 4195332, 2099202, 6291462, 1051649, 4195332, 3147779, 4195332, 6291462, 3072, 6291462, 3072, 7340039, 1051649, 5243909, 3147779, 3072, 6291462, 1051649, 5243909, 3072, 7340039, 1051649, 3072, 3147779, 1051649, 5243909, 2099202, 7340039, 4195332, 1051649, 4195332, 2099202, 4195332, 3147779, 3147779, 7340039, 2099202, 5243909, 3072, 3147779, 7340039, 5243909, 1051649, 2099202, 7340039, 3147779, 5243909, 1051649, 4195332, 3072, 7340039, 4195332, - 3072, 4195332, 1051649, 4195332, 6291462, 5243909, 3072, 2099202, 1051649, 5243909, 7340039, 2099202, 5243909, 3072, 2099202, 6291462, 1051649, 6291462, 1051649, 7340039, 3147779, 3072, 6291462, 1051649, 7340039, 2099202, 4195332, 7340039, 5243909, 3072, 3147779, 1051649, 4195332, 7340039, 4195332, 2099202, 5243909, 7340039, 1051649, 2099202, 3072, 6291462, 5243909, 1051649, 6291462, 3072, 5243909, 1051649, 6291462, 6291462, 4195332, 7340039, 3147779, 5243909, 4195332, 3147779, 3072, 6291462, 1051649, 6291462, 3147779, 1051649, 5243909, 3147779, 7340039, 4195332, 2099202, 4195332, 4195332, 7340039, 1051649, 4195332, 7340039, 5243909, 1051649, 5243909, 3072, 6291462, 3147779, 5243909, 3072, 7340039, 2099202, 1051649, 4195332, 3147779, 6291462, 4195332, 3072, 4195332, 1051649, 5243909, 4195332, 7340039, 3147779, 2099202, 4195332, 3147779, 5243909, 4195332, 7340039, 1051649, 6291462, 3072, 3147779, 7340039, 3072, 6291462, 1051649, 5243909, 2099202, 5243909, 3072, 4195332, 6291462, 1051649, 4195332, 3072, 7340039, 3147779, 4195332, 1051649, 2099202, 6291462, 7340039, 3147779, 1051649, 6291462, - 7340039, 3147779, 6291462, 2099202, 1051649, 3147779, 7340039, 4195332, 7340039, 3072, 2099202, 6291462, 1051649, 7340039, 4195332, 3072, 4195332, 3147779, 5243909, 1051649, 5243909, 2099202, 4195332, 5243909, 3147779, 3072, 6291462, 1051649, 3147779, 2099202, 6291462, 1051649, 6291462, 3072, 3147779, 7340039, 1051649, 3147779, 6291462, 7340039, 4195332, 3072, 4195332, 7340039, 3147779, 2099202, 4195332, 7340039, 3072, 1051649, 5243909, 3072, 6291462, 3072, 2099202, 6291462, 5243909, 2099202, 5243909, 3072, 7340039, 4195332, 6291462, 1051649, 5243909, 3072, 7340039, 1051649, 6291462, 3072, 5243909, 3147779, 3072, 2099202, 6291462, 3147779, 7340039, 1051649, 2099202, 7340039, 4195332, 2099202, 6291462, 3147779, 7340039, 1051649, 1051649, 3147779, 7340039, 3147779, 7340039, 6291462, 2099202, 3072, 5243909, 1051649, 6291462, 3072, 7340039, 2099202, 5243909, 2099202, 4195332, 5243909, 4195332, 2099202, 5243909, 3147779, 7340039, 3072, 6291462, 1051649, 7340039, 2099202, 3147779, 7340039, 2099202, 5243909, 3147779, 6291462, 3072, 7340039, 4195332, 3147779, 1051649, 5243909, 4195332, 2099202, - 1051649, 5243909, 3072, 7340039, 3147779, 5243909, 1051649, 2099202, 6291462, 4195332, 5243909, 3072, 4195332, 3147779, 6291462, 5243909, 7340039, 3072, 2099202, 6291462, 4195332, 1051649, 6291462, 3072, 7340039, 5243909, 3147779, 4195332, 7340039, 1051649, 4195332, 5243909, 2099202, 6291462, 3072, 6291462, 2099202, 5243909, 3072, 3147779, 1051649, 6291462, 3147779, 1051649, 5243909, 6291462, 1051649, 3147779, 5243909, 7340039, 3147779, 3147779, 2099202, 4195332, 7340039, 1051649, 3072, 4195332, 3147779, 5243909, 2099202, 3072, 2099202, 7340039, 3147779, 1051649, 3147779, 6291462, 2099202, 3147779, 5243909, 2099202, 7340039, 4195332, 7340039, 1051649, 3147779, 5243909, 3072, 6291462, 1051649, 5243909, 3072, 5243909, 2099202, 7340039, 4195332, 6291462, 1051649, 5243909, 2099202, 3072, 4195332, 6291462, 3147779, 7340039, 2099202, 4195332, 1051649, 5243909, 3072, 6291462, 3147779, 1051649, 3072, 7340039, 1051649, 5243909, 2099202, 4195332, 3147779, 5243909, 4195332, 6291462, 3072, 5243909, 3072, 6291462, 1051649, 2099202, 6291462, 3147779, 3072, 5243909, 1051649, 7340039, 2099202, 6291462, - 4195332, 3147779, 6291462, 4195332, 3072, 2099202, 6291462, 5243909, 1051649, 2099202, 3147779, 7340039, 1051649, 7340039, 3072, 2099202, 2099202, 6291462, 3147779, 3072, 2099202, 7340039, 3147779, 2099202, 4195332, 2099202, 3072, 5243909, 1051649, 6291462, 3072, 3147779, 5243909, 2099202, 5243909, 1051649, 4195332, 6291462, 2099202, 7340039, 4195332, 5243909, 2099202, 6291462, 3072, 4195332, 6291462, 2099202, 3072, 4195332, 1051649, 7340039, 6291462, 1051649, 5243909, 3147779, 5243909, 3147779, 7340039, 1051649, 6291462, 4195332, 6291462, 4195332, 3072, 5243909, 6291462, 1051649, 5243909, 7340039, 3072, 6291462, 3147779, 1051649, 4195332, 2099202, 6291462, 4195332, 2099202, 4195332, 1051649, 3147779, 6291462, 4195332, 3072, 5243909, 2099202, 3072, 6291462, 1051649, 6291462, 3147779, 7340039, 1051649, 4195332, 3072, 4195332, 6291462, 2099202, 3147779, 6291462, 1051649, 7340039, 5243909, 3147779, 6291462, 4195332, 3147779, 3072, 6291462, 3072, 2099202, 1051649, 3147779, 7340039, 2099202, 4195332, 3147779, 4195332, 5243909, 1051649, 5243909, 2099202, 7340039, 4195332, 3072, 4195332, 3072, - 7340039, 2099202, 1051649, 5243909, 7340039, 4195332, 1051649, 3147779, 5243909, 7340039, 3072, 6291462, 4195332, 1051649, 3147779, 6291462, 4195332, 1051649, 5243909, 7340039, 4195332, 3072, 5243909, 6291462, 1051649, 6291462, 7340039, 3147779, 2099202, 5243909, 3147779, 7340039, 1051649, 4195332, 3147779, 7340039, 4195332, 3072, 5243909, 1051649, 4195332, 3072, 7340039, 3147779, 5243909, 2099202, 3072, 6291462, 5243909, 3147779, 5243909, 3072, 2099202, 4195332, 1051649, 7340039, 1051649, 6291462, 3072, 7340039, 1051649, 3147779, 1051649, 4195332, 7340039, 3147779, 2099202, 4195332, 3072, 3147779, 4195332, 3072, 5243909, 6291462, 3072, 5243909, 3147779, 3072, 7340039, 2099202, 7340039, 5243909, 3072, 3147779, 7340039, 2099202, 4195332, 7340039, 3147779, 4195332, 3072, 3147779, 5243909, 2099202, 7340039, 1051649, 6291462, 1051649, 4195332, 7340039, 2099202, 4195332, 3072, 7340039, 2099202, 3072, 1051649, 7340039, 6291462, 4195332, 7340039, 5243909, 6291462, 3072, 5243909, 2099202, 6291462, 3072, 7340039, 3072, 7340039, 2099202, 6291462, 1051649, 3147779, 7340039, 5243909, 2099202, - 1051649, 7340039, 5243909, 3072, 2099202, 5243909, 7340039, 3072, 4195332, 2099202, 4195332, 3147779, 2099202, 5243909, 6291462, 1051649, 5243909, 7340039, 2099202, 3147779, 1051649, 6291462, 3147779, 3072, 4195332, 4195332, 3147779, 3072, 7340039, 6291462, 3072, 2099202, 7340039, 3072, 5243909, 1051649, 2099202, 6291462, 3147779, 3147779, 7340039, 2099202, 4195332, 1051649, 7340039, 5243909, 2099202, 4195332, 1051649, 7340039, 2099202, 7340039, 5243909, 3147779, 6291462, 4195332, 2099202, 5243909, 3147779, 2099202, 3147779, 7340039, 5243909, 2099202, 3072, 5243909, 1051649, 6291462, 2099202, 6291462, 2099202, 7340039, 3147779, 2099202, 7340039, 1051649, 6291462, 5243909, 1051649, 5243909, 3072, 2099202, 6291462, 4195332, 1051649, 5243909, 1051649, 4195332, 3072, 7340039, 5243909, 2099202, 3072, 6291462, 3147779, 5243909, 2099202, 5243909, 3072, 3147779, 6291462, 2099202, 4195332, 2099202, 5243909, 3147779, 5243909, 1051649, 4195332, 2099202, 1051649, 2099202, 3147779, 6291462, 1051649, 7340039, 1051649, 6291462, 3147779, 4195332, 1051649, 4195332, 3072, 5243909, 4195332, 1051649, 3072, 5243909, - 4195332, 3072, 4195332, 3147779, 6291462, 1051649, 2099202, 6291462, 5243909, 1051649, 6291462, 3072, 7340039, 3147779, 2099202, 4195332, 3072, 3147779, 5243909, 1051649, 7340039, 4195332, 2099202, 7340039, 6291462, 3072, 1051649, 5243909, 4195332, 1051649, 7340039, 4195332, 3147779, 6291462, 2099202, 7340039, 4195332, 1051649, 7340039, 3072, 5243909, 1051649, 6291462, 3147779, 3072, 3147779, 7340039, 5243909, 2099202, 4195332, 3072, 3147779, 1051649, 6291462, 3072, 2099202, 6291462, 3072, 5243909, 4195332, 6291462, 3072, 2099202, 6291462, 4195332, 1051649, 7340039, 3147779, 7340039, 1051649, 5243909, 1051649, 5243909, 1051649, 4195332, 4195332, 3072, 3147779, 2099202, 6291462, 4195332, 7340039, 3147779, 3072, 7340039, 3147779, 6291462, 2099202, 6291462, 2099202, 3147779, 6291462, 4195332, 1051649, 5243909, 3072, 7340039, 3147779, 7340039, 5243909, 3072, 5243909, 1051649, 6291462, 1051649, 7340039, 3147779, 7340039, 3072, 3147779, 5243909, 7340039, 4195332, 3072, 4195332, 3147779, 5243909, 3147779, 2099202, 5243909, 2099202, 5243909, 3147779, 7340039, 3072, 6291462, 6291462, 3147779, - 7340039, 3147779, 6291462, 1051649, 4195332, 3147779, 7340039, 3147779, 3072, 7340039, 3147779, 5243909, 1051649, 5243909, 3072, 7340039, 3147779, 6291462, 3072, 4195332, 3147779, 3072, 5243909, 1051649, 2099202, 5243909, 7340039, 3147779, 1051649, 4195332, 2099202, 5243909, 3072, 1051649, 5243909, 3072, 5243909, 1051649, 5243909, 5243909, 2099202, 4195332, 3072, 7340039, 4195332, 1051649, 4195332, 3072, 7340039, 1051649, 6291462, 4195332, 6291462, 2099202, 4195332, 7340039, 4195332, 3147779, 7340039, 3072, 2099202, 7340039, 3147779, 3072, 6291462, 3147779, 5243909, 3072, 2099202, 4195332, 3147779, 6291462, 3072, 6291462, 2099202, 7340039, 3147779, 7340039, 4195332, 3072, 3147779, 1051649, 6291462, 4195332, 2099202, 5243909, 3072, 5243909, 4195332, 3072, 6291462, 1051649, 7340039, 4195332, 2099202, 6291462, 4195332, 1051649, 3147779, 1051649, 7340039, 3147779, 6291462, 4195332, 1051649, 5243909, 3072, 4195332, 5243909, 6291462, 1051649, 2099202, 1051649, 6291462, 7340039, 2099202, 5243909, 3072, 6291462, 3072, 7340039, 1051649, 6291462, 2099202, 3147779, 2099202, 4195332, 2099202, - 2099202, 5243909, 1051649, 6291462, 3072, 5243909, 1051649, 4195332, 6291462, 2099202, 4195332, 2099202, 6291462, 4195332, 6291462, 1051649, 4195332, 2099202, 7340039, 2099202, 6291462, 2099202, 7340039, 3147779, 6291462, 1051649, 4195332, 6291462, 2099202, 6291462, 3072, 6291462, 4195332, 6291462, 2099202, 3147779, 7340039, 3147779, 3147779, 1051649, 6291462, 2099202, 6291462, 3147779, 5243909, 1051649, 6291462, 2099202, 3147779, 6291462, 2099202, 3072, 4195332, 3072, 5243909, 1051649, 5243909, 1051649, 1051649, 5243909, 1051649, 5243909, 4195332, 6291462, 2099202, 7340039, 3072, 6291462, 4195332, 7340039, 3072, 2099202, 4195332, 4195332, 5243909, 1051649, 5243909, 1051649, 6291462, 2099202, 5243909, 5243909, 1051649, 3147779, 6291462, 1051649, 3147779, 7340039, 1051649, 7340039, 2099202, 5243909, 3147779, 3072, 7340039, 1051649, 5243909, 2099202, 6291462, 4195332, 3147779, 3072, 2099202, 3147779, 7340039, 2099202, 6291462, 2099202, 3147779, 3072, 4195332, 7340039, 5243909, 3147779, 3072, 4195332, 1051649, 7340039, 4195332, 6291462, 2099202, 4195332, 1051649, 5243909, 7340039, 1051649, 6291462, 3072, - 6291462, 1051649, 7340039, 3147779, 7340039, 2099202, 6291462, 3147779, 3072, 6291462, 1051649, 7340039, 3072, 3147779, 2099202, 7340039, 3072, 5243909, 1051649, 5243909, 5243909, 1051649, 4195332, 3072, 2099202, 7340039, 3147779, 3072, 5243909, 3147779, 7340039, 2099202, 3072, 4195332, 1051649, 7340039, 3072, 6291462, 3072, 7340039, 2099202, 7340039, 3072, 4195332, 2099202, 6291462, 3147779, 7340039, 3072, 5243909, 3147779, 5243909, 7340039, 3147779, 7340039, 2099202, 3147779, 6291462, 4195332, 3147779, 7340039, 3147779, 1051649, 5243909, 3072, 3147779, 5243909, 2099202, 1051649, 3147779, 5243909, 6291462, 7340039, 3072, 3147779, 6291462, 3072, 4195332, 3147779, 7340039, 3072, 4195332, 7340039, 2099202, 3072, 7340039, 5243909, 3072, 5243909, 3147779, 4195332, 3072, 6291462, 2099202, 5243909, 3147779, 3072, 7340039, 4195332, 3072, 6291462, 5243909, 7340039, 4195332, 3072, 5243909, 1051649, 4195332, 7340039, 5243909, 1051649, 2099202, 3072, 6291462, 2099202, 7340039, 3147779, 1051649, 3147779, 3147779, 5243909, 3072, 7340039, 3147779, 3072, 5243909, 3147779, 4195332, -}; + GDK_RGB_INPUT_RGB, /* 3 bytes per pixel */ + GDK_RGB_INPUT_RGBX, /* 4 bytes per pixel */ + GDK_RGB_INPUT_GRAY, /* 1 byte per pixel */ + GDK_RGB_INPUT_INDEXED, /* 1 byte per pixel, colors from a GdkRgbCmap */ + GDK_RGB_INPUT_RGB48, /* 3 native 16-bit words per pixel */ + GDK_RGB_INPUT_RGBX64 /* 4 native 16-bit words per pixel */ +} GdkRgbInput; -#else -#define DM_WIDTH 8 -#define DM_WIDTH_SHIFT 3 -#define DM_HEIGHT 8 -static const guchar DM[8][8] = +static const guint8 gdk_rgb_input_bytes[] = { 3, 4, 1, 1, 6, 8 }; + +#define ROW_MAX GDK_SCRATCH_IMAGE_WIDTH + +/* Makes 8-bit RGB out of any other input. */ +static const guchar * +gdk_rgb_stage_row (guchar *stage, + GdkRgbInput input, + const guchar *in, + gint width, + GdkRgbCmap *cmap) { - { 0, 32, 8, 40, 2, 34, 10, 42 }, - { 48, 16, 56, 24, 50, 18, 58, 26 }, - { 12, 44, 4, 36, 14, 46, 6, 38 }, - { 60, 28, 52, 20, 62, 30, 54, 22 }, - { 3, 35, 11, 43, 1, 33, 9, 41 }, - { 51, 19, 59, 27, 49, 17, 57, 25 }, - { 15, 47, 7, 39, 13, 45, 5, 37 }, - { 63, 31, 55, 23, 61, 29, 53, 21 } -}; + const guint16 *in16 = (const guint16 *) in; + guchar *p = stage; + gint x; -static const guint32 DM_565[8 * 8] = -{ - 3072, 4195332, 1051649, 5243909, 3072, 4195332, 1051649, 5243909, - 6291462, 2099202, 7340039, 3147779, 6291462, 2099202, 7340039, 3147779, - 1051649, 5243909, 3072, 4195332, 1051649, 5243909, 3072, 4195332, - 7340039, 3147779, 6291462, 2099202, 7340039, 3147779, 6291462, 2099202, - 3072, 4195332, 1051649, 5243909, 3072, 4195332, 1051649, 5243909, - 6291462, 2099202, 7340039, 3147779, 6291462, 2099202, 7340039, 3147779, - 1051649, 5243909, 3072, 4195332, 1051649, 5243909, 3072, 4195332, - 7340039, 3147779, 6291462, 2099202, 7340039, 3147779, 6291462, 2099202, -}; - -#endif - -#if 0 -static void -gdk_rgb_preprocess_dm_565 (void) -{ - int i; - guint32 dith; - - if (DM_565 == NULL) + switch (input) { - DM_565 = g_new (guint32, DM_WIDTH * DM_HEIGHT); - for (i = 0; i < DM_WIDTH * DM_HEIGHT; i++) - { - dith = DM[0][i] >> 3; - DM_565[i] = (dith << 20) | dith | (((7 - dith) >> 1) << 10); -#ifdef VERBOSE - g_print ("%i %x %x\n", i, dith, DM_565[i]); -#endif - } - } -} -#else -#define gdk_rgb_preprocess_dm_565() -#endif - -static void -gdk_rgb_convert_8_d666 (GdkRgbInfo *image_info, GdkImage *image, - gint x0, gint y0, gint width, gint height, - const guchar *buf, int rowstride, - gint x_align, gint y_align, GdkRgbCmap *cmap) -{ - int x, y; - gint bpl; - guchar *obuf, *obptr; - const guchar *bptr, *bp2; - gint r, g, b; - const guchar *dmp; - gint dith; - guchar *colorcube_d = image_info->colorcube_d; - - bptr = buf; - bpl = image->bpl; - obuf = ((guchar *)image->mem) + y0 * bpl + x0; - for (y = 0; y < height; y++) - { - dmp = DM[(y_align + y) & (DM_HEIGHT - 1)]; - bp2 = bptr; - obptr = obuf; - for (x = 0; x < width; x++) - { - r = *bp2++; - g = *bp2++; - b = *bp2++; - dith = (dmp[(x_align + x) & (DM_WIDTH - 1)] << 2) | 7; - r = ((r * 5) + dith) >> 8; - g = ((g * 5) + (262 - dith)) >> 8; - b = ((b * 5) + dith) >> 8; - obptr[0] = colorcube_d[(r << 6) | (g << 3) | b]; - obptr++; - } - bptr += rowstride; - obuf += bpl; - } -} - -static void -gdk_rgb_convert_8_d (GdkRgbInfo *image_info, GdkImage *image, - gint x0, gint y0, gint width, gint height, - const guchar *buf, int rowstride, - gint x_align, gint y_align, - GdkRgbCmap *cmap) -{ - int x, y; - gint bpl; - guchar *obuf, *obptr; - const guchar *bptr, *bp2; - gint r, g, b; - const guchar *dmp; - gint dith; - gint rs, gs, bs; - guchar *colorcube_d = image_info->colorcube_d; - - bptr = buf; - bpl = image->bpl; - rs = image_info->nred_shades - 1; - gs = image_info->ngreen_shades - 1; - bs = image_info->nblue_shades - 1; - obuf = ((guchar *)image->mem) + y0 * bpl + x0; - for (y = 0; y < height; y++) - { - dmp = DM[(y_align + y) & (DM_HEIGHT - 1)]; - bp2 = bptr; - obptr = obuf; - for (x = 0; x < width; x++) - { - r = *bp2++; - g = *bp2++; - b = *bp2++; - dith = (dmp[(x_align + x) & (DM_WIDTH - 1)] << 2) | 7; - r = ((r * rs) + dith) >> 8; - g = ((g * gs) + (262 - dith)) >> 8; - b = ((b * bs) + dith) >> 8; - obptr[0] = colorcube_d[(r << 6) | (g << 3) | b]; - obptr++; - } - bptr += rowstride; - obuf += bpl; - } -} - -static void -gdk_rgb_convert_8_indexed (GdkRgbInfo *image_info, GdkImage *image, - gint x0, gint y0, gint width, gint height, - const guchar *buf, int rowstride, - gint x_align, gint y_align, GdkRgbCmap *cmap) -{ - int x, y; - gint bpl; - guchar *obuf, *obptr; - const guchar *bptr, *bp2; - guchar c; - guchar *lut; - GdkRgbCmapInfo *cmap_info = gdk_rgb_cmap_get_info (cmap, image_info); - - lut = cmap_info->lut; - bptr = buf; - bpl = image->bpl; - obuf = ((guchar *)image->mem) + y0 * bpl + x0; - for (y = 0; y < height; y++) - { - bp2 = bptr; - obptr = obuf; - for (x = 0; x < width; x++) - { - c = *bp2++; - obptr[0] = lut[c]; - obptr++; - } - bptr += rowstride; - obuf += bpl; - } -} - -static void -gdk_rgb_convert_gray8 (GdkRgbInfo *image_info, GdkImage *image, - gint x0, gint y0, gint width, gint height, - const guchar *buf, int rowstride, - gint x_align, gint y_align, GdkRgbCmap *cmap) -{ - int x, y; - gint bpl; - guchar *obuf, *obptr; - const guchar *bptr, *bp2; - gint r, g, b; - - bptr = buf; - bpl = image->bpl; - obuf = ((guchar *)image->mem) + y0 * bpl + x0; - for (y = 0; y < height; y++) - { - bp2 = bptr; - obptr = obuf; - for (x = 0; x < width; x++) - { - r = *bp2++; - g = *bp2++; - b = *bp2++; - obptr[0] = (g + ((b + r) >> 1)) >> 1; - obptr++; - } - bptr += rowstride; - obuf += bpl; - } -} - -static void -gdk_rgb_convert_gray8_gray (GdkRgbInfo *image_info, GdkImage *image, - gint x0, gint y0, gint width, gint height, - const guchar *buf, int rowstride, - gint x_align, gint y_align, GdkRgbCmap *cmap) -{ - int y; - gint bpl; - guchar *obuf; - const guchar *bptr; - - bptr = buf; - bpl = image->bpl; - obuf = ((guchar *)image->mem) + y0 * bpl + x0; - for (y = 0; y < height; y++) - { - memcpy (obuf, bptr, width); - bptr += rowstride; - obuf += bpl; - } -} - - -#if G_BYTE_ORDER == G_BIG_ENDIAN -#if defined(__powerpc__) || defined(__powerpc64__) || \ - defined(__ppc__) || defined(__ppc64__) || \ - defined(__PPC__) || defined(__PPC64__) || \ - defined(__POWERPC__) || defined(_ARCH_PPC) -#define GDK_RGB_FAST_BE565_RGB -#define GDK_RGB_FAST_BE565_GRAY -#define GDK_RGB_FAST_BE565_DITHER -#elif defined(__s390x__) -#define GDK_RGB_FAST_BE565_RGB -#elif defined(__aarch64__) -#define GDK_RGB_FAST_BE565_RGB -#define GDK_RGB_FAST_BE565_GRAY -#elif defined(__arm__) && defined(__ARM_ARCH) && \ - __ARM_ARCH >= 5 -#define GDK_RGB_FAST_BE565_RGB -#define GDK_RGB_FAST_BE565_GRAY -#elif defined(__m68k__) -#define GDK_RGB_FAST_BE565_GRAY -#endif -#endif - -/* Render a 24-bit RGB image in buf into the GdkImage, without dithering. - The four-pixel inner loop uses compile-time-specialized native word - layouts for little- and big-endian systems. */ -#if G_BYTE_ORDER == G_LITTLE_ENDIAN || defined(GDK_RGB_FAST_BE565_RGB) -static void -gdk_rgb_convert_565 (GdkRgbInfo *image_info, GdkImage *image, - gint x0, gint y0, gint width, gint height, - const guchar *buf, int rowstride, - gint x_align, gint y_align, GdkRgbCmap *cmap) -{ - int x, y; - guchar *obuf, *obptr; - gint bpl; - const guchar *bptr, *bp2; - guchar r, g, b; - - bptr = buf; - bpl = image->bpl; - obuf = ((guchar *)image->mem) + y0 * bpl + x0 * 2; - for (y = 0; y < height; y++) - { - bp2 = bptr; - obptr = obuf; - if (((guintptr)obuf | (guintptr) bp2) & 3) - { - for (x = 0; x < width; x++) - { - r = *bp2++; - g = *bp2++; - b = *bp2++; - ((guint16 *)obptr)[0] = ((r & 0xf8) << 8) | - ((g & 0xfc) << 3) | - (b >> 3); - obptr += 2; - } - } - else - { - for (x = 0; x < width - 3; x += 4) - { - guint32 r1b0g0r0; - guint32 g2r2b1g1; - guint32 b3g3r3b2; - - r1b0g0r0 = ((guint32 *)bp2)[0]; - g2r2b1g1 = ((guint32 *)bp2)[1]; - b3g3r3b2 = ((guint32 *)bp2)[2]; -#if G_BYTE_ORDER == G_LITTLE_ENDIAN - ((guint32 *)obptr)[0] = - ((r1b0g0r0 & 0xf8) << 8) | - ((r1b0g0r0 & 0xfc00) >> 5) | - ((r1b0g0r0 & 0xf80000) >> 19) | - (r1b0g0r0 & 0xf8000000) | - ((g2r2b1g1 & 0xfc) << 19) | - ((g2r2b1g1 & 0xf800) << 5); - ((guint32 *)obptr)[1] = - ((g2r2b1g1 & 0xf80000) >> 8) | - ((g2r2b1g1 & 0xfc000000) >> 21) | - ((b3g3r3b2 & 0xf8) >> 3) | - ((b3g3r3b2 & 0xf800) << 16) | - ((b3g3r3b2 & 0xfc0000) << 3) | - ((b3g3r3b2 & 0xf8000000) >> 11); -#else - ((guint32 *)obptr)[0] = - (r1b0g0r0 & 0xf8000000) | - ((r1b0g0r0 & 0x00fc0000) << 3) | - ((r1b0g0r0 & 0x0000f800) << 5) | - ((r1b0g0r0 & 0x000000f8) << 8) | - ((g2r2b1g1 & 0xfc000000) >> 21) | - ((g2r2b1g1 & 0x00f80000) >> 19); - ((guint32 *)obptr)[1] = - ((g2r2b1g1 & 0x0000f800) << 16) | - ((g2r2b1g1 & 0x000000fc) << 19) | - ((b3g3r3b2 & 0xf8000000) >> 11) | - ((b3g3r3b2 & 0x00f80000) >> 8) | - ((b3g3r3b2 & 0x0000fc00) >> 5) | - ((b3g3r3b2 & 0x000000f8) >> 3); -#endif - bp2 += 12; - obptr += 8; - } - for (; x < width; x++) - { - r = *bp2++; - g = *bp2++; - b = *bp2++; - ((guint16 *)obptr)[0] = ((r & 0xf8) << 8) | - ((g & 0xfc) << 3) | - (b >> 3); - obptr += 2; - } - } - bptr += rowstride; - obuf += bpl; - } -} -#else -static void -gdk_rgb_convert_565 (GdkRgbInfo *image_info, GdkImage *image, - gint x0, gint y0, gint width, gint height, - const guchar *buf, int rowstride, - gint x_align, gint y_align, GdkRgbCmap *cmap) -{ - int x, y; - guchar *obuf; - gint bpl; - const guchar *bptr, *bp2; - guchar r, g, b; - - bptr = buf; - bpl = image->bpl; - obuf = ((guchar *)image->mem) + y0 * bpl + x0 * 2; - for (y = 0; y < height; y++) - { - bp2 = bptr; - for (x = 0; x < width; x++) - { - r = *bp2++; - g = *bp2++; - b = *bp2++; - ((unsigned short *)obuf)[x] = ((r & 0xf8) << 8) | - ((g & 0xfc) << 3) | - (b >> 3); - } - bptr += rowstride; - obuf += bpl; - } -} -#endif - -#if G_BYTE_ORDER == G_LITTLE_ENDIAN || defined(GDK_RGB_FAST_BE565_GRAY) -static void -gdk_rgb_convert_565_gray (GdkRgbInfo *image_info, GdkImage *image, - gint x0, gint y0, gint width, gint height, - const guchar *buf, int rowstride, - gint x_align, gint y_align, GdkRgbCmap *cmap) -{ - int x, y; - guchar *obuf, *obptr; - gint bpl; - const guchar *bptr, *bp2; - guchar g; - - bptr = buf; - bpl = image->bpl; - obuf = ((guchar *)image->mem) + y0 * bpl + x0 * 2; - for (y = 0; y < height; y++) - { - bp2 = bptr; - obptr = obuf; - if (((guintptr)obuf | (guintptr) bp2) & 3) - { - for (x = 0; x < width; x++) - { - g = *bp2++; - ((guint16 *)obptr)[0] = ((g & 0xf8) << 8) | - ((g & 0xfc) << 3) | - (g >> 3); - obptr += 2; - } - } - else - { - for (x = 0; x < width - 3; x += 4) - { - guint32 g3g2g1g0; - - g3g2g1g0 = ((guint32 *)bp2)[0]; -#if G_BYTE_ORDER == G_LITTLE_ENDIAN - ((guint32 *)obptr)[0] = - ((g3g2g1g0 & 0xf8) << 8) | - ((g3g2g1g0 & 0xfc) << 3) | - ((g3g2g1g0 & 0xf8) >> 3) | - (g3g2g1g0 & 0xf800) << 16 | - ((g3g2g1g0 & 0xfc00) << 11) | - ((g3g2g1g0 & 0xf800) << 5); - ((guint32 *)obptr)[1] = - ((g3g2g1g0 & 0xf80000) >> 8) | - ((g3g2g1g0 & 0xfc0000) >> 13) | - ((g3g2g1g0 & 0xf80000) >> 19) | - (g3g2g1g0 & 0xf8000000) | - ((g3g2g1g0 & 0xfc000000) >> 5) | - ((g3g2g1g0 & 0xf8000000) >> 11); -#else - ((guint32 *)obptr)[0] = - (g3g2g1g0 & 0xf8000000) | - ((g3g2g1g0 & 0xfc000000) >> 5) | - ((g3g2g1g0 & 0xf8000000) >> 11) | - ((g3g2g1g0 & 0x00f80000) >> 8) | - ((g3g2g1g0 & 0x00fc0000) >> 13) | - ((g3g2g1g0 & 0x00f80000) >> 19); - ((guint32 *)obptr)[1] = - ((g3g2g1g0 & 0x0000f800) << 16) | - ((g3g2g1g0 & 0x0000fc00) << 11) | - ((g3g2g1g0 & 0x0000f800) << 5) | - ((g3g2g1g0 & 0x000000f8) << 8) | - ((g3g2g1g0 & 0x000000fc) << 3) | - ((g3g2g1g0 & 0x000000f8) >> 3); -#endif - bp2 += 4; - obptr += 8; - } - for (; x < width; x++) - { - g = *bp2++; - ((guint16 *)obptr)[0] = ((g & 0xf8) << 8) | - ((g & 0xfc) << 3) | - (g >> 3); - obptr += 2; - } - } - bptr += rowstride; - obuf += bpl; - } -} -#else -static void -gdk_rgb_convert_565_gray (GdkRgbInfo *image_info, GdkImage *image, - gint x0, gint y0, gint width, gint height, - const guchar *buf, int rowstride, - gint x_align, gint y_align, GdkRgbCmap *cmap) -{ - int x, y; - guchar *obuf; - gint bpl; - const guchar *bptr, *bp2; - guchar g; - - bptr = buf; - bpl = image->bpl; - obuf = ((guchar *)image->mem) + y0 * bpl + x0 * 2; - for (y = 0; y < height; y++) - { - bp2 = bptr; - for (x = 0; x < width; x++) - { - g = *bp2++; - ((guint16 *)obuf)[x] = ((g & 0xf8) << 8) | - ((g & 0xfc) << 3) | - (g >> 3); - } - bptr += rowstride; - obuf += bpl; - } -} -#endif - -static void -gdk_rgb_convert_565_br (GdkRgbInfo *image_info, GdkImage *image, - gint x0, gint y0, gint width, gint height, - const guchar *buf, int rowstride, - gint x_align, gint y_align, GdkRgbCmap *cmap) -{ - int x, y; - guchar *obuf; - gint bpl; - const guchar *bptr, *bp2; - guchar r, g, b; - - bptr = buf; - bpl = image->bpl; - obuf = ((guchar *)image->mem) + y0 * bpl + x0 * 2; - for (y = 0; y < height; y++) - { - bp2 = bptr; - for (x = 0; x < width; x++) - { - r = *bp2++; - g = *bp2++; - b = *bp2++; - /* final word is: - g4 g3 g2 b7 b6 b5 b4 b3 r7 r6 r5 r4 r3 g7 g6 g5 - */ - ((unsigned short *)obuf)[x] = (r & 0xf8) | - ((g & 0xe0) >> 5) | - ((g & 0x1c) << 11) | - ((b & 0xf8) << 5); - } - bptr += rowstride; - obuf += bpl; - } -} - -/* Thanks to Ray Lehtiniemi for a patch that resulted in a ~25% speedup - in this mode. */ -#if G_BYTE_ORDER == G_LITTLE_ENDIAN || defined(GDK_RGB_FAST_BE565_DITHER) -static void -gdk_rgb_convert_565_d (GdkRgbInfo *image_info, GdkImage *image, - gint x0, gint y0, gint width, gint height, - const guchar *buf, int rowstride, - gint x_align, gint y_align, GdkRgbCmap *cmap) -{ - /* Now this is what I'd call some highly tuned code! */ - int x, y; - guchar *obuf, *obptr; - gint bpl; - const guchar *bptr, *bp2; - - width += x_align; - height += y_align; - - bptr = buf; - bpl = image->bpl; - obuf = ((guchar *)image->mem) + y0 * bpl + x0 * 2; - for (y = y_align; y < height; y++) - { - const guint32 *dmp = DM_565 + ((y & (DM_HEIGHT - 1)) << DM_WIDTH_SHIFT); - bp2 = bptr; - obptr = obuf; - if (((guintptr)obuf | (guintptr) bp2) & 3) - { - for (x = x_align; x < width; x++) - { - gint32 rgb = *bp2++ << 20; - rgb += *bp2++ << 10; - rgb += *bp2++; - rgb += dmp[x & (DM_WIDTH - 1)]; - rgb += 0x10040100 - - ((rgb & 0x1e0001e0) >> 5) - - ((rgb & 0x00070000) >> 6); - - ((unsigned short *)obptr)[0] = - ((rgb & 0x0f800000) >> 12) | - ((rgb & 0x0003f000) >> 7) | - ((rgb & 0x000000f8) >> 3); - obptr += 2; - } - } - else - { - for (x = x_align; x < width - 3; x += 4) - { - guint32 r1b0g0r0; - guint32 g2r2b1g1; - guint32 b3g3r3b2; - guint32 rgb02, rgb13; - - r1b0g0r0 = ((guint32 *)bp2)[0]; - g2r2b1g1 = ((guint32 *)bp2)[1]; - b3g3r3b2 = ((guint32 *)bp2)[2]; -#if G_BYTE_ORDER == G_LITTLE_ENDIAN - rgb02 = - ((r1b0g0r0 & 0xff) << 20) + - ((r1b0g0r0 & 0xff00) << 2) + - ((r1b0g0r0 & 0xff0000) >> 16) + - dmp[x & (DM_WIDTH - 1)]; - rgb02 += 0x10040100 - - ((rgb02 & 0x1e0001e0) >> 5) - - ((rgb02 & 0x00070000) >> 6); - rgb13 = - ((r1b0g0r0 & 0xff000000) >> 4) + - ((g2r2b1g1 & 0xff) << 10) + - ((g2r2b1g1 & 0xff00) >> 8) + - dmp[(x + 1) & (DM_WIDTH - 1)]; - rgb13 += 0x10040100 - - ((rgb13 & 0x1e0001e0) >> 5) - - ((rgb13 & 0x00070000) >> 6); - ((guint32 *)obptr)[0] = - ((rgb02 & 0x0f800000) >> 12) | - ((rgb02 & 0x0003f000) >> 7) | - ((rgb02 & 0x000000f8) >> 3) | - ((rgb13 & 0x0f800000) << 4) | - ((rgb13 & 0x0003f000) << 9) | - ((rgb13 & 0x000000f8) << 13); - rgb02 = - ((g2r2b1g1 & 0xff0000) << 4) + - ((g2r2b1g1 & 0xff000000) >> 14) + - (b3g3r3b2 & 0xff) + - dmp[(x + 2) & (DM_WIDTH - 1)]; - rgb02 += 0x10040100 - - ((rgb02 & 0x1e0001e0) >> 5) - - ((rgb02 & 0x00070000) >> 6); - rgb13 = - ((b3g3r3b2 & 0xff00) << 12) + - ((b3g3r3b2 & 0xff0000) >> 6) + - ((b3g3r3b2 & 0xff000000) >> 24) + - dmp[(x + 3) & (DM_WIDTH - 1)]; - rgb13 += 0x10040100 - - ((rgb13 & 0x1e0001e0) >> 5) - - ((rgb13 & 0x00070000) >> 6); - ((guint32 *)obptr)[1] = - ((rgb02 & 0x0f800000) >> 12) | - ((rgb02 & 0x0003f000) >> 7) | - ((rgb02 & 0x000000f8) >> 3) | - ((rgb13 & 0x0f800000) << 4) | - ((rgb13 & 0x0003f000) << 9) | - ((rgb13 & 0x000000f8) << 13); -#else - rgb02 = - ((r1b0g0r0 & 0xff000000) >> 4) + - ((r1b0g0r0 & 0x00ff0000) >> 6) + - ((r1b0g0r0 & 0x0000ff00) >> 8) + - dmp[x & (DM_WIDTH - 1)]; - rgb02 += 0x10040100 - - ((rgb02 & 0x1e0001e0) >> 5) - - ((rgb02 & 0x00070000) >> 6); - rgb13 = - ((r1b0g0r0 & 0x000000ff) << 20) + - ((g2r2b1g1 & 0xff000000) >> 14) + - ((g2r2b1g1 & 0x00ff0000) >> 16) + - dmp[(x + 1) & (DM_WIDTH - 1)]; - rgb13 += 0x10040100 - - ((rgb13 & 0x1e0001e0) >> 5) - - ((rgb13 & 0x00070000) >> 6); - ((guint32 *)obptr)[0] = - ((rgb02 & 0x0f800000) << 4) | - ((rgb02 & 0x0003f000) << 9) | - ((rgb02 & 0x000000f8) << 13) | - ((rgb13 & 0x0f800000) >> 12) | - ((rgb13 & 0x0003f000) >> 7) | - ((rgb13 & 0x000000f8) >> 3); - rgb02 = - ((g2r2b1g1 & 0x0000ff00) << 12) + - ((g2r2b1g1 & 0x000000ff) << 10) + - ((b3g3r3b2 & 0xff000000) >> 24) + - dmp[(x + 2) & (DM_WIDTH - 1)]; - rgb02 += 0x10040100 - - ((rgb02 & 0x1e0001e0) >> 5) - - ((rgb02 & 0x00070000) >> 6); - rgb13 = - ((b3g3r3b2 & 0x00ff0000) << 4) + - ((b3g3r3b2 & 0x0000ff00) << 2) + - (b3g3r3b2 & 0x000000ff) + - dmp[(x + 3) & (DM_WIDTH - 1)]; - rgb13 += 0x10040100 - - ((rgb13 & 0x1e0001e0) >> 5) - - ((rgb13 & 0x00070000) >> 6); - ((guint32 *)obptr)[1] = - ((rgb02 & 0x0f800000) << 4) | - ((rgb02 & 0x0003f000) << 9) | - ((rgb02 & 0x000000f8) << 13) | - ((rgb13 & 0x0f800000) >> 12) | - ((rgb13 & 0x0003f000) >> 7) | - ((rgb13 & 0x000000f8) >> 3); -#endif - bp2 += 12; - obptr += 8; - } - for (; x < width; x++) - { - gint32 rgb = *bp2++ << 20; - rgb += *bp2++ << 10; - rgb += *bp2++; - rgb += dmp[x & (DM_WIDTH - 1)]; - rgb += 0x10040100 - - ((rgb & 0x1e0001e0) >> 5) - - ((rgb & 0x00070000) >> 6); - - ((unsigned short *)obptr)[0] = - ((rgb & 0x0f800000) >> 12) | - ((rgb & 0x0003f000) >> 7) | - ((rgb & 0x000000f8) >> 3); - obptr += 2; - } - } - bptr += rowstride; - obuf += bpl; - } -} -#else -static void -gdk_rgb_convert_565_d (GdkRgbInfo *image_info, GdkImage *image, - gint x0, gint y0, gint width, gint height, - const guchar *buf, int rowstride, - gint x_align, gint y_align, GdkRgbCmap *cmap) -{ - int x, y; - guchar *obuf; - gint bpl; - const guchar *bptr; - - width += x_align; - height += y_align; - - bptr = buf; - bpl = image->bpl; - obuf = ((guchar *)image->mem) + y0 * bpl + (x0 - x_align) * 2; - - for (y = y_align; y < height; y++) - { - const guint32 *dmp = DM_565 + ((y & (DM_HEIGHT - 1)) << DM_WIDTH_SHIFT); - guchar *bp2 = bptr; - - for (x = x_align; x < width; x++) + case GDK_RGB_INPUT_RGB: + return in; + case GDK_RGB_INPUT_RGBX: + for (x = 0; x < width; x++, in += 4, p += 3) + p[0] = in[0], p[1] = in[1], p[2] = in[2]; + break; + case GDK_RGB_INPUT_GRAY: + for (x = 0; x < width; x++, p += 3) + p[0] = p[1] = p[2] = in[x]; + break; + case GDK_RGB_INPUT_INDEXED: + for (x = 0; x < width; x++, p += 3) { - gint32 rgb = *bp2++ << 20; - rgb += *bp2++ << 10; - rgb += *bp2++; - rgb += dmp[x & (DM_WIDTH - 1)]; - rgb += 0x10040100 - - ((rgb & 0x1e0001e0) >> 5) - - ((rgb & 0x00070000) >> 6); + guint32 rgb = cmap->colors[in[x]]; + p[0] = rgb >> 16, p[1] = rgb >> 8, p[2] = rgb; + } + break; + case GDK_RGB_INPUT_RGB48: + case GDK_RGB_INPUT_RGBX64: + for (x = 0; x < width; x++, p += 3) + { + p[0] = in16[0] >> 8, p[1] = in16[1] >> 8, p[2] = in16[2] >> 8; + in16 += input == GDK_RGB_INPUT_RGB48 ? 3 : 4; + } + break; + } - ((unsigned short *)obuf)[x] = - ((rgb & 0x0f800000) >> 12) | - ((rgb & 0x0003f000) >> 7) | - ((rgb & 0x000000f8) >> 3); + return stage; +} + +/* Reading 8-bit RGB a word at a time: four pixels are three loads + * instead of twelve, which matters on CPUs with one load unit. */ +#ifdef __GNUC__ +typedef guint32 __attribute__ ((__may_alias__)) GdkRgbWord; +#else +typedef guint32 GdkRgbWord; +#endif + +/* Byte @j of a word as it lies in memory */ +#if G_BYTE_ORDER == G_LITTLE_ENDIAN +#define BYTE_OF(w, j) (((w) >> (8 * (j))) & 0xff) +#define WORD_OF(b0, b1, b2, b3) ((b0) | ((b1) << 8) | ((b2) << 16) | ((guint32) (b3) << 24)) +#else +#define BYTE_OF(w, j) (((w) >> (24 - 8 * (j))) & 0xff) +#define WORD_OF(b0, b1, b2, b3) (((guint32) (b0) << 24) | ((b1) << 16) | ((b2) << 8) | (b3)) +#endif + +/* Calls PUT (arg, x, r, g, b) for each pixel of a row of 8-bit RGB. */ +#define FOR_EACH_RGB(in, width, PUT, arg) \ + G_STMT_START { \ + const guchar *p_ = (in); \ + gint x_ = 0; \ + \ + if (((gsize) p_ & 3) == 0) \ + for (; x_ + 4 <= (width); x_ += 4, p_ += 12) \ + { \ + const guint32 w0_ = ((const GdkRgbWord *) p_)[0]; \ + const guint32 w1_ = ((const GdkRgbWord *) p_)[1]; \ + const guint32 w2_ = ((const GdkRgbWord *) p_)[2]; \ + \ + PUT (arg, x_, BYTE_OF (w0_, 0), BYTE_OF (w0_, 1), BYTE_OF (w0_, 2)); \ + PUT (arg, x_ + 1, BYTE_OF (w0_, 3), BYTE_OF (w1_, 0), BYTE_OF (w1_, 1)); \ + PUT (arg, x_ + 2, BYTE_OF (w1_, 2), BYTE_OF (w1_, 3), BYTE_OF (w2_, 0)); \ + PUT (arg, x_ + 3, BYTE_OF (w2_, 1), BYTE_OF (w2_, 2), BYTE_OF (w2_, 3)); \ + } \ + for (; x_ < (width); x_++, p_ += 3) \ + PUT (arg, x_, p_[0], p_[1], p_[2]); \ + } G_STMT_END + +/** TrueColor + */ + +/* The pixel layouts with their own loops. The shifts are constants + * there, so compilers can use insert instructions (rlwimi on PowerPC, + * shifted operands on ARM) instead of table lookups. */ +enum +{ + GDK_RGB_LAYOUT_TABLES, /* anything, through info->tables */ + GDK_RGB_LAYOUT_565, + GDK_RGB_LAYOUT_555, + GDK_RGB_LAYOUT_X888, + GDK_RGB_LAYOUT_X2101010, + GDK_RGB_LAYOUT_BYTES /* 8-bit channels in whole bytes, any order */ +}; + +/* Size of a dither table: 8-bit value plus the largest dither offset */ +#define DTABLE_SIZE 384 + +/* Fills the channel tables and the shifts for 16-bit input. + * + * info->tables holds 256 entries per channel: the bits of the value in + * the pixel, with the fill bits (those of no channel) in the red table. + * Visuals with channels of less than 8 bits get a dither table per + * channel after that: value plus dither offset to pixel bits. The three + * offsets for each of the 64 dither levels are packed in 10-bit lanes. */ +static void +gdk_rgb_init_truecolor (GdkRgbInfo *info, + gint bits_per_pixel) +{ + GdkVisual *visual = info->visual; + const gint shift[3] = { visual->red_shift, visual->green_shift, visual->blue_shift }; + const gint prec[3] = { visual->red_prec, visual->green_prec, visual->blue_prec }; + gboolean ditherable = FALSE, bytes = TRUE; + guint32 fill; + gint c, v; + + fill = ~(visual->red_mask | visual->green_mask | visual->blue_mask); + if (bits_per_pixel < 32) + fill &= (1u << bits_per_pixel) - 1; + + for (c = 0; c < 3; c++) + { + ditherable |= prec[c] >= 1 && prec[c] < 8; + bytes &= prec[c] == 8 && shift[c] % 8 == 0; + } + + info->tables = g_new (guint32, 3 * 256 + (ditherable ? 3 * DTABLE_SIZE : 0)); + memset (info->dither_pack, 0, sizeof (info->dither_pack)); + for (c = 0; c < 3; c++) + { + gint p = MIN (prec[c], 16); + guint32 *dtable = info->tables + 3 * 256 + c * DTABLE_SIZE; + + for (v = 0; v < 256; v++) + info->tables[c * 256 + v] = + (guint32) (p <= 8 ? v >> (8 - p) : (v << (p - 8)) | (v >> (16 - p))) << shift[c]; + + info->shift16[c][0] = 16 - p; + info->shift16[c][1] = shift[c]; + + /* repeating the bits, as the tables do for more than 8 bits */ + for (v = 0; p >= 1 && p <= 8 && v < (1 << p); v++) + { + gint bits = 0, w = v, n; + + for (n = 0; n < 8; n += p) + bits = (bits << p) | w; + info->unpack[c][v] = bits >> (n - 8); } - bptr += rowstride; - obuf += bpl; + if (!ditherable) + continue; + + if (p >= 1 && p < 8) + for (v = 0; v < 64; v++) + info->dither_pack[v] |= (guint32) (((c == 1 ? 63 - v : v) << 2) >> p) << (20 - 10 * c); + for (v = 0; v < DTABLE_SIZE; v++) + if (p >= 1 && p < 8) + dtable[v] = (guint32) ((v - (v >> p)) >> (8 - p)) << shift[c]; + else + dtable[v] = info->tables[c * 256 + MIN (v, 255)]; } + for (v = 0; v < 256; v++) + info->tables[v] |= fill; + info->fill = fill; + info->ditherable = ditherable; + + if (bytes && (bits_per_pixel == 24 || bits_per_pixel == 32)) + info->layout = GDK_RGB_LAYOUT_BYTES; + else + info->layout = GDK_RGB_LAYOUT_TABLES; + if (visual->red_mask == 0xf800 && visual->green_mask == 0x7e0 && + visual->blue_mask == 0x1f && bits_per_pixel == 16) + info->layout = GDK_RGB_LAYOUT_565; + else if (visual->red_mask == 0x7c00 && visual->green_mask == 0x3e0 && + visual->blue_mask == 0x1f && bits_per_pixel == 16) + info->layout = GDK_RGB_LAYOUT_555; + else if (visual->red_mask == 0xff0000 && visual->green_mask == 0xff00 && + visual->blue_mask == 0xff && bits_per_pixel == 32) + info->layout = GDK_RGB_LAYOUT_X888; + else if (visual->red_mask == 0x3ff00000 && visual->green_mask == 0xffc00 && + visual->blue_mask == 0x3ff && bits_per_pixel == 32) + info->layout = GDK_RGB_LAYOUT_X2101010; } -#endif -#undef GDK_RGB_FAST_BE565_RGB -#undef GDK_RGB_FAST_BE565_GRAY -#undef GDK_RGB_FAST_BE565_DITHER +#define T(c, v) (tables[(c) * 256 + (v)]) +#define PUT_PIXEL(PIX, x, r, g, b) (out[x] = PIX (r, g, b)) -static void -gdk_rgb_convert_555 (GdkRgbInfo *image_info, GdkImage *image, - gint x0, gint y0, gint width, gint height, - const guchar *buf, int rowstride, - gint x_align, gint y_align, GdkRgbCmap *cmap) +/* Makes a row of pixels in the byte order of the machine, from 8-bit + * values with PIX8 and from 16-bit values with PIX16. Indexed and gray + * input can come with a lut of finished pixels. */ +#define DEFINE_TRUECOLOR_ROW(name, type, PIX8, PIX16) \ +static void \ +name (GdkRgbInfo *info, type *out, GdkRgbInput input, \ + const guchar *in, gint width, const guint32 *lut) \ +{ \ + const guint32 *tables = info->tables; \ + const guint16 *in16 = (const guint16 *) in; \ + const guint32 fill = info->fill; \ + const gint r0 = info->shift16[0][0], r1 = info->shift16[0][1]; \ + const gint g0 = info->shift16[1][0], g1 = info->shift16[1][1]; \ + const gint b0 = info->shift16[2][0], b1 = info->shift16[2][1]; \ + gint x; \ + \ + switch (input) \ + { \ + case GDK_RGB_INPUT_RGB: \ + FOR_EACH_RGB (in, width, PUT_PIXEL, PIX8); \ + break; \ + case GDK_RGB_INPUT_RGBX: \ + for (x = 0; x < width; x++, in += 4) \ + out[x] = PIX8 (in[0], in[1], in[2]); \ + break; \ + case GDK_RGB_INPUT_GRAY: \ + if (lut) \ + for (x = 0; x < width; x++) \ + out[x] = lut[in[x]]; \ + else \ + for (x = 0; x < width; x++) \ + out[x] = PIX8 (in[x], in[x], in[x]); \ + break; \ + case GDK_RGB_INPUT_INDEXED: \ + for (x = 0; x < width; x++) \ + out[x] = lut[in[x]]; \ + break; \ + case GDK_RGB_INPUT_RGB48: \ + for (x = 0; x < width; x++, in16 += 3) \ + out[x] = PIX16 ((guint32) in16[0], (guint32) in16[1], (guint32) in16[2]); \ + break; \ + case GDK_RGB_INPUT_RGBX64: \ + for (x = 0; x < width; x++, in16 += 4) \ + out[x] = PIX16 ((guint32) in16[0], (guint32) in16[1], (guint32) in16[2]); \ + break; \ + } \ + (void) tables; (void) fill; \ + (void) r0; (void) r1; (void) g0; (void) g1; (void) b0; (void) b1; \ +} + +#define TABLES8(r, g, b) (T (0, r) | T (1, g) | T (2, b)) +#define TABLES16(r, g, b) (((r >> r0) << r1) | ((g >> g0) << g1) | ((b >> b0) << b1) | fill) +DEFINE_TRUECOLOR_ROW (gdk_rgb_truecolor_row16, guint16, TABLES8, TABLES16) +DEFINE_TRUECOLOR_ROW (gdk_rgb_truecolor_row32, guint32, TABLES8, TABLES16) + +#define RGB565_8(r, g, b) (((r & 0xf8) << 8) | ((g & 0xfc) << 3) | (b >> 3)) +#define RGB565_16(r, g, b) ((r & 0xf800) | ((g & 0xfc00) >> 5) | (b >> 11)) +DEFINE_TRUECOLOR_ROW (gdk_rgb_row_565, guint16, RGB565_8, RGB565_16) + +#define RGB555_8(r, g, b) (((r & 0xf8) << 7) | ((g & 0xf8) << 2) | (b >> 3) | fill) +#define RGB555_16(r, g, b) (((r & 0xf800) >> 1) | ((g & 0xf800) >> 6) | (b >> 11) | fill) +DEFINE_TRUECOLOR_ROW (gdk_rgb_row_555, guint16, RGB555_8, RGB555_16) + +#define X888_8(r, g, b) (((guint32) (r) << 16) | ((g) << 8) | (b) | fill) +#define X888_16(r, g, b) (((r & 0xff00) << 8) | (g & 0xff00) | (b >> 8) | fill) +DEFINE_TRUECOLOR_ROW (gdk_rgb_row_x888, guint32, X888_8, X888_16) + +#define X2101010_8(r, g, b) (((guint32) (r) << 22) | ((guint32) ((r) & 0xc0) << 14) | \ + ((g) << 12) | (((g) & 0xc0) << 4) | \ + ((b) << 2) | ((b) >> 6) | fill) +#define X2101010_16(r, g, b) (((r & 0xffc0) << 14) | ((g & 0xffc0) << 4) | (b >> 6) | fill) +DEFINE_TRUECOLOR_ROW (gdk_rgb_row_x2101010, guint32, X2101010_8, X2101010_16) + +#undef DEFINE_TRUECOLOR_ROW + +/* Ordered dithering of 8-bit RGB: the packed offsets are added to all + * three channels at once, the dither tables do the rest. */ +#define PUT_DITHERED(unused, x, r, g, b) \ + G_STMT_START { \ + const guint32 v_ = (((guint32) (r) << 20) | ((g) << 10) | (b)) + \ + pack[dm[(x_dith + (x)) & (DM_WIDTH - 1)]]; \ + out[x] = dr[v_ >> 20] | dg[(v_ >> 10) & 0x3ff] | db[v_ & 0x3ff] | fill; \ + } G_STMT_END + +#define DEFINE_TRUECOLOR_ROW_DITHER(name, type) \ +static void \ +name (GdkRgbInfo *info, type *out, const guchar *in, gint width, \ + const guchar *dm, gint x_dith) \ +{ \ + const guint32 *dr = info->tables + 3 * 256; \ + const guint32 *dg = dr + DTABLE_SIZE; \ + const guint32 *db = dg + DTABLE_SIZE; \ + const guint32 *pack = info->dither_pack; \ + const guint32 fill = info->fill; \ + \ + FOR_EACH_RGB (in, width, PUT_DITHERED, 0); \ +} + +DEFINE_TRUECOLOR_ROW_DITHER (gdk_rgb_truecolor_row16_dither, guint16) +DEFINE_TRUECOLOR_ROW_DITHER (gdk_rgb_truecolor_row32_dither, guint32) + +#undef DEFINE_TRUECOLOR_ROW_DITHER +#undef PUT_DITHERED +#undef PUT_PIXEL +#undef T + +/* Writes 24 and 32 bit pixels with 8-bit channels byte by byte, in any + * channel order and byte order. Returns FALSE for other input. */ +static gboolean +gdk_rgb_bytes_row (GdkRgbInfo *info, + guchar *out, + gint nbytes, + gboolean msb_first, + GdkRgbInput input, + const guchar *in, + gint width) { - int x, y; - guchar *obuf; - gint bpl; - const guchar *bptr, *bp2; - guchar r, g, b; + GdkVisual *visual = info->visual; + gint r, g, b, f, o, k, step, x; + guchar fill; - bptr = buf; - bpl = image->bpl; - obuf = ((guchar *)image->mem) + y0 * bpl + x0 * 2; - for (y = 0; y < height; y++) + switch (input) { - bp2 = bptr; + case GDK_RGB_INPUT_RGB: step = 3; o = 0; k = 1; break; + case GDK_RGB_INPUT_RGBX: step = 4; o = 0; k = 1; break; + case GDK_RGB_INPUT_GRAY: step = 1; o = 0; k = 0; break; + case GDK_RGB_INPUT_RGB48: step = 6; o = G_BYTE_ORDER == G_LITTLE_ENDIAN; k = 2; break; + case GDK_RGB_INPUT_RGBX64: step = 8; o = G_BYTE_ORDER == G_LITTLE_ENDIAN; k = 2; break; + default: + return FALSE; + } + + r = visual->red_shift / 8; + g = visual->green_shift / 8; + b = visual->blue_shift / 8; + f = 6 - r - g - b; /* the byte of no channel, when 4 */ + fill = info->fill >> (f * 8); + if (msb_first) + { + r = nbytes - 1 - r; + g = nbytes - 1 - g; + b = nbytes - 1 - b; + f = nbytes - 1 - f; + } + + if (nbytes == 3 && step == 3 && r == 0 && g == 1 && b == 2) + memcpy (out, in, width * 3); + else if (nbytes == 3 && step == 3 && r == 2 && g == 1 && b == 0) + { + /* BGR, the usual 24-bit layout: four pixels in three words */ + x = 0; + if ((((gsize) in | (gsize) out) & 3) == 0) + for (; x + 4 <= width; x += 4, in += 12, out += 12) + { + const guint32 w0 = ((const GdkRgbWord *) in)[0]; + const guint32 w1 = ((const GdkRgbWord *) in)[1]; + const guint32 w2 = ((const GdkRgbWord *) in)[2]; + + ((GdkRgbWord *) out)[0] = WORD_OF (BYTE_OF (w0, 2), BYTE_OF (w0, 1), + BYTE_OF (w0, 0), BYTE_OF (w1, 1)); + ((GdkRgbWord *) out)[1] = WORD_OF (BYTE_OF (w1, 0), BYTE_OF (w0, 3), + BYTE_OF (w2, 0), BYTE_OF (w1, 3)); + ((GdkRgbWord *) out)[2] = WORD_OF (BYTE_OF (w1, 2), BYTE_OF (w2, 3), + BYTE_OF (w2, 2), BYTE_OF (w2, 1)); + } + for (; x < width; x++, in += 3, out += 3) + { + out[0] = in[2]; + out[1] = in[1]; + out[2] = in[0]; + } + } + else if (nbytes == 3) + for (x = 0; x < width; x++, in += step, out += 3) + { + out[r] = in[o]; + out[g] = in[o + k]; + out[b] = in[o + 2 * k]; + } + else + for (x = 0; x < width; x++, in += step, out += 4) + { + out[r] = in[o]; + out[g] = in[o + k]; + out[b] = in[o + 2 * k]; + out[f] = fill; + } + + return TRUE; +} + +/* Stores pixels of the machine's byte order in the image. This is for + * images of the other byte order (remote displays) and 24-bit pixels. */ +static void +gdk_rgb_store_row (guchar *out, + const guint32 *pixels, + gint width, + gint bits_per_pixel, + gboolean msb_first) +{ + gint x; + + switch (bits_per_pixel) + { + case 8: for (x = 0; x < width; x++) - { - r = *bp2++; - g = *bp2++; - b = *bp2++; - ((unsigned short *)obuf)[x] = ((r & 0xf8) << 7) | - ((g & 0xf8) << 2) | - (b >> 3); - } - bptr += rowstride; - obuf += bpl; - } -} - -static void -gdk_rgb_convert_555_br (GdkRgbInfo *image_info, GdkImage *image, - gint x0, gint y0, gint width, gint height, - const guchar *buf, int rowstride, - gint x_align, gint y_align, GdkRgbCmap *cmap) -{ - int x, y; - guchar *obuf; - gint bpl; - const guchar *bptr, *bp2; - guchar r, g, b; - - bptr = buf; - bpl = image->bpl; - obuf = ((guchar *)image->mem) + y0 * bpl + x0 * 2; - for (y = 0; y < height; y++) - { - bp2 = bptr; - for (x = 0; x < width; x++) - { - r = *bp2++; - g = *bp2++; - b = *bp2++; - /* final word is: - g5 g4 g3 b7 b6 b5 b4 b3 0 r7 r6 r5 r4 r3 g7 g6 - */ - ((unsigned short *)obuf)[x] = ((r & 0xf8) >> 1) | - ((g & 0xc0) >> 6) | - ((g & 0x38) << 10) | - ((b & 0xf8) << 5); - } - bptr += rowstride; - obuf += bpl; - } -} - -static void -gdk_rgb_convert_888_msb (GdkRgbInfo *image_info, GdkImage *image, - gint x0, gint y0, gint width, gint height, - const guchar *buf, int rowstride, - gint x_align, gint y_align, GdkRgbCmap *cmap) -{ - int y; - guchar *obuf; - gint bpl; - const guchar *bptr; - - bptr = buf; - bpl = image->bpl; - obuf = ((guchar *)image->mem) + y0 * bpl + x0 * 3; - for (y = 0; y < height; y++) - { - memcpy (obuf, bptr, width + width + width); - bptr += rowstride; - obuf += bpl; - } -} - -/* todo: optimize this */ -#if G_BYTE_ORDER == G_LITTLE_ENDIAN -#define HAIRY_CONVERT_888 -#endif - -#ifdef HAIRY_CONVERT_888 -static void -gdk_rgb_convert_888_lsb (GdkRgbInfo *image_info, GdkImage *image, - gint x0, gint y0, gint width, gint height, - const guchar *buf, int rowstride, - gint x_align, gint y_align, GdkRgbCmap *cmap) -{ - int x, y; - guchar *obuf, *obptr; - gint bpl; - const guchar *bptr, *bp2; - int r, g, b; - - bptr = buf; - bpl = image->bpl; - obuf = ((guchar *)image->mem) + y0 * bpl + x0 * 3; - for (y = 0; y < height; y++) - { - bp2 = bptr; - obptr = obuf; - if (((guintptr)obuf | (guintptr) bp2) & 3) - { - for (x = 0; x < width; x++) - { - r = bp2[0]; - g = bp2[1]; - b = bp2[2]; - *obptr++ = b; - *obptr++ = g; - *obptr++ = r; - bp2 += 3; - } - } + out[x] = pixels[x]; + break; + case 16: + if (msb_first) + for (x = 0; x < width; x++, out += 2) + out[0] = pixels[x] >> 8, out[1] = pixels[x]; else - { - for (x = 0; x < width - 3; x += 4) - { - guint32 r1b0g0r0; - guint32 g2r2b1g1; - guint32 b3g3r3b2; - - r1b0g0r0 = ((guint32 *)bp2)[0]; - g2r2b1g1 = ((guint32 *)bp2)[1]; - b3g3r3b2 = ((guint32 *)bp2)[2]; - ((guint32 *)obptr)[0] = - (r1b0g0r0 & 0xff00) | - ((r1b0g0r0 & 0xff0000) >> 16) | - (((g2r2b1g1 & 0xff00) | (r1b0g0r0 & 0xff)) << 16); - ((guint32 *)obptr)[1] = - (g2r2b1g1 & 0xff0000ff) | - ((r1b0g0r0 & 0xff000000) >> 16) | - ((b3g3r3b2 & 0xff) << 16); - ((guint32 *)obptr)[2] = - (((g2r2b1g1 & 0xff0000) | (b3g3r3b2 & 0xff000000)) >> 16) | - ((b3g3r3b2 & 0xff00) << 16) | - ((b3g3r3b2 & 0xff0000)); - bp2 += 12; - obptr += 12; - } - for (; x < width; x++) - { - r = bp2[0]; - g = bp2[1]; - b = bp2[2]; - *obptr++ = b; - *obptr++ = g; - *obptr++ = r; - bp2 += 3; - } - } - bptr += rowstride; - obuf += bpl; + for (x = 0; x < width; x++, out += 2) + out[0] = pixels[x], out[1] = pixels[x] >> 8; + break; + case 24: + if (msb_first) + for (x = 0; x < width; x++, out += 3) + out[0] = pixels[x] >> 16, out[1] = pixels[x] >> 8, out[2] = pixels[x]; + else + for (x = 0; x < width; x++, out += 3) + out[0] = pixels[x], out[1] = pixels[x] >> 8, out[2] = pixels[x] >> 16; + break; + case 32: + if (msb_first) + for (x = 0; x < width; x++, out += 4) + out[0] = pixels[x] >> 24, out[1] = pixels[x] >> 16, out[2] = pixels[x] >> 8, out[3] = pixels[x]; + else + for (x = 0; x < width; x++, out += 4) + out[0] = pixels[x], out[1] = pixels[x] >> 8, out[2] = pixels[x] >> 16, out[3] = pixels[x] >> 24; + break; } } -#else -static void -gdk_rgb_convert_888_lsb (GdkRgbInfo *image_info, GdkImage *image, - gint x0, gint y0, gint width, gint height, - const guchar *buf, int rowstride, - gint x_align, gint y_align, GdkRgbCmap *cmap) -{ - int x, y; - guchar *obuf; - gint bpl; - const guchar *bptr, *bp2; - int r, g, b; - bptr = buf; - bpl = image->bpl; - obuf = ((guchar *)image->mem) + y0 * bpl + x0 * 3; - for (y = 0; y < height; y++) +/* Converts a row of TrueColor pixels. */ +static void +gdk_rgb_truecolor_row (GdkRgbInfo *info, + guchar *out, + guint32 *row, + gint bits, + gboolean msb_first, + GdkRgbInput input, + const guchar *in, + gint width, + const guint32 *lut, + const guchar *dm, + gint x_dith) +{ + gboolean native = msb_first == (G_BYTE_ORDER == G_BIG_ENDIAN) && bits != 24; + guint16 *out16 = (guint16 *) out; + guint32 *out32 = (guint32 *) out; + + if (dm) { - bp2 = bptr; - for (x = 0; x < width; x++) - { - r = bp2[0]; - g = bp2[1]; - b = bp2[2]; - obuf[x * 3] = b; - obuf[x * 3 + 1] = g; - obuf[x * 3 + 2] = r; - bp2 += 3; - } - bptr += rowstride; - obuf += bpl; + if (native && bits == 16) + gdk_rgb_truecolor_row16_dither (info, out16, in, width, dm, x_dith); + else if (native && bits == 32) + gdk_rgb_truecolor_row32_dither (info, out32, in, width, dm, x_dith); + else + { + gdk_rgb_truecolor_row32_dither (info, row, in, width, dm, x_dith); + gdk_rgb_store_row (out, row, width, bits, msb_first); + } + return; } -} -#endif -/* convert 24-bit packed to 32-bit unpacked */ -/* todo: optimize this */ -static void -gdk_rgb_convert_0888 (GdkRgbInfo *image_info, GdkImage *image, - gint x0, gint y0, gint width, gint height, - const guchar *buf, int rowstride, - gint x_align, gint y_align, GdkRgbCmap *cmap) -{ - int y, w; - guchar *obuf, *p; - gint bpl; - const guchar *bptr, *bp2; - - bptr = buf; - bpl = image->bpl; - obuf = ((guchar *)image->mem) + y0 * bpl + x0 * 4; - for (y = 0; y < height; y++) + if (info->layout == GDK_RGB_LAYOUT_BYTES || + (info->layout == GDK_RGB_LAYOUT_X888 && !native)) { - bp2 = bptr; - p = obuf; - w = width; - while (w--) - { - p[0] = bp2[2]; - p[1] = bp2[1]; - p[2] = bp2[0]; - p[3] = 0xff; - bp2 += 3; - p += 4; - } - bptr += rowstride; - obuf += bpl; + if (gdk_rgb_bytes_row (info, out, bits / 8, msb_first, input, in, width)) + return; } -} -#ifdef USE_MEDIALIB25 -/* convert 24-bit packed to 32-bit unpacked */ -static void -gdk_rgb_convert_0888_medialib (GdkRgbInfo *image_info, GdkImage *image, - gint x0, gint y0, gint width, gint height, - const guchar *buf, int rowstride, - gint x_align, gint y_align, GdkRgbCmap *cmap) -{ - int y, w; - guchar *obuf, *p; - gint bpl; - const guchar *bptr, *bp2; - - bptr = buf; - bpl = image->bpl; - obuf = ((guchar *)image->mem) + y0 * bpl + x0 * 4; - - mlib_VideoColorRGBint_to_BGRAint (obuf, bptr, NULL, 0xff, - width, height, bpl, - rowstride, 0); -} -#endif - -static void -gdk_rgb_convert_0888_br (GdkRgbInfo *image_info, GdkImage *image, - gint x0, gint y0, gint width, gint height, - const guchar *buf, int rowstride, - gint x_align, gint y_align, GdkRgbCmap *cmap) -{ - int y, w; - guchar *obuf, *p; - gint bpl; - const guchar *bptr, *bp2; - - bptr = buf; - bpl = image->bpl; - obuf = ((guchar *)image->mem) + y0 * bpl + x0 * 4; - for (y = 0; y < height; y++) + /* vector code where there is some, C for the rest of the row */ + if (native && (input == GDK_RGB_INPUT_RGB || input == GDK_RGB_INPUT_RGBX)) { - bp2 = bptr; - p = obuf; - w = width; - while (w--) - { - p[0] = 0xff; - p[1] = bp2[0]; - p[2] = bp2[1]; - p[3] = bp2[2]; - bp2 += 3; - p += 4; - } - bptr += rowstride; - obuf += bpl; + const GdkRgbSimd *simd = _gdk_rgb_simd_get (); + gint done = 0; + + if (bits == 32 && info->layout == GDK_RGB_LAYOUT_X888 && input == GDK_RGB_INPUT_RGB) + done = simd->rgb_to_x888 ? simd->rgb_to_x888 (out32, in, width) : 0; + else if (bits == 32 && info->layout == GDK_RGB_LAYOUT_X888) + done = simd->rgbx_to_x888 ? simd->rgbx_to_x888 (out32, in, width) : 0; + else if (bits == 16 && info->layout == GDK_RGB_LAYOUT_565 && input == GDK_RGB_INPUT_RGB) + done = simd->rgb_to_565 ? simd->rgb_to_565 (out16, in, width) : 0; + else if (bits == 16 && info->layout == GDK_RGB_LAYOUT_555 && input == GDK_RGB_INPUT_RGB) + done = simd->rgb_to_555 ? simd->rgb_to_555 (out16, in, width) : 0; + + out16 += done; + out32 += done; + in += done * gdk_rgb_input_bytes[input]; + width -= done; } -} -static void -gdk_rgb_convert_8880_br (GdkRgbInfo *image_info, GdkImage *image, - gint x0, gint y0, gint width, gint height, - const guchar *buf, int rowstride, - gint x_align, gint y_align, GdkRgbCmap *cmap) -{ - int x, y; - guchar *obuf; - gint bpl; - const guchar *bptr, *bp2; - int r, g, b; + if (native && bits == 16) + switch (info->layout) + { + case GDK_RGB_LAYOUT_565: + gdk_rgb_row_565 (info, out16, input, in, width, lut); + return; + case GDK_RGB_LAYOUT_555: + gdk_rgb_row_555 (info, out16, input, in, width, lut); + return; + default: + gdk_rgb_truecolor_row16 (info, out16, input, in, width, lut); + return; + } - bptr = buf; - bpl = image->bpl; - obuf = ((guchar *)image->mem) + y0 * bpl + x0 * 4; - for (y = 0; y < height; y++) + if (!native || bits != 32) + out32 = row; + switch (info->layout) { - bp2 = bptr; - for (x = 0; x < width; x++) - { - r = bp2[0]; - g = bp2[1]; - b = bp2[2]; - ((guint32 *)obuf)[x] = (b << 16) | (g << 8) | r; - bp2 += 3; - } - bptr += rowstride; - obuf += bpl; + case GDK_RGB_LAYOUT_X888: + gdk_rgb_row_x888 (info, out32, input, in, width, lut); + break; + case GDK_RGB_LAYOUT_X2101010: + gdk_rgb_row_x2101010 (info, out32, input, in, width, lut); + break; + default: + gdk_rgb_truecolor_row32 (info, out32, input, in, width, lut); + break; } + if (out32 == row) + gdk_rgb_store_row (out, row, width, bits, msb_first); } -#define DEFINE_GDK_RGB_CONVERT_101010(name, high, low, to_order) \ -static void \ -name (GdkRgbInfo *image_info, GdkImage *image, \ - gint x0, gint y0, gint width, gint height, \ - const guchar *buf, int rowstride, \ - gint x_align, gint y_align, GdkRgbCmap *cmap) \ -{ \ - int y, w; \ - guchar *obuf, *p; \ - gint bpl; \ - const guchar *bptr, *bp2; \ - guint32 r, g, b; \ - guint32 pixel; \ - guint32 alpha_mask; \ - \ - alpha_mask = image_info->visual->depth == 32 ? 0xc0000000U : 0; \ - \ - bptr = buf; \ - bpl = image->bpl; \ - obuf = ((guchar *) image->mem) + y0 * bpl + x0 * 4; \ - \ - for (y = 0; y < height; y++) \ - { \ - bp2 = bptr; \ - p = obuf; \ - w = width; \ - \ - while (w--) \ - { \ - r = *bp2++; \ - g = *bp2++; \ - b = *bp2++; \ - \ - r = (r << 2) | (r >> 6); \ - g = (g << 2) | (g >> 6); \ - b = (b << 2) | (b >> 6); \ - \ - pixel = alpha_mask | \ - (high << 20) | \ - (g << 10) | \ - low; \ - \ - *((guint32 *) p) = to_order (pixel); \ - p += 4; \ - } \ - \ - bptr += rowstride; \ - obuf += bpl; \ - } \ -} +/** Palettes and gray levels + */ -DEFINE_GDK_RGB_CONVERT_101010 (gdk_rgb_convert_101010_r_low_lsb, - b, r, GUINT32_TO_LE) -DEFINE_GDK_RGB_CONVERT_101010 (gdk_rgb_convert_101010_b_low_lsb, - r, b, GUINT32_TO_LE) -DEFINE_GDK_RGB_CONVERT_101010 (gdk_rgb_convert_101010_r_low_msb, - b, r, GUINT32_TO_BE) -DEFINE_GDK_RGB_CONVERT_101010 (gdk_rgb_convert_101010_b_low_msb, - r, b, GUINT32_TO_BE) +/* Color cube of up to 16 levels per channel. */ +#define PUT_CUBE(cube, x, r, g, b) (out[x] = cube[(((r) & 0xf0) << 4) | ((g) & 0xf0) | ((b) >> 4)]) -#undef DEFINE_GDK_RGB_CONVERT_101010 - -/* Generic truecolor/directcolor conversion function. Slow, but these - are oddball modes. */ static void -gdk_rgb_convert_truecolor_lsb (GdkRgbInfo *image_info, GdkImage *image, - gint x0, gint y0, gint width, gint height, - const guchar *buf, int rowstride, - gint x_align, gint y_align, - GdkRgbCmap *cmap) +gdk_rgb_index_row_cube (GdkRgbInfo *info, guchar *out, const guchar *in, + gint width, const guchar *dm, gint x_dith) { - int x, y; - guchar *obuf, *obptr; - gint bpl; - const guchar *bptr, *bp2; - gint r, g, b; - gint r_right, r_left; - gint g_right, g_left; - gint b_right, b_left; - gint bpp; - guint32 pixel; - guint32 alpha_mask = gdk_rgb_alpha_mask (image_info); - gint i; + const guchar *cube = info->colorcube; - r_right = 8 - image_info->visual->red_prec; - r_left = image_info->visual->red_shift; - g_right = 8 - image_info->visual->green_prec; - g_left = image_info->visual->green_shift; - b_right = 8 - image_info->visual->blue_prec; - b_left = image_info->visual->blue_shift; - bpp = image_info->bpp; - bptr = buf; - bpl = image->bpl; - obuf = ((guchar *)image->mem) + y0 * bpl + x0 * bpp; - for (y = 0; y < height; y++) + FOR_EACH_RGB (in, width, PUT_CUBE, cube); +} + +#undef PUT_CUBE + +static void +gdk_rgb_index_row_cube_dither (GdkRgbInfo *info, guchar *out, const guchar *in, + gint width, const guchar *dm, gint x_dith) +{ + gint rs = info->nred_shades - 1; + gint gs = info->ngreen_shades - 1; + gint bs = info->nblue_shades - 1; + gint x; + + for (x = 0; x < width; x++, in += 3) { - obptr = obuf; - bp2 = bptr; - for (x = 0; x < width; x++) - { - r = bp2[0]; - g = bp2[1]; - b = bp2[2]; - pixel = ((r >> r_right) << r_left) | - ((g >> g_right) << g_left) | - ((b >> b_right) << b_left) | alpha_mask; - for (i = 0; i < bpp; i++) - { - *obptr++ = pixel & 0xff; - pixel >>= 8; - } - bp2 += 3; - } - bptr += rowstride; - obuf += bpl; + gint dith = (dm[(x_dith + x) & (DM_WIDTH - 1)] << 2) | 7; + gint r = (in[0] * rs + dith) >> 8; + gint g = (in[1] * gs + 262 - dith) >> 8; + gint b = (in[2] * bs + dith) >> 8; + + out[x] = info->colorcube_d[(r << 6) | (g << 3) | b]; } } +/* Two levels per channel (3 to 7 bit color displays). */ static void -gdk_rgb_convert_truecolor_lsb_d (GdkRgbInfo *image_info, GdkImage *image, - gint x0, gint y0, gint width, gint height, - const guchar *buf, int rowstride, - gint x_align, gint y_align, - GdkRgbCmap *cmap) +gdk_rgb_index_row_cube_222 (GdkRgbInfo *info, guchar *out, const guchar *in, + gint width, const guchar *dm, gint x_dith) { - int x, y; - guchar *obuf, *obptr; - gint bpl; - const guchar *bptr, *bp2; - gint r, g, b; - gint r_right, r_left, r_prec; - gint g_right, g_left, g_prec; - gint b_right, b_left, b_prec; - gint bpp; - guint32 pixel; - guint32 alpha_mask = gdk_rgb_alpha_mask (image_info); - gint i; - gint dith; - gint r1, g1, b1; - const guchar *dmp; + gint x; - r_right = 8 - image_info->visual->red_prec; - r_left = image_info->visual->red_shift; - r_prec = image_info->visual->red_prec; - g_right = 8 - image_info->visual->green_prec; - g_left = image_info->visual->green_shift; - g_prec = image_info->visual->green_prec; - b_right = 8 - image_info->visual->blue_prec; - b_left = image_info->visual->blue_shift; - b_prec = image_info->visual->blue_prec; - bpp = image_info->bpp; - bptr = buf; - bpl = image->bpl; - obuf = ((guchar *)image->mem) + y0 * bpl + x0 * bpp; - for (y = 0; y < height; y++) + for (x = 0; x < width; x++, in += 3) { - dmp = DM[(y_align + y) & (DM_HEIGHT - 1)]; - obptr = obuf; - bp2 = bptr; - for (x = 0; x < width; x++) - { - r = bp2[0]; - g = bp2[1]; - b = bp2[2]; - dith = dmp[(x_align + x) & (DM_WIDTH - 1)] << 2; - r1 = r + (dith >> r_prec); - g1 = g + ((252 - dith) >> g_prec); - b1 = b + (dith >> b_prec); - pixel = (((r1 - (r1 >> r_prec)) >> r_right) << r_left) | - (((g1 - (g1 >> g_prec)) >> g_right) << g_left) | - (((b1 - (b1 >> b_prec)) >> b_right) << b_left) | alpha_mask; - for (i = 0; i < bpp; i++) - { - *obptr++ = pixel & 0xff; - pixel >>= 8; - } - bp2 += 3; - } - bptr += rowstride; - obuf += bpl; + gint dith = (dm[(x_dith + x) & (DM_WIDTH - 1)] << 2) | 3; + + out[x] = info->colorcube_d[(((in[0] + dith) & 0x100) >> 2) | + (((in[1] + 258 - dith) & 0x100) >> 5) | + (((in[2] + dith) & 0x100) >> 8)]; } } static void -gdk_rgb_convert_truecolor_msb (GdkRgbInfo *image_info, GdkImage *image, - gint x0, gint y0, gint width, gint height, - const guchar *buf, int rowstride, - gint x_align, gint y_align, - GdkRgbCmap *cmap) +gdk_rgb_index_row_gray (GdkRgbInfo *info, guchar *out, const guchar *in, + gint width, const guchar *dm, gint x_dith) { - int x, y; - guchar *obuf, *obptr; - gint bpl; - const guchar *bptr, *bp2; - gint r, g, b; - gint r_right, r_left; - gint g_right, g_left; - gint b_right, b_left; - gint bpp; - guint32 pixel; - guint32 alpha_mask = gdk_rgb_alpha_mask (image_info); - gint shift, shift_init; + gint shift = 9 - info->visual->depth; + gint x; - r_right = 8 - image_info->visual->red_prec; - r_left = image_info->visual->red_shift; - g_right = 8 - image_info->visual->green_prec; - g_left = image_info->visual->green_shift; - b_right = 8 - image_info->visual->blue_prec; - b_left = image_info->visual->blue_shift; - bpp = image_info->bpp; - bptr = buf; - bpl = image->bpl; - obuf = ((guchar *)image->mem) + y0 * bpl + x0 * bpp; - shift_init = (bpp - 1) << 3; - for (y = 0; y < height; y++) + for (x = 0; x < width; x++, in += 3) + out[x] = (in[1] + ((in[2] + in[0]) >> 1)) >> shift; +} + +static void +gdk_rgb_index_row_gray_dither (GdkRgbInfo *info, guchar *out, const guchar *in, + gint width, const guchar *dm, gint x_dith) +{ + gint prec = info->visual->depth; + gint x; + + for (x = 0; x < width; x++, in += 3) { - obptr = obuf; - bp2 = bptr; - for (x = 0; x < width; x++) - { - r = bp2[0]; - g = bp2[1]; - b = bp2[2]; - pixel = ((r >> r_right) << r_left) | - ((g >> g_right) << g_left) | - ((b >> b_right) << b_left) | alpha_mask; - for (shift = shift_init; shift >= 0; shift -= 8) - { - *obptr++ = (pixel >> shift) & 0xff; - } - bp2 += 3; - } - bptr += rowstride; - obuf += bpl; + gint gray = (in[1] + ((in[2] + in[0]) >> 1)) >> 1; + + gray += (dm[(x_dith + x) & (DM_WIDTH - 1)] << 2) >> prec; + out[x] = (gray - (gray >> prec)) >> (8 - prec); } } +/* Black and white. */ static void -gdk_rgb_convert_truecolor_msb_d (GdkRgbInfo *image_info, GdkImage *image, - gint x0, gint y0, gint width, gint height, - const guchar *buf, int rowstride, - gint x_align, gint y_align, - GdkRgbCmap *cmap) +gdk_rgb_index_row_mono (GdkRgbInfo *info, guchar *out, const guchar *in, + gint width, const guchar *dm, gint x_dith) { - int x, y; - guchar *obuf, *obptr; - gint bpl; - const guchar *bptr, *bp2; - gint r, g, b; - gint r_right, r_left, r_prec; - gint g_right, g_left, g_prec; - gint b_right, b_left, b_prec; - gint bpp; - guint32 pixel; - guint32 alpha_mask = gdk_rgb_alpha_mask (image_info); - gint shift, shift_init; - gint dith; - gint r1, g1, b1; - const guchar *dmp; + gint x; - r_right = 8 - image_info->visual->red_prec; - r_left = image_info->visual->red_shift; - r_prec = image_info->visual->red_prec; - g_right = 8 - image_info->visual->green_prec; - g_left = image_info->visual->green_shift; - g_prec = image_info->visual->green_prec; - b_right = 8 - image_info->visual->blue_prec; - b_left = image_info->visual->blue_shift; - b_prec = image_info->visual->blue_prec; - bpp = image_info->bpp; - bptr = buf; - bpl = image->bpl; - obuf = ((guchar *)image->mem) + y0 * bpl + x0 * bpp; - shift_init = (bpp - 1) << 3; - for (y = 0; y < height; y++) + for (x = 0; x < width; x++, in += 3) + out[x] = in[0] + in[1] + in[1] + in[2] + + ((dm[(x_dith + x) & (DM_WIDTH - 1)] << 4) | 4) > 1020; +} + +/* Packs pixels of fewer than 8 bits, keeping the other pixels of a + * partly covered first and last byte. */ +static void +gdk_rgb_pack_row (guchar *out, + gint x0, + const guchar *pixels, + gint width, + gint bits_per_pixel, + gboolean msb_first) +{ + const guint mask = (1 << bits_per_pixel) - 1; + gint bit = (x0 * bits_per_pixel) & 7; + gint x = 0, n; + +#define PACK_ONE() \ + G_STMT_START { \ + const gint s_ = msb_first ? 8 - bits_per_pixel - bit : bit; \ + \ + *out = (*out & ~(mask << s_)) | ((pixels[x++] & mask) << s_); \ + bit += bits_per_pixel; \ + if (bit == 8) \ + bit = 0, out++; \ + } G_STMT_END +#define P(k) (pixels[x + (msb_first ? (k) : n - 1 - (k))] & mask) + + out += (x0 * bits_per_pixel) >> 3; + while (bit != 0 && x < width) + PACK_ONE (); + + /* whole bytes */ + switch (bits_per_pixel) { - dmp = DM[(y_align + y) & (DM_HEIGHT - 1)]; - obptr = obuf; - bp2 = bptr; - for (x = 0; x < width; x++) - { - r = bp2[0]; - g = bp2[1]; - b = bp2[2]; - dith = dmp[(x_align + x) & (DM_WIDTH - 1)] << 2; - r1 = r + (dith >> r_prec); - g1 = g + ((252 - dith) >> g_prec); - b1 = b + (dith >> b_prec); - pixel = (((r1 - (r1 >> r_prec)) >> r_right) << r_left) | - (((g1 - (g1 >> g_prec)) >> g_right) << g_left) | - (((b1 - (b1 >> b_prec)) >> b_right) << b_left) | alpha_mask; - for (shift = shift_init; shift >= 0; shift -= 8) - { - *obptr++ = (pixel >> shift) & 0xff; - } - bp2 += 3; - } - bptr += rowstride; - obuf += bpl; + case 1: + for (n = 8; x + n <= width; x += n) + *out++ = (P (0) << 7) | (P (1) << 6) | (P (2) << 5) | (P (3) << 4) | + (P (4) << 3) | (P (5) << 2) | (P (6) << 1) | P (7); + break; + case 2: + for (n = 4; x + n <= width; x += n) + *out++ = (P (0) << 6) | (P (1) << 4) | (P (2) << 2) | P (3); + break; + case 4: + for (n = 2; x + n <= width; x += n) + *out++ = (P (0) << 4) | P (1); + break; } + + while (x < width) + PACK_ONE (); + +#undef P +#undef PACK_ONE } -/* This actually works for depths from 3 to 7 */ -static void -gdk_rgb_convert_4 (GdkRgbInfo *image_info, GdkImage *image, - gint x0, gint y0, gint width, gint height, - const guchar *buf, int rowstride, - gint x_align, gint y_align, - GdkRgbCmap *cmap) -{ - int x, y; - gint bpl; - guchar *obuf, *obptr; - const guchar *bptr, *bp2; - gint r, g, b; - const guchar *dmp; - gint dith; - guchar *colorcube_d = image_info->colorcube_d; +#undef FOR_EACH_RGB +#undef WORD_OF +#undef BYTE_OF - bptr = buf; - bpl = image->bpl; - obuf = ((guchar *)image->mem) + y0 * bpl + x0; - for (y = 0; y < height; y++) - { - dmp = DM[(y_align + y) & (DM_HEIGHT - 1)]; - bp2 = bptr; - obptr = obuf; - for (x = 0; x < width; x += 1) - { - r = *bp2++; - g = *bp2++; - b = *bp2++; - dith = (dmp[(x_align + x) & (DM_WIDTH - 1)] << 2) | 3; - obptr[0] = colorcube_d[(((r + dith) & 0x100) >> 2) | - (((g + 258 - dith) & 0x100) >> 5) | - (((b + dith) & 0x100) >> 8)]; - obptr++; - } - bptr += rowstride; - obuf += bpl; - } -} +/** Setup and driver + */ static void -gdk_rgb_convert_4_pack (GdkRgbInfo *image_info, GdkImage *image, - gint x0, gint y0, gint width, gint height, - const guchar *buf, int rowstride, - gint x_align, gint y_align, - GdkRgbCmap *cmap) +gdk_rgb_select_conv (GdkRgbInfo *info) { - int x, y, ix; - gint bpl; - guchar *obuf, *obptr; - const guchar *bptr, *bp2; - gint r, g, b; - const guchar *dmp; - gint dith; - guchar *colorcube_d = image_info->colorcube_d; - guchar pix0, pix1; + GdkVisual *visual = info->visual; + GdkVisualType type = visual->type; + gint depth = visual->depth; + gint bits = info->bits_per_pixel; + gboolean gray = type == GDK_VISUAL_STATIC_GRAY || type == GDK_VISUAL_GRAYSCALE; - bptr = buf; - bpl = image->bpl; - obuf = ((guchar *)image->mem) + y0 * bpl + (x0 >> 1); - for (y = 0; y < height; y++) - { - dmp = DM[(y_align + y) & (DM_HEIGHT - 1)]; - bp2 = bptr; - obptr = obuf; - - x = 0; - if (x0 & 1) - { - r = *bp2++; - g = *bp2++; - b = *bp2++; - dith = (dmp[(x_align + x) & (DM_WIDTH - 1)] << 2) | 3; - ix = (((r + dith) & 0x100) >> 2) | - (((g + 258 - dith) & 0x100) >> 5) | - (((b + dith) & 0x100) >> 8); - pix1 = (colorcube_d[ix]); - *obptr = (*obptr & 0xF0) | pix1; - obptr++; - x++; - } - while (x + 1 < width) - { - r = *bp2++; - g = *bp2++; - b = *bp2++; - dith = (dmp[(x_align + x) & (DM_WIDTH - 1)] << 2) | 3; - ix = (((r + dith) & 0x100) >> 2) | - (((g + 258 - dith) & 0x100) >> 5) | - (((b + dith) & 0x100) >> 8); - pix0 = (colorcube_d[ix]); - x++; - { - r = *bp2++; - g = *bp2++; - b = *bp2++; - dith = (dmp[(x_align + x) & (DM_WIDTH - 1)] << 2) | 3; - ix = (((r + dith) & 0x100) >> 2) | - (((g + 258 - dith) & 0x100) >> 5) | - (((b + dith) & 0x100) >> 8); - pix1 = (colorcube_d[ix]); - x++; - } - *obptr++ = (pix0 << 4) | pix1; - } - if (x < width) - { - r = *bp2++; - g = *bp2++; - b = *bp2++; - dith = (dmp[(x_align + x) & (DM_WIDTH - 1)] << 2) | 3; - ix = (((r + dith) & 0x100) >> 2) | - (((g + 258 - dith) & 0x100) >> 5) | - (((b + dith) & 0x100) >> 8); - pix0 = (colorcube_d[ix]); - *obptr = (pix0 << 4) | (*obptr & 0x0F); - } - bptr += rowstride; - obuf += bpl; - } -} - -/* This actually works for depths from 3 to 7 */ -static void -gdk_rgb_convert_gray4 (GdkRgbInfo *image_info, GdkImage *image, - gint x0, gint y0, gint width, gint height, - const guchar *buf, int rowstride, - gint x_align, gint y_align, GdkRgbCmap *cmap) -{ - int x, y; - gint bpl; - guchar *obuf, *obptr; - const guchar *bptr, *bp2; - gint r, g, b; - gint shift; - - bptr = buf; - bpl = image->bpl; - obuf = ((guchar *)image->mem) + y0 * bpl + x0; - shift = 9 - image_info->visual->depth; - for (y = 0; y < height; y++) - { - bp2 = bptr; - obptr = obuf; - for (x = 0; x < width; x++) - { - r = *bp2++; - g = *bp2++; - b = *bp2++; - obptr[0] = (g + ((b + r) >> 1)) >> shift; - obptr++; - } - bptr += rowstride; - obuf += bpl; - } -} - -static void -gdk_rgb_convert_gray4_pack (GdkRgbInfo *image_info, GdkImage *image, - gint x0, gint y0, gint width, gint height, - const guchar *buf, int rowstride, - gint x_align, gint y_align, GdkRgbCmap *cmap) -{ - int x, y; - gint bpl; - guchar *obuf, *obptr; - const guchar *bptr, *bp2; - gint r, g, b; - gint shift; - guchar pix0, pix1; - /* todo: this is hardcoded to big-endian. Make endian-agile. */ - - bptr = buf; - bpl = image->bpl; - obuf = ((guchar *)image->mem) + y0 * bpl + (x0 >> 1); - shift = 9 - image_info->visual->depth; - for (y = 0; y < height; y++) - { - bp2 = bptr; - obptr = obuf; - - x = 0; - if (x0 & 1) - { - r = *bp2++; - g = *bp2++; - b = *bp2++; - pix1 = (g + ((b + r) >> 1)) >> shift; - *obptr = (*obptr & 0xF0) | pix1; - obptr++; - x++; - } - while (x < width) - { - r = *bp2++; - g = *bp2++; - b = *bp2++; - pix0 = (g + ((b + r) >> 1)) >> shift; - x++; - if (x == width) - pix1 = (*obptr & 0x0F); - else - { - r = *bp2++; - g = *bp2++; - b = *bp2++; - pix1 = (g + ((b + r) >> 1)) >> shift; - x++; - } - *obptr++ = (pix0 << 4) | pix1; - } - bptr += rowstride; - obuf += bpl; - } -} - -/* This actually works for depths from 3 to 7 */ -static void -gdk_rgb_convert_gray4_d (GdkRgbInfo *image_info, GdkImage *image, - gint x0, gint y0, gint width, gint height, - const guchar *buf, int rowstride, - gint x_align, gint y_align, GdkRgbCmap *cmap) -{ - int x, y; - gint bpl; - guchar *obuf, *obptr; - const guchar *bptr, *bp2; - gint r, g, b; - const guchar *dmp; - gint prec, right; - gint gray; - - bptr = buf; - bpl = image->bpl; - obuf = ((guchar *)image->mem) + y0 * bpl + x0; - prec = image_info->visual->depth; - right = 8 - prec; - for (y = 0; y < height; y++) - { - bp2 = bptr; - obptr = obuf; - dmp = DM[(y_align + y) & (DM_HEIGHT - 1)]; - for (x = 0; x < width; x++) - { - r = *bp2++; - g = *bp2++; - b = *bp2++; - gray = (g + ((b + r) >> 1)) >> 1; - gray += (dmp[(x_align + x) & (DM_WIDTH - 1)] << 2) >> prec; - obptr[0] = (gray - (gray >> prec)) >> right; - obptr++; - } - bptr += rowstride; - obuf += bpl; - } -} - -static void -gdk_rgb_convert_gray4_d_pack (GdkRgbInfo *image_info, GdkImage *image, - gint x0, gint y0, gint width, gint height, - const guchar *buf, int rowstride, - gint x_align, gint y_align, GdkRgbCmap *cmap) -{ - int x, y; - gint bpl; - guchar *obuf, *obptr; - const guchar *bptr, *bp2; - gint r, g, b; - const guchar *dmp; - gint prec, right; - gint gray; - guchar pix0, pix1; - /* todo: this is hardcoded to big-endian. Make endian-agile. */ - - bptr = buf; - bpl = image->bpl; - obuf = ((guchar *)image->mem) + y0 * bpl + (x0 >> 1); - prec = image_info->visual->depth; - right = 8 - prec; - for (y = 0; y < height; y++) - { - bp2 = bptr; - obptr = obuf; - dmp = DM[(y_align + y) & (DM_HEIGHT - 1)]; - - x = 0; - if (x0 & 1) - { - r = *bp2++; - g = *bp2++; - b = *bp2++; - gray = (g + ((b + r) >> 1)) >> 1; - gray += (dmp[(x_align + x + 1) & (DM_WIDTH - 1)] << 2) >> prec; - pix1 = (gray - (gray >> prec)) >> right; - *obptr = (*obptr & 0xF0) | pix1; - obptr++; - x++; - } - while (x < width) - { - r = *bp2++; - g = *bp2++; - b = *bp2++; - gray = (g + ((b + r) >> 1)) >> 1; - gray += (dmp[(x_align + x) & (DM_WIDTH - 1)] << 2) >> prec; - pix0 = (gray - (gray >> prec)) >> right; - x++; - if (x == width) - pix1 = (*obptr & 0x0F); - else - { - r = *bp2++; - g = *bp2++; - b = *bp2++; - gray = (g + ((b + r) >> 1)) >> 1; - gray += (dmp[(x_align + x + 1) & (DM_WIDTH - 1)] << 2) >> prec; - pix1 = (gray - (gray >> prec)) >> right; - x++; - } - *obptr++ = (pix0 << 4) | pix1; - } - bptr += rowstride; - obuf += bpl; - } -} - -static void -gdk_rgb_convert_1 (GdkRgbInfo *image_info, GdkImage *image, - gint x0, gint y0, gint width, gint height, - const guchar *buf, int rowstride, - gint x_align, gint y_align, - GdkRgbCmap *cmap) -{ - int x, y; - gint bpl; - guchar *obuf, *obptr; - const guchar *bptr, *bp2; - gint r, g, b; - const guchar *dmp; - gint dith; - guchar byte; - - bptr = buf; - bpl = image->bpl; - obuf = ((guchar *)image->mem) + y0 * bpl + (x0 >> 3); - byte = 0; /* unnecessary, but it keeps gcc from complaining */ - for (y = 0; y < height; y++) - { - dmp = DM[(y_align + y) & (DM_HEIGHT - 1)]; - bp2 = bptr; - obptr = obuf; - for (x = 0; x < width; x++) - { - r = *bp2++; - g = *bp2++; - b = *bp2++; - dith = (dmp[(x_align + x) & (DM_WIDTH - 1)] << 4) | 4; - byte += byte + (r + g + g + b + dith > 1020); - if ((x & 7) == 7) - { - obptr[0] = byte; - obptr++; - } - } - if (x & 7) - obptr[0] = byte << (8 - (x & 7)); - bptr += rowstride; - obuf += bpl; - } -} - -/* Returns a pointer to the stage buffer. */ -static guchar * -gdk_rgb_ensure_stage (GdkRgbInfo *image_info) -{ - if (image_info->stage_buf == NULL) - image_info->stage_buf = g_malloc (GDK_SCRATCH_IMAGE_HEIGHT * STAGE_ROWSTRIDE); - return image_info->stage_buf; -} - -/* This is slow. Speed me up, please. */ -static void -gdk_rgb_32_to_stage (GdkRgbInfo *image_info, - const guchar *buf, gint rowstride, gint width, gint height) -{ - gint x, y; - const guchar *pi_start; - guchar *po_start; - const guchar *pi; - guchar *po; - - pi_start = buf; - po_start = gdk_rgb_ensure_stage (image_info); - for (y = 0; y < height; y++) - { - pi = pi_start; - po = po_start; - for (x = 0; x < width; x++) - { - *po++ = *pi++; - *po++ = *pi++; - *po++ = *pi++; - pi++; - } - pi_start += rowstride; - po_start += STAGE_ROWSTRIDE; - } -} - -/* Generic 32bit RGB conversion function - convert to 24bit packed, then - go from there. */ -static void -gdk_rgb_convert_32_generic (GdkRgbInfo *image_info, GdkImage *image, - gint x0, gint y0, gint width, gint height, - const guchar *buf, gint rowstride, - gint x_align, gint y_align, GdkRgbCmap *cmap) -{ - gdk_rgb_32_to_stage (image_info, buf, rowstride, width, height); - - (*image_info->conv) (image_info, image, x0, y0, width, height, - image_info->stage_buf, STAGE_ROWSTRIDE, - x_align, y_align, cmap); -} - -/* Generic 32bit RGB conversion function - convert to 24bit packed, then - go from there. */ -static void -gdk_rgb_convert_32_generic_d (GdkRgbInfo *image_info, GdkImage *image, - gint x0, gint y0, gint width, gint height, - const guchar *buf, gint rowstride, - gint x_align, gint y_align, GdkRgbCmap *cmap) -{ - gdk_rgb_32_to_stage (image_info, buf, rowstride, width, height); - - (*image_info->conv_d) (image_info, image, x0, y0, width, height, - image_info->stage_buf, STAGE_ROWSTRIDE, - x_align, y_align, cmap); -} - -/* This is slow. Speed me up, please. */ -static void -gdk_rgb_gray_to_stage (GdkRgbInfo *image_info, - const guchar *buf, gint rowstride, gint width, gint height) -{ - gint x, y; - const guchar *pi_start; - guchar *po_start; - const guchar *pi; - guchar *po; - guchar gray; - - pi_start = buf; - po_start = gdk_rgb_ensure_stage (image_info); - for (y = 0; y < height; y++) - { - pi = pi_start; - po = po_start; - for (x = 0; x < width; x++) - { - gray = *pi++; - *po++ = gray; - *po++ = gray; - *po++ = gray; - } - pi_start += rowstride; - po_start += STAGE_ROWSTRIDE; - } -} - -/* Generic gray conversion function - convert to 24bit packed, then go - from there. */ -static void -gdk_rgb_convert_gray_generic (GdkRgbInfo *image_info, GdkImage *image, - gint x0, gint y0, gint width, gint height, - const guchar *buf, gint rowstride, - gint x_align, gint y_align, GdkRgbCmap *cmap) -{ - gdk_rgb_gray_to_stage (image_info, buf, rowstride, width, height); - - (*image_info->conv) (image_info, image, x0, y0, width, height, - image_info->stage_buf, STAGE_ROWSTRIDE, - x_align, y_align, cmap); -} - -static void -gdk_rgb_convert_gray_generic_d (GdkRgbInfo *image_info, GdkImage *image, - gint x0, gint y0, gint width, gint height, - const guchar *buf, gint rowstride, - gint x_align, gint y_align, GdkRgbCmap *cmap) -{ - gdk_rgb_gray_to_stage (image_info, buf, rowstride, width, height); - - (*image_info->conv_d) (image_info, image, x0, y0, width, height, - image_info->stage_buf, STAGE_ROWSTRIDE, - x_align, y_align, cmap); -} - -/* Render grayscale using indexed method. */ -static void -gdk_rgb_convert_gray_cmap (GdkRgbInfo *image_info, GdkImage *image, - gint x0, gint y0, gint width, gint height, - const guchar *buf, gint rowstride, - gint x_align, gint y_align, GdkRgbCmap *cmap) -{ - (*image_info->conv_indexed) (image_info, image, x0, y0, width, height, - buf, rowstride, - x_align, y_align, image_info->gray_cmap); -} - -#if 0 -static void -gdk_rgb_convert_gray_cmap_d (GdkRgbInfo *image_info, GdkImage *image, - gint x0, gint y0, gint width, gint height, - const guchar *buf, gint rowstride, - gint x_align, gint y_align, GdkRgbCmap *cmap) -{ - (*image_info->conv_indexed_d) (image_info, image, x0, y0, width, height, - buf, rowstride, - x_align, y_align, image_info->gray_cmap); -} -#endif - -/* This is slow. Speed me up, please. */ -static void -gdk_rgb_indexed_to_stage (GdkRgbInfo *image_info, - const guchar *buf, gint rowstride, gint width, gint height, - GdkRgbCmap *cmap) -{ - gint x, y; - const guchar *pi_start; - guchar *po_start; - const guchar *pi; - guchar *po; - gint rgb; - - pi_start = buf; - po_start = gdk_rgb_ensure_stage (image_info); - for (y = 0; y < height; y++) - { - pi = pi_start; - po = po_start; - for (x = 0; x < width; x++) - { - rgb = cmap->colors[*pi++]; - *po++ = rgb >> 16; - *po++ = (rgb >> 8) & 0xff; - *po++ = rgb & 0xff; - } - pi_start += rowstride; - po_start += STAGE_ROWSTRIDE; - } -} - -/* Generic gray conversion function - convert to 24bit packed, then go - from there. */ -static void -gdk_rgb_convert_indexed_generic (GdkRgbInfo *image_info, GdkImage *image, - gint x0, gint y0, gint width, gint height, - const guchar *buf, gint rowstride, - gint x_align, gint y_align, GdkRgbCmap *cmap) -{ - gdk_rgb_indexed_to_stage (image_info, buf, rowstride, width, height, cmap); - - (*image_info->conv) (image_info, image, x0, y0, width, height, - image_info->stage_buf, STAGE_ROWSTRIDE, - x_align, y_align, cmap); -} - -static void -gdk_rgb_convert_indexed_generic_d (GdkRgbInfo *image_info, GdkImage *image, - gint x0, gint y0, gint width, gint height, - const guchar *buf, gint rowstride, - gint x_align, gint y_align, - GdkRgbCmap *cmap) -{ - gdk_rgb_indexed_to_stage (image_info, buf, rowstride, width, height, cmap); - - (*image_info->conv_d) (image_info, image, x0, y0, width, height, - image_info->stage_buf, STAGE_ROWSTRIDE, - x_align, y_align, cmap); -} - -/* Select a conversion function based on the visual and a - representative image. */ -static void -gdk_rgb_select_conv (GdkRgbInfo *image_info) -{ - GdkByteOrder byte_order; - gint depth, bpp, byterev; - GdkVisualType vtype; - guint32 red_mask, green_mask, blue_mask; - GdkRgbConvFunc conv, conv_d; - GdkRgbConvFunc conv_32, conv_32_d; - GdkRgbConvFunc conv_gray, conv_gray_d; - GdkRgbConvFunc conv_indexed, conv_indexed_d; - gboolean mask_rgb, mask_bgr; - GdkScreen *screen = gdk_visual_get_screen (image_info->visual); - - depth = image_info->visual->depth; - - bpp = _gdk_windowing_get_bits_for_depth (gdk_screen_get_display (screen), - image_info->visual->depth); - - byte_order = image_info->visual->byte_order; if (gdk_rgb_verbose) - g_print ("Chose visual type=%d depth=%d, image bpp=%d, %s first\n", - image_info->visual->type, image_info->visual->depth, - bpp, byte_order == GDK_LSB_FIRST ? "lsb" : "msb"); + g_print ("Chose visual type=%d depth=%d, image bpp=%d, %s first, vector code: %s\n", + type, depth, bits, visual->byte_order == GDK_LSB_FIRST ? "lsb" : "msb", + _gdk_rgb_simd_get ()->name); -#if G_BYTE_ORDER == G_BIG_ENDIAN - byterev = (byte_order == GDK_LSB_FIRST); -#else - byterev = (byte_order == GDK_MSB_FIRST); -#endif + info->dith_default = FALSE; + info->index_row = info->index_row_dither = NULL; - vtype = image_info->visual->type; - if (vtype == GDK_VISUAL_DIRECT_COLOR) - vtype = GDK_VISUAL_TRUE_COLOR; - - red_mask = image_info->visual->red_mask; - green_mask = image_info->visual->green_mask; - blue_mask = image_info->visual->blue_mask; - - mask_rgb = red_mask == 0xff0000 && green_mask == 0xff00 && blue_mask == 0xff; - mask_bgr = red_mask == 0xff && green_mask == 0xff00 && blue_mask == 0xff0000; - - conv = NULL; - conv_d = NULL; - - conv_32 = gdk_rgb_convert_32_generic; - conv_32_d = gdk_rgb_convert_32_generic_d; - - conv_gray = gdk_rgb_convert_gray_generic; - conv_gray_d = gdk_rgb_convert_gray_generic_d; - - conv_indexed = gdk_rgb_convert_indexed_generic; - conv_indexed_d = gdk_rgb_convert_indexed_generic_d; - - image_info->dith_default = FALSE; - - if (image_info->bitmap) - conv = gdk_rgb_convert_1; - else if (bpp == 16 && depth == 16 && !byterev && - red_mask == 0xf800 && green_mask == 0x7e0 && blue_mask == 0x1f) + if (info->bitmap) + info->index_row = gdk_rgb_index_row_mono; + else if ((type == GDK_VISUAL_TRUE_COLOR || type == GDK_VISUAL_DIRECT_COLOR) && + (bits == 8 || bits == 16 || bits == 24 || bits == 32)) + gdk_rgb_init_truecolor (info, bits); + else if (bits == 8 && depth > 4 && depth <= 8 && + (type == GDK_VISUAL_PSEUDO_COLOR || type == GDK_VISUAL_STATIC_COLOR || + type == GDK_VISUAL_GRAYSCALE)) { - conv = gdk_rgb_convert_565; - conv_d = gdk_rgb_convert_565_d; - conv_gray = gdk_rgb_convert_565_gray; - gdk_rgb_preprocess_dm_565 (); + /* Depths 5 to 7 only happen on Win32, for restricted palettes. */ + info->dith_default = TRUE; + info->index_row = gdk_rgb_index_row_cube; + if (type != GDK_VISUAL_GRAYSCALE) + info->index_row_dither = gdk_rgb_index_row_cube_dither; } - else if (bpp == 16 && depth == 16 && - vtype == GDK_VISUAL_TRUE_COLOR && byterev && - red_mask == 0xf800 && green_mask == 0x7e0 && blue_mask == 0x1f) - conv = gdk_rgb_convert_565_br; - - else if (bpp == 16 && depth == 15 && - vtype == GDK_VISUAL_TRUE_COLOR && !byterev && - red_mask == 0x7c00 && green_mask == 0x3e0 && blue_mask == 0x1f) - conv = gdk_rgb_convert_555; - - else if (bpp == 16 && depth == 15 && - vtype == GDK_VISUAL_TRUE_COLOR && byterev && - red_mask == 0x7c00 && green_mask == 0x3e0 && blue_mask == 0x1f) - conv = gdk_rgb_convert_555_br; - - /* I'm not 100% sure about the 24bpp tests - but testing will show*/ - else if (bpp == 24 && depth == 24 && vtype == GDK_VISUAL_TRUE_COLOR && - ((mask_rgb && byte_order == GDK_LSB_FIRST) || - (mask_bgr && byte_order == GDK_MSB_FIRST))) - conv = gdk_rgb_convert_888_lsb; - else if (bpp == 24 && depth == 24 && vtype == GDK_VISUAL_TRUE_COLOR && - ((mask_rgb && byte_order == GDK_MSB_FIRST) || - (mask_bgr && byte_order == GDK_LSB_FIRST))) - conv = gdk_rgb_convert_888_msb; - else if (bpp == 32 && - (depth == 24 || depth == 32) && - vtype == GDK_VISUAL_TRUE_COLOR && - (mask_rgb && byte_order == GDK_MSB_FIRST)) - conv = gdk_rgb_convert_0888_br; - else if (bpp == 32 && - (depth == 24 || depth == 32) && - vtype == GDK_VISUAL_TRUE_COLOR && - (mask_rgb && byte_order == GDK_LSB_FIRST)) + else if (gray && depth >= 2 && depth <= 8 && depth <= bits) { -#ifdef USE_MEDIALIB25 - if (_gdk_use_medialib ()) - conv = gdk_rgb_convert_0888_medialib; - else - conv = gdk_rgb_convert_0888; -#else - conv = gdk_rgb_convert_0888; -#endif + info->index_row = gdk_rgb_index_row_gray; + if (depth < 8) + info->index_row_dither = gdk_rgb_index_row_gray_dither; } - -#if G_BYTE_ORDER == G_BIG_ENDIAN - else if (bpp == 32 && depth == 24 && vtype == GDK_VISUAL_TRUE_COLOR && - (mask_bgr && byte_order == GDK_MSB_FIRST)) - conv = gdk_rgb_convert_8880_br; - else if (bpp == 32 && depth == 32 && vtype == GDK_VISUAL_TRUE_COLOR && - (mask_rgb && byte_order == GDK_LSB_FIRST)) - conv = gdk_rgb_convert_8880_br; - else if (bpp == 32 && depth == 32 && vtype == GDK_VISUAL_TRUE_COLOR && - (mask_rgb && byte_order == GDK_MSB_FIRST)) - conv = gdk_rgb_convert_8880_br; -#else - else if (bpp == 32 && depth == 24 && vtype == GDK_VISUAL_TRUE_COLOR && - (mask_bgr && byte_order == GDK_LSB_FIRST)) - conv = gdk_rgb_convert_8880_br; - else if (bpp == 32 && depth == 32 && vtype == GDK_VISUAL_TRUE_COLOR && - (mask_rgb && byte_order == GDK_LSB_FIRST)) - { -#ifdef USE_MEDIALIB25 - if (_gdk_use_medialib ()) - conv = gdk_rgb_convert_0888_medialib; - else - conv = gdk_rgb_convert_0888; -#else - conv = gdk_rgb_convert_0888; -#endif - } -#endif - else if (bpp == 32 && (depth == 30 || depth == 32) && - vtype == GDK_VISUAL_TRUE_COLOR && - byte_order == GDK_LSB_FIRST && - red_mask == 0x000003ff && - green_mask == 0x000ffc00 && - blue_mask == 0x3ff00000) - conv = gdk_rgb_convert_101010_r_low_lsb; - else if (bpp == 32 && (depth == 30 || depth == 32) && - vtype == GDK_VISUAL_TRUE_COLOR && - byte_order == GDK_LSB_FIRST && - red_mask == 0x3ff00000 && - green_mask == 0x000ffc00 && - blue_mask == 0x000003ff) - conv = gdk_rgb_convert_101010_b_low_lsb; - else if (bpp == 32 && (depth == 30 || depth == 32) && - vtype == GDK_VISUAL_TRUE_COLOR && - byte_order == GDK_MSB_FIRST && - red_mask == 0x000003ff && - green_mask == 0x000ffc00 && - blue_mask == 0x3ff00000) - conv = gdk_rgb_convert_101010_r_low_msb; - else if (bpp == 32 && (depth == 30 || depth == 32) && - vtype == GDK_VISUAL_TRUE_COLOR && - byte_order == GDK_MSB_FIRST && - red_mask == 0x3ff00000 && - green_mask == 0x000ffc00 && - blue_mask == 0x000003ff) - conv = gdk_rgb_convert_101010_b_low_msb; - else if (vtype == GDK_VISUAL_TRUE_COLOR && byte_order == GDK_LSB_FIRST) - { - conv = gdk_rgb_convert_truecolor_lsb; - conv_d = gdk_rgb_convert_truecolor_lsb_d; - } - else if (vtype == GDK_VISUAL_TRUE_COLOR && byte_order == GDK_MSB_FIRST) - { - conv = gdk_rgb_convert_truecolor_msb; - conv_d = gdk_rgb_convert_truecolor_msb_d; - } - else if (bpp == 8 && - depth <= 8 && - depth > 4 && - (vtype == GDK_VISUAL_PSEUDO_COLOR - || vtype == GDK_VISUAL_STATIC_COLOR -#ifdef ENABLE_GRAYSCALE - || vtype == GDK_VISUAL_GRAYSCALE -#endif - )) - { - /* Mainly for Win32: use these conversion functions also for the - * explicitly (on user request) restricted palette versions of - * 256-color, i.e. depths 5, 6 and 7. On X11, such depths - * probably never occur. - */ - image_info->dith_default = TRUE; - conv = gdk_rgb_convert_8; - if (vtype != GDK_VISUAL_GRAYSCALE) - { - if (image_info->nred_shades == 6 && - image_info->ngreen_shades == 6 && - image_info->nblue_shades == 6) - conv_d = gdk_rgb_convert_8_d666; - else - conv_d = gdk_rgb_convert_8_d; - } - conv_indexed = gdk_rgb_convert_8_indexed; - conv_gray = gdk_rgb_convert_gray_cmap; - } - else if (bpp == 8 && depth == 8 && (vtype == GDK_VISUAL_STATIC_GRAY -#ifdef not_ENABLE_GRAYSCALE - || vtype == GDK_VISUAL_GRAYSCALE -#endif - )) - { - conv = gdk_rgb_convert_gray8; - conv_gray = gdk_rgb_convert_gray8_gray; - } - else if (bpp == 8 && depth < 8 && depth >= 2 && - (vtype == GDK_VISUAL_STATIC_GRAY - || vtype == GDK_VISUAL_GRAYSCALE)) - { - conv = gdk_rgb_convert_gray4; - conv_d = gdk_rgb_convert_gray4_d; - } - else if (bpp == 8 && depth < 8 && depth >= 3) - { - conv = gdk_rgb_convert_4; - } - else if (bpp == 4 && depth <= 4 && depth >= 2 && - (vtype == GDK_VISUAL_STATIC_GRAY - || vtype == GDK_VISUAL_GRAYSCALE)) - { - conv = gdk_rgb_convert_gray4_pack; - conv_d = gdk_rgb_convert_gray4_d_pack; - } - else if (bpp == 4 && depth <= 4 && depth >= 2 && - vtype == GDK_VISUAL_STATIC_COLOR) - conv = gdk_rgb_convert_4_pack; - - if (!conv) + else if (depth >= 3 && depth <= 7 && depth <= bits && bits <= 8 && info->colorcube_d) + info->index_row = gdk_rgb_index_row_cube_222; + else g_error ("Visual type=%d depth=%d, image bpp=%d, %s first\n" - "is not supported by GdkRGB. Please submit a bug report\n" - "with the above values to bugzilla.gnome.org", - vtype, depth, bpp, - byte_order == GDK_LSB_FIRST ? "lsb" : "msb"); + "is not supported by GdkRGB.", + type, depth, bits, visual->byte_order == GDK_LSB_FIRST ? "lsb" : "msb"); - if (conv_d == NULL) - conv_d = conv; - - image_info->conv = conv; - image_info->conv_d = conv_d; - - image_info->conv_32 = conv_32; - image_info->conv_32_d = conv_32_d; - - image_info->conv_gray = conv_gray; - image_info->conv_gray_d = conv_gray_d; - - image_info->conv_indexed = conv_indexed; - image_info->conv_indexed_d = conv_indexed_d; + if (info->index_row_dither == NULL) + info->index_row_dither = info->index_row; } -static void -gdk_draw_rgb_image_core (GdkRgbInfo *image_info, - GdkDrawable *drawable, - GdkGC *gc, - gint x, - gint y, - gint width, - gint height, - const guchar *buf, - gint pixstride, - gint rowstride, - GdkRgbConvFunc conv, - GdkRgbCmap *cmap, - gint xdith, - gint ydith) +/* Whether dithering changes anything for this visual. */ +static gboolean +gdk_rgb_info_ditherable (GdkRgbInfo *info) { - gint y0, x0; - gint xs0, ys0; - GdkImage *image; - gint width1, height1; - const guchar *buf_ptr; + if (info->tables) + return info->ditherable; - if (image_info->bitmap) + return info->index_row_dither != info->index_row; +} + +/* Converts @width x @height pixels of @buf into @image at @x0, @y0. */ +static void +gdk_rgb_convert (GdkRgbInfo *info, + GdkImage *image, + gint x0, + gint y0, + gint width, + gint height, + GdkRgbInput input, + const guchar *buf, + gint rowstride, + gboolean dither, + gint x_dith, + gint y_dith, + GdkRgbCmap *cmap) +{ + guint32 stage_words[(ROW_MAX * 3 + 3) / 4]; /* aligned for word loads */ + guchar *stage = (guchar *) stage_words; + guint32 row[ROW_MAX]; + guint32 lut[256]; + guchar *out = (guchar *) image->mem + y0 * image->bpl; + gint bits = image->bits_per_pixel; + gboolean msb_first = image->byte_order == GDK_MSB_FIRST; + GdkRgbIndexRowFunc index_row; + GdkRgbCmapInfo *cmap_info = NULL; + gint y, i; + + dither = dither && gdk_rgb_info_ditherable (info); + + if (info->tables) { - if (image_info->own_gc == NULL) - image_info->own_gc = gdk_gc_new (drawable); - gc = image_info->own_gc; + const guint32 *t = info->tables; + gboolean use_lut; + + /* Each color of a palette is converted once, and so are the gray + * levels of larger gray images. */ + use_lut = !dither && + (input == GDK_RGB_INPUT_INDEXED || + (input == GDK_RGB_INPUT_GRAY && width * height >= 1024 && + !(info->layout == GDK_RGB_LAYOUT_BYTES && bits == 24))); + if (use_lut && input == GDK_RGB_INPUT_INDEXED) + for (i = 0; i < 256; i++) + lut[i] = t[(cmap->colors[i] >> 16) & 0xff] | + t[256 + ((cmap->colors[i] >> 8) & 0xff)] | + t[512 + (cmap->colors[i] & 0xff)]; + else if (use_lut) + for (i = 0; i < 256; i++) + lut[i] = t[i] | t[256 + i] | t[512 + i]; + + for (y = 0; y < height; y++, buf += rowstride, out += image->bpl) + { + guchar *p = out + x0 * (bits / 8); + + if (dither) + gdk_rgb_truecolor_row (info, p, row, bits, msb_first, GDK_RGB_INPUT_RGB, + gdk_rgb_stage_row (stage, input, buf, width, cmap), + width, NULL, DM[(y_dith + y) & (DM_HEIGHT - 1)], x_dith); + else + gdk_rgb_truecolor_row (info, p, row, bits, msb_first, input, buf, width, + use_lut ? lut : NULL, NULL, 0); + } + return; } - for (y0 = 0; y0 < height; y0 += GDK_SCRATCH_IMAGE_HEIGHT) + + index_row = dither ? info->index_row_dither : info->index_row; + + /* 8-bit palettes look indexed images up in a table per GdkRgbCmap. */ + if (bits == 8 && index_row == gdk_rgb_index_row_cube) { - height1 = MIN (height - y0, GDK_SCRATCH_IMAGE_HEIGHT); - for (x0 = 0; x0 < width; x0 += GDK_SCRATCH_IMAGE_WIDTH) - { - width1 = MIN (width - x0, GDK_SCRATCH_IMAGE_WIDTH); - buf_ptr = buf + y0 * rowstride + x0 * pixstride; - - image = _gdk_image_get_scratch (gdk_drawable_get_screen (drawable), - width1, height1, - image_info->visual->depth, &xs0, &ys0); - - conv (image_info, image, xs0, ys0, width1, height1, buf_ptr, rowstride, - x + x0 + xdith, y + y0 + ydith, cmap); - -#ifndef DONT_ACTUALLY_DRAW - gdk_draw_image (drawable, gc, - image, xs0, ys0, x + x0, y + y0, width1, height1); -#endif - } + if (input == GDK_RGB_INPUT_GRAY && info->gray_cmap) + cmap = info->gray_cmap, input = GDK_RGB_INPUT_INDEXED; + if (input == GDK_RGB_INPUT_INDEXED) + cmap_info = gdk_rgb_cmap_get_info (cmap, info); } + + for (y = 0; y < height; y++, buf += rowstride, out += image->bpl) + { + const guchar *dm = DM[(y_dith + y) & (DM_HEIGHT - 1)]; + guchar *pixels = bits == 8 ? out + x0 : (guchar *) row; + + if (cmap_info) + for (i = 0; i < width; i++) + pixels[i] = cmap_info->lut[buf[i]]; + else + index_row (info, pixels, gdk_rgb_stage_row (stage, input, buf, width, cmap), + width, dm, x_dith); + + if (bits < 8) + gdk_rgb_pack_row (out, x0, pixels, width, bits, msb_first); + } +} + +#define T(c, v) (tables[(c) * 256 + (v)]) + +/* @a * @s + (255 - @a) * @d, divided by 255 and rounded */ +static inline guint +gdk_rgb_blend8 (guint a, + guint s, + guint d) +{ + guint t = a * s + (255 - a) * d + 0x80; + + return (t + (t >> 8)) >> 8; +} + +/* Blends a row of RGBA (not premultiplied) over pixels with channels of + * up to 8 bits, rounding as gdk-pixbuf does. */ +#define DEFINE_COMPOSITE_ROW(name, type) \ +static void \ +name (GdkRgbInfo *info, type *pix, const guchar *src, gint width) \ +{ \ + const guint32 *tables = info->tables; \ + const guint8 *ur = info->unpack[0], *ug = info->unpack[1], *ub = info->unpack[2]; \ + const gint rs = info->shift16[0][1], gs = info->shift16[1][1], bs = info->shift16[2][1]; \ + const guint rm = info->visual->red_mask >> rs; \ + const guint gm = info->visual->green_mask >> gs; \ + const guint bm = info->visual->blue_mask >> bs; \ + gint x; \ + \ + for (x = 0; x < width; x++, src += 4) \ + { \ + const guint a = src[3]; \ + guint32 p; \ + \ + if (a == 0) \ + continue; \ + if (a == 255) \ + { \ + pix[x] = T (0, src[0]) | T (1, src[1]) | T (2, src[2]); \ + continue; \ + } \ + p = pix[x]; \ + pix[x] = T (0, gdk_rgb_blend8 (a, src[0], ur[(p >> rs) & rm])) | \ + T (1, gdk_rgb_blend8 (a, src[1], ug[(p >> gs) & gm])) | \ + T (2, gdk_rgb_blend8 (a, src[2], ub[(p >> bs) & bm])); \ + } \ +} + +DEFINE_COMPOSITE_ROW (gdk_rgb_composite_row16, guint16) +DEFINE_COMPOSITE_ROW (gdk_rgb_composite_row32, guint32) + +#undef DEFINE_COMPOSITE_ROW + +/* The same for channels of more than 8 bits (30-bit visuals): the + * channel keeps its precision, the source is widened to it. */ +static void +gdk_rgb_composite_row_deep (GdkRgbInfo *info, + guint32 *pix, + const guchar *src, + gint width) +{ + const guint32 *tables = info->tables; + GdkVisual *visual = info->visual; + const gint prec[3] = { visual->red_prec, visual->green_prec, visual->blue_prec }; + const guint32 mask[3] = { visual->red_mask, visual->green_mask, visual->blue_mask }; + gint x, c; + + for (x = 0; x < width; x++, src += 4) + { + const guint a = src[3]; + guint32 p; + + if (a == 0) + continue; + if (a == 255) + { + pix[x] = T (0, src[0]) | T (1, src[1]) | T (2, src[2]); + continue; + } + + p = info->fill; + for (c = 0; c < 3; c++) + { + const gint shift = info->shift16[c][1]; + const guint d = (pix[x] & mask[c]) >> shift; + + if (prec[c] <= 8) + p |= T (c, gdk_rgb_blend8 (a, src[c], info->unpack[c][d])) & mask[c]; + else + { + /* T () widens 8 bits by repeating them */ + const guint s = (T (c, src[c]) & mask[c]) >> shift; + + p |= ((a * s + (255 - a) * d + 127) / 255) << shift; + } + } + pix[x] = p; + } +} + +#undef T + +/** + * _gdk_rgb_composite: + * @colormap: the colormap of the drawable @image was read from + * @image: pixels of the drawable + * @rgba: RGBA pixels, not premultiplied + * @dither: the dithering the caller asked for + * + * Blends @width x @height pixels of @rgba over @image at @x0, @y0. + * + * Return value: %FALSE when this can't be done on the image itself: + * for palettes and gray levels, and when dithering is wanted + */ +gboolean +_gdk_rgb_composite (GdkColormap *colormap, + GdkImage *image, + gint x0, + gint y0, + gint width, + gint height, + const guchar *rgba, + gint rowstride, + GdkRgbDither dither) +{ + GdkRgbInfo *info = gdk_rgb_get_info_from_colormap (colormap); + GdkVisual *visual = info->visual; + gint bits = image->bits_per_pixel; + gboolean msb_first = image->byte_order == GDK_MSB_FIRST; + gboolean native = msb_first == (G_BYTE_ORDER == G_BIG_ENDIAN); + gboolean deep = visual->red_prec > 8 || visual->green_prec > 8 || visual->blue_prec > 8; + const GdkRgbSimd *simd = _gdk_rgb_simd_get (); + guchar *out = (guchar *) image->mem + y0 * image->bpl + x0 * (bits / 8); + guint32 row[ROW_MAX]; + gint y; + + if (!info->tables || bits % 8 != 0 || width > ROW_MAX || + (dither == GDK_RGB_DITHER_MAX && info->ditherable)) + return FALSE; + + for (y = 0; y < height; y++, rgba += rowstride, out += image->bpl) + { + gint done = 0; + + /* vector code where there is some, C for the rest of the row */ + if (native && bits == 16 && info->layout == GDK_RGB_LAYOUT_565 && simd->composite_565) + done = simd->composite_565 ((guint16 *) out, rgba, width); + else if (native && bits == 16 && info->layout == GDK_RGB_LAYOUT_555 && simd->composite_555) + done = simd->composite_555 ((guint16 *) out, rgba, width); + else if (native && bits == 32 && info->layout == GDK_RGB_LAYOUT_X888 && simd->composite_x888) + done = simd->composite_x888 ((guint32 *) out, rgba, width); + + if (native && bits == 16 && !deep) + gdk_rgb_composite_row16 (info, (guint16 *) out + done, rgba + done * 4, width - done); + else if (native && bits == 32 && !deep) + gdk_rgb_composite_row32 (info, (guint32 *) out + done, rgba + done * 4, width - done); + else if (native && bits == 32) + gdk_rgb_composite_row_deep (info, (guint32 *) out, rgba, width); + else + { + _gdk_image_read_row (image, x0, y0 + y, width, row); + if (deep) + gdk_rgb_composite_row_deep (info, row, rgba, width); + else + gdk_rgb_composite_row32 (info, row, rgba, width); + gdk_rgb_store_row (out, row, width, bits, msb_first); + } + } + + return TRUE; +} + +/** + * _gdk_rgb_prefers_own_blending: + * @colormap: a colormap + * @dither: the dithering asked for + * + * Whether pixbufs with alpha look better blended by GdkRGB than by + * the RENDER extension: for palettes and gray levels, which RENDER + * maps to its nearest colors, and for dithering, which RENDER doesn't do. + */ +gboolean +_gdk_rgb_prefers_own_blending (GdkColormap *colormap, + GdkRgbDither dither) +{ + GdkRgbInfo *info = gdk_rgb_get_info_from_colormap (colormap); + + if (!info->tables) + return TRUE; + + return dither == GDK_RGB_DITHER_MAX && info->ditherable; } static GdkRgbInfo * @@ -3548,6 +2056,62 @@ gdk_rgb_get_info_from_drawable (GdkDrawable *drawable) return gdk_rgb_get_info_from_colormap (cmap); } +static void +gdk_draw_rgb_image_core (GdkDrawable *drawable, + GdkGC *gc, + gint x, + gint y, + gint width, + gint height, + GdkRgbDither dith, + GdkRgbInput input, + const guchar *buf, + gint rowstride, + GdkRgbCmap *cmap, + gint xdith, + gint ydith) +{ + GdkRgbInfo *image_info = gdk_rgb_get_info_from_drawable (drawable); + gint pixstride = gdk_rgb_input_bytes[input]; + gboolean dither; + gint y0, x0; + gint xs0, ys0; + GdkImage *image; + gint width1, height1; + + if (!image_info) + return; + + dither = !(dith == GDK_RGB_DITHER_NONE || + (dith == GDK_RGB_DITHER_NORMAL && !image_info->dith_default)); + + if (image_info->bitmap) + { + if (image_info->own_gc == NULL) + image_info->own_gc = gdk_gc_new (drawable); + gc = image_info->own_gc; + } + for (y0 = 0; y0 < height; y0 += GDK_SCRATCH_IMAGE_HEIGHT) + { + height1 = MIN (height - y0, GDK_SCRATCH_IMAGE_HEIGHT); + for (x0 = 0; x0 < width; x0 += GDK_SCRATCH_IMAGE_WIDTH) + { + width1 = MIN (width - x0, GDK_SCRATCH_IMAGE_WIDTH); + + image = _gdk_image_get_scratch (gdk_drawable_get_screen (drawable), + width1, height1, + image_info->visual->depth, &xs0, &ys0); + + gdk_rgb_convert (image_info, image, xs0, ys0, width1, height1, input, + buf + y0 * rowstride + x0 * pixstride, rowstride, + dither, x + x0 + xdith, y + y0 + ydith, cmap); + + gdk_draw_image (drawable, gc, + image, xs0, ys0, x + x0, y + y0, width1, height1); + } + } +} + void gdk_draw_rgb_image (GdkDrawable *drawable, GdkGC *gc, @@ -3559,21 +2123,11 @@ gdk_draw_rgb_image (GdkDrawable *drawable, const guchar *rgb_buf, gint rowstride) { - GdkRgbInfo *image_info = gdk_rgb_get_info_from_drawable (drawable); - if (!image_info) - return; - - if (dith == GDK_RGB_DITHER_NONE || (dith == GDK_RGB_DITHER_NORMAL && - !image_info->dith_default)) - gdk_draw_rgb_image_core (image_info, drawable, gc, x, y, width, height, - rgb_buf, 3, rowstride, image_info->conv, NULL, - 0, 0); - else - gdk_draw_rgb_image_core (image_info, drawable, gc, x, y, width, height, - rgb_buf, 3, rowstride, image_info->conv_d, NULL, - 0, 0); + gdk_draw_rgb_image_core (drawable, gc, x, y, width, height, dith, + GDK_RGB_INPUT_RGB, rgb_buf, rowstride, NULL, 0, 0); } + void gdk_draw_rgb_image_dithalign (GdkDrawable *drawable, GdkGC *gc, @@ -3587,21 +2141,11 @@ gdk_draw_rgb_image_dithalign (GdkDrawable *drawable, gint xdith, gint ydith) { - GdkRgbInfo *image_info = gdk_rgb_get_info_from_drawable (drawable); - if (!image_info) - return; - - if (dith == GDK_RGB_DITHER_NONE || (dith == GDK_RGB_DITHER_NORMAL && - !image_info->dith_default)) - gdk_draw_rgb_image_core (image_info, drawable, gc, x, y, width, height, - rgb_buf, 3, rowstride, image_info->conv, NULL, - xdith, ydith); - else - gdk_draw_rgb_image_core (image_info, drawable, gc, x, y, width, height, - rgb_buf, 3, rowstride, image_info->conv_d, NULL, - xdith, ydith); + gdk_draw_rgb_image_core (drawable, gc, x, y, width, height, dith, + GDK_RGB_INPUT_RGB, rgb_buf, rowstride, NULL, xdith, ydith); } + void gdk_draw_rgb_32_image (GdkDrawable *drawable, GdkGC *gc, @@ -3613,21 +2157,11 @@ gdk_draw_rgb_32_image (GdkDrawable *drawable, const guchar *buf, gint rowstride) { - GdkRgbInfo *image_info = gdk_rgb_get_info_from_drawable (drawable); - if (!image_info) - return; - - if (dith == GDK_RGB_DITHER_NONE || (dith == GDK_RGB_DITHER_NORMAL && - !image_info->dith_default)) - gdk_draw_rgb_image_core (image_info, drawable, gc, x, y, width, height, - buf, 4, rowstride, - image_info->conv_32, NULL, 0, 0); - else - gdk_draw_rgb_image_core (image_info, drawable, gc, x, y, width, height, - buf, 4, rowstride, - image_info->conv_32_d, NULL, 0, 0); + gdk_draw_rgb_image_core (drawable, gc, x, y, width, height, dith, + GDK_RGB_INPUT_RGBX, buf, rowstride, NULL, 0, 0); } + /** * gdk_draw_rgb_32_image_dithalign: * @drawable: a #GdkDrawable @@ -3660,21 +2194,164 @@ gdk_draw_rgb_32_image_dithalign (GdkDrawable *drawable, gint xdith, gint ydith) { - GdkRgbInfo *image_info = gdk_rgb_get_info_from_drawable (drawable); - if (!image_info) - return; - - if (dith == GDK_RGB_DITHER_NONE || (dith == GDK_RGB_DITHER_NORMAL && - !image_info->dith_default)) - gdk_draw_rgb_image_core (image_info, drawable, gc, x, y, width, height, - buf, 4, rowstride, - image_info->conv_32, NULL, xdith, ydith); - else - gdk_draw_rgb_image_core (image_info, drawable, gc, x, y, width, height, - buf, 4, rowstride, - image_info->conv_32_d, NULL, xdith, ydith); + gdk_draw_rgb_image_core (drawable, gc, x, y, width, height, dith, + GDK_RGB_INPUT_RGBX, buf, rowstride, NULL, xdith, ydith); } + +static void +gdk_draw_rgb16_image (GdkDrawable *drawable, + GdkGC *gc, + gint x, + gint y, + gint width, + gint height, + GdkRgbDither dith, + GdkRgbInput input, + const guint16 *buf, + gint rowstride, + gint xdith, + gint ydith) +{ + g_return_if_fail (GDK_IS_DRAWABLE (drawable)); + g_return_if_fail (GDK_IS_GC (gc)); + g_return_if_fail (buf != NULL); + g_return_if_fail ((((guintptr) buf) & 1) == 0); + g_return_if_fail ((rowstride & 1) == 0); + + gdk_draw_rgb_image_core (drawable, gc, x, y, width, height, dith, input, + (const guchar *) buf, rowstride, NULL, xdith, ydith); +} + +/** + * gdk_draw_rgb_48_image: + * @drawable: a #GdkDrawable + * @gc: a #GdkGC + * @x: destination X coordinate + * @y: destination Y coordinate + * @width: image width + * @height: image height + * @dith: dithering mode + * @rgb_buf: host-endian RGB data with three 16-bit channels per pixel + * @rowstride: number of bytes between consecutive rows + * + * Draws 48-bit RGB image data. + **/ +void +gdk_draw_rgb_48_image (GdkDrawable *drawable, + GdkGC *gc, + gint x, + gint y, + gint width, + gint height, + GdkRgbDither dith, + const guint16 *rgb_buf, + gint rowstride) +{ + gdk_draw_rgb16_image (drawable, gc, x, y, width, height, dith, + GDK_RGB_INPUT_RGB48, rgb_buf, rowstride, 0, 0); +} + + +/** + * gdk_draw_rgb_48_image_dithalign: + * @drawable: a #GdkDrawable + * @gc: a #GdkGC + * @x: destination X coordinate + * @y: destination Y coordinate + * @width: image width + * @height: image height + * @dith: dithering mode + * @rgb_buf: host-endian RGB data with three 16-bit channels per pixel + * @rowstride: number of bytes between consecutive rows + * @xdith: X dither offset + * @ydith: Y dither offset + * + * Draws 48-bit RGB image data with explicit dither alignment. + **/ +void +gdk_draw_rgb_48_image_dithalign (GdkDrawable *drawable, + GdkGC *gc, + gint x, + gint y, + gint width, + gint height, + GdkRgbDither dith, + const guint16 *rgb_buf, + gint rowstride, + gint xdith, + gint ydith) +{ + gdk_draw_rgb16_image (drawable, gc, x, y, width, height, dith, + GDK_RGB_INPUT_RGB48, rgb_buf, rowstride, xdith, ydith); +} + + +/** + * gdk_draw_rgbx_64_image: + * @drawable: a #GdkDrawable + * @gc: a #GdkGC + * @x: destination X coordinate + * @y: destination Y coordinate + * @width: image width + * @height: image height + * @dith: dithering mode + * @rgbx_buf: host-endian RGBX data with four 16-bit channels per pixel + * @rowstride: number of bytes between consecutive rows + * + * Draws 64-bit RGBX image data. The X channel is ignored. + **/ +void +gdk_draw_rgbx_64_image (GdkDrawable *drawable, + GdkGC *gc, + gint x, + gint y, + gint width, + gint height, + GdkRgbDither dith, + const guint16 *rgbx_buf, + gint rowstride) +{ + gdk_draw_rgb16_image (drawable, gc, x, y, width, height, dith, + GDK_RGB_INPUT_RGBX64, rgbx_buf, rowstride, 0, 0); +} + + +/** + * gdk_draw_rgbx_64_image_dithalign: + * @drawable: a #GdkDrawable + * @gc: a #GdkGC + * @x: destination X coordinate + * @y: destination Y coordinate + * @width: image width + * @height: image height + * @dith: dithering mode + * @rgbx_buf: host-endian RGBX data with four 16-bit channels per pixel + * @rowstride: number of bytes between consecutive rows + * @xdith: X dither offset + * @ydith: Y dither offset + * + * Draws 64-bit RGBX image data with explicit dither alignment. + * The X channel is ignored. + **/ +void +gdk_draw_rgbx_64_image_dithalign (GdkDrawable *drawable, + GdkGC *gc, + gint x, + gint y, + gint width, + gint height, + GdkRgbDither dith, + const guint16 *rgbx_buf, + gint rowstride, + gint xdith, + gint ydith) +{ + gdk_draw_rgb16_image (drawable, gc, x, y, width, height, dith, + GDK_RGB_INPUT_RGBX64, rgbx_buf, rowstride, xdith, ydith); +} + + static void gdk_rgb_make_gray_cmap (GdkRgbInfo *info) { @@ -3708,17 +2385,11 @@ gdk_draw_gray_image (GdkDrawable *drawable, image_info->visual->type == GDK_VISUAL_GRAYSCALE)) gdk_rgb_make_gray_cmap (image_info); - if (dith == GDK_RGB_DITHER_NONE || (dith == GDK_RGB_DITHER_NORMAL && - !image_info->dith_default)) - gdk_draw_rgb_image_core (image_info, drawable, gc, x, y, width, height, - buf, 1, rowstride, - image_info->conv_gray, NULL, 0, 0); - else - gdk_draw_rgb_image_core (image_info, drawable, gc, x, y, width, height, - buf, 1, rowstride, - image_info->conv_gray_d, NULL, 0, 0); + gdk_draw_rgb_image_core (drawable, gc, x, y, width, height, dith, + GDK_RGB_INPUT_GRAY, buf, rowstride, NULL, 0, 0); } + static GdkRgbCmapInfo * gdk_rgb_cmap_get_info (GdkRgbCmap *cmap, GdkRgbInfo *image_info) @@ -3739,9 +2410,10 @@ gdk_rgb_cmap_get_info (GdkRgbCmap *cmap, while (tmp_list) { - cmap_info = tmp_list->data; + cmap_info = tmp_list->data; if (cmap_info->image_info == image_info) return cmap_info; + tmp_list = tmp_list->next; } cmap_info = g_new (GdkRgbCmapInfo, 1); @@ -3842,29 +2514,18 @@ gdk_draw_indexed_image (GdkDrawable *drawable, gint rowstride, GdkRgbCmap *cmap) { - GdkRgbInfo *image_info = gdk_rgb_get_info_from_drawable (drawable); - if (!image_info) - return; - - if (dith == GDK_RGB_DITHER_NONE || (dith == GDK_RGB_DITHER_NORMAL && - !image_info->dith_default)) - gdk_draw_rgb_image_core (image_info, drawable, gc, x, y, width, height, - buf, 1, rowstride, - image_info->conv_indexed, cmap, 0, 0); - else - gdk_draw_rgb_image_core (image_info, drawable, gc, x, y, width, height, - buf, 1, rowstride, - image_info->conv_indexed_d, cmap, 0, 0); + gdk_draw_rgb_image_core (drawable, gc, x, y, width, height, dith, + GDK_RGB_INPUT_INDEXED, buf, rowstride, cmap, 0, 0); } + gboolean gdk_rgb_colormap_ditherable (GdkColormap *cmap) { - GdkRgbInfo *image_info = gdk_rgb_get_info_from_colormap (cmap); - - return (image_info->conv != image_info->conv_d); + return gdk_rgb_info_ditherable (gdk_rgb_get_info_from_colormap (cmap)); } + gboolean gdk_rgb_ditherable (void) { diff --git a/gdk/gdkrgb.h b/gdk/gdkrgb.h index 44c576fb5..3fe82df92 100644 --- a/gdk/gdkrgb.h +++ b/gdk/gdkrgb.h @@ -127,7 +127,7 @@ void gdk_draw_indexed_image (GdkDrawable *drawable, const guchar *buf, gint rowstride, GdkRgbCmap *cmap); -GType gdk_rgb_cmap_get_type (void) G_GNUC_CONST; +GType gdk_rgb_cmap_get_type (void); GdkRgbCmap *gdk_rgb_cmap_copy (const GdkRgbCmap *cmap); GdkRgbCmap *gdk_rgb_cmap_new (guint32 *colors, gint n_colors); diff --git a/gdk/gdkrgb16.c b/gdk/gdkrgb16.c deleted file mode 100644 index 2564ef0d8..000000000 --- a/gdk/gdkrgb16.c +++ /dev/null @@ -1,742 +0,0 @@ -/* GTK - The GIMP Toolkit - * High-precision GdkRGB image conversion - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - */ - -#include "config.h" - -#include - -#include "gdkinternals.h" -#include "gdkrgb.h" -#include "gdkscreen.h" -#include "gdkalias.h" - -typedef void (*GdkRgb16ConvFunc) (GdkImage *image, - gint x0, - gint y0, - gint width, - gint height, - const guint16 *buf, - gint rowstride); - -#define GDK_RGB16_STORE_RGB(p, r, g, b, a) G_STMT_START { \ - (p)[0] = (r) >> 8; \ - (p)[1] = (g) >> 8; \ - (p)[2] = (b) >> 8; \ - (p) += 3; \ -} G_STMT_END - -#define GDK_RGB16_STORE_BGR(p, r, g, b, a) G_STMT_START { \ - (p)[0] = (b) >> 8; \ - (p)[1] = (g) >> 8; \ - (p)[2] = (r) >> 8; \ - (p) += 3; \ -} G_STMT_END - -#define GDK_RGB16_STORE_BGRA(p, r, g, b, a) G_STMT_START { \ - (p)[0] = (b) >> 8; \ - (p)[1] = (g) >> 8; \ - (p)[2] = (r) >> 8; \ - (p)[3] = 0xff; \ - (p) += 4; \ -} G_STMT_END - -#define GDK_RGB16_STORE_ARGB(p, r, g, b, a) G_STMT_START { \ - (p)[0] = 0xff; \ - (p)[1] = (r) >> 8; \ - (p)[2] = (g) >> 8; \ - (p)[3] = (b) >> 8; \ - (p) += 4; \ -} G_STMT_END - -#define GDK_RGB16_STORE_RGB0_NATIVE(p, r, g, b, a) G_STMT_START { \ - guint32 pixel__ = (((b) >> 8) << 16) | \ - (((g) >> 8) << 8) | \ - ((r) >> 8); \ - memcpy ((p), &pixel__, sizeof (pixel__)); \ - (p) += 4; \ -} G_STMT_END - -#define GDK_RGB16_STORE_565(p, r, g, b, a) G_STMT_START { \ - guint16 pixel__ = ((r) & 0xf800) | \ - (((g) & 0xfc00) >> 5) | \ - ((b) >> 11); \ - memcpy ((p), &pixel__, sizeof (pixel__)); \ - (p) += 2; \ -} G_STMT_END - -#define GDK_RGB16_STORE_565_BR(p, r, g, b, a) G_STMT_START { \ - guint16 pixel__ = ((r) & 0xf800) | \ - (((g) & 0xfc00) >> 5) | \ - ((b) >> 11); \ - pixel__ = (pixel__ >> 8) | (pixel__ << 8); \ - memcpy ((p), &pixel__, sizeof (pixel__)); \ - (p) += 2; \ -} G_STMT_END - -#define GDK_RGB16_STORE_555(p, r, g, b, a) G_STMT_START { \ - guint16 pixel__ = (((r) & 0xf800) >> 1) | \ - (((g) & 0xf800) >> 6) | \ - ((b) >> 11); \ - memcpy ((p), &pixel__, sizeof (pixel__)); \ - (p) += 2; \ -} G_STMT_END - -#define GDK_RGB16_STORE_555_BR(p, r, g, b, a) G_STMT_START { \ - guint16 pixel__ = (((r) & 0xf800) >> 1) | \ - (((g) & 0xf800) >> 6) | \ - ((b) >> 11); \ - pixel__ = (pixel__ >> 8) | (pixel__ << 8); \ - memcpy ((p), &pixel__, sizeof (pixel__)); \ - (p) += 2; \ -} G_STMT_END - -#define GDK_RGB16_STORE_101010_R_LOW_LE(p, r, g, b, a) \ -G_STMT_START { \ - guint32 pixel__ = (a) | \ - (((b) >> 6) << 20) | \ - (((g) >> 6) << 10) | \ - ((r) >> 6); \ - pixel__ = GUINT32_TO_LE (pixel__); \ - memcpy ((p), &pixel__, sizeof (pixel__)); \ - (p) += 4; \ -} G_STMT_END - -#define GDK_RGB16_STORE_101010_B_LOW_LE(p, r, g, b, a) \ -G_STMT_START { \ - guint32 pixel__ = (a) | \ - (((r) >> 6) << 20) | \ - (((g) >> 6) << 10) | \ - ((b) >> 6); \ - pixel__ = GUINT32_TO_LE (pixel__); \ - memcpy ((p), &pixel__, sizeof (pixel__)); \ - (p) += 4; \ -} G_STMT_END - -#define GDK_RGB16_STORE_101010_R_LOW_BE(p, r, g, b, a) \ -G_STMT_START { \ - guint32 pixel__ = (a) | \ - (((b) >> 6) << 20) | \ - (((g) >> 6) << 10) | \ - ((r) >> 6); \ - pixel__ = GUINT32_TO_BE (pixel__); \ - memcpy ((p), &pixel__, sizeof (pixel__)); \ - (p) += 4; \ -} G_STMT_END - -#define GDK_RGB16_STORE_101010_B_LOW_BE(p, r, g, b, a) \ -G_STMT_START { \ - guint32 pixel__ = (a) | \ - (((r) >> 6) << 20) | \ - (((g) >> 6) << 10) | \ - ((b) >> 6); \ - pixel__ = GUINT32_TO_BE (pixel__); \ - memcpy ((p), &pixel__, sizeof (pixel__)); \ - (p) += 4; \ -} G_STMT_END - -#define DEFINE_GDK_RGB16_CONVERTER(name, words, pixel_bytes, store) \ -static void \ -name (GdkImage *image, \ - gint x0, \ - gint y0, \ - gint width, \ - gint height, \ - const guint16 *buf, \ - gint rowstride) \ -{ \ - const guchar *row; \ - const guint16 *src; \ - guchar *dst_row; \ - guchar *dst; \ - guint32 r, g, b; \ - guint32 alpha_mask; \ - gint x, y; \ - \ - row = (const guchar *) buf; \ - dst_row = ((guchar *) image->mem) + \ - y0 * image->bpl + x0 * (pixel_bytes); \ - alpha_mask = image->depth == 32 ? 0xc0000000U : 0; \ - (void) alpha_mask; \ - \ - for (y = 0; y < height; y++) \ - { \ - src = (const guint16 *) row; \ - dst = dst_row; \ - \ - for (x = 0; x < width; x++) \ - { \ - r = src[0]; \ - g = src[1]; \ - b = src[2]; \ - src += (words); \ - store (dst, r, g, b, alpha_mask); \ - } \ - \ - row += rowstride; \ - dst_row += image->bpl; \ - } \ -} - -#define DEFINE_GDK_RGB16_PAIR(suffix, pixel_bytes, store) \ - DEFINE_GDK_RGB16_CONVERTER (gdk_rgb48_convert_ ## suffix, \ - 3, pixel_bytes, store) \ - DEFINE_GDK_RGB16_CONVERTER (gdk_rgbx64_convert_ ## suffix, \ - 4, pixel_bytes, store) - -DEFINE_GDK_RGB16_PAIR (rgb, 3, GDK_RGB16_STORE_RGB) -DEFINE_GDK_RGB16_PAIR (bgr, 3, GDK_RGB16_STORE_BGR) -DEFINE_GDK_RGB16_PAIR (bgra, 4, GDK_RGB16_STORE_BGRA) -DEFINE_GDK_RGB16_PAIR (argb, 4, GDK_RGB16_STORE_ARGB) -DEFINE_GDK_RGB16_PAIR (rgb0_native, 4, GDK_RGB16_STORE_RGB0_NATIVE) -DEFINE_GDK_RGB16_PAIR (565, 2, GDK_RGB16_STORE_565) -DEFINE_GDK_RGB16_PAIR (565_br, 2, GDK_RGB16_STORE_565_BR) -DEFINE_GDK_RGB16_PAIR (555, 2, GDK_RGB16_STORE_555) -DEFINE_GDK_RGB16_PAIR (555_br, 2, GDK_RGB16_STORE_555_BR) -DEFINE_GDK_RGB16_PAIR (101010_r_low_le, 4, - GDK_RGB16_STORE_101010_R_LOW_LE) -DEFINE_GDK_RGB16_PAIR (101010_b_low_le, 4, - GDK_RGB16_STORE_101010_B_LOW_LE) -DEFINE_GDK_RGB16_PAIR (101010_r_low_be, 4, - GDK_RGB16_STORE_101010_R_LOW_BE) -DEFINE_GDK_RGB16_PAIR (101010_b_low_be, 4, - GDK_RGB16_STORE_101010_B_LOW_BE) - -#undef DEFINE_GDK_RGB16_PAIR -#undef DEFINE_GDK_RGB16_CONVERTER - -#undef GDK_RGB16_STORE_RGB -#undef GDK_RGB16_STORE_BGR -#undef GDK_RGB16_STORE_BGRA -#undef GDK_RGB16_STORE_ARGB -#undef GDK_RGB16_STORE_RGB0_NATIVE -#undef GDK_RGB16_STORE_565 -#undef GDK_RGB16_STORE_565_BR -#undef GDK_RGB16_STORE_555 -#undef GDK_RGB16_STORE_555_BR -#undef GDK_RGB16_STORE_101010_R_LOW_LE -#undef GDK_RGB16_STORE_101010_B_LOW_LE -#undef GDK_RGB16_STORE_101010_R_LOW_BE -#undef GDK_RGB16_STORE_101010_B_LOW_BE - -static GdkRgb16ConvFunc -gdk_rgb16_select_converter (GdkDrawable *drawable, - gboolean is_rgbx, - GdkRgbDither dith) -{ - GdkVisual *visual; - GdkByteOrder byte_order; - GdkScreen *screen; - guint32 red_mask, green_mask, blue_mask; - gint depth; - gint bits_per_pixel; - gboolean byte_reversed; - gboolean mask_rgb; - gboolean mask_bgr; - -#define SELECT_PAIR(suffix) \ - return is_rgbx ? gdk_rgbx64_convert_ ## suffix \ - : gdk_rgb48_convert_ ## suffix - - /* - * Preserve the existing GdkRGB dither path for maximum dithering - * and for unknown future values. - */ - if (dith != GDK_RGB_DITHER_NONE && - dith != GDK_RGB_DITHER_NORMAL) - return NULL; - - visual = gdk_drawable_get_visual (drawable); - if (visual == NULL) - return NULL; - - if (gdk_visual_get_visual_type (visual) != GDK_VISUAL_TRUE_COLOR) - return NULL; - - screen = gdk_visual_get_screen (visual); - depth = gdk_visual_get_depth (visual); - byte_order = gdk_visual_get_byte_order (visual); - - gdk_visual_get_red_pixel_details (visual, &red_mask, NULL, NULL); - gdk_visual_get_green_pixel_details (visual, &green_mask, NULL, NULL); - gdk_visual_get_blue_pixel_details (visual, &blue_mask, NULL, NULL); - - bits_per_pixel = _gdk_windowing_get_bits_for_depth - (gdk_screen_get_display (screen), depth); - -#if G_BYTE_ORDER == G_BIG_ENDIAN - byte_reversed = byte_order == GDK_LSB_FIRST; -#else - byte_reversed = byte_order == GDK_MSB_FIRST; -#endif - - mask_rgb = red_mask == 0xff0000 && - green_mask == 0x00ff00 && - blue_mask == 0x0000ff; - - mask_bgr = red_mask == 0x0000ff && - green_mask == 0x00ff00 && - blue_mask == 0xff0000; - - if (bits_per_pixel == 16 && - depth == 16 && - red_mask == 0xf800 && - green_mask == 0x07e0 && - blue_mask == 0x001f) - { - if (byte_reversed) - SELECT_PAIR (565_br); - - SELECT_PAIR (565); - } - - if (bits_per_pixel == 16 && - depth == 15 && - red_mask == 0x7c00 && - green_mask == 0x03e0 && - blue_mask == 0x001f) - { - if (byte_reversed) - SELECT_PAIR (555_br); - - SELECT_PAIR (555); - } - - if (bits_per_pixel == 24 && - depth == 24 && - ((mask_rgb && byte_order == GDK_LSB_FIRST) || - (mask_bgr && byte_order == GDK_MSB_FIRST))) - SELECT_PAIR (bgr); - - if (bits_per_pixel == 24 && - depth == 24 && - ((mask_rgb && byte_order == GDK_MSB_FIRST) || - (mask_bgr && byte_order == GDK_LSB_FIRST))) - SELECT_PAIR (rgb); - - if (bits_per_pixel == 32 && - (depth == 24 || depth == 32) && - mask_rgb && - byte_order == GDK_MSB_FIRST) - SELECT_PAIR (argb); - - if (bits_per_pixel == 32 && - (depth == 24 || depth == 32) && - mask_rgb && - byte_order == GDK_LSB_FIRST) - SELECT_PAIR (bgra); - -#if G_BYTE_ORDER == G_BIG_ENDIAN - if (bits_per_pixel == 32 && - depth == 24 && - mask_bgr && - byte_order == GDK_MSB_FIRST) - SELECT_PAIR (rgb0_native); -#else - if (bits_per_pixel == 32 && - depth == 24 && - mask_bgr && - byte_order == GDK_LSB_FIRST) - SELECT_PAIR (rgb0_native); -#endif - - if (bits_per_pixel == 32 && - (depth == 30 || depth == 32) && - byte_order == GDK_LSB_FIRST && - red_mask == 0x000003ff && - green_mask == 0x000ffc00 && - blue_mask == 0x3ff00000) - SELECT_PAIR (101010_r_low_le); - - if (bits_per_pixel == 32 && - (depth == 30 || depth == 32) && - byte_order == GDK_LSB_FIRST && - red_mask == 0x3ff00000 && - green_mask == 0x000ffc00 && - blue_mask == 0x000003ff) - SELECT_PAIR (101010_b_low_le); - - if (bits_per_pixel == 32 && - (depth == 30 || depth == 32) && - byte_order == GDK_MSB_FIRST && - red_mask == 0x000003ff && - green_mask == 0x000ffc00 && - blue_mask == 0x3ff00000) - SELECT_PAIR (101010_r_low_be); - - if (bits_per_pixel == 32 && - (depth == 30 || depth == 32) && - byte_order == GDK_MSB_FIRST && - red_mask == 0x3ff00000 && - green_mask == 0x000ffc00 && - blue_mask == 0x000003ff) - SELECT_PAIR (101010_b_low_be); - -#undef SELECT_PAIR - - return NULL; -} - -static void -gdk_rgb16_draw_direct (GdkDrawable *drawable, - GdkGC *gc, - gint x, - gint y, - gint width, - gint height, - const guint16 *buf, - gint pixel_words, - gint rowstride, - GdkRgb16ConvFunc converter) -{ - GdkScreen *screen; - GdkImage *image; - const guint16 *tile; - gint depth; - gint x0, y0; - gint xs0, ys0; - gint width1, height1; - - screen = gdk_drawable_get_screen (drawable); - depth = gdk_drawable_get_depth (drawable); - - for (y0 = 0; y0 < height; y0 += GDK_SCRATCH_IMAGE_HEIGHT) - { - height1 = MIN (height - y0, GDK_SCRATCH_IMAGE_HEIGHT); - - for (x0 = 0; x0 < width; x0 += GDK_SCRATCH_IMAGE_WIDTH) - { - width1 = MIN (width - x0, GDK_SCRATCH_IMAGE_WIDTH); - - tile = (const guint16 *) - ((const guchar *) buf + - y0 * rowstride + - x0 * pixel_words * sizeof (guint16)); - - image = _gdk_image_get_scratch (screen, - width1, - height1, - depth, - &xs0, - &ys0); - - converter (image, - xs0, - ys0, - width1, - height1, - tile, - rowstride); - - gdk_draw_image (drawable, - gc, - image, - xs0, - ys0, - x + x0, - y + y0, - width1, - height1); - } - } -} - -static void -gdk_rgb16_draw_fallback (GdkDrawable *drawable, - GdkGC *gc, - gint x, - gint y, - gint width, - gint height, - GdkRgbDither dith, - const guint16 *buf, - gint pixel_words, - gint rowstride, - gint xdith, - gint ydith) -{ - const guchar *input_row; - const guint16 *input; - guchar *stage; - guchar *output; - gint stage_rowstride; - gint x0, y0; - gint x1, y1; - gint width1, height1; - - stage = g_malloc (MIN (width, GDK_SCRATCH_IMAGE_WIDTH) * - MIN (height, GDK_SCRATCH_IMAGE_HEIGHT) * 3); - - for (y0 = 0; y0 < height; y0 += GDK_SCRATCH_IMAGE_HEIGHT) - { - height1 = MIN (height - y0, GDK_SCRATCH_IMAGE_HEIGHT); - - for (x0 = 0; x0 < width; x0 += GDK_SCRATCH_IMAGE_WIDTH) - { - width1 = MIN (width - x0, GDK_SCRATCH_IMAGE_WIDTH); - stage_rowstride = width1 * 3; - - input_row = (const guchar *) buf + - y0 * rowstride + - x0 * pixel_words * sizeof (guint16); - output = stage; - - for (y1 = 0; y1 < height1; y1++) - { - input = (const guint16 *) input_row; - - for (x1 = 0; x1 < width1; x1++) - { - *output++ = input[0] >> 8; - *output++ = input[1] >> 8; - *output++ = input[2] >> 8; - input += pixel_words; - } - - input_row += rowstride; - } - - gdk_draw_rgb_image_dithalign (drawable, - gc, - x + x0, - y + y0, - width1, - height1, - dith, - stage, - stage_rowstride, - xdith, - ydith); - } - } - - g_free (stage); -} - -static void -gdk_draw_rgb16_image (GdkDrawable *drawable, - GdkGC *gc, - gint x, - gint y, - gint width, - gint height, - GdkRgbDither dith, - const guint16 *buf, - gint rowstride, - gint xdith, - gint ydith, - gboolean is_rgbx) -{ - GdkRgb16ConvFunc converter; - gint pixel_words; - - g_return_if_fail (GDK_IS_DRAWABLE (drawable)); - g_return_if_fail (GDK_IS_GC (gc)); - g_return_if_fail (buf != NULL); - g_return_if_fail ((((guintptr) buf) & 1) == 0); - g_return_if_fail ((rowstride & 1) == 0); - - if (width <= 0 || height <= 0) - return; - - pixel_words = is_rgbx ? 4 : 3; - converter = gdk_rgb16_select_converter (drawable, is_rgbx, dith); - - if (converter != NULL) - gdk_rgb16_draw_direct (drawable, - gc, - x, - y, - width, - height, - buf, - pixel_words, - rowstride, - converter); - else - gdk_rgb16_draw_fallback (drawable, - gc, - x, - y, - width, - height, - dith, - buf, - pixel_words, - rowstride, - xdith, - ydith); -} - -/** - * gdk_draw_rgb_48_image: - * @drawable: a #GdkDrawable - * @gc: a #GdkGC - * @x: destination X coordinate - * @y: destination Y coordinate - * @width: image width - * @height: image height - * @dith: dithering mode - * @rgb_buf: host-endian RGB data with three 16-bit channels per pixel - * @rowstride: number of bytes between consecutive rows - * - * Draws 48-bit RGB image data. - **/ -void -gdk_draw_rgb_48_image (GdkDrawable *drawable, - GdkGC *gc, - gint x, - gint y, - gint width, - gint height, - GdkRgbDither dith, - const guint16 *rgb_buf, - gint rowstride) -{ - gdk_draw_rgb16_image (drawable, - gc, - x, - y, - width, - height, - dith, - rgb_buf, - rowstride, - 0, - 0, - FALSE); -} - -/** - * gdk_draw_rgb_48_image_dithalign: - * @drawable: a #GdkDrawable - * @gc: a #GdkGC - * @x: destination X coordinate - * @y: destination Y coordinate - * @width: image width - * @height: image height - * @dith: dithering mode - * @rgb_buf: host-endian RGB data with three 16-bit channels per pixel - * @rowstride: number of bytes between consecutive rows - * @xdith: X dither offset - * @ydith: Y dither offset - * - * Draws 48-bit RGB image data with explicit dither alignment. - **/ -void -gdk_draw_rgb_48_image_dithalign (GdkDrawable *drawable, - GdkGC *gc, - gint x, - gint y, - gint width, - gint height, - GdkRgbDither dith, - const guint16 *rgb_buf, - gint rowstride, - gint xdith, - gint ydith) -{ - gdk_draw_rgb16_image (drawable, - gc, - x, - y, - width, - height, - dith, - rgb_buf, - rowstride, - xdith, - ydith, - FALSE); -} - -/** - * gdk_draw_rgbx_64_image: - * @drawable: a #GdkDrawable - * @gc: a #GdkGC - * @x: destination X coordinate - * @y: destination Y coordinate - * @width: image width - * @height: image height - * @dith: dithering mode - * @rgbx_buf: host-endian RGBX data with four 16-bit channels per pixel - * @rowstride: number of bytes between consecutive rows - * - * Draws 64-bit RGBX image data. The X channel is ignored. - **/ -void -gdk_draw_rgbx_64_image (GdkDrawable *drawable, - GdkGC *gc, - gint x, - gint y, - gint width, - gint height, - GdkRgbDither dith, - const guint16 *rgbx_buf, - gint rowstride) -{ - gdk_draw_rgb16_image (drawable, - gc, - x, - y, - width, - height, - dith, - rgbx_buf, - rowstride, - 0, - 0, - TRUE); -} - -/** - * gdk_draw_rgbx_64_image_dithalign: - * @drawable: a #GdkDrawable - * @gc: a #GdkGC - * @x: destination X coordinate - * @y: destination Y coordinate - * @width: image width - * @height: image height - * @dith: dithering mode - * @rgbx_buf: host-endian RGBX data with four 16-bit channels per pixel - * @rowstride: number of bytes between consecutive rows - * @xdith: X dither offset - * @ydith: Y dither offset - * - * Draws 64-bit RGBX image data with explicit dither alignment. - * The X channel is ignored. - **/ -void -gdk_draw_rgbx_64_image_dithalign (GdkDrawable *drawable, - GdkGC *gc, - gint x, - gint y, - gint width, - gint height, - GdkRgbDither dith, - const guint16 *rgbx_buf, - gint rowstride, - gint xdith, - gint ydith) -{ - gdk_draw_rgb16_image (drawable, - gc, - x, - y, - width, - height, - dith, - rgbx_buf, - rowstride, - xdith, - ydith, - TRUE); -} - -#define __GDK_RGB16_C__ -#include "gdkaliasdef.c" diff --git a/gdk/gdkrgbsimd.c b/gdk/gdkrgbsimd.c new file mode 100644 index 000000000..7e8c14e26 --- /dev/null +++ b/gdk/gdkrgbsimd.c @@ -0,0 +1,304 @@ +/* GDK - The GIMP Drawing Kit + * Choosing the vector versions of GdkRGB loops for this CPU + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + */ + +#include "config.h" + +#include +#include + +#include "gdkrgbsimd.h" + +#if defined(__i386__) || defined(__x86_64__) +#if defined(__GNUC__) +#include +#endif +#elif defined(__powerpc__) || defined(__ppc__) || defined(__arm__) +#if defined(HAVE_GETAUXVAL) || defined(HAVE_ELF_AUX_INFO) +#include +#elif defined(__APPLE__) +#include +#include +#endif +#endif + +/* All instruction sets, from the least to the most preferred: each + * kernel comes from the last set that has it and the CPU can run */ +static const GdkRgbSimdSet all_sets[] = +{ + { "mmx", _gdk_rgb_simd_init_mmx }, + { "mmxext", _gdk_rgb_simd_init_mmxext }, + { "3dnow", _gdk_rgb_simd_init_3dnow }, + { "3dnowext", _gdk_rgb_simd_init_3dnowext }, + { "sse2", _gdk_rgb_simd_init_sse2 }, + { "ssse3", _gdk_rgb_simd_init_ssse3 }, + { "avx2", _gdk_rgb_simd_init_avx2 }, + { "altivec", _gdk_rgb_simd_init_altivec }, + { "armv6", _gdk_rgb_simd_init_armv6 }, + { "neon", _gdk_rgb_simd_init_neon }, +}; + +static const GdkRgbSimdOp all_ops[] = +{ + { "rgb_to_x888", G_STRUCT_OFFSET (GdkRgbSimd, rgb_to_x888) }, + { "rgbx_to_x888", G_STRUCT_OFFSET (GdkRgbSimd, rgbx_to_x888) }, + { "rgb_to_565", G_STRUCT_OFFSET (GdkRgbSimd, rgb_to_565) }, + { "rgb_to_555", G_STRUCT_OFFSET (GdkRgbSimd, rgb_to_555) }, + { "composite_x888", G_STRUCT_OFFSET (GdkRgbSimd, composite_x888) }, + { "composite_565", G_STRUCT_OFFSET (GdkRgbSimd, composite_565) }, + { "composite_555", G_STRUCT_OFFSET (GdkRgbSimd, composite_555) }, + { "rgba_to_argb", G_STRUCT_OFFSET (GdkRgbSimd, rgba_to_argb) }, +}; + +#define OP(simd, i) G_STRUCT_MEMBER (gpointer, (simd), all_ops[i].offset) + +/* The CPU's hardware capabilities word, as the kernel tells them */ +#if (defined(__powerpc__) || defined(__arm__)) && \ + (defined(HAVE_GETAUXVAL) || defined(HAVE_ELF_AUX_INFO)) +static unsigned long +hwcap (void) +{ +#if defined(HAVE_GETAUXVAL) + return getauxval (AT_HWCAP); +#else + unsigned long caps = 0; + + if (elf_aux_info (AT_HWCAP, &caps, sizeof (caps)) != 0) + return 0; + return caps; +#endif +} +#endif + +#if (defined(__x86_64__) || defined(__i386__)) && defined(__GNUC__) +/* AVX2: the CPU has it, and the system saves the wide registers + * (OSXSAVE, then XCR0 says SSE and AVX state) */ +static gboolean +cpu_has_avx2 (unsigned int ecx) +{ + unsigned int eax, ebx, ecx7, edx, xcr0_low, xcr0_high; + + if ((ecx & (1 << 27)) == 0 || (ecx & (1 << 28)) == 0 || + __get_cpuid_max (0, NULL) < 7) + return FALSE; + __cpuid_count (7, 0, eax, ebx, ecx7, edx); + if ((ebx & (1 << 5)) == 0) + return FALSE; + __asm__ (".byte 0x0f, 0x01, 0xd0" /* xgetbv, which old assemblers do not know */ + : "=a" (xcr0_low), "=d" (xcr0_high) : "c" (0)); + + return (xcr0_low & 6) == 6; +} +#endif + +/* Whether this CPU can run the set */ +static gboolean +cpu_has (const gchar *set) +{ +#if defined(__x86_64__) + unsigned int eax, ebx, ecx, edx; + + /* every x86-64 CPU has SSE2, which beats the older sets */ + if (strcmp (set, "sse2") == 0) + return TRUE; + if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx)) + return FALSE; + if (strcmp (set, "ssse3") == 0) + return (ecx & (1 << 9)) != 0; + if (strcmp (set, "avx2") == 0) + return cpu_has_avx2 (ecx); + return FALSE; + +#elif defined(__i386__) && defined(__GNUC__) + unsigned int eax, ebx, ecx, edx, ext = 0, max_ext; + + if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx)) + return FALSE; + /* CPUs without the extended leaves answer with something else */ + max_ext = __get_cpuid_max (0x80000000, NULL); + if ((max_ext & 0xffff0000) == 0x80000000 && max_ext >= 0x80000001) + { + unsigned int a, b, c; + + __cpuid (0x80000001, a, b, c, ext); + } + + if (strcmp (set, "mmx") == 0) + return (edx & (1 << 23)) != 0; + /* the integer part of SSE, or AMD's extensions to MMX */ + if (strcmp (set, "mmxext") == 0) + return (edx & (1 << 25)) != 0 || (ext & (1 << 22)) != 0; + if (strcmp (set, "3dnow") == 0) + return (ext & (1u << 31)) != 0; + if (strcmp (set, "3dnowext") == 0) + return (ext & (1 << 30)) != 0 && (ext & (1u << 31)) != 0 && (ext & (1 << 22)) != 0; + if (strcmp (set, "sse2") == 0) + return (edx & (1 << 26)) != 0; + if (strcmp (set, "ssse3") == 0) + return (ecx & (1 << 9)) != 0; + if (strcmp (set, "avx2") == 0) + return cpu_has_avx2 (ecx); + return FALSE; + +#elif defined(__aarch64__) + return strcmp (set, "neon") == 0; + +#elif defined(__arm__) && (defined(HAVE_GETAUXVAL) || defined(HAVE_ELF_AUX_INFO)) + if (strcmp (set, "armv6") == 0) + { +#if defined(__ARM_ARCH) && __ARM_ARCH >= 6 + return TRUE; /* what all of this is built for */ +#elif defined(HAVE_GETAUXVAL) + /* "v6l", "v7l", "v8l" */ + const gchar *platform = (const gchar *) getauxval (AT_PLATFORM); + + return platform && platform[0] == 'v' && atoi (platform + 1) >= 6; +#else + return FALSE; +#endif + } + return strcmp (set, "neon") == 0 && (hwcap () & (1 << 12)) != 0; /* HWCAP_NEON */ + +#elif defined(__powerpc__) && (defined(HAVE_GETAUXVAL) || defined(HAVE_ELF_AUX_INFO)) + return strcmp (set, "altivec") == 0 && (hwcap () & 0x10000000) != 0; /* PPC_FEATURE_HAS_ALTIVEC */ + +#elif defined(__ppc__) && defined(__APPLE__) + int vector_unit = 0; + size_t size = sizeof (vector_unit); + + return strcmp (set, "altivec") == 0 && + sysctlbyname ("hw.vectorunit", &vector_unit, &size, NULL, 0) == 0 && vector_unit; +#else + return FALSE; +#endif +} + +/** + * _gdk_rgb_simd_sets: + * @n_sets: the number of sets + * + * The instruction sets this CPU can run, least preferred first. The + * init function of a set fills in only what is in it. + */ +const GdkRgbSimdSet * +_gdk_rgb_simd_sets (gint *n_sets) +{ + static GdkRgbSimdSet sets[G_N_ELEMENTS (all_sets)]; + static gint n = -1; + guint i; + + if (n < 0) + { + n = 0; + for (i = 0; i < G_N_ELEMENTS (all_sets); i++) + if (cpu_has (all_sets[i].name)) + { + GdkRgbSimd probe = { NULL, }; + + /* a set the compiler couldn't build fills in nothing */ + all_sets[i].init (&probe); + if (probe.name) + sets[n++] = all_sets[i]; + } + } + + *n_sets = n; + return sets; +} + +/** + * _gdk_rgb_simd_ops: + * @n_ops: the number of operations + * + * The names of the kernels and where they are in a #GdkRgbSimd. + */ +const GdkRgbSimdOp * +_gdk_rgb_simd_ops (gint *n_ops) +{ + *n_ops = G_N_ELEMENTS (all_ops); + return all_ops; +} + +/* GDK_RGB_SIMD picks sets by hand, to try them: "c" for none, a set + * for that one wherever it has a kernel, "op=set" or "op=c" for one + * kernel; several of these separated by commas, applied in order. */ +static void +choose_by_hand (GdkRgbSimd *simd, + const gchar *spec, + const GdkRgbSimdSet *sets, + gint n_sets) +{ + gchar **items = g_strsplit (spec, ",", -1); + gint i, k, s; + + for (i = 0; items[i]; i++) + { + gchar *item = g_strstrip (items[i]); + gchar *eq = strchr (item, '='); + const gchar *set = eq ? eq + 1 : item; + GdkRgbSimd from = { NULL, }; + + if (eq) + *eq = '\0'; + + for (s = 0; s < n_sets; s++) + if (strcmp (sets[s].name, set) == 0) + { + sets[s].init (&from); + break; + } + if (s == n_sets && strcmp (set, "c") != 0) + { + g_warning ("GDK_RGB_SIMD: %s is not an instruction set this CPU has", set); + continue; + } + + for (k = 0; k < (gint) G_N_ELEMENTS (all_ops); k++) + if (!eq || strcmp (item, all_ops[k].name) == 0) + OP (simd, k) = OP (&from, k); + } + + simd->name = "by hand"; + g_strfreev (items); +} + +const GdkRgbSimd * +_gdk_rgb_simd_get (void) +{ + static GdkRgbSimd simd = { "none", }; + static gboolean done = FALSE; + + if (!done) + { + const gchar *disable = g_getenv ("GDK_DISABLE_SIMD"); + const gchar *spec = g_getenv ("GDK_RGB_SIMD"); + const GdkRgbSimdSet *sets; + gint n_sets, s, k; + + done = TRUE; + if (disable && *disable && *disable != '0') + return &simd; + + sets = _gdk_rgb_simd_sets (&n_sets); + for (s = 0; s < n_sets; s++) + { + GdkRgbSimd set = { NULL, }; + + sets[s].init (&set); + for (k = 0; k < (gint) G_N_ELEMENTS (all_ops); k++) + if (OP (&set, k)) + OP (&simd, k) = OP (&set, k); + simd.name = set.name; + } + + if (spec && *spec) + choose_by_hand (&simd, spec, sets, n_sets); + } + + return &simd; +} diff --git a/gdk/gdkrgbsimd.h b/gdk/gdkrgbsimd.h new file mode 100644 index 000000000..ffaf5a687 --- /dev/null +++ b/gdk/gdkrgbsimd.h @@ -0,0 +1,84 @@ +/* GDK - The GIMP Drawing Kit + * Vector versions of GdkRGB loops + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + */ + +/* Vector versions of the busiest GdkRGB loops. + * + * Each converts pixels from the start of a row, as many as it likes, and + * returns how many; the C code does the rest. Pixels are words in the + * byte order of the machine: + * + * x888 0xffRRGGBB, 32 bits + * 565 RRRRRGGG GGGBBBBB, 16 bits + * 555 1RRRRRGG GGGBBBBB, 16 bits, with the unused bit set + * argb 0xAARRGGBB, 32 bits, R, G and B multiplied by A / 255, + * rounded to the nearest: cairo's ARGB32 + * + * RGB and RGBA are bytes in that order; RGBA is not premultiplied. + * Blending rounds as GdkRGB's C code does, so the results are the same. + * No alignment is required of any pointer. + */ + +#ifndef __GDK_RGB_SIMD_H__ +#define __GDK_RGB_SIMD_H__ + +#include + +G_BEGIN_DECLS + +typedef struct _GdkRgbSimd GdkRgbSimd; + +struct _GdkRgbSimd +{ + const gchar *name; + + gint (*rgb_to_x888) (guint32 *out, const guchar *rgb, gint n); + gint (*rgbx_to_x888) (guint32 *out, const guchar *rgbx, gint n); + gint (*rgb_to_565) (guint16 *out, const guchar *rgb, gint n); + gint (*rgb_to_555) (guint16 *out, const guchar *rgb, gint n); + gint (*composite_x888) (guint32 *pixels, const guchar *rgba, gint n); + gint (*composite_565) (guint16 *pixels, const guchar *rgba, gint n); + gint (*composite_555) (guint16 *pixels, const guchar *rgba, gint n); + gint (*rgba_to_argb) (guint32 *out, const guchar *rgba, gint n); +}; + +typedef struct +{ + const gchar *name; + void (*init) (GdkRgbSimd *simd); +} GdkRgbSimdSet; + +typedef struct +{ + const gchar *name; + glong offset; +} GdkRgbSimdOp; + +/* Each fills in what its instruction set does better than C; they are + * only called when the CPU has it. */ +void _gdk_rgb_simd_init_mmx (GdkRgbSimd *simd); +void _gdk_rgb_simd_init_mmxext (GdkRgbSimd *simd); +void _gdk_rgb_simd_init_3dnow (GdkRgbSimd *simd); +void _gdk_rgb_simd_init_3dnowext (GdkRgbSimd *simd); +void _gdk_rgb_simd_init_sse2 (GdkRgbSimd *simd); +void _gdk_rgb_simd_init_ssse3 (GdkRgbSimd *simd); +void _gdk_rgb_simd_init_avx2 (GdkRgbSimd *simd); +void _gdk_rgb_simd_init_altivec (GdkRgbSimd *simd); +void _gdk_rgb_simd_init_armv6 (GdkRgbSimd *simd); +void _gdk_rgb_simd_init_neon (GdkRgbSimd *simd); + +/* The kernels for this CPU, or none with GDK_DISABLE_SIMD set */ +const GdkRgbSimd *_gdk_rgb_simd_get (void); + +/* For trying them: the sets this CPU has and the kernels by name */ +const GdkRgbSimdSet *_gdk_rgb_simd_sets (gint *n_sets); +const GdkRgbSimdOp *_gdk_rgb_simd_ops (gint *n_ops); + +G_END_DECLS + +#endif /* __GDK_RGB_SIMD_H__ */ diff --git a/gdk/gdkscreen.c b/gdk/gdkscreen.c index 9df10fa25..0febaae8e 100644 --- a/gdk/gdkscreen.c +++ b/gdk/gdkscreen.c @@ -27,6 +27,7 @@ #include "gdkwindow.h" #include "gdkscreen.h" #include "gdkintl.h" +#include "gdkinternals.h" #include "gdkalias.h" static void gdk_screen_dispose (GObject *object); @@ -541,5 +542,30 @@ gdk_screen_set_property (GObject *object, } } +/** + * gdk_screen_get_monitor_scale_factor: + * @screen: a #GdkScreen + * @monitor_num: number of the monitor, between 0 and gdk_screen_get_n_monitors (screen) + * + * Returns the internal scale factor that maps from monitor coordinates + * to the actual device pixels, as in GTK+ 3: on traditional systems + * this is 1, on high density outputs it can be higher (typically 2). + * The coordinates of GDK and GTK+ stay in units of the scale 1. + * + * Returns: the scale factor + * + * Since: 2.24 + */ +gint +gdk_screen_get_monitor_scale_factor (GdkScreen *screen, + gint monitor_num) +{ + g_return_val_if_fail (GDK_IS_SCREEN (screen), 1); + g_return_val_if_fail (monitor_num >= 0, 1); + g_return_val_if_fail (monitor_num < gdk_screen_get_n_monitors (screen), 1); + + return _gdk_windowing_screen_get_monitor_scale (screen, monitor_num); +} + #define __GDK_SCREEN_C__ #include "gdkaliasdef.c" diff --git a/gdk/gdkscreen.h b/gdk/gdkscreen.h index 954431629..9956c1269 100644 --- a/gdk/gdkscreen.h +++ b/gdk/gdkscreen.h @@ -66,7 +66,7 @@ struct _GdkScreenClass void (*monitors_changed) (GdkScreen *screen); }; -GType gdk_screen_get_type (void) G_GNUC_CONST; +GType gdk_screen_get_type (void); GdkColormap *gdk_screen_get_default_colormap (GdkScreen *screen); void gdk_screen_set_default_colormap (GdkScreen *screen, GdkColormap *colormap); @@ -106,6 +106,8 @@ gint gdk_screen_get_monitor_height_mm (GdkScreen *screen, gint monitor_num); gchar * gdk_screen_get_monitor_plug_name (GdkScreen *screen, gint monitor_num); +gint gdk_screen_get_monitor_scale_factor (GdkScreen *screen, + gint monitor_num); void gdk_screen_broadcast_client_message (GdkScreen *screen, GdkEvent *event); diff --git a/gdk/gdkvisual.h b/gdk/gdkvisual.h index 1131b552f..be806fbf7 100644 --- a/gdk/gdkvisual.h +++ b/gdk/gdkvisual.h @@ -97,7 +97,7 @@ struct _GdkVisual gint GSEAL (blue_prec); }; -GType gdk_visual_get_type (void) G_GNUC_CONST; +GType gdk_visual_get_type (void); #ifndef GDK_MULTIHEAD_SAFE gint gdk_visual_get_best_depth (void); diff --git a/gdk/gdkwindow.c b/gdk/gdkwindow.c index aa5e2fe80..d947a395f 100644 --- a/gdk/gdkwindow.c +++ b/gdk/gdkwindow.c @@ -34,6 +34,7 @@ #include "gdkdrawable.h" #include "gdkintl.h" #include "gdkscreen.h" +#include "gdkregion-generic.h" #include "gdkmarshalers.h" #include "gdkalias.h" @@ -150,6 +151,7 @@ struct _GdkWindowPaint guint uses_implicit : 1; guint flushed : 1; guint32 region_tag; + gint width, height; /* of the pixmap of an implicit paint */ }; typedef struct { @@ -828,7 +830,7 @@ gdk_window_update_visibility (GdkWindowObject *private) private->effective_visibility = new_visibility; if (new_visibility != GDK_VISIBILITY_NOT_VIEWABLE && - private->event_mask & GDK_VISIBILITY_NOTIFY) + private->event_mask & GDK_VISIBILITY_NOTIFY_MASK) { event = _gdk_make_event ((GdkWindow *)private, GDK_VISIBILITY_NOTIFY, NULL, FALSE); @@ -909,6 +911,32 @@ apply_clip_as_shape (GdkWindowObject *private) apply_shape (private, NULL); } +/* HiDPI: the shapes of a native window set again, after its scale + * changed (the window system has them in its pixels) */ +void +_gdk_window_reapply_shapes (GdkWindow *window) +{ + GdkWindowObject *private = (GdkWindowObject *) window; + GdkWindowImplIface *impl_iface; + + if (!gdk_window_has_impl (private) || private->destroyed) + return; + + impl_iface = GDK_WINDOW_IMPL_GET_IFACE (private->impl); + if (should_apply_clip_as_shape (private)) + { + if (private->applied_shape) + apply_clip_as_shape (private); + } + else if (private->shape) + impl_iface->shape_combine_region (window, private->shape, 0, 0); + if (private->input_shape) + impl_iface->input_shape_combine_region (window, private->input_shape, 0, 0); +} + +/* the window recompute_visible_regions_in_place() is about */ +static GdkWindowObject *unmoved_window; + static void recompute_visible_regions_internal (GdkWindowObject *private, gboolean recalculate_clip, @@ -1061,9 +1089,23 @@ recompute_visible_regions_internal (GdkWindowObject *private, should_apply_clip_as_shape (private)) apply_clip_as_shape (private); + /* An input-only window takes no part in the clip of its siblings nor + * in the clip of its parent with children (see remove_child_area()): + * when one is shown, moved or restacked, theirs stay as they are. + * Without this, mapping a container with many such windows (the + * event windows of buttons) computes the clip of every sibling again + * for each of them. */ if (recalculate_siblings && + !private->input_only && !gdk_window_is_toplevel (private)) { + GdkRectangle area; + + area.x = private->x; + area.y = private->y; + area.width = private->width; + area.height = private->height; + /* If we moved a child window in parent or changed the stacking order, then we * need to recompute the visible area of all the other children in the parent */ @@ -1071,8 +1113,24 @@ recompute_visible_regions_internal (GdkWindowObject *private, { child = l->data; - if (child != private) - recompute_visible_regions_internal (child, TRUE, FALSE, FALSE); + if (child == private) + continue; + + /* a window shown, hidden, raised or lowered in its place takes + * part in the clip of a sibling only where they overlap */ + if (private == unmoved_window) + { + GdkRectangle r; + + r.x = child->x; + r.y = child->y; + r.width = child->width; + r.height = child->height; + if (!gdk_rectangle_intersect (&area, &r, NULL)) + continue; + } + + recompute_visible_regions_internal (child, TRUE, FALSE, FALSE); } /* We also need to recompute the _with_children clip for the parent */ @@ -1090,9 +1148,9 @@ recompute_visible_regions_internal (GdkWindowObject *private, _gdk_windowing_set_cairo_surface_size (private->cairo_surface, width, height); - cairo_surface_set_device_offset (private->cairo_surface, - private->abs_x, - private->abs_y); + _gdk_cairo_surface_set_device_offset (private->cairo_surface, + private->abs_x, + private->abs_y); } } @@ -1122,6 +1180,19 @@ recompute_visible_regions (GdkWindowObject *private, recalculate_children); } +/* recompute_visible_regions() with siblings, for a window that was + * shown, hidden, raised or lowered, but kept its place and size: the + * clip of the siblings that do not overlap it stays as it is. Showing + * the many child windows of one parent (the items of a list) would + * otherwise compute the clip of all siblings again for each of them. */ +static void +recompute_visible_regions_in_place (GdkWindowObject *private) +{ + unmoved_window = private; + recompute_visible_regions (private, TRUE, FALSE); + unmoved_window = NULL; +} + void _gdk_window_update_size (GdkWindow *window) { @@ -1173,6 +1244,9 @@ find_native_sibling_above (GdkWindowObject *parent, { GdkWindowObject *w; + if (!parent) + return NULL; + w = find_native_sibling_above_helper (parent, child); if (w) return w; @@ -1183,6 +1257,67 @@ find_native_sibling_above (GdkWindowObject *parent, return find_native_sibling_above (parent->parent, parent); } +static GQuark +touch_wanted_quark (void) +{ + static GQuark quark; + + if (!quark) + quark = g_quark_from_static_string ("gdk-touch-wanted"); + return quark; +} + +static GdkEventMask get_native_event_mask (GdkWindowObject *private); + +/* A window that asks for GDK_TOUCH_MASK makes its native window take + * the touches, for all inside (see proxy_touch_event()) */ +static void +note_touch_wanted (GdkWindowObject *private) +{ + GdkWindowObject *impl_window = private->impl_window; + + if (!(private->event_mask & GDK_TOUCH_MASK) || impl_window == NULL || + g_object_get_qdata (G_OBJECT (impl_window), touch_wanted_quark ())) + return; + + g_object_set_qdata (G_OBJECT (impl_window), touch_wanted_quark (), GINT_TO_POINTER (1)); + if (impl_window != private && !GDK_WINDOW_DESTROYED (impl_window)) + GDK_WINDOW_IMPL_GET_IFACE (impl_window->impl)->set_events ((GdkWindow *) impl_window, + get_native_event_mask (impl_window)); +} + +/** + * gdk_window_set_touch_emulation_libgtk_only: + * @window: a #GdkWindow + * + * The native window of @window takes the touches, so that GDK makes + * the pointer events of the first finger, marked with + * gdk_event_get_pointer_emulated(), for its windows without + * %GDK_TOUCH_MASK; GtkScrolledWindow scrolls with a finger then. Only + * on X11, where the X server makes them otherwise, without the mark; + * Windows marks them itself. + */ +void +gdk_window_set_touch_emulation_libgtk_only (GdkWindow *window) +{ +#ifdef GDK_WINDOWING_X11 + GdkWindowObject *impl_window; + + g_return_if_fail (GDK_IS_WINDOW (window)); + + impl_window = ((GdkWindowObject *) window)->impl_window; + if (impl_window == NULL || GDK_WINDOW_DESTROYED (impl_window) || + impl_window->window_type == GDK_WINDOW_ROOT || + impl_window->window_type == GDK_WINDOW_FOREIGN || + g_object_get_qdata (G_OBJECT (impl_window), touch_wanted_quark ())) + return; + + g_object_set_qdata (G_OBJECT (impl_window), touch_wanted_quark (), GINT_TO_POINTER (1)); + GDK_WINDOW_IMPL_GET_IFACE (impl_window->impl)->set_events ((GdkWindow *) impl_window, + get_native_event_mask (impl_window)); +#endif +} + static GdkEventMask get_native_event_mask (GdkWindowObject *private) { @@ -1234,6 +1369,10 @@ get_native_event_mask (GdkWindowObject *private) GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_SCROLL_MASK; + /* touches, where a window inside asked for them */ + if (g_object_get_qdata (G_OBJECT (private), touch_wanted_quark ())) + mask |= GDK_TOUCH_MASK; + return mask; } } @@ -1413,6 +1552,7 @@ gdk_window_new (GdkWindow *parent, visual = gdk_screen_get_system_visual (screen); private->event_mask = attributes->event_mask; + _gdk_event_note_event_mask (private->event_mask); if (attributes->wclass == GDK_INPUT_OUTPUT) { @@ -1465,9 +1605,13 @@ gdk_window_new (GdkWindow *parent, { private->impl_window = g_object_ref (private->parent->impl_window); private->impl = g_object_ref (private->impl_window->impl); + note_touch_wanted (private); } - recompute_visible_regions (private, TRUE, FALSE); + /* a new window is not mapped yet: it takes no part in the clip of its + * siblings and of its parent (see remove_child_area()), which stay as + * they are */ + recompute_visible_regions (private, FALSE, FALSE); if (private->parent->window_type != GDK_WINDOW_ROOT) { @@ -2587,6 +2731,9 @@ gdk_window_add_filter (GdkWindow *window, if ((filter->function == function) && (filter->data == data)) { filter->ref_count++; + /* The filter may have been removed while it is being run (and + * is only kept by that); added again, it has to run again. */ + filter->flags = 0; return; } tmp_list = tmp_list->next; @@ -2816,15 +2963,29 @@ gdk_window_begin_implicit_paint (GdkWindow *window, GdkRectangle *rect) paint->uses_implicit = FALSE; paint->flushed = FALSE; paint->surface = NULL; - paint->pixmap = - gdk_pixmap_new (window, - MAX (rect->width, 1), MAX (rect->height, 1), -1); + /* made when a double-buffered paint first draws into it: windows + * whose drawing does not go through GDK's double buffer (Pale Moon, + * Firefox, video players, GL) would otherwise have a pixmap the size + * of the exposed area made and freed in the X server for every frame */ + paint->pixmap = NULL; + paint->width = MAX (rect->width, 1); + paint->height = MAX (rect->height, 1); private->implicit_paint = paint; return TRUE; } +static GdkPixmap * +gdk_window_implicit_paint_get_pixmap (GdkWindow *window, + GdkWindowPaint *paint) +{ + if (paint->pixmap == NULL) + paint->pixmap = gdk_pixmap_new (window, paint->width, paint->height, -1); + + return paint->pixmap; +} + /* Ensure that all content related to this (sub)window is pushed to the native region. If there is an active paint then that area is not pushed, in order to not show partially finished double buffers. */ @@ -2844,6 +3005,8 @@ gdk_window_flush_implicit_paint (GdkWindow *window) paint = impl_window->implicit_paint; paint->flushed = TRUE; + if (paint->pixmap == NULL) + return; /* nothing has been drawn into it */ region = gdk_region_copy (private->clip_region_with_children); /* Don't flush active double buffers, as that may show partially done @@ -2891,7 +3054,8 @@ gdk_window_end_implicit_paint (GdkWindow *window) private->implicit_paint = NULL; - if (!GDK_WINDOW_DESTROYED (window) && !gdk_region_empty (paint->region)) + if (!GDK_WINDOW_DESTROYED (window) && paint->pixmap != NULL && + !gdk_region_empty (paint->region)) { /* Some regions are valid, push these to window now */ tmp_gc = _gdk_drawable_get_scratch_gc ((GdkDrawable *)window, FALSE); @@ -2904,7 +3068,8 @@ gdk_window_end_implicit_paint (GdkWindow *window) else gdk_region_destroy (paint->region); - g_object_unref (paint->pixmap); + if (paint->pixmap) + g_object_unref (paint->pixmap); g_free (paint); } @@ -3026,7 +3191,8 @@ gdk_window_begin_paint_region (GdkWindow *window, if (implicit_paint) { paint->uses_implicit = TRUE; - paint->pixmap = g_object_ref (implicit_paint->pixmap); + paint->pixmap = g_object_ref (gdk_window_implicit_paint_get_pixmap ((GdkWindow *) impl_window, + implicit_paint)); paint->x_offset = -private->abs_x + implicit_paint->x_offset; paint->y_offset = -private->abs_y + implicit_paint->y_offset; } @@ -3043,14 +3209,16 @@ gdk_window_begin_paint_region (GdkWindow *window, paint->surface = _gdk_drawable_ref_cairo_surface (paint->pixmap); if (paint->surface) - cairo_surface_set_device_offset (paint->surface, - -paint->x_offset, -paint->y_offset); + _gdk_cairo_surface_set_device_offset (paint->surface, + -paint->x_offset, -paint->y_offset); for (list = private->paint_stack; list != NULL; list = list->next) { GdkWindowPaint *tmp_paint = list->data; gdk_region_subtract (tmp_paint->region, paint->region); + /* a GC may still have the clip of the paint as it was before */ + tmp_paint->region_tag = new_region_tag (); } private->paint_stack = g_slist_prepend (private->paint_stack, paint); @@ -3731,14 +3899,12 @@ start_draw_helper (GdkDrawable *drawable, } if (x_offset != 0 || y_offset != 0) - { - gdk_gc_set_clip_origin (gc, + _gdk_gc_set_draw_origins (gc, old_clip_x - x_offset, - old_clip_y - y_offset); - gdk_gc_set_ts_origin (gc, - gc->ts_x_origin - x_offset, - gc->ts_y_origin - y_offset); - } + old_clip_y - y_offset, + gc->ts_x_origin - x_offset, + gc->ts_y_origin - y_offset, + FALSE); *x_offset_out = x_offset; *y_offset_out = y_offset; @@ -3786,6 +3952,10 @@ start_draw_helper (GdkDrawable *drawable, * window offset, need to take that into * consideration */ -old_clip_x, -old_clip_y); + else + /* the clip of another window or paint, left on the GC from a + * drawing before, does not belong to this one */ + _gdk_gc_remove_drawable_clip (gc); return impl; } @@ -3803,10 +3973,8 @@ start_draw_helper (GdkDrawable *drawable, #define END_DRAW \ if (x_offset != 0 || y_offset != 0) \ - { \ - gdk_gc_set_clip_origin (gc, old_clip_x, old_clip_y); \ - gdk_gc_set_ts_origin (gc, old_ts_x, old_ts_y); \ - } \ + _gdk_gc_set_draw_origins (gc, old_clip_x, old_clip_y, \ + old_ts_x, old_ts_y, TRUE); \ } #define BEGIN_DRAW_MACRO \ @@ -4125,7 +4293,7 @@ gdk_window_get_composite_drawable (GdkDrawable *drawable, rect.y += private->abs_y; overlap = gdk_region_rect_in (implicit_paint->region, &rect); - if (overlap == GDK_OVERLAP_RECTANGLE_IN) + if (overlap == GDK_OVERLAP_RECTANGLE_IN && implicit_paint->pixmap != NULL) { *composite_x_offset = -private->abs_x + implicit_paint->x_offset; *composite_y_offset = -private->abs_y + implicit_paint->y_offset; @@ -5192,9 +5360,9 @@ gdk_window_ref_cairo_surface (GdkDrawable *drawable) { private->impl_window->outstanding_surfaces++; - cairo_surface_set_device_offset (private->cairo_surface, - private->abs_x, - private->abs_y); + _gdk_cairo_surface_set_device_offset (private->cairo_surface, + private->abs_x, + private->abs_y); cairo_surface_set_user_data (private->cairo_surface, &gdk_window_cairo_key, drawable, gdk_window_cairo_surface_destroy); @@ -5249,6 +5417,71 @@ gdk_window_set_cairo_clip (GdkDrawable *drawable, } } +/* The region gdk_window_set_cairo_clip() clips to, or %NULL if it + * sets no clip */ +static const GdkRegion * +gdk_window_get_cairo_clip_region (GdkWindowObject *private) +{ + GdkWindowPaint *paint; + + if (!private->paint_stack) + return private->clip_region_with_children; + + paint = private->paint_stack->data; + return paint->uses_implicit ? paint->region : NULL; +} + +/* The number of rectangles of the clip a context made with + * gdk_cairo_create() for @window gets, 0 if it gets none */ +gint +_gdk_window_get_cairo_clip_n_rects (GdkWindow *window) +{ + const GdkRegion *region; + + region = gdk_window_get_cairo_clip_region ((GdkWindowObject *) window); + + return region ? region->numRects : 0; +} + +/* Clips @cr as gdk_window_set_cairo_clip() does, for drawing that + * stays within @area: only the parts of the clip region inside @area + * are made into the clip, which saves building a path out of every + * rectangle of a region with many (the parts of a window around its + * child windows, or an expose of many separate areas). */ +void +_gdk_window_set_cairo_clip_in_area (GdkWindow *window, + cairo_t *cr, + const GdkRectangle *area) +{ + const GdkRegion *region; + gint i; + + region = gdk_window_get_cairo_clip_region ((GdkWindowObject *) window); + + cairo_reset_clip (cr); + if (!region) + return; + + cairo_save (cr); + cairo_identity_matrix (cr); + cairo_new_path (cr); + + for (i = 0; i < region->numRects; i++) + { + const GdkRegionBox *box = ®ion->rects[i]; + gint x1 = MAX (box->x1, area->x); + gint y1 = MAX (box->y1, area->y); + gint x2 = MIN (box->x2, area->x + area->width); + gint y2 = MIN (box->y2, area->y + area->height); + + if (x1 < x2 && y1 < y2) + cairo_rectangle (cr, x1, y1, x2 - x1, y2 - y1); + } + + cairo_restore (cr); + cairo_clip (cr); +} + /* Code for dirty-region queueing */ static GSList *update_windows = NULL; @@ -5407,18 +5640,19 @@ _gdk_window_process_updates_recurse (GdkWindow *window, GdkWindowObject *private = (GdkWindowObject *)window; GdkWindowObject *child; GdkRegion *child_region; - GdkRectangle r; + GdkRectangle r, extents; GList *l, *children; if (gdk_region_empty (expose_region)) return; - /* Make this reentrancy safe for expose handlers freeing windows */ - children = g_list_copy (private->children); - g_list_foreach (children, (GFunc)g_object_ref, NULL); + gdk_region_get_clipbox (expose_region, &extents); - /* Iterate over children, starting at topmost */ - for (l = children; l != NULL; l = l->next) + /* Only the children the exposed area reaches: the others take + * neither region work nor references. The list holds references, + * so expose handlers can free windows. */ + children = NULL; + for (l = private->children; l != NULL; l = l->next) { child = l->data; @@ -5435,6 +5669,26 @@ _gdk_window_process_updates_recurse (GdkWindow *window, r.width = child->width; r.height = child->height; + if (!gdk_rectangle_intersect (&extents, &r, NULL)) + continue; + + children = g_list_prepend (children, g_object_ref (child)); + } + children = g_list_reverse (children); + + /* Iterate over children, starting at topmost */ + for (l = children; l != NULL; l = l->next) + { + child = l->data; + + if (child->destroyed || !GDK_WINDOW_IS_MAPPED (child)) + continue; + + r.x = child->x; + r.y = child->y; + r.width = child->width; + r.height = child->height; + child_region = gdk_region_rectangle (&r); if (child->shape) { @@ -5791,6 +6045,29 @@ gdk_window_process_all_updates (void) * this is useful to produce nicer scrolling behavior, for example. * **/ +/* The descendants of @window with an impl of their own, referenced and + * topmost first; the caller turns the list around to process them from + * the bottom. Client side windows share the impl of their parent and + * were updated with it, so they are only walked through. */ +static GList * +find_native_children_to_update (GList *list, + GdkWindowObject *window) +{ + GList *node; + + for (node = g_list_last (window->children); node; node = node->prev) + { + GdkWindowObject *child = node->data; + + if (child->impl != window->impl) + list = g_list_prepend (list, g_object_ref (child)); + else + list = find_native_children_to_update (list, child); + } + + return list; +} + void gdk_window_process_updates (GdkWindow *window, gboolean update_children) @@ -5827,10 +6104,9 @@ gdk_window_process_updates (GdkWindow *window, */ GList *node, *children; - children = g_list_copy (private->children); - g_list_foreach (children, (GFunc)g_object_ref, NULL); + children = g_list_reverse (find_native_children_to_update (NULL, private)); - for (node = g_list_last (children); node; node = node->prev) + for (node = children; node; node = node->next) { gdk_window_process_updates (node->data, TRUE); g_object_unref (node->data); @@ -6663,7 +6939,8 @@ get_all_native_children (GdkWindowObject *private, } -static inline void +/* TRUE when @window was not on top of its siblings before */ +static gboolean gdk_window_raise_internal (GdkWindow *window) { GdkWindowObject *private = (GdkWindowObject *)window; @@ -6672,11 +6949,13 @@ gdk_window_raise_internal (GdkWindow *window) GList *native_children; GList *l, listhead; GdkWindowImplIface *impl_iface; + gboolean did_raise = FALSE; - if (parent) + if (parent && parent->children->data != window) { parent->children = g_list_remove (parent->children, window); parent->children = g_list_prepend (parent->children, window); + did_raise = TRUE; } impl_iface = GDK_WINDOW_IMPL_GET_IFACE (private->impl); @@ -6727,6 +7006,8 @@ gdk_window_raise_internal (GdkWindow *window) } } + + return did_raise; } /* Returns TRUE If the native window was mapped or unmapped */ @@ -6823,7 +7104,7 @@ gdk_window_show_internal (GdkWindow *window, gboolean raise) GdkWindowObject *private; GdkWindowImplIface *impl_iface; gboolean was_mapped, was_viewable; - gboolean did_show; + gboolean did_show, did_raise = FALSE; g_return_if_fail (GDK_IS_WINDOW (window)); @@ -6836,7 +7117,7 @@ gdk_window_show_internal (GdkWindow *window, gboolean raise) if (raise) /* Keep children in (reverse) stacking order */ - gdk_window_raise_internal (window); + did_raise = gdk_window_raise_internal (window); if (gdk_window_has_impl (private)) { @@ -6873,9 +7154,9 @@ gdk_window_show_internal (GdkWindow *window, gboolean raise) _gdk_make_event (GDK_WINDOW (private), GDK_MAP, NULL, FALSE); } - if (!was_mapped || raise) + if (!was_mapped || did_raise) { - recompute_visible_regions (private, TRUE, FALSE); + recompute_visible_regions_in_place (private); /* If any decendants became visible we need to send visibility notify */ gdk_window_update_visibility_recursively (private, NULL); @@ -6930,6 +7211,14 @@ gdk_window_raise (GdkWindow *window) if (private->destroyed) return; + /* Already on top of its siblings: only the native window is raised + * again, in case others stacked it without GDK; nothing new shows. */ + if (private->parent && private->parent->children->data == private) + { + gdk_window_raise_internal (window); + return; + } + gdk_window_flush_if_exposing (window); old_region = NULL; @@ -6940,7 +7229,7 @@ gdk_window_raise (GdkWindow *window) /* Keep children in (reverse) stacking order */ gdk_window_raise_internal (window); - recompute_visible_regions (private, TRUE, FALSE); + recompute_visible_regions_in_place (private); if (old_region) { @@ -7073,7 +7362,7 @@ gdk_window_lower (GdkWindow *window) /* Keep children in (reverse) stacking order */ gdk_window_lower_internal (window); - recompute_visible_regions (private, TRUE, FALSE); + recompute_visible_regions_in_place (private); _gdk_synthesize_crossing_events_for_geometry_change (window); gdk_window_invalidate_in_parent (private); @@ -7288,7 +7577,7 @@ gdk_window_hide (GdkWindow *window) impl_iface->hide (window); } - recompute_visible_regions (private, TRUE, FALSE); + recompute_visible_regions_in_place (private); /* all decendants became non-visible, we need to send visibility notify */ gdk_window_update_visibility_recursively (private, NULL); @@ -7383,6 +7672,8 @@ gdk_window_set_events (GdkWindow *window, _gdk_display_enable_motion_hints (display); private->event_mask = event_mask; + _gdk_event_note_event_mask (event_mask); + note_touch_wanted (private); if (gdk_window_has_impl (private)) { @@ -8422,10 +8713,10 @@ gdk_window_get_root_coords (GdkWindow *window, if (GDK_WINDOW_DESTROYED (window)) { - if (x) - *root_x = x; - if (y) - *root_y = y; + if (root_x) + *root_x = 0; + if (root_y) + *root_y = 0; return; } @@ -8769,6 +9060,15 @@ do_child_shapes (GdkWindow *window, if (merge && private->shape) gdk_region_subtract (region, private->shape); + /* what is left is where neither the children nor the shape are; the + * shape is the rest */ + { + GdkRegion *full = gdk_region_rectangle (&r); + + gdk_region_xor (region, full); + gdk_region_destroy (full); + } + gdk_window_shape_combine_region (window, region, 0, 0); gdk_region_destroy (region); @@ -8947,7 +9247,18 @@ do_child_input_shapes (GdkWindow *window, if (merge && private->input_shape) gdk_region_subtract (region, private->input_shape); + /* what is left is where neither the children nor the shape are; the + * shape is the rest */ + { + GdkRegion *full = gdk_region_rectangle (&r); + + gdk_region_xor (region, full); + gdk_region_destroy (full); + } + gdk_window_input_shape_combine_region (window, region, 0, 0); + + gdk_region_destroy (region); } @@ -9855,6 +10166,10 @@ static const guint type_masks[] = { 0, /* GDK_OWNER_CHANGE = 34 */ 0, /* GDK_GRAB_BROKEN = 35 */ 0, /* GDK_DAMAGE = 36 */ + GDK_TOUCH_MASK, /* GDK_TOUCH_BEGIN = 37 */ + GDK_TOUCH_MASK, /* GDK_TOUCH_UPDATE = 38 */ + GDK_TOUCH_MASK, /* GDK_TOUCH_END = 39 */ + GDK_TOUCH_MASK, /* GDK_TOUCH_CANCEL = 40 */ }; G_STATIC_ASSERT (G_N_ELEMENTS (type_masks) == GDK_EVENT_LAST); @@ -9879,6 +10194,25 @@ update_evmask_for_button_motion (guint evmask, return evmask; } +static gboolean +is_touch_type (GdkEventType type) +{ + return type == GDK_TOUCH_BEGIN || + type == GDK_TOUCH_UPDATE || + type == GDK_TOUCH_END || + type == GDK_TOUCH_CANCEL; +} + +/* a pointer event made of the first finger of a touch (see + * proxy_touch_event()), as opposed to a scroll event made of a smooth + * one, which is marked the same */ +static gboolean +is_touch_emulated (GdkEvent *event) +{ + return event->type != GDK_SCROLL && + (((GdkEventPrivate *) event)->flags & GDK_EVENT_POINTER_EMULATED) != 0; +} + static gboolean is_button_type (GdkEventType type) { @@ -10276,7 +10610,8 @@ get_pointer_window (GdkDisplay *display, grab = _gdk_display_has_pointer_grab (display, serial); if (grab != NULL && !grab->owner_events && - pointer_window != grab->window) + pointer_window != grab->window && + !gdk_window_is_ancestor (pointer_window, grab->window)) pointer_window = NULL; return pointer_window; @@ -10711,9 +11046,16 @@ proxy_pointer_event (GdkDisplay *display, } } + /* the pointer made of a finger goes where no touches are taken */ + if (event_win && is_touch_emulated (source_event) && + (gdk_window_get_events (event_win) & GDK_TOUCH_MASK)) + event_win = NULL; + if (event_win && !display->ignore_core_events) { event = _gdk_make_event (event_win, GDK_MOTION_NOTIFY, source_event, FALSE); + ((GdkEventPrivate *) event)->flags |= + ((GdkEventPrivate *) source_event)->flags & GDK_EVENT_POINTER_EMULATED; event->motion.time = time_; convert_toplevel_coords_to_window (event_win, toplevel_x, toplevel_y, @@ -10808,12 +11150,25 @@ proxy_button_event (GdkEvent *source_event, if (event_win == NULL || display->ignore_core_events) return TRUE; + /* smooth scroll events only where asked for, the whole steps made of + * them not there */ + if (type == GDK_SCROLL && !_gdk_event_scroll_for_window (source_event, event_win)) + return TRUE; + + /* the pointer made of a finger goes where no touches are taken */ + if (type != GDK_SCROLL && is_touch_emulated (source_event) && + (gdk_window_get_events (event_win) & GDK_TOUCH_MASK)) + return TRUE; + event = _gdk_make_event (event_win, type, source_event, FALSE); switch (type) { case GDK_BUTTON_PRESS: case GDK_BUTTON_RELEASE: + ((GdkEventPrivate *) event)->flags |= + ((GdkEventPrivate *) source_event)->flags & (GDK_EVENT_POINTER_EMULATED | + GDK_EVENT_TOUCHPAD_EMULATED); event->button.button = source_event->button.button; convert_toplevel_coords_to_window (event_win, toplevel_x, toplevel_y, @@ -10836,6 +11191,11 @@ proxy_button_event (GdkEvent *source_event, event->scroll.y_root = source_event->scroll.y_root; event->scroll.state = state; event->scroll.device = source_event->scroll.device; + ((GdkEventPrivate *) event)->flags |= + ((GdkEventPrivate *) source_event)->flags & (GDK_EVENT_POINTER_EMULATED | + GDK_EVENT_TOUCHPAD_EMULATED); + if (source_event->scroll.direction == GDK_SCROLL_SMOOTH) + ((GdkEventPrivate *) event)->delta = ((GdkEventPrivate *) source_event)->delta; return TRUE; default: @@ -10936,6 +11296,179 @@ is_input_event (GdkDisplay *display, return FALSE; } +/* Touches, as in GTK+ 3.4, for windows that ask for them with + * GDK_TOUCH_MASK. Each finger goes to the window under it at its + * begin, until its end, whatever happens to the pointer. The finger + * that the window system marks as moving the pointer (the first) is + * also made into pointer events, marked as emulated (see + * gdk_event_get_pointer_emulated()), for all the windows that do not + * take touches: they work with a finger as with a mouse, as in GTK+ 3. + * The backends only send touches to native windows of which a window + * asked for them; elsewhere the window system moves the pointer. */ + +static GHashTable * +touch_targets (GdkDisplay *display) +{ + GHashTable *targets = g_object_get_data (G_OBJECT (display), "gdk-touch-targets"); + + if (targets == NULL) + { + targets = g_hash_table_new_full (NULL, NULL, NULL, g_object_unref); + g_object_set_data_full (G_OBJECT (display), g_intern_static_string ("gdk-touch-targets"), targets, + (GDestroyNotify) g_hash_table_destroy); + } + return targets; +} + +/* the window with GDK_TOUCH_MASK from the one under the finger up */ +static GdkWindow * +touch_window_at (GdkWindow *toplevel, + gdouble toplevel_x, + gdouble toplevel_y) +{ + GdkWindowObject *w; + + w = (GdkWindowObject *) _gdk_window_find_descendant_at (toplevel, toplevel_x, toplevel_y, + NULL, NULL); + for (; w != NULL && w->window_type != GDK_WINDOW_ROOT; w = get_event_parent (w)) + if (w->event_mask & GDK_TOUCH_MASK) + return (GdkWindow *) w; + + return NULL; +} + +/* Puts the event into the queue before @stop, the event that followed + * the touch from the window system (NULL for none), so after what the + * touch and the events emulated before have become, and handles it. */ +static void +emulate_pointer (GdkDisplay *display, + GdkEvent *touch, + GList *stop, + GdkEventType type, + gulong serial) +{ + GdkEvent *event = gdk_event_new (type); + GList *link; + + event->any.window = g_object_ref (touch->any.window); + event->any.send_event = touch->any.send_event; + gdk_event_set_screen (event, gdk_drawable_get_screen (touch->any.window)); + ((GdkEventPrivate *) event)->flags |= GDK_EVENT_POINTER_EMULATED; + + if (type == GDK_MOTION_NOTIFY) + { + event->motion.time = touch->touch.time; + event->motion.x = touch->touch.x; + event->motion.y = touch->touch.y; + event->motion.x_root = touch->touch.x_root; + event->motion.y_root = touch->touch.y_root; + event->motion.state = touch->touch.state; + if (touch->type == GDK_TOUCH_UPDATE) + event->motion.state |= GDK_BUTTON1_MASK; + event->motion.is_hint = FALSE; + event->motion.device = touch->touch.device; + } + else + { + event->button.time = touch->touch.time; + event->button.x = touch->touch.x; + event->button.y = touch->touch.y; + event->button.x_root = touch->touch.x_root; + event->button.y_root = touch->touch.y_root; + event->button.state = touch->touch.state; + if (type == GDK_BUTTON_RELEASE) + event->button.state |= GDK_BUTTON1_MASK; + event->button.button = 1; + event->button.device = touch->touch.device; + } + + if (stop) + { + display->queued_events = g_list_insert_before (display->queued_events, stop, event); + link = stop->prev; + } + else + link = _gdk_event_queue_append (display, event); + _gdk_windowing_got_event (display, link, event, serial); +} + +static gboolean +proxy_touch_event (GdkDisplay *display, + GdkEvent *source_event, + gulong serial) +{ + GHashTable *targets = touch_targets (display); + GdkEventSequence *sequence = source_event->touch.sequence; + GdkWindow *toplevel, *target; + gdouble toplevel_x, toplevel_y; + GdkEvent *event; + GList *link = g_list_find (display->queued_events, source_event); + GList *stop = link ? link->next : NULL; + + toplevel = convert_native_coords_to_toplevel (source_event->any.window, + source_event->touch.x, source_event->touch.y, + &toplevel_x, &toplevel_y); + + if (source_event->type == GDK_TOUCH_BEGIN) + { + target = touch_window_at (toplevel, toplevel_x, toplevel_y); + if (target) + g_hash_table_insert (targets, sequence, g_object_ref (target)); + else + g_hash_table_remove (targets, sequence); + } + else + target = g_hash_table_lookup (targets, sequence); + + if (target && !GDK_WINDOW_DESTROYED (target)) + { + event = _gdk_make_event (target, source_event->type, source_event, FALSE); + event->touch = source_event->touch; + event->touch.window = target; /* the reference of _gdk_make_event */ + convert_toplevel_coords_to_window (target, toplevel_x, toplevel_y, + &event->touch.x, &event->touch.y); + event->touch.axes = NULL; + event->touch.emulating_pointer = source_event->touch.emulating_pointer; + gdk_event_set_screen (event, gdk_drawable_get_screen (target)); + } + + if (source_event->type == GDK_TOUCH_END || + source_event->type == GDK_TOUCH_CANCEL) + g_hash_table_remove (targets, sequence); + + /* the pointer for the windows that do not take touches */ + if (source_event->touch.emulating_pointer && !_gdk_native_windows && + !(((GdkEventPrivate *) source_event)->flags & GDK_EVENT_TOUCH_SYSTEM_POINTER)) + switch (source_event->type) + { + case GDK_TOUCH_BEGIN: + /* the finger brings the pointer into its toplevel, as the + * window system does with the cursor, where it does */ + if (display->pointer_info.toplevel_under_pointer != toplevel && + toplevel && !GDK_WINDOW_DESTROYED (toplevel)) + { + if (display->pointer_info.toplevel_under_pointer) + g_object_unref (display->pointer_info.toplevel_under_pointer); + display->pointer_info.toplevel_under_pointer = g_object_ref (toplevel); + } + /* the pointer moves there, then presses */ + emulate_pointer (display, source_event, stop, GDK_MOTION_NOTIFY, serial); + emulate_pointer (display, source_event, stop, GDK_BUTTON_PRESS, serial); + break; + case GDK_TOUCH_UPDATE: + emulate_pointer (display, source_event, stop, GDK_MOTION_NOTIFY, serial); + break; + case GDK_TOUCH_END: + case GDK_TOUCH_CANCEL: + emulate_pointer (display, source_event, stop, GDK_BUTTON_RELEASE, serial); + break; + default: + break; + } + + return TRUE; +} + void _gdk_windowing_got_event (GdkDisplay *display, GList *event_link, @@ -11021,6 +11554,12 @@ _gdk_windowing_got_event (GdkDisplay *display, if (is_input_event (display, event)) return; + if (is_touch_type (event->type)) + { + unlink_event = proxy_touch_event (display, event, serial); + goto out; + } + if (!(is_button_type (event->type) || is_motion_type (event->type)) || event_private->window_type == GDK_WINDOW_ROOT) @@ -11378,6 +11917,49 @@ gdk_window_get_height (GdkWindow *window) return height; } +/** + * gdk_window_get_scale_factor: + * @window: window to get scale factor for + * + * Returns the internal scale factor that maps from window coordinates + * to the actual device pixels, as in GTK+ 3. On traditional systems + * this is 1, but on very high density outputs this can be a higher + * value (often 2). GDK and GTK+ draw sharp at the device resolution by + * themselves; programs that draw on the window system's window directly + * (GDK_WINDOW_XID() and the like) have to multiply their sizes by it. + * + * Returns: the scale factor + * + * Since: 2.24 + */ +gint +gdk_window_get_scale_factor (GdkWindow *window) +{ + GdkWindowObject *private = (GdkWindowObject *) window; + + g_return_val_if_fail (GDK_IS_WINDOW (window), 1); + + if (GDK_WINDOW_DESTROYED (window) || private->impl == NULL) + return 1; + + return _gdk_windowing_drawable_get_scale (private->impl); +} + +/* cairo_surface_set_device_offset() takes pixels of the device: for a + * surface of a scaled window they are more than GDK's */ +void +_gdk_cairo_surface_set_device_offset (cairo_surface_t *surface, + gdouble x, + gdouble y) +{ + gdouble sx = 1, sy = 1; + +#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE (1, 14, 0) + cairo_surface_get_device_scale (surface, &sx, &sy); +#endif + cairo_surface_set_device_offset (surface, x * sx, y * sy); +} + #define __GDK_WINDOW_C__ #include "gdkaliasdef.c" diff --git a/gdk/gdkwindow.h b/gdk/gdkwindow.h index ca6d0bdf6..5574887a5 100644 --- a/gdk/gdkwindow.h +++ b/gdk/gdkwindow.h @@ -328,7 +328,7 @@ struct _GdkWindowObjectClass /* Windows */ -GType gdk_window_object_get_type (void) G_GNUC_CONST; +GType gdk_window_object_get_type (void); GdkWindow* gdk_window_new (GdkWindow *parent, GdkWindowAttr *attributes, gint attributes_mask); @@ -341,6 +341,7 @@ GdkDisplay* gdk_window_get_display (GdkWindow *window); GdkVisual* gdk_window_get_visual (GdkWindow *window); int gdk_window_get_width (GdkWindow *window); int gdk_window_get_height (GdkWindow *window); +gint gdk_window_get_scale_factor (GdkWindow *window); GdkWindow* gdk_window_at_pointer (gint *win_x, gint *win_y); @@ -679,6 +680,7 @@ void gdk_window_thaw_updates (GdkWindow *window); void gdk_window_freeze_toplevel_updates_libgtk_only (GdkWindow *window); void gdk_window_thaw_toplevel_updates_libgtk_only (GdkWindow *window); +void gdk_window_set_touch_emulation_libgtk_only (GdkWindow *window); void gdk_window_process_all_updates (void); void gdk_window_process_updates (GdkWindow *window, diff --git a/gdk/gdkwindowimpl.h b/gdk/gdkwindowimpl.h index ee84e0408..2fb304fc7 100644 --- a/gdk/gdkwindowimpl.h +++ b/gdk/gdkwindowimpl.h @@ -150,7 +150,7 @@ struct _GdkWindowImplIface }; /* Interface Functions */ -GType gdk_window_impl_get_type (void) G_GNUC_CONST; +GType gdk_window_impl_get_type (void); /* private definitions from gdkwindow.h */ diff --git a/gdk/makefile.msc b/gdk/makefile.msc index 6175c3f21..f8785e818 100644 --- a/gdk/makefile.msc +++ b/gdk/makefile.msc @@ -92,7 +92,14 @@ gdk_OBJECTS = \ gdkrectangle.obj \ gdkregion-generic.obj \ gdkrgb.obj \ - gdkrgb16.obj \ + gdkrgbsimd.obj \ + gdkrgb-mmx.obj \ + gdkrgb-sse2.obj \ + gdkrgb-ssse3.obj \ + gdkrgb-avx2.obj \ + gdkrgb-altivec.obj \ + gdkrgb-armv6.obj \ + gdkrgb-neon.obj \ gdkscreen.obj \ gdkselection.obj \ gdkvisual.obj \ diff --git a/gdk/makegdkalias.pl b/gdk/makegdkalias.pl index 27646cc0a..0f608f270 100755 --- a/gdk/makegdkalias.pl +++ b/gdk/makegdkalias.pl @@ -14,7 +14,7 @@ print < -#if defined(G_HAVE_GNUC_VISIBILITY) && !defined(__APPLE__) +#if defined(G_HAVE_GNUC_VISIBILITY) && !defined(__APPLE__) && !defined(G_OS_WIN32) EOF diff --git a/gdk/quartz/GdkQuartzView.c b/gdk/quartz/GdkQuartzView.c index bad737da2..15a74a9ee 100644 --- a/gdk/quartz/GdkQuartzView.c +++ b/gdk/quartz/GdkQuartzView.c @@ -32,7 +32,9 @@ if ((self = [super initWithFrame: frameRect])) { markedRange = NSMakeRange (NSNotFound, 0); - selectedRange = NSMakeRange (NSNotFound, 0); + /* the caret, not NSNotFound: without a location, macOS shows no + * window of accented characters when a key is held down */ + selectedRange = NSMakeRange (0, 0); } return self; @@ -59,6 +61,14 @@ -(void) keyDown: (NSEvent *) theEvent { GDK_NOTE (EVENTS, g_print ("keyDown\n")); + + /* A key held down for the window of accented characters (10.7 and + * later) calls none of the methods below while it repeats: the key is + * the input method's then. Any text, marked text or command clears + * or replaces this. */ + g_object_set_data (G_OBJECT (gdk_window), GIC_FILTER_KEY, + GUINT_TO_POINTER (GIC_FILTER_FILTERED)); + [self interpretKeyEvents: [NSArray arrayWithObject: theEvent]]; } @@ -126,7 +136,8 @@ { GDK_NOTE (EVENTS, g_print ("unmarkText\n")); gchar *prev_str; - markedRange = selectedRange = NSMakeRange (NSNotFound, 0); + selectedRange = NSMakeRange (0, 0); + markedRange = NSMakeRange (NSNotFound, 0); prev_str = g_object_get_data (G_OBJECT (gdk_window), TIC_MARKED_TEXT); if (prev_str) @@ -184,11 +195,21 @@ GDK_NOTE (EVENTS, g_print ("doCommandBySelector\n")); if ([self respondsToSelector: aSelector]) [self performSelector: aSelector]; + + /* whatever the command, GTK+ handles the key itself (as in GTK+ 3.24) */ + g_object_set_data (G_OBJECT (gdk_window), GIC_FILTER_KEY, + GUINT_TO_POINTER (GIC_FILTER_PASSTHRU)); } /* This gets called on OS X 10.6 and upwards from interpretKeyEvents */ -(void)insertText: (id)aString replacementRange: (NSRange)replacementRange { + /* the window of accented characters replaces the character typed + * before it: the input method deletes it around the cursor */ + if (replacementRange.location != NSNotFound && replacementRange.length > 0) + g_object_set_data (G_OBJECT (gdk_window), TIC_INSERT_TEXT_REPLACE_LEN, + GINT_TO_POINTER (replacementRange.length)); + [self insertText:aString]; } @@ -223,6 +244,7 @@ else { str = [string UTF8String]; + selectedRange = NSMakeRange ([string length], 0); } prev_str = g_object_get_data (G_OBJECT (gdk_window), TIC_INSERT_TEXT); @@ -530,6 +552,20 @@ GUINT_TO_POINTER (GIC_FILTER_PASSTHRU)); } +-(void)scrollPageDown: (id)sender +{ + GDK_NOTE (EVENTS, g_message ("scrollPageDown")); + g_object_set_data (G_OBJECT (gdk_window), GIC_FILTER_KEY, + GUINT_TO_POINTER (GIC_FILTER_PASSTHRU)); +} + +-(void)scrollPageUp: (id)sender +{ + GDK_NOTE (EVENTS, g_message ("scrollPageUp")); + g_object_set_data (G_OBJECT (gdk_window), GIC_FILTER_KEY, + GUINT_TO_POINTER (GIC_FILTER_PASSTHRU)); +} + -(void)selectAll: (id)sender { GDK_NOTE (EVENTS, g_print ("selectAll\n")); @@ -618,6 +654,45 @@ [super viewWillDraw]; } +/* What AppKit invalidates goes into GDK's bookkeeping too, so that + * drawRect: knows all of it (see _gdk_quartz_use_gdk_invalidation()) */ +-(void)noteNeedsDisplayInRect: (NSRect)rect +{ + GdkWindowImplQuartz *impl; + GdkRectangle gdk_rect; + NSRect bounds = [self bounds]; + + if (!gdk_window || GDK_WINDOW_DESTROYED (gdk_window) || + !_gdk_quartz_use_gdk_invalidation ()) + return; + + impl = GDK_WINDOW_IMPL_QUARTZ (GDK_WINDOW_OBJECT (gdk_window)->impl); + rect = NSIntersectionRect (rect, bounds); + if (NSIsEmptyRect (rect)) + return; + + gdk_rect.x = floor (rect.origin.x); + gdk_rect.y = floor (rect.origin.y); + gdk_rect.width = ceil (rect.origin.x + rect.size.width) - gdk_rect.x; + gdk_rect.height = ceil (rect.origin.y + rect.size.height) - gdk_rect.y; + if (!impl->needs_display_region) + impl->needs_display_region = gdk_region_new (); + gdk_region_union_with_rect (impl->needs_display_region, &gdk_rect); +} + +-(void)setNeedsDisplayInRect: (NSRect)rect +{ + [self noteNeedsDisplayInRect: rect]; + [super setNeedsDisplayInRect: rect]; +} + +-(void)setNeedsDisplay: (BOOL)flag +{ + if (flag) + [self noteNeedsDisplayInRect: [self bounds]]; + [super setNeedsDisplay: flag]; +} + -(void)drawRect: (NSRect)rect { GdkRectangle gdk_rect; @@ -626,7 +701,7 @@ const NSRect *drawn_rects; NSInteger count; int i; - GdkRegion *region; + GdkRegion *region, *needs; if (GDK_WINDOW_DESTROYED (gdk_window)) return; @@ -648,7 +723,13 @@ */ [NSGraphicsContext saveGraphicsState]; - [[NSColor windowBackgroundColor] setFill]; + if (impl->background_color_set) + [[NSColor colorWithCalibratedRed: impl->background_color.red / 65535.0 + green: impl->background_color.green / 65535.0 + blue: impl->background_color.blue / 65535.0 + alpha: 1.0] setFill]; + else + [[NSColor windowBackgroundColor] setFill]; [NSBezierPath fillRect: rect]; [NSGraphicsContext restoreGraphicsState]; @@ -656,25 +737,49 @@ return; } - /* Clear our own bookkeeping of regions that need display */ - if (impl->needs_display_region) + /* Our own bookkeeping of what needs display; taken here, as an + * expose may invalidate again */ + needs = impl->needs_display_region; + impl->needs_display_region = NULL; + + if (needs && _gdk_quartz_use_gdk_invalidation () && + !NSContainsRect (rect, [self bounds])) { - gdk_region_destroy (impl->needs_display_region); - impl->needs_display_region = NULL; + /* Layer-backed views (10.14 and newer) merge the invalidated + * rects into one, or give the whole view: the windows of two + * small meters in opposite corners would expose all between. + * What GDK and AppKit invalidated is known here exactly (from + * Ardour's YTK). */ + GdkRegion *drawing; + + gdk_rect.x = rect.origin.x; + gdk_rect.y = rect.origin.y; + gdk_rect.width = rect.size.width; + gdk_rect.height = rect.size.height; + drawing = gdk_region_rectangle (&gdk_rect); + region = needs; + needs = NULL; + gdk_region_intersect (region, drawing); + gdk_region_destroy (drawing); + } + else + { + [self getRectsBeingDrawn: &drawn_rects count: &count]; + region = gdk_region_new (); + + for (i = 0; i < count; i++) + { + gdk_rect.x = drawn_rects[i].origin.x; + gdk_rect.y = drawn_rects[i].origin.y; + gdk_rect.width = drawn_rects[i].size.width; + gdk_rect.height = drawn_rects[i].size.height; + + gdk_region_union_with_rect (region, &gdk_rect); + } } - [self getRectsBeingDrawn: &drawn_rects count: &count]; - region = gdk_region_new (); - - for (i = 0; i < count; i++) - { - gdk_rect.x = drawn_rects[i].origin.x; - gdk_rect.y = drawn_rects[i].origin.y; - gdk_rect.width = drawn_rects[i].size.width; - gdk_rect.height = drawn_rects[i].size.height; - - gdk_region_union_with_rect (region, &gdk_rect); - } + if (needs) + gdk_region_destroy (needs); impl->in_paint_rect_count++; _gdk_window_process_updates_recurse (gdk_window, region); diff --git a/gdk/quartz/GdkQuartzView.h b/gdk/quartz/GdkQuartzView.h index 2f86de71e..2b0d6e4c7 100644 --- a/gdk/quartz/GdkQuartzView.h +++ b/gdk/quartz/GdkQuartzView.h @@ -26,6 +26,7 @@ #define TIC_SELECTED_POS "tic-selected-pos" #define TIC_SELECTED_LEN "tic-selected-len" #define TIC_INSERT_TEXT "tic-insert-text" +#define TIC_INSERT_TEXT_REPLACE_LEN "tic-insert-text-replace-len" #define TIC_IN_KEY_DOWN "tic-in-key-down" /* GtkIMContext */ diff --git a/gdk/quartz/GdkQuartzWindow.c b/gdk/quartz/GdkQuartzWindow.c index e704cd733..8965c2fd7 100644 --- a/gdk/quartz/GdkQuartzWindow.c +++ b/gdk/quartz/GdkQuartzWindow.c @@ -69,6 +69,9 @@ _gdk_quartz_window_attach_to_parent (window); gdk_synthesize_window_state (window, GDK_WINDOW_STATE_ICONIFIED, 0); + + /* newer systems may come back with stale contents (Ardour) */ + [[self contentView] setNeedsDisplay:YES]; } -(void)windowDidBecomeKey:(NSNotification *)aNotification @@ -429,9 +432,13 @@ return YES; } --(BOOL)isInManualResize +/* Used by gdkevents-quartz.c to decide if our sendEvent() handler above + * will see the event or if it will be subjected to standard processing + * by GDK. + */ +-(BOOL)isInManualResizeOrMove { - return inManualResize; + return inManualResize || inManualMove; } -(void)beginManualResize diff --git a/gdk/quartz/GdkQuartzWindow.h b/gdk/quartz/GdkQuartzWindow.h index 9cdee6ba3..5ddcfbb3c 100644 --- a/gdk/quartz/GdkQuartzWindow.h +++ b/gdk/quartz/GdkQuartzWindow.h @@ -39,7 +39,7 @@ -(BOOL)isInMove; -(void)beginManualMove; -(BOOL)trackManualMove; --(BOOL)isInManualResize; +-(BOOL)isInManualResizeOrMove; -(void)beginManualResize; -(BOOL)trackManualResize; -(void)showAndMakeKey:(BOOL)makeKey; diff --git a/gdk/quartz/gdkdrawable-quartz.c b/gdk/quartz/gdkdrawable-quartz.c index eb520f08d..bf2f2d995 100644 --- a/gdk/quartz/gdkdrawable-quartz.c +++ b/gdk/quartz/gdkdrawable-quartz.c @@ -79,6 +79,11 @@ _gdk_windowing_create_cairo_surface (GdkDrawable *drawable, surface_data, gdk_quartz_cairo_surface_destroy); + /* HiDPI: AppKit puts the points on the pixels of a Retina screen; + * pixbufs with a picture of those pixels use it */ + if (cg_context && GDK_IS_WINDOW_IMPL_QUARTZ (drawable)) + _gdk_cairo_surface_set_hidpi_scale (surface, _gdk_windowing_drawable_get_scale (drawable)); + return surface; } @@ -100,7 +105,13 @@ gdk_quartz_ref_cairo_surface (GdkDrawable *drawable) width, height); } else - cairo_surface_reference (impl->cairo_surface); + { + cairo_surface_reference (impl->cairo_surface); + /* HiDPI: the window may be on a screen of another scale by now */ + if (GDK_IS_WINDOW_IMPL_QUARTZ (drawable)) + _gdk_cairo_surface_set_hidpi_scale (impl->cairo_surface, + _gdk_windowing_drawable_get_scale (drawable)); + } return impl->cairo_surface; } @@ -652,21 +663,34 @@ gdk_quartz_draw_pixbuf (GdkDrawable *drawable, void *data; int rowstride, pixbuf_width, pixbuf_height; gboolean has_alpha; + GdkPixbuf *picture = pixbuf; if (!context) return; pixbuf_width = gdk_pixbuf_get_width (pixbuf); pixbuf_height = gdk_pixbuf_get_height (pixbuf); - rowstride = gdk_pixbuf_get_rowstride (pixbuf); - has_alpha = gdk_pixbuf_get_has_alpha (pixbuf); - data = gdk_pixbuf_get_pixels (pixbuf); + /* HiDPI: on a Retina screen the picture made for it, drawn into the + * same points */ + if (GDK_IS_WINDOW_IMPL_QUARTZ (drawable)) + { + GdkPixbuf *hires = _gdk_pixbuf_get_hires (pixbuf, _gdk_windowing_drawable_get_scale (drawable)); + + if (hires) + picture = hires; + } + + rowstride = gdk_pixbuf_get_rowstride (picture); + has_alpha = gdk_pixbuf_get_has_alpha (picture); + + data = gdk_pixbuf_get_pixels (picture); colorspace = CGColorSpaceCreateDeviceRGB (); - data_provider = CGDataProviderCreateWithData (NULL, data, pixbuf_height * rowstride, NULL); + data_provider = CGDataProviderCreateWithData (NULL, data, + gdk_pixbuf_get_height (picture) * rowstride, NULL); - image = CGImageCreate (pixbuf_width, pixbuf_height, 8, + image = CGImageCreate (gdk_pixbuf_get_width (picture), gdk_pixbuf_get_height (picture), 8, has_alpha ? 32 : 24, rowstride, colorspace, has_alpha ? kCGImageAlphaLast : 0, @@ -844,14 +868,16 @@ gdk_quartz_drawable_get_context (GdkDrawable *drawable, void _gdk_quartz_drawable_flush (GdkDrawable *drawable) { - static struct timeval prev_tv; + /* intervals on the monotonic clock: setting the clock, or a 32-bit + * time_t after 2038, does not stop the flushing */ + static gint64 prev_time; static gint intervals[4]; static gint index; - struct timeval tv; + gint64 now; gint ms; - gettimeofday (&tv, NULL); - ms = (tv.tv_sec - prev_tv.tv_sec) * 1000 + (tv.tv_usec - prev_tv.tv_usec) / 1000; + now = g_get_monotonic_time (); + ms = (gint) MIN ((now - prev_time) / 1000, G_MAXINT / 8); intervals[index++ % 4] = ms; if (drawable) @@ -868,11 +894,11 @@ _gdk_quartz_drawable_flush (GdkDrawable *drawable) [window_impl->toplevel flushWindow]; } - prev_tv = tv; + prev_time = now; } } else - prev_tv = tv; + prev_time = now; } void diff --git a/gdk/quartz/gdkevents-quartz.c b/gdk/quartz/gdkevents-quartz.c index 9d62ec55a..cf86d09e0 100644 --- a/gdk/quartz/gdkevents-quartz.c +++ b/gdk/quartz/gdkevents-quartz.c @@ -25,6 +25,7 @@ #include #include #include +#include #import #include @@ -225,6 +226,19 @@ _gdk_quartz_events_break_all_grabs (guint32 time) _gdk_display_pointer_grab_update (_gdk_display, 0); } + +/* The touchpad gestures of Mac OS X 10.5.2 and later: a pinch + * (magnify) and a swipe with three fingers. Older SDKs do not know + * them; Mac OS X before 10.5.2 never sends them. */ +#define GDK_QUARTZ_EVENT_MAGNIFY 30 +#define GDK_QUARTZ_EVENT_SWIPE 31 + +#if MAC_OS_X_VERSION_MAX_ALLOWED < 1060 +@interface NSEvent (GdkTouchpadGestures) +- (CGFloat)magnification; +@end +#endif + static void fixup_event (GdkEvent *event) { @@ -250,6 +264,12 @@ append_event (GdkEvent *event, _gdk_windowing_got_event (_gdk_display, node, event, 0); } +static void +append_scroll_event (GdkEvent *event) +{ + append_event (event, TRUE); +} + static gint gdk_event_apply_filters (NSEvent *nsevent, GdkEvent *event, @@ -400,11 +420,14 @@ get_event_mask_from_ns_event (NSEvent *nsevent) case NSMouseMoved: return GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK; case NSScrollWheel: + case GDK_QUARTZ_EVENT_MAGNIFY: /* scroll steps with Ctrl */ /* Since applications that want button press events can get * scroll events on X11 (since scroll wheel events are really * button press events there), we need to use GDK_BUTTON_PRESS_MASK too. */ return GDK_SCROLL_MASK | GDK_BUTTON_PRESS_MASK; + case GDK_QUARTZ_EVENT_SWIPE: /* the back and forward buttons */ + return GDK_BUTTON_PRESS_MASK; case NSLeftMouseDragged: return (GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_MOTION_MASK | GDK_BUTTON1_MOTION_MASK | @@ -545,6 +568,29 @@ get_toplevel_from_ns_event (NSEvent *nsevent, * here, not very nice. */ _gdk_quartz_events_break_all_grabs (get_time_from_ns_event (nsevent)); + + /* Check if the event occurred on the titlebar. If it did, + * explicitly return NULL to prevent going through the + * fallback path, which could match the window that is + * directly under the titlebar. + */ + if (view_point.y < 0 && + view_point.x >= view_frame.origin.x && + view_point.x < view_frame.origin.x + view_frame.size.width) + { + NSView *superview = [view superview]; + if (superview) + { + NSRect superview_frame = [superview frame]; + int titlebar_height = superview_frame.size.height - + view_frame.size.height; + + if (titlebar_height > 0 && view_point.y >= -titlebar_height) + { + return NULL; + } + } + } } else { @@ -714,6 +760,48 @@ find_toplevel_under_pointer (GdkDisplay *display, /* This function finds the correct window to send an event to, taking * into account grabs, event propagation, and event masks. */ +/* A native view of the program inside a GDK window (a plugin's interface, + * video, a web view) that took a mouse button; the pointer events stay + * with Cocoa until the button is up (from Ardour's YTK) */ +static NSView *foreign_mouse_down_view; + +/* whether the pointer is over a view of the program's own, not GDK's, + * inside @toplevel; a press there keeps the following events for it */ +static gboolean +pointer_on_foreign_view (NSEvent *nsevent, + GdkWindow *toplevel) +{ + GdkWindowImplQuartz *impl = GDK_WINDOW_IMPL_QUARTZ (GDK_WINDOW_OBJECT (toplevel)->impl); + NSView *content, *hit; + NSPoint point; + + if (!impl || !impl->view || [nsevent window] != impl->toplevel) + return FALSE; + + content = impl->view; + if ([[content subviews] count] == 0) + return FALSE; + + point = [nsevent locationInWindow]; + if ([content superview]) + point = [[content superview] convertPoint:point fromView:nil]; + hit = [content hitTest:point]; + if (hit == nil || [hit isKindOfClass:[GdkQuartzView class]]) + return FALSE; + + switch ([nsevent type]) + { + case NSLeftMouseDown: + case NSRightMouseDown: + case NSOtherMouseDown: + foreign_mouse_down_view = hit; + break; + default: + break; + } + return TRUE; +} + static GdkWindow * find_window_for_ns_event (NSEvent *nsevent, gint *x, @@ -745,6 +833,8 @@ find_window_for_ns_event (NSEvent *nsevent, case NSOtherMouseUp: case NSMouseMoved: case NSScrollWheel: + case GDK_QUARTZ_EVENT_MAGNIFY: + case GDK_QUARTZ_EVENT_SWIPE: case NSLeftMouseDragged: case NSRightMouseDragged: case NSOtherMouseDragged: @@ -752,6 +842,14 @@ find_window_for_ns_event (NSEvent *nsevent, GdkDisplay *display; GdkPointerGrabInfo *grab; + if (foreign_mouse_down_view) + { + if (event_type == NSLeftMouseUp || event_type == NSRightMouseUp || + event_type == NSOtherMouseUp) + foreign_mouse_down_view = nil; + return NULL; + } + display = gdk_drawable_get_display (toplevel); /* From the docs for XGrabPointer: @@ -845,6 +943,9 @@ find_window_for_ns_event (NSEvent *nsevent, *y = y_tmp; } + if (pointer_on_foreign_view (nsevent, toplevel)) + return NULL; + return toplevel; } } @@ -857,8 +958,36 @@ find_window_for_ns_event (NSEvent *nsevent, */ if ([view trackingRect] == [nsevent trackingNumber]) return toplevel; - else - return NULL; + + /* macOS 13 no longer sends the events of the tracking rect, but + * those of the cursor rects, which earlier ones were left out: + * they come 4 pixels outside the frame of the window (the same + * fix as GTK+ 3 and Ardour's YTK) */ + if (gdk_quartz_osx_version () >= GDK_OSX_VENTURA && + (![nsevent respondsToSelector:@selector(trackingArea)] || + [(id) nsevent trackingArea] == nil)) + { + const CGFloat border_width = 4; + NSRect frame = [[nsevent window] frame]; + gboolean inside, at_edge; + + frame.origin.x -= border_width; + frame.origin.y -= border_width; + frame.size.width += 2 * border_width; + frame.size.height += 2 * border_width; + inside = (screen_point.x >= frame.origin.x && + screen_point.x <= frame.origin.x + frame.size.width && + screen_point.y >= frame.origin.y && + screen_point.y <= frame.origin.y + frame.size.height); + at_edge = (screen_point.x >= frame.origin.x - 1 && + screen_point.x <= frame.origin.x + frame.size.width + 1 && + screen_point.y >= frame.origin.y - 1 && + screen_point.y <= frame.origin.y + frame.size.height + 1); + + if ((event_type == NSMouseEntered && inside) || at_edge) + return toplevel; + } + return NULL; case NSKeyDown: case NSKeyUp: @@ -1004,6 +1133,72 @@ fill_scroll_event (GdkWindow *window, event->scroll.device = _gdk_display->core_pointer; } +/* A pinch becomes scroll steps with Ctrl and a swipe the back or + * forward button, for programs that know nothing of gestures + * (gdkevents.c); the first event goes into @event */ +static gboolean +touchpad_gesture_event (GdkWindow *window, + GdkEvent *event, + NSEvent *nsevent, + gint x, + gint y, + gint x_root, + gint y_root) +{ + static gdouble pinch_rest; + static NSTimeInterval pinch_time; + GdkEvent template_event; + GList *events, *l; + + memset (&template_event, 0, sizeof template_event); + fill_scroll_event (window, &template_event, nsevent, x, y, x_root, y_root, GDK_SCROLL_UP); + + if ([nsevent type] == GDK_QUARTZ_EVENT_MAGNIFY) + { + CGFloat magnification; + + if (![nsevent respondsToSelector:@selector(magnification)]) + return FALSE; + + magnification = [nsevent magnification]; + if (magnification <= -1) + return FALSE; + + /* a pause starts a new pinch */ + if ([nsevent timestamp] - pinch_time > 0.3) + pinch_rest = 0; + pinch_time = [nsevent timestamp]; + + events = _gdk_event_touchpad_pinch (&template_event, log1p (magnification), &pinch_rest); + } + else + { + /* deltaX is 1 for a swipe to the left: forward, as on X11 */ + events = _gdk_event_touchpad_swipe (&template_event, - [nsevent deltaX]); + } + + if (!events) + return FALSE; + + /* the first one is @event, the window of which gets its reference + * from the caller */ + *event = *(GdkEvent *) events->data; + ((GdkEventPrivate *) event)->flags |= GDK_EVENT_TOUCHPAD_EMULATED; + gdk_event_free (events->data); + + for (l = events->next; l; l = l->next) + { + GdkEvent *other = l->data; + + /* append_event() takes a reference of its own */ + g_object_unref (other->any.window); + append_event (other, TRUE); + } + g_list_free (events); + + return TRUE; +} + static void fill_key_event (GdkWindow *window, GdkEvent *event, @@ -1387,10 +1582,10 @@ gdk_event_translate (GdkEvent *event, return FALSE; } - /* Also when in a manual resize, we ignore events so that these are - * pushed to GdkQuartzWindow's sendEvent handler. + /* Also when in a manual resize or move, we ignore events so that + * these are pushed to GdkQuartzWindow's sendEvent handler. */ - if ([(GdkQuartzWindow *)nswindow isInManualResize]) + if ([(GdkQuartzWindow *)nswindow isInManualResizeOrMove]) return FALSE; /* Find the right GDK window to send the event to, taking grabs and @@ -1489,32 +1684,46 @@ gdk_event_translate (GdkEvent *event, case NSScrollWheel: { - float dx = [nsevent deltaX]; - float dy = [nsevent deltaY]; - GdkScrollDirection direction; + /* Trackpads and the Magic Mouse tell how far to scroll in + * pixels, as GTK+ 3 takes them, and in lines, which make up + * whole steps of the wheel; a plain wheel just turns, a step + * each time, as before */ + static gdouble rest[2]; + GdkEvent scroll; + gdouble dx = [nsevent deltaX]; + gdouble dy = [nsevent deltaY]; + gdouble px = 0, py = 0; + gboolean precise = FALSE; - if (dy != 0) + /* from 10.7; older SDKs do not know these */ +#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070 + precise = [nsevent respondsToSelector:@selector(hasPreciseScrollingDeltas)] && + [nsevent hasPreciseScrollingDeltas]; + if (precise) { - if (dy < 0.0) - direction = GDK_SCROLL_DOWN; - else - direction = GDK_SCROLL_UP; - - fill_scroll_event (window, event, nsevent, x, y, x_root, y_root, direction); + px = - [nsevent scrollingDeltaX]; + py = - [nsevent scrollingDeltaY]; + } + else +#endif + { + dx = dx > 0 ? 1 : dx < 0 ? -1 : 0; + dy = dy > 0 ? 1 : dy < 0 ? -1 : 0; + rest[0] = rest[1] = 0; } - if (dx != 0) - { - if (dx < 0.0) - direction = GDK_SCROLL_RIGHT; - else - direction = GDK_SCROLL_LEFT; - - fill_scroll_event (window, event, nsevent, x, y, x_root, y_root, direction); - } + memset (&scroll, 0, sizeof scroll); + fill_scroll_event (window, &scroll, nsevent, x, y, x_root, y_root, GDK_SCROLL_SMOOTH); + _gdk_event_emit_scroll (event, &scroll, precise, px, py, - dx, - dy, rest, + append_scroll_event); } break; + case GDK_QUARTZ_EVENT_MAGNIFY: + case GDK_QUARTZ_EVENT_SWIPE: + return_val = touchpad_gesture_event (window, event, nsevent, x, y, x_root, y_root); + break; + case NSMouseExited: if (WINDOW_IS_TOPLEVEL (window)) [[NSCursor arrowCursor] set]; diff --git a/gdk/quartz/gdkglobals-quartz.c b/gdk/quartz/gdkglobals-quartz.c index 4e596eef5..1901b44e0 100644 --- a/gdk/quartz/gdkglobals-quartz.c +++ b/gdk/quartz/gdkglobals-quartz.c @@ -22,6 +22,8 @@ #include "gdktypes.h" #include "gdkprivate.h" #include "gdkquartz.h" +#include "gdkprivate-quartz.h" +#include GdkDisplay *_gdk_display = NULL; GdkScreen *_gdk_screen = NULL; @@ -57,3 +59,43 @@ gdk_quartz_osx_version (void) else return minor; } + +/* -1: not set, GDK_QUARTZ_COCOA_INVALIDATION or the version decide */ +static gint use_cocoa_invalidation = -1; + +/** + * gdk_quartz_set_use_cocoa_invalidation: + * @use: %TRUE to expose what AppKit says is being drawn + * + * From macOS 10.14 GDK exposes exactly what it and AppKit invalidated, + * not the merged rectangles of the layer-backed views; %TRUE goes back + * to those (as in Ardour's YTK). The environment variable + * GDK_QUARTZ_COCOA_INVALIDATION=1 does the same. + */ +void +gdk_quartz_set_use_cocoa_invalidation (gboolean use) +{ + use_cocoa_invalidation = use != FALSE; +} + +gboolean +gdk_quartz_get_use_cocoa_invalidation (void) +{ + return !_gdk_quartz_use_gdk_invalidation (); +} + +gboolean +_gdk_quartz_use_gdk_invalidation (void) +{ + if (use_cocoa_invalidation < 0) + { + const gchar *env = g_getenv ("GDK_QUARTZ_COCOA_INVALIDATION"); + + if (env && *env) + use_cocoa_invalidation = atoi (env) != 0; + else + use_cocoa_invalidation = gdk_quartz_osx_version () < GDK_OSX_MOJAVE; + } + + return !use_cocoa_invalidation; +} diff --git a/gdk/quartz/gdkimage-quartz.c b/gdk/quartz/gdkimage-quartz.c index abe620487..012f9c7a9 100644 --- a/gdk/quartz/gdkimage-quartz.c +++ b/gdk/quartz/gdkimage-quartz.c @@ -145,9 +145,19 @@ _gdk_quartz_image_copy_to_image (GdkDrawable *drawable, if (GDK_WINDOW_IMPL_QUARTZ (drawable) == GDK_WINDOW_IMPL_QUARTZ (GDK_WINDOW_OBJECT (_gdk_root)->impl)) { +#if MAC_OS_X_VERSION_MAX_ALLOWED < 1050 + /* the screen cannot be read before 10.5 (CGWindowListCreateImage) */ + return image; +#else /* Special case for the root window. */ CGRect rect = CGRectMake (src_x, src_y, width, height); - CGImageRef root_image_ref = CGWindowListCreateImage (rect, + CGImageRef root_image_ref; + + /* weakly linked where 10.4 is the oldest system */ + if (CGWindowListCreateImage == NULL) + return image; + + root_image_ref = CGWindowListCreateImage (rect, kCGWindowListOptionOnScreenOnly, kCGNullWindowID, kCGWindowImageDefault); @@ -170,6 +180,7 @@ _gdk_quartz_image_copy_to_image (GdkDrawable *drawable, rep = [[NSBitmapImageRep alloc] initWithCGImage: root_image_ref]; CGImageRelease (root_image_ref); +#endif } else { diff --git a/gdk/quartz/gdkkeys-quartz.c b/gdk/quartz/gdkkeys-quartz.c index 98fccd175..674a7aef8 100644 --- a/gdk/quartz/gdkkeys-quartz.c +++ b/gdk/quartz/gdkkeys-quartz.c @@ -470,7 +470,8 @@ update_keymap (void) p[0] = known_numeric_keys[i].keypad_keyval; } - g_signal_emit_by_name (default_keymap, "keys-changed"); + if (default_keymap != NULL) + g_signal_emit_by_name (default_keymap, "keys-changed"); } static void @@ -696,7 +697,6 @@ gdk_keymap_translate_keyboard_state (GdkKeymap *keymap, { guint tmp_keyval; GdkModifierType bit; - guint tmp_modifiers = 0; g_return_val_if_fail (keymap == NULL || GDK_IS_KEYMAP (keymap), FALSE); g_return_val_if_fail (group >= 0 && group <= 1, FALSE); @@ -716,24 +716,23 @@ gdk_keymap_translate_keyboard_state (GdkKeymap *keymap, if (hardware_keycode < 0 || hardware_keycode >= NUM_KEYCODES) return FALSE; - /* Check if modifiers modify the keyval */ - for (bit = GDK_SHIFT_MASK; bit < GDK_BUTTON1_MASK; bit <<= 1) - { - if (translate_keysym (hardware_keycode, - (bit == GDK_MOD1_MASK) ? 0 : group, - state & ~bit, - NULL, NULL) != - translate_keysym (hardware_keycode, - (bit == GDK_MOD1_MASK) ? 1 : group, - state | bit, - NULL, NULL)) - tmp_modifiers |= bit; - } - tmp_keyval = translate_keysym (hardware_keycode, group, state, level, effective_group); + /* Check if modifiers modify the keyval */ if (consumed_modifiers) - *consumed_modifiers = tmp_modifiers; + { + guint tmp_modifiers = (state & GDK_MODIFIER_MASK); + + for (bit = 1; bit <= tmp_modifiers; bit <<= 1) + { + if ((bit & tmp_modifiers) && + translate_keysym (hardware_keycode, group, state & ~bit, + NULL, NULL) == tmp_keyval) + tmp_modifiers &= ~bit; + } + + *consumed_modifiers = tmp_modifiers; + } if (keyval) *keyval = tmp_keyval; diff --git a/gdk/quartz/gdkprivate-quartz.h b/gdk/quartz/gdkprivate-quartz.h index b78c35369..34956a378 100644 --- a/gdk/quartz/gdkprivate-quartz.h +++ b/gdk/quartz/gdkprivate-quartz.h @@ -219,4 +219,6 @@ gboolean _gdk_quartz_window_queue_antiexpose (GdkWindow *window, /* Pixmap */ CGImageRef _gdk_pixmap_get_cgimage (GdkPixmap *pixmap); +gboolean _gdk_quartz_use_gdk_invalidation (void); + #endif /* __GDK_PRIVATE_QUARTZ_H__ */ diff --git a/gdk/quartz/gdkquartz.h b/gdk/quartz/gdkquartz.h index 42aac50b9..79ef9482d 100644 --- a/gdk/quartz/gdkquartz.h +++ b/gdk/quartz/gdkquartz.h @@ -71,6 +71,8 @@ NSImage *gdk_quartz_pixbuf_to_ns_image_libgtk_only (GdkPixbuf id gdk_quartz_drag_context_get_dragging_info_libgtk_only (GdkDragContext *context); NSEvent *gdk_quartz_event_get_nsevent (GdkEvent *event); GdkOSXVersion gdk_quartz_osx_version (void); +void gdk_quartz_set_use_cocoa_invalidation (gboolean use); +gboolean gdk_quartz_get_use_cocoa_invalidation (void); GdkAtom gdk_quartz_pasteboard_type_to_atom_libgtk_only (NSString *type); NSString *gdk_quartz_target_to_pasteboard_type_libgtk_only (const gchar *target); diff --git a/gdk/quartz/gdkscreen-quartz.c b/gdk/quartz/gdkscreen-quartz.c index 68e1cfaf1..eb04d238b 100644 --- a/gdk/quartz/gdkscreen-quartz.c +++ b/gdk/quartz/gdkscreen-quartz.c @@ -62,6 +62,7 @@ static void gdk_screen_quartz_dispose (GObject *object); static void gdk_screen_quartz_finalize (GObject *object); static void gdk_screen_quartz_calculate_layout (GdkScreenQuartz *screen); +static CGFloat gdk_quartz_screen_user_space_scale (NSScreen *screen); static void display_reconfiguration_callback (CGDirectDisplayID display, CGDisplayChangeSummaryFlags flags, @@ -89,7 +90,7 @@ _gdk_screen_quartz_init (GdkScreenQuartz *screen_quartz) nsscreen = [[NSScreen screens] objectAtIndex:0]; gdk_screen_set_resolution (screen, - 72.0 * [nsscreen userSpaceScaleFactor]); + 72.0 * gdk_quartz_screen_user_space_scale (nsscreen)); gdk_screen_quartz_calculate_layout (screen_quartz); @@ -354,6 +355,17 @@ gdk_screen_get_height (GdkScreen *screen) return GDK_SCREEN_QUARTZ (screen)->height; } +/* -userSpaceScaleFactor is the scale of the resolution independence of + * 10.4 to 10.6; newer systems no longer have the message, and sending + * it there throws (as Ardour found) */ +static CGFloat +gdk_quartz_screen_user_space_scale (NSScreen *screen) +{ + if ([screen respondsToSelector:@selector(userSpaceScaleFactor)]) + return (CGFloat) [(id) screen userSpaceScaleFactor]; + return 1.0; +} + static gint get_mm_from_pixels (NSScreen *screen, int pixels) { @@ -362,7 +374,7 @@ get_mm_from_pixels (NSScreen *screen, int pixels) * and 25.4 is the number of millimeters per inch. */ #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_3 - float dpi = [screen userSpaceScaleFactor] * 72.0; + float dpi = gdk_quartz_screen_user_space_scale (screen) * 72.0; #else float dpi = 96.0 / 72.0; #endif @@ -493,3 +505,58 @@ gdk_screen_is_composited (GdkScreen *screen) return TRUE; } + +/* HiDPI: AppKit already draws GDK's points in the pixels of Retina + * screens (10.7 and later), sharp for paths and text; GDK coordinates + * stay the points. These scales only let pictures of more pixels be + * used (icons, see gdk_quartz_draw_pixbuf () and + * gdk_cairo_set_source_pixbuf ()); pixmaps stay at one pixel per point. */ +static gint +gdk_quartz_nsscreen_get_scale (NSScreen *nsscreen) +{ + CGFloat scale = 1.0; + +#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070 + if (nsscreen && [nsscreen respondsToSelector:@selector(backingScaleFactor)]) + scale = [nsscreen backingScaleFactor]; +#endif + + return MAX ((gint) (scale + 0.5), 1); +} + +gint +_gdk_windowing_drawable_get_scale (GdkDrawable *drawable) +{ + CGFloat scale = 1.0; + + if (GDK_IS_WINDOW (drawable)) + drawable = GDK_WINDOW_OBJECT (drawable)->impl; + if (!GDK_IS_WINDOW_IMPL_QUARTZ (drawable)) + return 1; + +#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070 + { + GdkWindow *toplevel = gdk_window_get_toplevel (GDK_DRAWABLE_IMPL_QUARTZ (drawable)->wrapper); + NSWindow *nswindow = toplevel ? GDK_WINDOW_IMPL_QUARTZ (GDK_WINDOW_OBJECT (toplevel)->impl)->toplevel : nil; + + if (nswindow && [nswindow respondsToSelector:@selector(backingScaleFactor)]) + scale = [nswindow backingScaleFactor]; + } +#endif + + return MAX ((gint) (scale + 0.5), 1); +} + +gint +_gdk_windowing_screen_get_monitor_scale (GdkScreen *screen, + gint monitor_num) +{ + gint scale; + + GDK_QUARTZ_ALLOC_POOL; + scale = gdk_quartz_nsscreen_get_scale (get_nsscreen_for_monitor (monitor_num)); + GDK_QUARTZ_RELEASE_POOL; + + return scale; +} + diff --git a/gdk/quartz/gdkwindow-quartz.c b/gdk/quartz/gdkwindow-quartz.c index 38ada80b2..04d7b19bf 100644 --- a/gdk/quartz/gdkwindow-quartz.c +++ b/gdk/quartz/gdkwindow-quartz.c @@ -207,6 +207,7 @@ gdk_window_impl_quartz_finalize (GObject *object) if (impl->transient_for) g_object_unref (impl->transient_for); + impl->transient_for = NULL; G_OBJECT_CLASS (parent_class)->finalize (object); } @@ -1130,7 +1131,13 @@ _gdk_windowing_update_window_sizes (GdkScreen *screen) windows = gdk_screen_get_toplevel_windows (screen); for (list = windows; list; list = list->next) - _gdk_quartz_window_update_position (list->data); + { + /* Offscreen windows have no NSWindow to take the position from */ + if (GDK_WINDOW_TYPE (list->data) == GDK_WINDOW_OFFSCREEN) + continue; + + _gdk_quartz_window_update_position (list->data); + } g_list_free (windows); } @@ -1202,6 +1209,12 @@ _gdk_quartz_window_destroy (GdkWindow *window, else if (impl->view) [impl->view removeFromSuperview]; + /* The window is released when closed (and with it its view), a + * view removed from its superview is released; don't keep + * dangling pointers to them. */ + impl->view = NULL; + impl->toplevel = NULL; + GDK_QUARTZ_RELEASE_POOL; } } @@ -1749,9 +1762,16 @@ static void gdk_window_quartz_set_background (GdkWindow *window, const GdkColor *color) { - /* FIXME: We could theoretically set the background color for toplevels - * here. (Currently we draw the background before emitting expose events) - */ + GdkWindowImplQuartz *impl = GDK_WINDOW_IMPL_QUARTZ (GDK_WINDOW_OBJECT (window)->impl); + + /* The background is drawn before the expose events; this colour is + * only for a view that is drawn before its window is mapped, so that + * a dark theme does not flash light first */ + if (color) + { + impl->background_color = *color; + impl->background_color_set = TRUE; + } } static void @@ -1941,11 +1961,29 @@ gdk_window_get_root_origin (GdkWindow *window, gint *y) { GdkRectangle rect; + GdkWindow *toplevel; + GdkWindowImplQuartz *impl; rect.x = 0; rect.y = 0; - gdk_window_get_frame_extents (window, &rect); + /* Where gdk_window_move() puts a toplevel is the top left of its + * content (Quartz places the content rect), so that is what this + * gives, for gtk_window_get_position(): with the frame, a window + * that a program puts back where it was went up by the height of + * the title bar each time (as Ardour found) */ + toplevel = gdk_window_get_effective_toplevel (window); + impl = GDK_WINDOW_IMPL_QUARTZ (GDK_WINDOW_OBJECT (toplevel)->impl); + if (impl->toplevel) + { + NSRect ns_rect = [impl->toplevel contentRectForFrameRect:[impl->toplevel frame]]; + + _gdk_quartz_window_xy_to_gdk_xy (ns_rect.origin.x, + ns_rect.origin.y + ns_rect.size.height, + &rect.x, &rect.y); + } + else + gdk_window_get_frame_extents (window, &rect); if (x) *x = rect.x; @@ -2271,8 +2309,11 @@ gdk_window_set_transient_for (GdkWindow *window, GdkWindowImplQuartz *window_impl; GdkWindowImplQuartz *parent_impl; + /* an offscreen window, or a child of one, has no NSWindow to be + * transient for */ if (GDK_WINDOW_DESTROYED (window) || GDK_WINDOW_DESTROYED (parent) || - !WINDOW_IS_TOPLEVEL (window)) + !WINDOW_IS_TOPLEVEL (window) || + !GDK_IS_WINDOW_IMPL_QUARTZ (GDK_WINDOW_OBJECT (parent)->impl)) return; window_impl = GDK_WINDOW_IMPL_QUARTZ (GDK_WINDOW_OBJECT (window)->impl); @@ -2559,7 +2600,8 @@ gdk_window_set_modal_hint (GdkWindow *window, !WINDOW_IS_TOPLEVEL (window)) return; - /* FIXME: Implement */ + /* kept, so that gdk_window_get_modal_hint() is right (Ardour) */ + ((GdkWindowObject *) window)->modal_hint = modal; } void @@ -2842,9 +2884,45 @@ void gdk_window_set_functions (GdkWindow *window, GdkWMFunction functions) { + GdkWindowImplQuartz *impl; + gboolean close, minimize, maximize; + g_return_if_fail (GDK_IS_WINDOW (window)); - /* FIXME: Implement */ + if (GDK_WINDOW_DESTROYED (window) || + !WINDOW_IS_TOPLEVEL (window)) + return; + + impl = GDK_WINDOW_IMPL_QUARTZ (GDK_WINDOW_OBJECT (window)->impl); + if (!impl->toplevel) + return; + + /* GDK_FUNC_ALL turns the meaning of the other bits around, as on X11 */ + if (functions & GDK_FUNC_ALL) + { + close = !(functions & GDK_FUNC_CLOSE); + minimize = !(functions & GDK_FUNC_MINIMIZE); + maximize = !(functions & GDK_FUNC_MAXIMIZE); + } + else + { + close = (functions & GDK_FUNC_CLOSE) != 0; + minimize = (functions & GDK_FUNC_MINIMIZE) != 0; + maximize = (functions & GDK_FUNC_MAXIMIZE) != 0; + } + + /* The buttons of the title bar, so that gtk_window_set_deletable() + * works. Enabling and disabling them works from Mac OS X 10.2 on and + * leaves the style of the window (and whether it can be resized, which + * the geometry hints decide) alone; a window without a title bar has + * no buttons, so nothing happens there. */ + GDK_QUARTZ_ALLOC_POOL; + + [[impl->toplevel standardWindowButton:NSWindowCloseButton] setEnabled:close]; + [[impl->toplevel standardWindowButton:NSWindowMiniaturizeButton] setEnabled:minimize]; + [[impl->toplevel standardWindowButton:NSWindowZoomButton] setEnabled:maximize]; + + GDK_QUARTZ_RELEASE_POOL; } gboolean @@ -3000,6 +3078,12 @@ gdk_window_fullscreen (GdkWindow *window) !WINDOW_IS_TOPLEVEL (window)) return; + /* In the full screen of the system already (the green button, 10.7 + * and newer): changing the decorations there throws (as Ardour + * found). The bit of NSFullScreenWindowMask, for older SDKs. */ + if ([impl->toplevel styleMask] & (1 << 14)) + return; + geometry = get_fullscreen_geometry (window); if (!geometry) { diff --git a/gdk/quartz/gdkwindow-quartz.h b/gdk/quartz/gdkwindow-quartz.h index 38f20f37f..3b7e99c54 100644 --- a/gdk/quartz/gdkwindow-quartz.h +++ b/gdk/quartz/gdkwindow-quartz.h @@ -60,6 +60,10 @@ struct _GdkWindowImplQuartz GList *sorted_children; GdkRegion *needs_display_region; + + /* drawn before the first expose (from Ardour's YTK) */ + GdkColor background_color; + gboolean background_color_set; }; struct _GdkWindowImplQuartzClass diff --git a/gdk/rgbsimdbench.c b/gdk/rgbsimdbench.c new file mode 100644 index 000000000..3a4402d2f --- /dev/null +++ b/gdk/rgbsimdbench.c @@ -0,0 +1,310 @@ +/* rgbsimdbench: checks and times GdkRGB's vector kernels on this machine + * + * Every kernel of every instruction set the CPU has is run against the + * C code it stands in for: first on random data, which must come out + * the same, then for speed. The table at the end shows millions of + * pixels per second; the fastest of each row is marked. + * + * make -C gdk rgbsimdbench && gdk/rgbsimdbench + * + * GDK_RGB_SIMD="op=set,..." tries a choice in a running program. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + */ + +#include "config.h" + +#include +#include + +#include + +#include "gdkrgbsimd.h" + +#define WIDTH 256 +#define ROWS 64 + +typedef gint (*Kernel) (gpointer out, gconstpointer in, gint n); + +static guint32 seed = 1; + +static guint +rnd (void) +{ + seed = seed * 1103515245 + 12345; + return seed >> 8; +} + +static inline guint +blend8 (guint a, guint s, guint d) +{ + guint t = a * s + (255 - a) * d + 0x80; + + return (t + (t >> 8)) >> 8; +} + +/* The C code of GdkRGB and gdk_cairo_set_source_pixbuf(), as plain as + * there, for one pixel at position i */ +static void +c_pixel (gint op, gpointer out, const guchar *s, gint i) +{ + guint32 *o32 = (guint32 *) out + i; + guint16 *o16 = (guint16 *) out + i; + guint r, g, b; + + switch (op) + { + case 0: /* rgb_to_x888 */ + case 1: /* rgbx_to_x888 */ + *o32 = 0xff000000 | (s[0] << 16) | (s[1] << 8) | s[2]; + break; + case 2: /* rgb_to_565 */ + *o16 = ((s[0] & 0xf8) << 8) | ((s[1] & 0xfc) << 3) | (s[2] >> 3); + break; + case 3: /* rgb_to_555 */ + *o16 = 0x8000 | ((s[0] & 0xf8) << 7) | ((s[1] & 0xf8) << 2) | (s[2] >> 3); + break; + case 4: /* composite_x888 */ + if (s[3] == 0) + break; + if (s[3] == 255) + *o32 = 0xff000000 | (s[0] << 16) | (s[1] << 8) | s[2]; + else + *o32 = 0xff000000 | (blend8 (s[3], s[0], (*o32 >> 16) & 0xff) << 16) | + (blend8 (s[3], s[1], (*o32 >> 8) & 0xff) << 8) | blend8 (s[3], s[2], *o32 & 0xff); + break; + case 5: /* composite_565 */ + if (s[3] == 0) + break; + r = *o16 >> 11, g = (*o16 >> 5) & 0x3f, b = *o16 & 0x1f; + r = blend8 (s[3], s[0], (r << 3) | (r >> 2)); + g = blend8 (s[3], s[1], (g << 2) | (g >> 4)); + b = blend8 (s[3], s[2], (b << 3) | (b >> 2)); + *o16 = ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | (b >> 3); + break; + case 6: /* composite_555 */ + if (s[3] == 0) + break; + r = (*o16 >> 10) & 0x1f, g = (*o16 >> 5) & 0x1f, b = *o16 & 0x1f; + r = blend8 (s[3], s[0], (r << 3) | (r >> 2)); + g = blend8 (s[3], s[1], (g << 3) | (g >> 2)); + b = blend8 (s[3], s[2], (b << 3) | (b >> 2)); + *o16 = 0x8000 | ((r & 0xf8) << 7) | ((g & 0xf8) << 2) | (b >> 3); + break; + case 7: /* rgba_to_argb */ + *o32 = ((guint32) s[3] << 24) | (blend8 (s[3], s[0], 0) << 16) | + (blend8 (s[3], s[1], 0) << 8) | blend8 (s[3], s[2], 0); + break; + } +} + +static gint +in_bytes (gint op) +{ + return op == 0 || op == 2 || op == 3 ? 3 : 4; +} + +static gint +out_bytes (gint op) +{ + return op == 2 || op == 3 || op == 5 || op == 6 ? 2 : 4; +} + +static void +run_c (gint op, gpointer out, const guchar *in, gint n) +{ + gint i, step = in_bytes (op); + + for (i = 0; i < n; i++) + c_pixel (op, out, in + i * step, i); +} + +static void +run (gint op, Kernel kernel, gpointer out, const guchar *in, gint n) +{ + gint done = kernel ? kernel (out, in, n) : 0, i, step = in_bytes (op); + + /* the C code does the rest of the row */ + for (i = done; i < n; i++) + c_pixel (op, out, in + i * step, i); +} + +/* Source rows: for the alpha either like icons, mostly nothing or + * everything, or like soft shadows, everything in between */ +static void +fill_source (guchar *in, gint op, gboolean icons) +{ + gint i, n = ROWS * WIDTH * in_bytes (op); + + for (i = 0; i < n; i++) + in[i] = rnd (); + if (in_bytes (op) == 4) + for (i = 3; i < n; i += 4) + { + guint k = rnd () % 10; + + if (icons && k < 4) + in[i] = 0; + else if (icons && k < 8) + in[i] = 255; + } +} + +static gboolean +check (gint op, Kernel kernel) +{ + static guchar in[WIDTH * 4 + 16], a[WIDTH * 4 + 16], b[WIDTH * 4 + 16]; + gint t, i; + + for (t = 0; t < 2000; t++) + { + gint n = rnd () % WIDTH, ia = rnd () % 16, oa = (rnd () % 8) * 2; + + for (i = 0; i < (gint) sizeof in; i++) + in[i] = rnd (); + for (i = 3; i < (gint) sizeof in; i += 4) + if (rnd () % 3 == 0) + in[i] = rnd () % 2 ? 0 : 255; + for (i = 0; i < (gint) sizeof a; i++) + a[i] = b[i] = rnd (); + run_c (op, a + oa, in + ia, n); + run (op, kernel, b + oa, in + ia, n); + if (memcmp (a, b, sizeof a) != 0) + return FALSE; + } + + return TRUE; +} + +/* Millions of pixels per second */ +static gdouble +measure (gint op, Kernel kernel, gboolean c_only, gboolean icons) +{ + static guchar in[ROWS * WIDTH * 4], out[ROWS * WIDTH * 4]; + gint64 start, elapsed; + gint rounds = 0, y; + + seed = 7; + fill_source (in, op, icons); + for (y = 0; y < (gint) sizeof out; y++) + out[y] = rnd (); + + start = g_get_monotonic_time (); + do + { + for (y = 0; y < ROWS; y++) + { + const guchar *src = in + y * WIDTH * in_bytes (op); + guchar *dst = out + y * WIDTH * out_bytes (op); + + if (c_only) + run_c (op, dst, src, WIDTH); + else + run (op, kernel, dst, src, WIDTH); + } + rounds++; + elapsed = g_get_monotonic_time () - start; + } + while (elapsed < 300000); + + return (gdouble) rounds * ROWS * WIDTH / elapsed; +} + +static void +print_cpu (void) +{ + gchar *info = NULL, **lines; + gint i, shown = 0; + + if (!g_file_get_contents ("/proc/cpuinfo", &info, NULL, NULL)) + return; + lines = g_strsplit (info, "\n", -1); + for (i = 0; lines[i] && shown < 4; i++) + if (g_str_has_prefix (lines[i], "model name") || g_str_has_prefix (lines[i], "cpu\t") || + g_str_has_prefix (lines[i], "vendor_id") || g_str_has_prefix (lines[i], "flags") || + g_str_has_prefix (lines[i], "Features") || g_str_has_prefix (lines[i], "CPU part") || + g_str_has_prefix (lines[i], "Hardware")) + { + printf ("%.150s\n", lines[i]); + shown++; + } + g_strfreev (lines); + g_free (info); +} + +int +main (int argc, char **argv) +{ + const GdkRgbSimdSet *sets; + const GdkRgbSimdOp *ops; + const GdkRgbSimd *chosen; + gint n_sets, n_ops, s, k, pass; + gboolean all_good = TRUE; + + print_cpu (); + sets = _gdk_rgb_simd_sets (&n_sets); + ops = _gdk_rgb_simd_ops (&n_ops); + chosen = _gdk_rgb_simd_get (); + + printf ("\nMillions of pixels per second, * the fastest, < what GDK takes now\n\n"); + printf ("%-22s %8s", "", "c"); + for (s = 0; s < n_sets; s++) + printf (" %9s", sets[s].name); + printf ("\n"); + + for (k = 0; k < n_ops; k++) + for (pass = 0; pass < (in_bytes (k) == 4 && k != 1 ? 2 : 1); pass++) + { + gdouble speed[16], best = 0; + const gchar *mark[16]; + gchar label[64]; + Kernel now = G_STRUCT_MEMBER (Kernel, chosen, ops[k].offset); + + g_snprintf (label, sizeof label, "%s%s", ops[k].name, + in_bytes (k) == 4 && k != 1 ? (pass ? " soft" : " icons") : ""); + speed[0] = measure (k, NULL, TRUE, !pass); + best = speed[0]; + for (s = 0; s < n_sets; s++) + { + GdkRgbSimd set; + Kernel kernel; + + memset (&set, 0, sizeof set); + sets[s].init (&set); + kernel = G_STRUCT_MEMBER (Kernel, &set, ops[k].offset); + speed[s + 1] = -1; + mark[s + 1] = " "; + if (!kernel) + continue; + if (!check (k, kernel)) + { + printf ("%s of %s does not give what the C code does!\n", ops[k].name, sets[s].name); + all_good = FALSE; + continue; + } + speed[s + 1] = measure (k, kernel, FALSE, !pass); + if (speed[s + 1] > best) + best = speed[s + 1]; + if (kernel == now) + mark[s + 1] = "<"; + } + + printf ("%-22s %7.1f%s", label, speed[0], speed[0] == best ? "*" : (now ? " " : "<")); + for (s = 0; s < n_sets; s++) + { + if (speed[s + 1] < 0) + printf (" %9s", "-"); + else + printf (" %8.1f%s", speed[s + 1], speed[s + 1] == best ? "*" : mark[s + 1]); + } + printf ("\n"); + } + + if (!all_good) + printf ("\nSome kernels are wrong on this machine; please send this output.\n"); + + return all_good ? 0 : 1; +} diff --git a/gdk/win32/gdkcursor-win32.c b/gdk/win32/gdkcursor-win32.c index 82fb35b2c..13e585810 100644 --- a/gdk/win32/gdkcursor-win32.c +++ b/gdk/win32/gdkcursor-win32.c @@ -66,6 +66,7 @@ hcursor_from_type (GdkCursorType cursor_type) gint i, j, x, y, ofs; HCURSOR rv; gint w, h; + gint s = _gdk_win32_scale; guchar *and_plane, *xor_plane; if (cursor_type != GDK_BLANK_CURSOR) @@ -84,6 +85,12 @@ hcursor_from_type (GdkCursorType cursor_type) w = GetSystemMetrics (SM_CXCURSOR); h = GetSystemMetrics (SM_CYCURSOR); + /* HiDPI: each pixel of the X cursor as s x s pixels of Windows */ + if (cursor_type != GDK_BLANK_CURSOR && s > 1) + { + w = MAX (w, (cursors[i].width * s + 31) / 32 * 32); + h = MAX (h, cursors[i].height * s); + } and_plane = g_malloc ((w/8) * h); memset (and_plane, 0xff, (w/8) * h); @@ -96,16 +103,18 @@ hcursor_from_type (GdkCursorType cursor_type) #define SET_BIT(v,b) (v |= (1 << b)) #define RESET_BIT(v,b) (v &= ~(1 << b)) - for (j = 0, y = 0; y < cursors[i].height && y < h ; y++) + for (y = 0; y < cursors[i].height * s && y < h ; y++) { ofs = (y * w) / 8; - j = y * cursors[i].width; - for (x = 0; x < cursors[i].width && x < w ; x++, j++) + for (x = 0; x < cursors[i].width * s && x < w ; x++) { gint pofs = ofs + x / 8; - guchar data = (cursors[i].data[j/4] & (0xc0 >> (2 * (j%4)))) >> (2 * (3 - (j%4))); - gint bit = 7 - (j % cursors[i].width) % 8; + guchar data; + gint bit = 7 - x % 8; + + j = (y / s) * cursors[i].width + x / s; + data = (cursors[i].data[j/4] & (0xc0 >> (2 * (j%4)))) >> (2 * (3 - (j%4))); if (data) { @@ -119,7 +128,9 @@ hcursor_from_type (GdkCursorType cursor_type) #undef SET_BIT #undef RESET_BIT - rv = CreateCursor (_gdk_app_hmodule, cursors[i].hotx, cursors[i].hoty, + rv = CreateCursor (_gdk_app_hmodule, + cursors[i].hotx * s + s / 2, + cursors[i].hoty * s + s / 2, w, h, and_plane, xor_plane); } else @@ -210,14 +221,24 @@ gdk_cursor_new_from_pixmap (GdkPixmap *source, g_return_val_if_fail (source_impl->width == mask_impl->width && source_impl->height == mask_impl->height, NULL); - width = source_impl->width; - height = source_impl->height; + g_return_val_if_fail (source_impl->scale == mask_impl->scale, NULL); + + /* HiDPI: the bits are in pixels of Windows, and so is the cursor */ + width = source_impl->width * MAX (source_impl->scale, 1); + height = source_impl->height * MAX (source_impl->scale, 1); + x = x * MAX (source_impl->scale, 1) + MAX (source_impl->scale, 1) / 2; + y = y * MAX (source_impl->scale, 1) + MAX (source_impl->scale, 1) / 2; cursor_width = GetSystemMetrics (SM_CXCURSOR); cursor_height = GetSystemMetrics (SM_CYCURSOR); - g_return_val_if_fail (width <= cursor_width && height <= cursor_height, + g_return_val_if_fail (source_impl->width <= cursor_width / _gdk_win32_scale && + source_impl->height <= cursor_height / _gdk_win32_scale, NULL); + /* a cursor as large as the scaled bits when Windows' size is not */ + cursor_width = MAX (cursor_width, (width + 31) / 32 * 32); + cursor_height = MAX (cursor_height, height); + residue = (1 << ((8-(width%8))%8)) - 1; source_bits = source_impl->bits; @@ -228,7 +249,7 @@ gdk_cursor_new_from_pixmap (GdkPixmap *source, NULL); source_bpl = ((width - 1)/32 + 1)*4; - mask_bpl = ((mask_impl->width - 1)/32 + 1)*4; + mask_bpl = source_bpl; GDK_NOTE (CURSOR, { g_print ("gdk_cursor_new_from_pixmap: source=%p:\n", @@ -626,7 +647,27 @@ gdk_cursor_new_from_pixbuf (GdkDisplay *display, g_return_val_if_fail (0 <= x && x < gdk_pixbuf_get_width (pixbuf), NULL); g_return_val_if_fail (0 <= y && y < gdk_pixbuf_get_height (pixbuf), NULL); - hcursor = _gdk_win32_pixbuf_to_hcursor (pixbuf, x, y); + if (_gdk_win32_scale > 1) + { + /* HiDPI: the cursor in pixels of Windows, from the picture made + * for it if there is one */ + GdkPixbuf *hires = _gdk_pixbuf_get_hires (pixbuf, _gdk_win32_scale); + gint s = _gdk_win32_scale; + + if (hires) + g_object_ref (hires); + else + hires = gdk_pixbuf_scale_simple (pixbuf, + gdk_pixbuf_get_width (pixbuf) * s, + gdk_pixbuf_get_height (pixbuf) * s, + GDK_INTERP_NEAREST); + if (!hires) + return NULL; + hcursor = _gdk_win32_pixbuf_to_hcursor (hires, x * s + s / 2, y * s + s / 2); + g_object_unref (hires); + } + else + hcursor = _gdk_win32_pixbuf_to_hcursor (pixbuf, x, y); if (!hcursor) return NULL; return cursor_new_from_hcursor (hcursor, GDK_CURSOR_IS_PIXMAP); @@ -653,7 +694,8 @@ gdk_display_get_default_cursor_size (GdkDisplay *display) { g_return_val_if_fail (display == _gdk_display, 0); - return MIN (GetSystemMetrics (SM_CXCURSOR), GetSystemMetrics (SM_CYCURSOR)); + /* in pixels of GDK (HiDPI) */ + return MAX (MIN (GetSystemMetrics (SM_CXCURSOR), GetSystemMetrics (SM_CYCURSOR)) / _gdk_win32_scale, 1); } void @@ -663,10 +705,11 @@ gdk_display_get_maximal_cursor_size (GdkDisplay *display, { g_return_if_fail (display == _gdk_display); + /* in pixels of GDK (HiDPI) */ if (width) - *width = GetSystemMetrics (SM_CXCURSOR); + *width = MAX (GetSystemMetrics (SM_CXCURSOR) / _gdk_win32_scale, 1); if (height) - *height = GetSystemMetrics (SM_CYCURSOR); + *height = MAX (GetSystemMetrics (SM_CYCURSOR) / _gdk_win32_scale, 1); } diff --git a/gdk/win32/gdkdisplay-win32.c b/gdk/win32/gdkdisplay-win32.c index 7447525f7..3aee7b5d6 100644 --- a/gdk/win32/gdkdisplay-win32.c +++ b/gdk/win32/gdkdisplay-win32.c @@ -91,7 +91,7 @@ enum_monitor (HMONITOR hmonitor, monitor = _gdk_monitors + *index; - monitor_info.cbSize = sizeof (MONITORINFOEX); + monitor_info.cbSize = sizeof (MONITORINFOEXA2); GetMonitorInfoA (hmonitor, (MONITORINFO *) &monitor_info); #ifndef MONITORINFOF_PRIMARY @@ -159,11 +159,17 @@ _gdk_monitor_init (void) GDK_NOTE (MISC, g_print ("Multi-monitor offset: (%d,%d)\n", _gdk_offset_x, _gdk_offset_y)); - /* Translate monitor coords into GDK coordinate space */ + /* Translate monitor coords into GDK coordinate space, also in its + * pixels (HiDPI) */ for (i = 0; i < _gdk_num_monitors; i++) { - _gdk_monitors[i].rect.x += _gdk_offset_x; - _gdk_monitors[i].rect.y += _gdk_offset_y; + GdkRectangle *r = &_gdk_monitors[i].rect; + gint x2 = r->x + r->width + _gdk_offset_x, y2 = r->y + r->height + _gdk_offset_y; + + r->x = _gdk_win32_unscale (r->x + _gdk_offset_x); + r->y = _gdk_win32_unscale (r->y + _gdk_offset_y); + r->width = _gdk_win32_unscale (x2) - r->x; + r->height = _gdk_win32_unscale (y2) - r->y; GDK_NOTE (MISC, g_print ("Monitor %d: %dx%d@%+d%+d\n", i, _gdk_monitors[i].rect.width, _gdk_monitors[i].rect.height, @@ -183,8 +189,8 @@ _gdk_monitor_init (void) ReleaseDC (NULL, hDC); _gdk_monitors[0].rect.x = 0; _gdk_monitors[0].rect.y = 0; - _gdk_monitors[0].rect.width = GetSystemMetrics (SM_CXSCREEN); - _gdk_monitors[0].rect.height = GetSystemMetrics (SM_CYSCREEN); + _gdk_monitors[0].rect.width = _gdk_win32_unscale (GetSystemMetrics (SM_CXSCREEN)); + _gdk_monitors[0].rect.height = _gdk_win32_unscale (GetSystemMetrics (SM_CYSCREEN)); _gdk_offset_x = 0; _gdk_offset_y = 0; #endif @@ -216,6 +222,24 @@ gdk_display_open (const gchar *display_name) _gdk_monitor_init (); _gdk_visual_init (); + + /* HiDPI: fonts are laid out in pixels of GDK and drawn in those of + * Windows; widths rounded to GDK's pixels would space the letters + * unevenly */ + if (_gdk_win32_scale > 1) + { + cairo_font_options_t *options = cairo_font_options_create (); + + cairo_font_options_set_hint_metrics (options, CAIRO_HINT_METRICS_OFF); + gdk_screen_set_font_options (_gdk_screen, options); + cairo_font_options_destroy (options); + } + + /* HiDPI: the resolution of fonts in pixels of GDK; Pango would take + * that of Windows, in its pixels (GTK+ sets it from gtk-xft-dpi only + * on X11) */ + if (_gdk_win32_font_dpi () > 0) + gdk_screen_set_resolution (_gdk_screen, _gdk_win32_font_dpi ()); gdk_screen_set_default_colormap (_gdk_screen, gdk_screen_get_system_colormap (_gdk_screen)); _gdk_windowing_window_init (_gdk_screen); @@ -505,10 +529,11 @@ gdk_display_request_selection_notification (GdkDisplay *display, { static HWND hwndViewer = NULL; gboolean ret = FALSE; + gchar *selection_name = gdk_atom_name (selection); GDK_NOTE (DND, g_print ("gdk_display_request_selection_notification (..., %s)", - gdk_atom_name (selection))); + selection_name)); if (selection == GDK_SELECTION_CLIPBOARD || selection == GDK_SELECTION_PRIMARY) @@ -526,6 +551,8 @@ gdk_display_request_selection_notification (GdkDisplay *display, ret = FALSE; } + g_free (selection_name); + GDK_NOTE (DND, g_print (" -> %s\n", ret ? "TRUE" : "FALSE")); return ret; } diff --git a/gdk/win32/gdkdnd-win32.c b/gdk/win32/gdkdnd-win32.c index fa00226c3..5e755c5ac 100644 --- a/gdk/win32/gdkdnd-win32.c +++ b/gdk/win32/gdkdnd-win32.c @@ -454,8 +454,8 @@ dnd_event_put (GdkEventType type, e.dnd.send_event = FALSE; e.dnd.context = context; e.dnd.time = GDK_CURRENT_TIME; - e.dnd.x_root = pt.x + _gdk_offset_x; - e.dnd.y_root = pt.x + _gdk_offset_y; + e.dnd.x_root = GDK_WIN32_SCREEN_TO_ROOT_X (pt.x); + e.dnd.y_root = GDK_WIN32_SCREEN_TO_ROOT_Y (pt.y); g_object_ref (e.dnd.context); if (e.dnd.window != NULL) @@ -1477,8 +1477,8 @@ gdk_dropfiles_filter (GdkXEvent *xev, DragQueryPoint (hdrop, &pt); ClientToScreen (msg->hwnd, &pt); - event->dnd.x_root = pt.x + _gdk_offset_x; - event->dnd.y_root = pt.y + _gdk_offset_y; + event->dnd.x_root = GDK_WIN32_SCREEN_TO_ROOT_X (pt.x); + event->dnd.y_root = GDK_WIN32_SCREEN_TO_ROOT_Y (pt.y); event->dnd.time = _gdk_win32_get_next_tick (msg->time); nfiles = DragQueryFile (hdrop, 0xFFFFFFFF, NULL, 0); @@ -1551,8 +1551,7 @@ gdk_dropfiles_filter (GdkXEvent *xev, g_free (fileName); g_string_append (result, "\015\012"); } - _gdk_dropfiles_store (result->str); - g_string_free (result, FALSE); + _gdk_dropfiles_store (g_string_free (result, FALSE)); DragFinish (hdrop); @@ -1736,8 +1735,8 @@ local_send_motion (GdkDragContext *context, tmp_event.dnd.x_root = x_root; tmp_event.dnd.y_root = y_root; - PRIVATE_DATA (current_dest_drag)->last_pt.x = x_root - _gdk_offset_x; - PRIVATE_DATA (current_dest_drag)->last_pt.y = y_root - _gdk_offset_y; + PRIVATE_DATA (current_dest_drag)->last_pt.x = GDK_WIN32_ROOT_TO_SCREEN_X (x_root); + PRIVATE_DATA (current_dest_drag)->last_pt.y = GDK_WIN32_ROOT_TO_SCREEN_Y (y_root); PRIVATE_DATA (context)->drag_status = GDK_DRAG_STATUS_MOTION_WAIT; @@ -1770,8 +1769,8 @@ local_send_drop (GdkDragContext *context, tmp_event.dnd.context = current_dest_drag; tmp_event.dnd.time = GDK_CURRENT_TIME; - tmp_event.dnd.x_root = private->last_pt.x + _gdk_offset_x; - tmp_event.dnd.y_root = private->last_pt.y + _gdk_offset_y; + tmp_event.dnd.x_root = GDK_WIN32_SCREEN_TO_ROOT_X (private->last_pt.x); + tmp_event.dnd.y_root = GDK_WIN32_SCREEN_TO_ROOT_Y (private->last_pt.y); current_dest_drag = NULL; @@ -2023,8 +2022,8 @@ gdk_drag_find_window_for_screen (GdkDragContext *context, GdkWindow *dw; find_window_enum_arg a; - a.x = x_root - _gdk_offset_x; - a.y = y_root - _gdk_offset_y; + a.x = GDK_WIN32_ROOT_TO_SCREEN_X (x_root); + a.y = GDK_WIN32_ROOT_TO_SCREEN_Y (y_root); a.ignore = drag_window ? GDK_WINDOW_HWND (drag_window) : NULL; a.result = NULL; @@ -2154,8 +2153,8 @@ gdk_drag_motion (GdkDragContext *context, /* Send a drag-motion event */ - private->last_pt.x = x_root - _gdk_offset_x; - private->last_pt.y = y_root - _gdk_offset_y; + private->last_pt.x = GDK_WIN32_ROOT_TO_SCREEN_X (x_root); + private->last_pt.y = GDK_WIN32_ROOT_TO_SCREEN_Y (y_root); if (context->dest_window) { diff --git a/gdk/win32/gdkdrawable-win32.c b/gdk/win32/gdkdrawable-win32.c index 01193e722..95f425a9f 100644 --- a/gdk/win32/gdkdrawable-win32.c +++ b/gdk/win32/gdkdrawable-win32.c @@ -689,11 +689,20 @@ generic_draw (GdkDrawable *drawable, * the areas where mask is one. (It is filled with said pattern.) */ - GDI_CALL (MaskBlt, (hdc, region->extents.x1, region->extents.y1, - width, height, - tile_hdc, 0, 0, - GDK_PIXMAP_HBITMAP (mask_pixmap), 0, 0, - MAKEROP4 (rop2_to_rop3 (gcwin32->rop2), ROP3_D))); + /* the mask's bits are in pixels of Windows, so all is (HiDPI) */ + { + gint s = _gdk_win32_scale; + + _gdk_win32_dc_set_scale (hdc, 1); + _gdk_win32_dc_set_scale (tile_hdc, 1); + GDI_CALL (MaskBlt, (hdc, region->extents.x1 * s, region->extents.y1 * s, + width * s, height * s, + tile_hdc, 0, 0, + GDK_PIXMAP_HBITMAP (mask_pixmap), 0, 0, + MAKEROP4 (rop2_to_rop3 (gcwin32->rop2), ROP3_D))); + _gdk_win32_dc_set_scale (tile_hdc, s); + _gdk_win32_dc_set_scale (hdc, _gdk_win32_drawable_scale (drawable)); + } /* Cleanup */ gdk_win32_hdc_release (mask_pixmap, mask_gc, blitting_mask); @@ -1386,6 +1395,63 @@ gdk_win32_draw_lines (GdkDrawable *drawable, g_free (pts); } +/* HiDPI: the scale of a drawable, pixels of its bitmap or window for + * one of GDK */ +gint +_gdk_win32_drawable_scale (GdkDrawable *drawable) +{ + if (GDK_IS_PIXMAP (drawable)) + drawable = GDK_PIXMAP_OBJECT (drawable)->impl; + if (GDK_IS_PIXMAP_IMPL_WIN32 (drawable)) + return MAX (GDK_PIXMAP_IMPL_WIN32 (drawable)->scale, 1); + + return _gdk_win32_scale; +} + +/* HiDPI: a BitBlt () in pixels of GDK from a DC of @ss pixels per pixel + * of GDK to one with @ds, done in the pixels themselves; the DCs keep + * the mapping they had */ +static BOOL +blit_scaled (HDC hdc, + gint ds, + gint xdest, + gint ydest, + gint width, + gint height, + HDC srcdc, + gint ss, + gint xsrc, + gint ysrc, + DWORD rop) +{ + BOOL ok; + + if (_gdk_win32_scale <= 1) + return BitBlt (hdc, xdest, ydest, width, height, srcdc, xsrc, ysrc, rop); + + _gdk_win32_dc_set_scale (hdc, 1); + if (srcdc != hdc) + _gdk_win32_dc_set_scale (srcdc, 1); + + if (ds == ss) + ok = BitBlt (hdc, xdest * ds, ydest * ds, width * ds, height * ds, + srcdc, xsrc * ss, ysrc * ss, rop); + else + { + /* a GdkImage, which has GDK's pixels: the nearest pixel, as + * everywhere else in GDK */ + int old_mode = SetStretchBltMode (hdc, COLORONCOLOR); + + ok = StretchBlt (hdc, xdest * ds, ydest * ds, width * ds, height * ds, + srcdc, xsrc * ss, ysrc * ss, width * ss, height * ss, rop); + SetStretchBltMode (hdc, old_mode); + } + + _gdk_win32_dc_set_scale (hdc, ds); + + return ok; +} + static void blit_from_pixmap (gboolean use_fg_bg, GdkDrawableImplWin32 *dest, @@ -1503,8 +1569,10 @@ blit_from_pixmap (gboolean use_fg_bg, } if (ok) - if (!BitBlt (hdc, xdest, ydest, width, height, - srcdc, xsrc, ysrc, rop2_to_rop3 (gcwin32->rop2)) && + if (!blit_scaled (hdc, _gdk_win32_drawable_scale (GDK_DRAWABLE (dest)), + xdest, ydest, width, height, + srcdc, MAX (src->scale, 1), xsrc, ysrc, + rop2_to_rop3 (gcwin32->rop2)) && GetLastError () != ERROR_INVALID_HANDLE) WIN32_GDI_FAILED ("BitBlt"); @@ -1549,15 +1617,23 @@ blit_inside_drawable (HDC hdc, HRGN updateRgn; GdkRegion *update_region; - clipRect.left = xdest; - clipRect.top = ydest; - clipRect.right = xdest + width; - clipRect.bottom = ydest + height; + BOOL scrolled; + + /* in pixels of Windows (HiDPI) */ + clipRect.left = GDK_WIN32_SC (xdest); + clipRect.top = GDK_WIN32_SC (ydest); + clipRect.right = GDK_WIN32_SC (xdest + width); + clipRect.bottom = GDK_WIN32_SC (ydest + height); SetRectEmpty (&emptyRect); updateRgn = CreateRectRgnIndirect (&emptyRect); - if (!ScrollDC (hdc, xdest - xsrc, ydest - ysrc, NULL, &clipRect, updateRgn, NULL)) + _gdk_win32_dc_set_scale (hdc, 1); + scrolled = ScrollDC (hdc, GDK_WIN32_SC (xdest - xsrc), GDK_WIN32_SC (ydest - ysrc), + NULL, &clipRect, updateRgn, NULL); + _gdk_win32_dc_set_scale (hdc, _gdk_win32_scale); + + if (!scrolled) WIN32_GDI_FAILED ("ScrollDC"); else { @@ -1573,13 +1649,17 @@ blit_inside_drawable (HDC hdc, } else { - GDI_CALL (BitBlt, (hdc, xdest, ydest, width, height, - hdc, xsrc, ysrc, rop2_to_rop3 (gcwin32->rop2))); + gint s = _gdk_win32_drawable_scale (GDK_DRAWABLE (src)); + + if (!blit_scaled (hdc, s, xdest, ydest, width, height, + hdc, s, xsrc, ysrc, rop2_to_rop3 (gcwin32->rop2))) + WIN32_GDI_FAILED ("BitBlt"); } } static void blit_from_window (HDC hdc, + GdkDrawableImplWin32 *dest, GdkGCWin32 *gcwin32, GdkDrawableImplWin32 *src, gint xsrc, @@ -1615,8 +1695,11 @@ blit_from_window (HDC hdc, g_print ("blit_from_window: realized %d\n", k)); } - GDI_CALL (BitBlt, (hdc, xdest, ydest, width, height, - srcdc, xsrc, ysrc, rop2_to_rop3 (gcwin32->rop2))); + if (!blit_scaled (hdc, _gdk_win32_drawable_scale (GDK_DRAWABLE (dest)), + xdest, ydest, width, height, + srcdc, _gdk_win32_scale, xsrc, ysrc, + rop2_to_rop3 (gcwin32->rop2))) + WIN32_GDI_FAILED ("BitBlt"); if (holdpal != NULL) GDI_CALL (SelectPalette, (srcdc, holdpal, FALSE)); @@ -1656,8 +1739,9 @@ _gdk_win32_blit (gboolean use_fg_bg, if (src == ((GdkWindowObject *)_gdk_root)->impl) { GDK_NOTE (DRAW, g_print ("... offsetting src coords\n")); - xsrc -= _gdk_offset_x; - ysrc -= _gdk_offset_y; + /* in pixels of GDK (HiDPI) */ + xsrc -= _gdk_win32_unscale (_gdk_offset_x); + ysrc -= _gdk_win32_unscale (_gdk_offset_y); } if (GDK_IS_DRAWABLE_IMPL_WIN32 (src)) @@ -1728,6 +1812,7 @@ _gdk_win32_blit (gboolean use_fg_bg, else if (comb != NULLREGION) { OffsetRgn (outside_rgn, xdest, ydest); + outside_rgn = _gdk_win32_hrgn_scale (outside_rgn); GDK_NOTE (DRAW, (GetRgnBox (outside_rgn, &r), g_print ("... InvalidateRgn " "bbox: %ldx%ld@%+ld%+ld\n", @@ -1772,7 +1857,7 @@ _gdk_win32_blit (gboolean use_fg_bg, (GdkPixmapImplWin32 *) src_impl, gc, xsrc, ysrc, xdest, ydest, width, height); else - blit_from_window (hdc, GDK_GC_WIN32 (gc), src_impl, + blit_from_window (hdc, draw_impl, GDK_GC_WIN32 (gc), src_impl, xsrc, ysrc, xdest, ydest, width, height); gdk_win32_hdc_release (&draw_impl->parent_instance, gc, GDK_GC_FOREGROUND); @@ -1931,6 +2016,16 @@ _gdk_windowing_create_cairo_surface (GdkDrawable *drawable, surface = cairo_win32_surface_create (hdc); +#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE (1, 14, 0) + /* HiDPI: drawn on in pixels of GDK */ + { + gint s = _gdk_win32_drawable_scale (drawable); + + if (s > 1) + cairo_surface_set_device_scale (surface, s, s); + } +#endif + /* Whenever the cairo surface is destroyed, we need to release the * HDC that was acquired */ cairo_surface_set_user_data (surface, &gdk_win32_cairo_hdc_key, diff --git a/gdk/win32/gdkevents-win32.c b/gdk/win32/gdkevents-win32.c index c4e212786..7d638233e 100644 --- a/gdk/win32/gdkevents-win32.c +++ b/gdk/win32/gdkevents-win32.c @@ -87,6 +87,13 @@ #define SYNAPSIS_ICON_WINDOW_CLASS "SynTrackCursorWindowClass" +/* The input GDK waits for. Headers for Windows 8 and later add touch + * and pointer messages to QS_ALLINPUT: with those GDK keeps waking up + * for messages it does not take from the queue, and Windows 7 and + * earlier refuse the unknown flags and report nothing at all. */ +#define GDK_QS_INPUT (QS_KEY | QS_MOUSEMOVE | QS_MOUSEBUTTON | QS_POSTMESSAGE | \ + QS_TIMER | QS_PAINT | QS_HOTKEY | QS_SENDMESSAGE | 0x0400 /* QS_RAWINPUT */) + static gboolean gdk_event_translate (MSG *msg, gint *ret_valp); static void handle_wm_paint (MSG *msg, @@ -176,7 +183,9 @@ _gdk_win32_get_next_tick (gulong suggested_tick) if (suggested_tick == 0) suggested_tick = GetTickCount (); - if (suggested_tick <= cur_tick) + /* Ticks eventually wrap around. + * This works as long as the interval between ticks is < 2147483648ms */ + if (suggested_tick <= cur_tick && ((cur_tick - suggested_tick) < 0x7FFFFFFF)) return cur_tick; else return cur_tick = suggested_tick; @@ -383,7 +392,7 @@ gdk_events_pending (void) { return (_gdk_event_queue_find_first (_gdk_display) || (modal_win32_dialog == NULL && - GetQueueStatus (QS_ALLINPUT) != 0)); + GetQueueStatus (GDK_QS_INPUT) != 0)); } GdkEvent* @@ -1261,10 +1270,10 @@ send_crossing_event (GdkDisplay *display, event->crossing.window = (GdkWindow *)window; event->crossing.subwindow = subwindow; event->crossing.time = _gdk_win32_get_next_tick (time_); - event->crossing.x = pt.x; - event->crossing.y = pt.y; - event->crossing.x_root = screen_pt->x + _gdk_offset_x; - event->crossing.y_root = screen_pt->y + _gdk_offset_y; + event->crossing.x = GDK_WIN32_UNSCALE_D (pt.x); + event->crossing.y = GDK_WIN32_UNSCALE_D (pt.y); + event->crossing.x_root = GDK_WIN32_SCREEN_TO_ROOT_D (screen_pt->x, _gdk_offset_x); + event->crossing.y_root = GDK_WIN32_SCREEN_TO_ROOT_D (screen_pt->y, _gdk_offset_y); event->crossing.mode = mode; event->crossing.detail = notify_type; event->crossing.mode = mode; @@ -1482,10 +1491,11 @@ synthesize_expose_events (GdkWindow *window) { event = gdk_event_new (GDK_EXPOSE); event->expose.window = window; - event->expose.area.x = r.left; - event->expose.area.y = r.top; - event->expose.area.width = r.right - r.left; - event->expose.area.height = r.bottom - r.top; + /* HiDPI: in pixels of GDK, all that is touched */ + event->expose.area.x = _gdk_win32_unscale (r.left); + event->expose.area.y = _gdk_win32_unscale (r.top); + event->expose.area.width = _gdk_win32_unscale_up (r.right) - event->expose.area.x; + event->expose.area.height = _gdk_win32_unscale_up (r.bottom) - event->expose.area.y; event->expose.region = gdk_region_rectangle (&(event->expose.area)); event->expose.count = 0; @@ -1669,9 +1679,18 @@ _gdk_win32_emit_configure_event (GdkWindow *window) if (gdk_window_get_parent (window) == _gdk_root) { ClientToScreen (hwnd, &point); - point.x += _gdk_offset_x; - point.y += _gdk_offset_y; + point.x = GDK_WIN32_SCREEN_TO_ROOT_X (point.x); + point.y = GDK_WIN32_SCREEN_TO_ROOT_Y (point.y); } + else + { + point.x = _gdk_win32_unscale (point.x); + point.y = _gdk_win32_unscale (point.y); + } + + /* HiDPI: a size of Windows not divisible by the scale is covered */ + client_rect.right = client_rect.left + _gdk_win32_unscale_up (client_rect.right - client_rect.left); + client_rect.bottom = client_rect.top + _gdk_win32_unscale_up (client_rect.bottom - client_rect.top); window_object->width = client_rect.right - client_rect.left; window_object->height = client_rect.bottom - client_rect.top; @@ -1727,10 +1746,11 @@ _gdk_win32_hrgn_to_region (HRGN hrgn) { GdkRectangle r; - r.x = rects[i].left; - r.y = rects[i].top; - r.width = rects[i].right - r.x; - r.height = rects[i].bottom - r.y; + /* in pixels of GDK, all that is partly in it */ + r.x = _gdk_win32_unscale (rects[i].left); + r.y = _gdk_win32_unscale (rects[i].top); + r.width = _gdk_win32_unscale_up (rects[i].right) - r.x; + r.height = _gdk_win32_unscale_up (rects[i].bottom) - r.y; gdk_region_union_with_rect (result, &r); } @@ -1795,11 +1815,9 @@ handle_wm_paint (MSG *msg, *event = gdk_event_new (GDK_EXPOSE); (*event)->expose.window = window; - (*event)->expose.area.x = paintstruct.rcPaint.left; - (*event)->expose.area.y = paintstruct.rcPaint.top; - (*event)->expose.area.width = paintstruct.rcPaint.right - paintstruct.rcPaint.left; - (*event)->expose.area.height = paintstruct.rcPaint.bottom - paintstruct.rcPaint.top; (*event)->expose.region = _gdk_win32_hrgn_to_region (hrgn); + /* in pixels of GDK (HiDPI), as the region */ + gdk_region_get_clipbox ((*event)->expose.region, &(*event)->expose.area); (*event)->expose.count = 0; while (list != NULL) @@ -1892,6 +1910,154 @@ handle_display_change (void) g_signal_emit_by_name (_gdk_screen, "size_changed"); } +/* Touches of Windows 7 and later, from user32 when there: RegisterTouchWindow() + * for the windows with GDK_TOUCH_MASK, which then get WM_TOUCH. Windows + * keeps sending the mouse messages of the first finger, marked in + * GetMessageExtraInfo(), which GDK keeps from the windows that take + * touches (gdkwindow.c). Windows XP and Vista: no touches, as before. */ +#define GDK_WM_TOUCH 0x0240 +#define GDK_TOUCHEVENTF_MOVE 0x0001 +#define GDK_TOUCHEVENTF_DOWN 0x0002 +#define GDK_TOUCHEVENTF_UP 0x0004 +#define GDK_TOUCHEVENTF_PRIMARY 0x0010 +#define GDK_MI_WP_SIGNATURE 0xFF515700 +#define GDK_MI_SIGNATURE_MASK 0xFFFFFF00 +#define GDK_MI_TOUCH 0x80 + +typedef struct +{ + LONG x, y; /* hundredths of a screen pixel */ + HANDLE hSource; + DWORD dwID; + DWORD dwFlags; + DWORD dwMask; + DWORD dwTime; + ULONG_PTR dwExtraInfo; + DWORD cxContact, cyContact; +} GdkTouchInput; + +typedef BOOL (WINAPI *t_RegisterTouchWindow) (HWND, ULONG); +typedef BOOL (WINAPI *t_UnregisterTouchWindow) (HWND); +typedef BOOL (WINAPI *t_GetTouchInputInfo) (HANDLE, UINT, GdkTouchInput *, int); +typedef BOOL (WINAPI *t_CloseTouchInputHandle) (HANDLE); + +static t_RegisterTouchWindow p_RegisterTouchWindow; +static t_UnregisterTouchWindow p_UnregisterTouchWindow; +static t_GetTouchInputInfo p_GetTouchInputInfo; +static t_CloseTouchInputHandle p_CloseTouchInputHandle; + +static gboolean +touch_api (void) +{ + static gint state; /* 0 not looked, 1 there, 2 not */ + + if (state == 0) + { + HMODULE user32 = GetModuleHandleW (L"user32.dll"); + + p_RegisterTouchWindow = (t_RegisterTouchWindow) GetProcAddress (user32, "RegisterTouchWindow"); + p_UnregisterTouchWindow = (t_UnregisterTouchWindow) GetProcAddress (user32, "UnregisterTouchWindow"); + p_GetTouchInputInfo = (t_GetTouchInputInfo) GetProcAddress (user32, "GetTouchInputInfo"); + p_CloseTouchInputHandle = (t_CloseTouchInputHandle) GetProcAddress (user32, "CloseTouchInputHandle"); + state = p_RegisterTouchWindow && p_UnregisterTouchWindow && + p_GetTouchInputInfo && p_CloseTouchInputHandle ? 1 : 2; + } + + return state == 1; +} + +void +_gdk_win32_window_update_touch (GdkWindow *window, + gboolean touch) +{ + HWND hwnd; + + if (GDK_WINDOW_DESTROYED (window) || !touch_api ()) + return; + + hwnd = GDK_WINDOW_HWND (window); + if (hwnd == NULL || GDK_WINDOW_TYPE (window) == GDK_WINDOW_ROOT || + GDK_WINDOW_TYPE (window) == GDK_WINDOW_FOREIGN) + return; + + if (touch) + p_RegisterTouchWindow (hwnd, 0); + else + p_UnregisterTouchWindow (hwnd); +} + +/* a mouse message that Windows made of a finger */ +static gboolean +mouse_message_from_touch (void) +{ + LPARAM extra = GetMessageExtraInfo (); + + return (extra & GDK_MI_SIGNATURE_MASK) == GDK_MI_WP_SIGNATURE && + (extra & GDK_MI_TOUCH) != 0; +} + +static gboolean +handle_wm_touch (GdkWindow *window, + MSG *msg) +{ + UINT n = LOWORD (msg->wParam), i; + GdkTouchInput *inputs; + POINT origin = { 0, 0 }; + guint state; + + if (n == 0 || !touch_api () || GDK_WINDOW_DESTROYED (window)) + return FALSE; + + inputs = g_new (GdkTouchInput, n); + if (!p_GetTouchInputInfo ((HANDLE) msg->lParam, n, inputs, sizeof (GdkTouchInput))) + { + g_free (inputs); + return FALSE; + } + + ClientToScreen (GDK_WINDOW_HWND (window), &origin); + state = build_pointer_event_state (msg) & + ~(GDK_BUTTON1_MASK | GDK_BUTTON2_MASK | GDK_BUTTON3_MASK | GDK_BUTTON4_MASK | GDK_BUTTON5_MASK); + + for (i = 0; i < n; i++) + { + GdkEvent *event; + GdkEventType type; + gdouble sx = inputs[i].x / 100.0, sy = inputs[i].y / 100.0; + + if (inputs[i].dwFlags & GDK_TOUCHEVENTF_DOWN) + type = GDK_TOUCH_BEGIN; + else if (inputs[i].dwFlags & GDK_TOUCHEVENTF_UP) + type = GDK_TOUCH_END; + else if (inputs[i].dwFlags & GDK_TOUCHEVENTF_MOVE) + type = GDK_TOUCH_UPDATE; + else + continue; + + event = gdk_event_new (type); + event->touch.window = window; + event->touch.time = _gdk_win32_get_next_tick (msg->time); + event->touch.x = GDK_WIN32_UNSCALE_D (sx - origin.x); + event->touch.y = GDK_WIN32_UNSCALE_D (sy - origin.y); + event->touch.x_root = GDK_WIN32_SCREEN_TO_ROOT_D (sx, _gdk_offset_x); + event->touch.y_root = GDK_WIN32_SCREEN_TO_ROOT_D (sy, _gdk_offset_y); + event->touch.axes = NULL; + event->touch.state = state; + /* the ids of Windows may be 0 */ + event->touch.sequence = GUINT_TO_POINTER (inputs[i].dwID + 1); + event->touch.emulating_pointer = (inputs[i].dwFlags & GDK_TOUCHEVENTF_PRIMARY) != 0; + event->touch.device = _gdk_display->core_pointer; + ((GdkEventPrivate *) event)->flags |= GDK_EVENT_TOUCH_SYSTEM_POINTER; + + _gdk_win32_append_event (event); + } + + p_CloseTouchInputHandle ((HANDLE) msg->lParam); + g_free (inputs); + + return TRUE; +} + static void generate_button_event (GdkEventType type, gint button, @@ -1900,12 +2066,17 @@ generate_button_event (GdkEventType type, { GdkEvent *event = gdk_event_new (type); + if (mouse_message_from_touch ()) + ((GdkEventPrivate *) event)->flags |= GDK_EVENT_POINTER_EMULATED; + event->button.window = window; event->button.time = _gdk_win32_get_next_tick (msg->time); - event->button.x = current_x = (gint16) GET_X_LPARAM (msg->lParam); - event->button.y = current_y = (gint16) GET_Y_LPARAM (msg->lParam); - event->button.x_root = msg->pt.x + _gdk_offset_x; - event->button.y_root = msg->pt.y + _gdk_offset_y; + current_x = (gint16) GET_X_LPARAM (msg->lParam); + current_y = (gint16) GET_Y_LPARAM (msg->lParam); + event->button.x = GDK_WIN32_UNSCALE_D (current_x); + event->button.y = GDK_WIN32_UNSCALE_D (current_y); + event->button.x_root = GDK_WIN32_SCREEN_TO_ROOT_D (msg->pt.x, _gdk_offset_x); + event->button.y_root = GDK_WIN32_SCREEN_TO_ROOT_D (msg->pt.y, _gdk_offset_y); event->button.axes = NULL; event->button.state = build_pointer_event_state (msg); event->button.button = button; @@ -2352,6 +2523,10 @@ gdk_event_translate (MSG *msg, LOBYTE (HIWORD (msg->lParam)) == _gdk_win32_keymap_get_rshift_scancode (GDK_WIN32_KEYMAP (gdk_keymap_get_default ()))) event->key.hardware_keycode = VK_RSHIFT; + event->key.is_modifier = (msg->wParam == VK_CONTROL || + msg->wParam == VK_SHIFT || + msg->wParam == VK_MENU); + /* g_print ("ctrl:%02x lctrl:%02x rctrl:%02x alt:%02x lalt:%02x ralt:%02x\n", key_state[VK_CONTROL], key_state[VK_LCONTROL], key_state[VK_RCONTROL], key_state[VK_MENU], key_state[VK_LMENU], key_state[VK_RMENU]); */ build_key_event_state (event, key_state); @@ -2666,20 +2841,32 @@ gdk_event_translate (MSG *msg, event = gdk_event_new (GDK_MOTION_NOTIFY); event->motion.window = window; event->motion.time = _gdk_win32_get_next_tick (msg->time); - event->motion.x = current_x = (gint16) GET_X_LPARAM (msg->lParam); - event->motion.y = current_y = (gint16) GET_Y_LPARAM (msg->lParam); - event->motion.x_root = current_root_x; - event->motion.y_root = current_root_y; + current_x = (gint16) GET_X_LPARAM (msg->lParam); + current_y = (gint16) GET_Y_LPARAM (msg->lParam); + event->motion.x = GDK_WIN32_UNSCALE_D (current_x); + event->motion.y = GDK_WIN32_UNSCALE_D (current_y); + event->motion.x_root = GDK_WIN32_UNSCALE_D (current_root_x); + event->motion.y_root = GDK_WIN32_UNSCALE_D (current_root_y); event->motion.axes = NULL; event->motion.state = build_pointer_event_state (msg); event->motion.is_hint = FALSE; event->motion.device = _gdk_display->core_pointer; + if (mouse_message_from_touch ()) + ((GdkEventPrivate *) event)->flags |= GDK_EVENT_POINTER_EMULATED; _gdk_win32_append_event (event); return_val = TRUE; break; + case GDK_WM_TOUCH: + if (handle_wm_touch (window, msg)) + { + *ret_valp = 0; + return_val = TRUE; + } + break; + case WM_NCMOUSEMOVE: GDK_NOTE (EVENTS, g_print (" (%d,%d)", @@ -2778,28 +2965,35 @@ gdk_event_translate (MSG *msg, ScreenToClient (msg->hwnd, &point); - event = gdk_event_new (GDK_SCROLL); - event->scroll.window = window; + { + /* What the wheel turned, in steps of WHEEL_DELTA: precision + * touchpads and fine wheels send fractions, which become + * smooth scroll events and, once they make up a step, the + * usual ones as well */ + static gdouble rest[2]; + GdkEvent scroll; + gdouble delta = (short) HIWORD (msg->wParam) / (gdouble) WHEEL_DELTA; + gdouble dx = 0, dy = 0; - if (msg->message == WM_MOUSEWHEEL) - { - event->scroll.direction = (((short) HIWORD (msg->wParam)) > 0) ? - GDK_SCROLL_UP : GDK_SCROLL_DOWN; - } - else if (msg->message == WM_MOUSEHWHEEL) - { - event->scroll.direction = (((short) HIWORD (msg->wParam)) > 0) ? - GDK_SCROLL_RIGHT : GDK_SCROLL_LEFT; - } - event->scroll.time = _gdk_win32_get_next_tick (msg->time); - event->scroll.x = (gint16) point.x; - event->scroll.y = (gint16) point.y; - event->scroll.x_root = (gint16) GET_X_LPARAM (msg->lParam) + _gdk_offset_x; - event->scroll.y_root = (gint16) GET_Y_LPARAM (msg->lParam) + _gdk_offset_y; - event->scroll.state = build_pointer_event_state (msg); - event->scroll.device = _gdk_display->core_pointer; + if (msg->message == WM_MOUSEWHEEL) + dy = - delta; + else + dx = delta; - _gdk_win32_append_event (event); + memset (&scroll, 0, sizeof scroll); + scroll.scroll.type = GDK_SCROLL; + scroll.scroll.window = window; + scroll.scroll.time = _gdk_win32_get_next_tick (msg->time); + scroll.scroll.x = GDK_WIN32_UNSCALE_D ((gint16) point.x); + scroll.scroll.y = GDK_WIN32_UNSCALE_D ((gint16) point.y); + scroll.scroll.x_root = GDK_WIN32_SCREEN_TO_ROOT_D ((gint16) GET_X_LPARAM (msg->lParam), _gdk_offset_x); + scroll.scroll.y_root = GDK_WIN32_SCREEN_TO_ROOT_D ((gint16) GET_Y_LPARAM (msg->lParam), _gdk_offset_y); + scroll.scroll.state = build_pointer_event_state (msg); + scroll.scroll.device = _gdk_display->core_pointer; + + _gdk_event_emit_scroll (NULL, &scroll, TRUE, dx, dy, dx, dy, rest, + _gdk_win32_append_event); + } return_val = TRUE; break; @@ -3169,8 +3363,8 @@ gdk_event_translate (MSG *msg, { /* Resize in increments relative to the base size */ rect.left = rect.top = 0; - rect.right = impl->hints.base_width; - rect.bottom = impl->hints.base_height; + rect.right = GDK_WIN32_SC (impl->hints.base_width); + rect.bottom = GDK_WIN32_SC (impl->hints.base_height); _gdk_win32_adjust_client_rect (window, &rect); point.x = rect.left; point.y = rect.top; @@ -3192,53 +3386,53 @@ gdk_event_translate (MSG *msg, case WMSZ_BOTTOM: if (drag->bottom == rect.bottom) break; - adjust_drag (&drag->bottom, rect.bottom, impl->hints.height_inc); + adjust_drag (&drag->bottom, rect.bottom, GDK_WIN32_SC (impl->hints.height_inc)); break; case WMSZ_BOTTOMLEFT: if (drag->bottom == rect.bottom && drag->left == rect.left) break; - adjust_drag (&drag->bottom, rect.bottom, impl->hints.height_inc); - adjust_drag (&drag->left, rect.left, impl->hints.width_inc); + adjust_drag (&drag->bottom, rect.bottom, GDK_WIN32_SC (impl->hints.height_inc)); + adjust_drag (&drag->left, rect.left, GDK_WIN32_SC (impl->hints.width_inc)); break; case WMSZ_LEFT: if (drag->left == rect.left) break; - adjust_drag (&drag->left, rect.left, impl->hints.width_inc); + adjust_drag (&drag->left, rect.left, GDK_WIN32_SC (impl->hints.width_inc)); break; case WMSZ_TOPLEFT: if (drag->top == rect.top && drag->left == rect.left) break; - adjust_drag (&drag->top, rect.top, impl->hints.height_inc); - adjust_drag (&drag->left, rect.left, impl->hints.width_inc); + adjust_drag (&drag->top, rect.top, GDK_WIN32_SC (impl->hints.height_inc)); + adjust_drag (&drag->left, rect.left, GDK_WIN32_SC (impl->hints.width_inc)); break; case WMSZ_TOP: if (drag->top == rect.top) break; - adjust_drag (&drag->top, rect.top, impl->hints.height_inc); + adjust_drag (&drag->top, rect.top, GDK_WIN32_SC (impl->hints.height_inc)); break; case WMSZ_TOPRIGHT: if (drag->top == rect.top && drag->right == rect.right) break; - adjust_drag (&drag->top, rect.top, impl->hints.height_inc); - adjust_drag (&drag->right, rect.right, impl->hints.width_inc); + adjust_drag (&drag->top, rect.top, GDK_WIN32_SC (impl->hints.height_inc)); + adjust_drag (&drag->right, rect.right, GDK_WIN32_SC (impl->hints.width_inc)); break; case WMSZ_RIGHT: if (drag->right == rect.right) break; - adjust_drag (&drag->right, rect.right, impl->hints.width_inc); + adjust_drag (&drag->right, rect.right, GDK_WIN32_SC (impl->hints.width_inc)); break; case WMSZ_BOTTOMRIGHT: if (drag->bottom == rect.bottom && drag->right == rect.right) break; - adjust_drag (&drag->bottom, rect.bottom, impl->hints.height_inc); - adjust_drag (&drag->right, rect.right, impl->hints.width_inc); + adjust_drag (&drag->bottom, rect.bottom, GDK_WIN32_SC (impl->hints.height_inc)); + adjust_drag (&drag->right, rect.right, GDK_WIN32_SC (impl->hints.width_inc)); break; } @@ -3375,8 +3569,8 @@ gdk_event_translate (MSG *msg, if (impl->hint_flags & GDK_HINT_MIN_SIZE) { rect.left = rect.top = 0; - rect.right = impl->hints.min_width; - rect.bottom = impl->hints.min_height; + rect.right = GDK_WIN32_SC (impl->hints.min_width); + rect.bottom = GDK_WIN32_SC (impl->hints.min_height); _gdk_win32_adjust_client_rect (window, &rect); @@ -3389,8 +3583,8 @@ gdk_event_translate (MSG *msg, int maxw, maxh; rect.left = rect.top = 0; - rect.right = impl->hints.max_width; - rect.bottom = impl->hints.max_height; + rect.right = GDK_WIN32_SC (impl->hints.max_width); + rect.bottom = GDK_WIN32_SC (impl->hints.max_height); _gdk_win32_adjust_client_rect (window, &rect); @@ -3402,8 +3596,36 @@ gdk_event_translate (MSG *msg, } else { + /* Apparently, this is just a very big number (bigger than any widget + * could realistically be) to make sure the window is as big as + * possible when maximized. + */ mmi->ptMaxTrackSize.x = 30000; mmi->ptMaxTrackSize.y = 30000; + + /* A window without a frame would be maximized over the whole + * monitor, taskbar included. Windows wants the maximized position + * and size as if the window were on the primary monitor, so only + * the taskbar of the nearest monitor is taken into account. + */ + if ((GetWindowLong (GDK_WINDOW_HWND (window), GWL_STYLE) & + (WS_BORDER | WS_THICKFRAME)) == 0) + { + HMONITOR nearest_monitor; + MONITORINFO nearest_info; + + nearest_monitor = MonitorFromWindow (GDK_WINDOW_HWND (window), + MONITOR_DEFAULTTONEAREST); + nearest_info.cbSize = sizeof (nearest_info); + + if (GetMonitorInfoA (nearest_monitor, &nearest_info)) + { + mmi->ptMaxPosition.x = nearest_info.rcWork.left - nearest_info.rcMonitor.left; + mmi->ptMaxPosition.y = nearest_info.rcWork.top - nearest_info.rcMonitor.top; + mmi->ptMaxSize.x = nearest_info.rcWork.right - nearest_info.rcWork.left; + mmi->ptMaxSize.y = nearest_info.rcWork.bottom - nearest_info.rcWork.top; + } + } } if (impl->hint_flags & (GDK_HINT_MIN_SIZE | GDK_HINT_MAX_SIZE)) @@ -3533,6 +3755,21 @@ gdk_event_translate (MSG *msg, break; } } + else if (msg->wParam == CF_HDROP) + { + /* the URIs of the clipboard as files for Explorer */ + _delayed_rendering_data = + _gdk_win32_selection_convert_to_hdrop (_delayed_rendering_data); + if (!_delayed_rendering_data) + break; + } + else if (msg->wParam == _cf_preferred_drop_effect) + { + _delayed_rendering_data = + _gdk_win32_selection_convert_to_drop_effect (_delayed_rendering_data); + if (!_delayed_rendering_data) + break; + } /* The requestor is holding the clipboard, no * OpenClipboard() is required/possible @@ -3654,7 +3891,7 @@ gdk_event_prepare (GSource *source, retval = (_gdk_event_queue_find_first (_gdk_display) != NULL || (modal_win32_dialog == NULL && - GetQueueStatus (QS_ALLINPUT) != 0)); + GetQueueStatus (GDK_QS_INPUT) != 0)); GDK_THREADS_LEAVE (); @@ -3672,7 +3909,7 @@ gdk_event_check (GSource *source) { retval = (_gdk_event_queue_find_first (_gdk_display) != NULL || (modal_win32_dialog == NULL && - GetQueueStatus (QS_ALLINPUT) != 0)); + GetQueueStatus (GDK_QS_INPUT) != 0)); } else { diff --git a/gdk/win32/gdkgc-win32.c b/gdk/win32/gdkgc-win32.c index 703e05a58..4c65532ce 100644 --- a/gdk/win32/gdkgc-win32.c +++ b/gdk/win32/gdkgc-win32.c @@ -745,7 +745,7 @@ static GdkDrawableImplWin32 * get_impl_drawable (GdkDrawable *drawable) { if (GDK_IS_OFFSCREEN_WINDOW (drawable)) - return _gdk_offscreen_window_get_real_drawable (GDK_OFFSCREEN_WINDOW (drawable)); + return GDK_DRAWABLE_IMPL_WIN32 (_gdk_offscreen_window_get_real_drawable (GDK_OFFSCREEN_WINDOW (drawable))); if (GDK_IS_DRAWABLE_IMPL_WIN32 (drawable)) return GDK_DRAWABLE_IMPL_WIN32(drawable); else if (GDK_IS_WINDOW (drawable)) @@ -808,6 +808,49 @@ get_impl_drawable (GdkDrawable *drawable) * * Return value: The HDC. **/ +/* HiDPI: a logical unit of the DC as @scale of its pixels (1 for the + * pixels themselves) */ +void +_gdk_win32_dc_set_scale (HDC hdc, + gint scale) +{ + if (_gdk_win32_scale <= 1) + return; + + if (scale > 1) + { + SetMapMode (hdc, MM_ANISOTROPIC); + SetWindowExtEx (hdc, 1, 1, NULL); + SetViewportExtEx (hdc, scale, scale, NULL); + } + else + SetMapMode (hdc, MM_TEXT); +} + +/* an HRGN of logical units of GDK as one of Windows */ +HRGN +_gdk_win32_hrgn_scale (HRGN hrgn) +{ + XFORM xform = { 0 }; + DWORD size; + RGNDATA *data; + HRGN result; + + if (_gdk_win32_scale <= 1 || (size = GetRegionData (hrgn, 0, NULL)) == 0) + return hrgn; + + data = g_malloc (size); + GetRegionData (hrgn, size, data); + xform.eM11 = xform.eM22 = (FLOAT) _gdk_win32_scale; + result = ExtCreateRegion (&xform, size, data); + g_free (data); + if (!result) + return hrgn; + + DeleteObject (hrgn); + return result; +} + HDC gdk_win32_hdc_get (GdkDrawable *drawable, GdkGC *gc, @@ -830,6 +873,11 @@ gdk_win32_hdc_get (GdkDrawable *drawable, if (ok && (win32_gc->saved_dc = SaveDC (win32_gc->hdc)) == 0) WIN32_GDI_FAILED ("SaveDC"), ok = FALSE; + /* HiDPI: GDK draws in its pixels, Windows maps them to its own (the + * DC goes back to them with RestoreDC in gdk_win32_hdc_release) */ + if (ok) + _gdk_win32_dc_set_scale (win32_gc->hdc, _gdk_win32_drawable_scale (GDK_DRAWABLE (impl))); + if (ok && (usage & (GDK_GC_FOREGROUND | GDK_GC_BACKGROUND))) ok = predraw (gc, impl->colormap); @@ -873,6 +921,23 @@ gdk_win32_hdc_get (GdkDrawable *drawable, style = win32_gc->pen_dashes; } + /* a cosmetic pen is one pixel of Windows wide, whatever the + * mapping; a geometric one gets as wide as GDK's pixel */ + if (_gdk_win32_scale > 1 && + (win32_gc->pen_style & PS_TYPE_MASK) == PS_COSMETIC) + win32_gc->pen_style = (win32_gc->pen_style & ~(PS_TYPE_MASK | PS_STYLE_MASK)) | + PS_GEOMETRIC | PS_ENDCAP_FLAT | + ((win32_gc->pen_style & PS_STYLE_MASK) == PS_ALTERNATE + ? PS_USERSTYLE : (win32_gc->pen_style & PS_STYLE_MASK)); + + if ((win32_gc->pen_style & PS_STYLE_MASK) == PS_USERSTYLE && !style) + { + static const DWORD dots[2] = { 1, 1 }; + + style_count = win32_gc->pen_dashes ? win32_gc->pen_num_dashes : 2; + style = win32_gc->pen_dashes ? win32_gc->pen_dashes : dots; + } + if ((hpen = ExtCreatePen (win32_gc->pen_style, MAX (win32_gc->pen_width, 1), &logbrush, @@ -906,6 +971,7 @@ gdk_win32_hdc_get (GdkDrawable *drawable, if (ok && win32_gc->values_mask & (GDK_GC_CLIP_X_ORIGIN | GDK_GC_CLIP_Y_ORIGIN) && OffsetClipRgn (win32_gc->hdc, + /* logical units: the mapping scales them */ win32_gc->values_mask & GDK_GC_CLIP_X_ORIGIN ? gc->clip_x_origin : 0, win32_gc->values_mask & GDK_GC_CLIP_Y_ORIGIN ? gc->clip_y_origin : 0) == ERROR) WIN32_API_FAILED ("OffsetClipRgn"), ok = FALSE; @@ -1010,8 +1076,11 @@ _gdk_win32_bitmap_to_hrgn (GdkPixmap *pixmap) g_assert (GDK_PIXMAP_OBJECT(pixmap)->depth == 1); bits = GDK_PIXMAP_IMPL_WIN32 (GDK_PIXMAP_OBJECT (pixmap)->impl)->bits; + /* the bits, so an HRGN in pixels of Windows (HiDPI) */ width = GDK_PIXMAP_IMPL_WIN32 (GDK_PIXMAP_OBJECT (pixmap)->impl)->width; height = GDK_PIXMAP_IMPL_WIN32 (GDK_PIXMAP_OBJECT (pixmap)->impl)->height; + width *= MAX (GDK_PIXMAP_IMPL_WIN32 (GDK_PIXMAP_OBJECT (pixmap)->impl)->scale, 1); + height *= MAX (GDK_PIXMAP_IMPL_WIN32 (GDK_PIXMAP_OBJECT (pixmap)->impl)->scale, 1); bpl = ((width - 1)/32 + 1)*4; /* For better performances, we will use the ExtCreateRegion() @@ -1104,6 +1173,10 @@ _gdk_win32_bitmap_to_hrgn (GdkPixmap *pixmap) /* Clean up*/ g_free (pData); + /* a bitmap of a GdkImage has GDK's pixels (HiDPI) */ + if (hRgn && GDK_PIXMAP_IMPL_WIN32 (GDK_PIXMAP_OBJECT (pixmap)->impl)->scale <= 1) + hRgn = _gdk_win32_hrgn_scale (hRgn); + return hRgn; } @@ -1131,10 +1204,11 @@ _gdk_win32_gdkregion_to_hrgn (const GdkRegion *region, { rect = ((RECT *) rgndata->Buffer) + rgndata->rdh.nCount++; - rect->left = boxes[i].x1 + x_origin; - rect->right = boxes[i].x2 + x_origin; - rect->top = boxes[i].y1 + y_origin; - rect->bottom = boxes[i].y2 + y_origin; + /* a region of GDK, an HRGN in pixels of Windows */ + rect->left = GDK_WIN32_SC (boxes[i].x1 + x_origin); + rect->right = GDK_WIN32_SC (boxes[i].x2 + x_origin); + rect->top = GDK_WIN32_SC (boxes[i].y1 + y_origin); + rect->bottom = GDK_WIN32_SC (boxes[i].y2 + y_origin); if (rect->left < rgndata->rdh.rcBound.left) rgndata->rdh.rcBound.left = rect->left; diff --git a/gdk/win32/gdkgeometry-win32.c b/gdk/win32/gdkgeometry-win32.c index d61824dc2..f91bcb77d 100644 --- a/gdk/win32/gdkgeometry-win32.c +++ b/gdk/win32/gdkgeometry-win32.c @@ -97,8 +97,9 @@ _gdk_window_move_resize_child (GdkWindow *window, width, height)); API_CALL (SetWindowPos, (GDK_WINDOW_HWND (window), NULL, - obj->x + obj->parent->abs_x, obj->y + obj->parent->abs_y, - width, height, + GDK_WIN32_SC (obj->x + obj->parent->abs_x), + GDK_WIN32_SC (obj->y + obj->parent->abs_y), + GDK_WIN32_SC (width), GDK_WIN32_SC (height), SWP_NOACTIVATE | SWP_NOZORDER)); //_gdk_win32_window_tmp_reset_parent_bg (window); diff --git a/gdk/win32/gdkglobals-win32.c b/gdk/win32/gdkglobals-win32.c index 1ec6ba595..fa594a78b 100644 --- a/gdk/win32/gdkglobals-win32.c +++ b/gdk/win32/gdkglobals-win32.c @@ -37,6 +37,7 @@ gint _gdk_num_monitors; GdkWin32Monitor *_gdk_monitors = NULL; gint _gdk_offset_x, _gdk_offset_y; +gint _gdk_win32_scale = 1; HDC _gdk_display_hdc; HINSTANCE _gdk_dll_hinstance; @@ -69,6 +70,8 @@ UINT _cf_png; UINT _cf_jfif; UINT _cf_gif; UINT _cf_url; +UINT _cf_preferred_drop_effect; +GdkAtom _gnome_copied_files; UINT _cf_html_format; UINT _cf_text_html; diff --git a/gdk/win32/gdkimage-win32.c b/gdk/win32/gdkimage-win32.c index 8afa53f35..8233b82e9 100644 --- a/gdk/win32/gdkimage-win32.c +++ b/gdk/win32/gdkimage-win32.c @@ -175,7 +175,7 @@ gdk_image_new_bitmap (GdkVisual *visual, gint data_bpl = (w-1)/8 + 1; gint i; - pixmap = gdk_pixmap_new (NULL, w, h, 1); + pixmap = _gdk_win32_pixmap_new_unscaled (w, h, 1); if (pixmap == NULL) return NULL; @@ -223,7 +223,7 @@ _gdk_image_new_for_depth (GdkScreen *screen, if (visual) depth = visual->depth; - pixmap = gdk_pixmap_new (NULL, width, height, depth); + pixmap = _gdk_win32_pixmap_new_unscaled (width, height, depth); if (pixmap == NULL) return NULL; diff --git a/gdk/win32/gdkinput-win32.c b/gdk/win32/gdkinput-win32.c index 0a1bf871f..f9a2bc16d 100644 --- a/gdk/win32/gdkinput-win32.c +++ b/gdk/win32/gdkinput-win32.c @@ -778,9 +778,9 @@ gdk_input_get_root_relative_geometry (HWND w, ClientToScreen (w, &pt); if (x_ret) - *x_ret = pt.x + _gdk_offset_x; + *x_ret = GDK_WIN32_SCREEN_TO_ROOT_X (pt.x); if (y_ret) - *y_ret = pt.y + _gdk_offset_y; + *y_ret = GDK_WIN32_SCREEN_TO_ROOT_Y (pt.y); } void diff --git a/gdk/win32/gdkkeys-win32.c b/gdk/win32/gdkkeys-win32.c index 9a34083c4..87551edfb 100644 --- a/gdk/win32/gdkkeys-win32.c +++ b/gdk/win32/gdkkeys-win32.c @@ -1289,7 +1289,7 @@ gdk_keymap_get_entries_for_keyval (GdkKeymap *gdk_keymap, else keymap = GDK_WIN32_KEYMAP (gdk_keymap); - update_keymap (gdk_keymap); + update_keymap (GDK_KEYMAP (keymap)); for (vk = 0; vk < KEY_STATE_SIZE; vk++) { diff --git a/gdk/win32/gdkmain-win32.c b/gdk/win32/gdkmain-win32.c index 18df58a3b..925c71c5d 100644 --- a/gdk/win32/gdkmain-win32.c +++ b/gdk/win32/gdkmain-win32.c @@ -74,6 +74,65 @@ DllMain (HINSTANCE hinstDLL, return TRUE; } +/* HiDPI. Without telling Windows that it handles the resolution itself, + * a program is drawn at 96 dpi and enlarged by Windows (blurred, from + * 150 %), or (XP, and below 150 % with "XP style" scaling) its fonts + * just stay small. So GDK tells it (Vista: SetProcessDPIAware, from + * 8.1 the system resolution of SetProcessDpiAwareness) and scales by + * itself: at 192 dpi and more each of its pixels is 2 of Windows (as on + * X11, see _gdk_x11_screen_new()), what remains of a fraction goes to + * the fonts (120 dpi: 1 with fonts of 120 dpi). GDK_SCALE sets the + * scale; GDK_WIN32_DPI_AWARE=0 leaves it to Windows as before. */ +static gint win32_font_dpi = 0; + +gint +_gdk_win32_font_dpi (void) +{ + return win32_font_dpi; +} + +void +_gdk_win32_init_scale (void) +{ + typedef HRESULT (WINAPI *t_SetProcessDpiAwareness) (int); + typedef BOOL (WINAPI *t_SetProcessDPIAware) (void); + const gchar *env = g_getenv ("GDK_WIN32_DPI_AWARE"); + const gchar *scale_env = g_getenv ("GDK_SCALE"); + gboolean aware = !(env && env[0] == '0'); + HDC hdc; + gint dpi; + + if (aware) + { + HMODULE shcore = LoadLibraryA ("shcore.dll"); + t_SetProcessDpiAwareness set_awareness = shcore ? + (t_SetProcessDpiAwareness) GetProcAddress (shcore, "SetProcessDpiAwareness") : NULL; + t_SetProcessDPIAware set_aware = (t_SetProcessDPIAware) + GetProcAddress (GetModuleHandleA ("user32.dll"), "SetProcessDPIAware"); + + /* 1: PROCESS_SYSTEM_DPI_AWARE; fails where a manifest said it */ + if (!set_awareness || set_awareness (1) != S_OK) + if (set_aware) + set_aware (); + } + + hdc = GetDC (NULL); + dpi = GetDeviceCaps (hdc, LOGPIXELSY); + ReleaseDC (NULL, hdc); + if (dpi <= 0) + dpi = 96; + + _gdk_win32_scale = 1; + if (scale_env && atoi (scale_env) >= 1) + _gdk_win32_scale = MIN (atoi (scale_env), 8); + else if (aware) + _gdk_win32_scale = CLAMP ((gint) (dpi / 96.0 + 0.25), 1, 8); + + /* fonts: the resolution in pixels of GDK, where Windows has another */ + if (aware && (dpi != 96 || _gdk_win32_scale > 1)) + win32_font_dpi = dpi / _gdk_win32_scale >= 72 ? dpi / _gdk_win32_scale : dpi; +} + void _gdk_windowing_init (void) { @@ -88,6 +147,7 @@ _gdk_windowing_init (void) GdiSetBatchLimit (1); _gdk_app_hmodule = GetModuleHandle (NULL); + _gdk_win32_init_scale (); _gdk_display_hdc = CreateDC ("DISPLAY", NULL, NULL, NULL); _gdk_input_locale = GetKeyboardLayout (0); _gdk_win32_keymap_set_active_layout (GDK_WIN32_KEYMAP (gdk_keymap_get_default ()), _gdk_input_locale); @@ -130,6 +190,9 @@ _gdk_windowing_init (void) _cf_gif = RegisterClipboardFormat ("GIF"); _cf_url = RegisterClipboardFormat ("UniformResourceLocatorW"); + /* Explorer: whether files on the clipboard were cut or copied */ + _cf_preferred_drop_effect = RegisterClipboardFormat ("Preferred DropEffect"); + _gnome_copied_files = gdk_atom_intern_static_string ("x-special/gnome-copied-files"); _cf_html_format = RegisterClipboardFormat ("HTML Format"); _cf_text_html = RegisterClipboardFormat ("text/html"); @@ -178,13 +241,13 @@ gdk_screen_get_height (GdkScreen *screen) gint gdk_screen_get_width_mm (GdkScreen *screen) { - return (double) gdk_screen_get_width (screen) / GetDeviceCaps (_gdk_display_hdc, LOGPIXELSX) * 25.4; + return (double) GDK_WIN32_SC (gdk_screen_get_width (screen)) / GetDeviceCaps (_gdk_display_hdc, LOGPIXELSX) * 25.4; } gint gdk_screen_get_height_mm (GdkScreen *screen) { - return (double) gdk_screen_get_height (screen) / GetDeviceCaps (_gdk_display_hdc, LOGPIXELSY) * 25.4; + return (double) GDK_WIN32_SC (gdk_screen_get_height (screen)) / GetDeviceCaps (_gdk_display_hdc, LOGPIXELSY) * 25.4; } void diff --git a/gdk/win32/gdkpixmap-win32.c b/gdk/win32/gdkpixmap-win32.c index 08f9e9abb..e60b96f1e 100644 --- a/gdk/win32/gdkpixmap-win32.c +++ b/gdk/win32/gdkpixmap-win32.c @@ -86,6 +86,25 @@ gdk_pixmap_impl_win32_init (GdkPixmapImplWin32 *impl) { impl->width = 1; impl->height = 1; + impl->scale = 1; +} + +static gboolean pixmap_unscaled = FALSE; + +/* a pixmap whose bitmap has one pixel for each of GDK (HiDPI), for + * GdkImage */ +GdkPixmap * +_gdk_win32_pixmap_new_unscaled (gint width, + gint height, + gint depth) +{ + GdkPixmap *pixmap; + + pixmap_unscaled = TRUE; + pixmap = gdk_pixmap_new (NULL, width, height, depth); + pixmap_unscaled = FALSE; + + return pixmap; } static void @@ -221,6 +240,11 @@ _gdk_pixmap_new (GdkDrawable *drawable, pixmap_impl->height = height; GDK_PIXMAP_OBJECT (pixmap)->depth = depth; + /* HiDPI: the bitmap in pixels of Windows */ + pixmap_impl->scale = pixmap_unscaled ? 1 : _gdk_win32_scale; + width *= pixmap_impl->scale; + height *= pixmap_impl->scale; + if (depth == window_depth) { cmap = gdk_drawable_get_colormap (drawable); @@ -336,6 +360,11 @@ _gdk_pixmap_new (GdkDrawable *drawable, /* No need to create a new surface when needed, as we have one already */ drawable_impl->cairo_surface = dib_surface; +#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE (1, 14, 0) + /* HiDPI: drawn on in pixels of GDK */ + if (pixmap_impl->scale > 1) + cairo_surface_set_device_scale (dib_surface, pixmap_impl->scale, pixmap_impl->scale); +#endif drawable_impl->handle = hbitmap; pixmap_impl->bits = bits; @@ -407,11 +436,27 @@ _gdk_bitmap_create_from_data (GdkDrawable *drawable, pixmap_impl = GDK_PIXMAP_IMPL_WIN32 (GDK_PIXMAP_OBJECT (pixmap)->impl); bits = pixmap_impl->bits; data_bpl = ((width - 1) / 8 + 1); - pixmap_bpl = ((width - 1)/32 + 1)*4; - for (i = 0; i < height; i++) - for (j = 0; j < data_bpl; j++) - bits[i*pixmap_bpl + j] = mirror[(guchar) data[i*data_bpl + j]]; + if (pixmap_impl->scale > 1) + { + /* HiDPI: each bit as a block of the bitmap's pixels */ + gint s = pixmap_impl->scale, dw = width * s; + + pixmap_bpl = ((dw - 1)/32 + 1)*4; + memset (bits, 0, pixmap_bpl * height * s); + for (i = 0; i < height * s; i++) + for (j = 0; j < dw; j++) + if ((guchar) data[(i / s) * data_bpl + (j / s) / 8] & (1 << ((j / s) % 8))) + bits[i * pixmap_bpl + j / 8] |= 0x80 >> (j % 8); + } + else + { + pixmap_bpl = ((width - 1)/32 + 1)*4; + + for (i = 0; i < height; i++) + for (j = 0; j < data_bpl; j++) + bits[i*pixmap_bpl + j] = mirror[(guchar) data[i*data_bpl + j]]; + } GDK_NOTE (PIXMAP, g_print ("gdk_bitmap_create_from_data: %dx%d=%p\n", width, height, GDK_PIXMAP_HBITMAP (pixmap))); @@ -519,8 +564,10 @@ gdk_pixmap_foreign_new (GdkNativeWindow anid) draw_impl->handle = hbitmap; draw_impl->colormap = NULL; pix_impl->is_foreign = TRUE; - pix_impl->width = size.cx; - pix_impl->height = size.cy; + /* in pixels of GDK */ + pix_impl->scale = _gdk_win32_scale; + pix_impl->width = MAX (size.cx / _gdk_win32_scale, 1); + pix_impl->height = MAX (size.cy / _gdk_win32_scale, 1); pix_impl->bits = NULL; gdk_win32_handle_table_insert (&GDK_PIXMAP_HBITMAP (pixmap), pixmap); diff --git a/gdk/win32/gdkpixmap-win32.h b/gdk/win32/gdkpixmap-win32.h index 81f85a142..26b5f657b 100644 --- a/gdk/win32/gdkpixmap-win32.h +++ b/gdk/win32/gdkpixmap-win32.h @@ -54,6 +54,9 @@ struct _GdkPixmapImplWin32 guchar *bits; guint is_foreign : 1; guint is_allocated : 1; + /* HiDPI: pixels of the bitmap for one of GDK (1 for the pixmaps + * behind a GdkImage, whose memory programs use directly) */ + gint scale; }; struct _GdkPixmapImplWin32Class diff --git a/gdk/win32/gdkprivate-win32.h b/gdk/win32/gdkprivate-win32.h index 9ef3209fe..bc79dc81c 100644 --- a/gdk/win32/gdkprivate-win32.h +++ b/gdk/win32/gdkprivate-win32.h @@ -396,6 +396,41 @@ extern GdkWin32Monitor *_gdk_monitors; */ extern gint _gdk_offset_x, _gdk_offset_y; +/* HiDPI: pixels of Windows for one of GDK, in each direction (see + * _gdk_win32_init_scale()); sizes and window coordinates of GDK are + * multiplied by it for Windows, root coordinates also moved by the + * offset of the virtual screen, which is in pixels of Windows */ +extern gint _gdk_win32_scale; + +static inline gint +_gdk_win32_unscale (gint value) +{ + gint s = _gdk_win32_scale; + return value >= 0 ? value / s : - ((- value + s - 1) / s); +} + +static inline gint +_gdk_win32_unscale_up (gint value) +{ + return - _gdk_win32_unscale (- value); +} + +#define GDK_WIN32_SC(v) ((v) * _gdk_win32_scale) +/* for coordinates of events, which keep the fraction */ +#define GDK_WIN32_UNSCALE_D(v) ((gdouble) (v) / _gdk_win32_scale) +#define GDK_WIN32_SCREEN_TO_ROOT_D(x, off) (((gdouble) (x) + (off)) / _gdk_win32_scale) +#define GDK_WIN32_ROOT_TO_SCREEN_X(x) ((x) * _gdk_win32_scale - _gdk_offset_x) +#define GDK_WIN32_ROOT_TO_SCREEN_Y(y) ((y) * _gdk_win32_scale - _gdk_offset_y) +#define GDK_WIN32_SCREEN_TO_ROOT_X(x) (_gdk_win32_unscale ((x) + _gdk_offset_x)) +#define GDK_WIN32_SCREEN_TO_ROOT_Y(y) (_gdk_win32_unscale ((y) + _gdk_offset_y)) + +void _gdk_win32_init_scale (void); +gint _gdk_win32_font_dpi (void); +void _gdk_win32_dc_set_scale (HDC hdc, gint scale); +gint _gdk_win32_drawable_scale (GdkDrawable *drawable); +GdkPixmap *_gdk_win32_pixmap_new_unscaled (gint width, gint height, gint depth); +HRGN _gdk_win32_hrgn_scale (HRGN hrgn); + extern HDC _gdk_display_hdc; extern HINSTANCE _gdk_dll_hinstance; extern HINSTANCE _gdk_app_hmodule; @@ -435,6 +470,13 @@ extern UINT _cf_png; extern UINT _cf_jfif; extern UINT _cf_gif; extern UINT _cf_url; +extern UINT _cf_preferred_drop_effect; + +gchar *_gdk_win32_hdrop_to_uri_list (HGLOBAL hdata, + const gchar *separator); +HGLOBAL _gdk_win32_selection_convert_to_hdrop (HGLOBAL hdata); +HGLOBAL _gdk_win32_selection_convert_to_drop_effect (HGLOBAL hdata); +extern GdkAtom _gnome_copied_files; extern UINT _cf_html_format; extern UINT _cf_text_html; @@ -494,6 +536,10 @@ HICON _gdk_win32_pixbuf_to_hcursor (GdkPixbuf *pixbuf, gint y_hotspot); gboolean _gdk_win32_pixbuf_to_hicon_supports_alpha (void); +/* Windows 7 touches (WM_TOUCH) for windows with GDK_TOUCH_MASK */ +void _gdk_win32_window_update_touch (GdkWindow *window, + gboolean touch); + void _gdk_win32_append_event (GdkEvent *event); void _gdk_win32_emit_configure_event (GdkWindow *window); GdkWindow *_gdk_win32_find_window_for_mouse_event (GdkWindow* reported_window, diff --git a/gdk/win32/gdkproperty-win32.c b/gdk/win32/gdkproperty-win32.c index a2ff79c00..b7fcacab4 100644 --- a/gdk/win32/gdkproperty-win32.c +++ b/gdk/win32/gdkproperty-win32.c @@ -29,6 +29,7 @@ #include #include #include +#include #include "gdkscreen.h" #include "gdkproperty.h" @@ -311,6 +312,49 @@ gdk_property_delete (GdkWindow *window, } } +/* the message font of Windows as a pango font name with its size in + * points, or NULL; bitmap fonts are left out, pango can not use them */ +static gchar * +get_system_font_name (HDC hdc) +{ + NONCLIENTMETRICSW ncm; + PangoFontDescription *font_desc; + gchar *result, *font_desc_string; + int logpixelsy; + gint font_size; + + /* without iPaddedBorderWidth, which Windows before Vista refuses */ + ncm.cbSize = G_STRUCT_OFFSET (NONCLIENTMETRICSW, lfMessageFont) + sizeof (LOGFONTW); + if (!SystemParametersInfoW (SPI_GETNONCLIENTMETRICS, ncm.cbSize, &ncm, 0)) + return NULL; + + if (ncm.lfMessageFont.lfFaceName[0] == 0 || + ncm.lfMessageFont.lfOutPrecision == OUT_STRING_PRECIS || + ncm.lfMessageFont.lfHeight >= 0) + return NULL; + + logpixelsy = GetDeviceCaps (hdc, LOGPIXELSY); + if (logpixelsy <= 0) + return NULL; + + font_desc = pango_win32_font_description_from_logfontw (&ncm.lfMessageFont); + pango_font_description_unset_fields (font_desc, PANGO_FONT_MASK_SIZE); + font_desc_string = pango_font_description_to_string (font_desc); + pango_font_description_free (font_desc); + + font_size = -MulDiv (ncm.lfMessageFont.lfHeight, 72, logpixelsy); + if (font_size <= 0) + { + g_free (font_desc_string); + return NULL; + } + + result = g_strdup_printf ("%s %d", font_desc_string, font_size); + g_free (font_desc_string); + + return result; +} + /* For reference, from gdk/x11/gdksettings.c: @@ -390,18 +434,24 @@ gdk_screen_get_setting (GdkScreen *screen, } else if (strcmp ("gtk-double-click-distance", name) == 0) { - gint i = MAX(GetSystemMetrics (SM_CXDOUBLECLK), GetSystemMetrics (SM_CYDOUBLECLK)); + gint i = MAX (_gdk_win32_unscale_up (MAX(GetSystemMetrics (SM_CXDOUBLECLK), GetSystemMetrics (SM_CYDOUBLECLK))), 1); GDK_NOTE(MISC, g_print("gdk_screen_get_setting(\"%s\") : %d\n", name, i)); g_value_set_int (value, i); return TRUE; } else if (strcmp ("gtk-dnd-drag-threshold", name) == 0) { - gint i = MAX(GetSystemMetrics (SM_CXDRAG), GetSystemMetrics (SM_CYDRAG)); + gint i = MAX (_gdk_win32_unscale_up (MAX(GetSystemMetrics (SM_CXDRAG), GetSystemMetrics (SM_CYDRAG))), 1); GDK_NOTE(MISC, g_print("gdk_screen_get_setting(\"%s\") : %d\n", name, i)); g_value_set_int (value, i); return TRUE; } + else if (strcmp ("gtk-xft-dpi", name) == 0 && _gdk_win32_font_dpi () > 0) + { + /* HiDPI: the resolution of Windows for fonts in pixels of GDK */ + g_value_set_int (value, _gdk_win32_font_dpi () * 1024); + return TRUE; + } else if (strcmp ("gtk-split-cursor", name) == 0) { GDK_NOTE(MISC, g_print("gdk_screen_get_setting(\"%s\") : FALSE\n", name)); @@ -420,41 +470,29 @@ gdk_screen_get_setting (GdkScreen *screen, g_value_set_boolean (value, TRUE); return TRUE; } -#if 0 - /* - * With 'MS Sans Serif' as windows menu font (default on win98se) you'll get a - * bunch of : - * WARNING **: Couldn't load font "MS Sans Serif 8" falling back to "Sans 8" - * at least with testfilechooser (regardless of the bitmap check below) - * so just disabling this code seems to be the best we can do --hb - */ else if (strcmp ("gtk-font-name", name) == 0) { - NONCLIENTMETRICS ncm; - ncm.cbSize = sizeof(NONCLIENTMETRICS); - if (SystemParametersInfo (SPI_GETNONCLIENTMETRICS, ncm.cbSize, &ncm, FALSE)) - { - /* Pango finally uses GetDeviceCaps to scale, we use simple - * approximation here. - */ - int nHeight = (0 > ncm.lfMenuFont.lfHeight ? -3*ncm.lfMenuFont.lfHeight/4 : 10); - if (OUT_STRING_PRECIS == ncm.lfMenuFont.lfOutPrecision) - GDK_NOTE(MISC, g_print("gdk_screen_get_setting(%s) : ignoring bitmap font '%s'\n", - name, ncm.lfMenuFont.lfFaceName)); - else if (ncm.lfMenuFont.lfFaceName && strlen(ncm.lfMenuFont.lfFaceName) > 0 && - /* Avoid issues like those described in bug #135098 */ - g_utf8_validate (ncm.lfMenuFont.lfFaceName, -1, NULL)) - { - char* s = g_strdup_printf ("%s %d", ncm.lfMenuFont.lfFaceName, nHeight); - GDK_NOTE(MISC, g_print("gdk_screen_get_setting(%s) : %s\n", name, s)); - g_value_set_string (value, s); + /* The message font of Windows ("Segoe UI 9", "Tahoma 8" on XP), as + * in GTK+ 3. A theme that sets gtk-font-name still wins. Before + * pango 1.43 the fallback list of pango only gave a good coverage + * of glyphs for "Segoe UI", so any other font is left to pango. */ + gchar *font_name = get_system_font_name (_gdk_display_hdc); - g_free(s); - return TRUE; - } + if (font_name && + pango_version_check (1, 43, 0) != NULL && + g_ascii_strncasecmp (font_name, "Segoe UI", strlen ("Segoe UI")) != 0) + { + g_free (font_name); + font_name = NULL; + } + + if (font_name) + { + GDK_NOTE(MISC, g_print("gdk_screen_get_setting(\"%s\") : %s\n", name, font_name)); + g_value_take_string (value, font_name); + return TRUE; } } -#endif return FALSE; } diff --git a/gdk/win32/gdkscreen-win32.c b/gdk/win32/gdkscreen-win32.c index 2a0a599fd..bc0ca1293 100644 --- a/gdk/win32/gdkscreen-win32.c +++ b/gdk/win32/gdkscreen-win32.c @@ -182,3 +182,18 @@ gdk_screen_is_composited (GdkScreen *screen) return FALSE; } + +/* HiDPI: one scale for the program (see _gdk_win32_init_scale()) */ +gint +_gdk_windowing_drawable_get_scale (GdkDrawable *drawable) +{ + return _gdk_win32_drawable_scale (drawable); +} + +gint +_gdk_windowing_screen_get_monitor_scale (GdkScreen *screen, + gint monitor_num) +{ + return _gdk_win32_scale; +} + diff --git a/gdk/win32/gdkselection-win32.c b/gdk/win32/gdkselection-win32.c index a57844a8a..6444b6ed2 100644 --- a/gdk/win32/gdkselection-win32.c +++ b/gdk/win32/gdkselection-win32.c @@ -35,6 +35,8 @@ #include "gdkdisplay.h" #include "gdkprivate-win32.h" +#include /* DROPFILES, DROPEFFECT_* of Explorer */ + /* We emulate the GDK_SELECTION window properties of windows (as used * in the X11 backend) by using a hash table from window handles to * GdkSelProp structs. @@ -420,11 +422,14 @@ gdk_selection_convert (GdkWindow *requestor, gboolean has_text = FALSE; gboolean has_png = FALSE; gboolean has_bmp = FALSE; + gboolean has_uris = FALSE; + gboolean has_copied_files = FALSE; if (!API_CALL (OpenClipboard, (GDK_WINDOW_HWND (requestor)))) return; - targets = g_new (GdkAtom, CountClipboardFormats ()); + /* CF_HDROP can stand for two */ + targets = g_new (GdkAtom, CountClipboardFormats () + 2); ntargets = 0; for (fmt = 0; 0 != (fmt = EnumClipboardFormats (fmt)); ) @@ -475,9 +480,31 @@ gdk_selection_convert (GdkWindow *requestor, if (!has_png) targets[ntargets++] = _image_gif; } + else if (fmt == CF_HDROP) + { + /* files from Explorer, for programs that take URIs and for + * file managers, as long as they are not there as such */ + if (!has_uris) + targets[ntargets++] = _text_uri_list; + if (!has_copied_files) + targets[ntargets++] = _gnome_copied_files; + has_uris = has_copied_files = TRUE; + } else if (GetClipboardFormatName (fmt, sFormat, 80) > 0) { - if (strcmp (sFormat, "image/bmp") == 0 || + if (strcmp (sFormat, "text/uri-list") == 0) + { + if (!has_uris) + targets[ntargets++] = _text_uri_list; + has_uris = TRUE; + } + else if (strcmp (sFormat, "x-special/gnome-copied-files") == 0) + { + if (!has_copied_files) + targets[ntargets++] = _gnome_copied_files; + has_copied_files = TRUE; + } + else if (strcmp (sFormat, "image/bmp") == 0 || strcmp (sFormat, "image/x-bmp") == 0 || strcmp (sFormat, "image/x-MS-bmp") == 0 || strcmp (sFormat, "image/x-icon") == 0 || @@ -740,6 +767,55 @@ gdk_selection_convert (GdkWindow *requestor, } } + API_CALL (CloseClipboard, ()); + } + else if (selection == GDK_SELECTION_CLIPBOARD && + (target == _text_uri_list || target == _gnome_copied_files) && + !IsClipboardFormatAvailable (RegisterClipboardFormat (target == _text_uri_list + ? "text/uri-list" + : "x-special/gnome-copied-files")) && + IsClipboardFormatAvailable (CF_HDROP)) + { + /* files from Explorer */ + gchar *text = NULL; + + if (!API_CALL (OpenClipboard, (GDK_WINDOW_HWND (requestor)))) + return; + + if ((hdata = GetClipboardData (CF_HDROP)) != NULL) + { + HGLOBAL effect_data = GetClipboardData (_cf_preferred_drop_effect); + DWORD effect = DROPEFFECT_COPY; + gchar *uris = _gdk_win32_hdrop_to_uri_list (hdata, target == _text_uri_list ? "\r\n" : "\n"); + + if (effect_data != NULL && GlobalSize (effect_data) >= sizeof (DWORD)) + { + DWORD *ptr = GlobalLock (effect_data); + + if (ptr) + { + effect = *ptr; + GlobalUnlock (effect_data); + } + } + + if (target == _text_uri_list) + text = uris; + else + { + /* as Nautilus: no newline after the last */ + if (g_str_has_suffix (uris, "\n")) + uris[strlen (uris) - 1] = '\0'; + text = g_strconcat ((effect & DROPEFFECT_MOVE) ? "cut\n" : "copy\n", uris, NULL); + g_free (uris); + } + } + + if (text) + selection_property_store (requestor, target, 8, (guchar *) text, strlen (text)); + else + property = GDK_NONE; + API_CALL (CloseClipboard, ()); } else if (selection == GDK_SELECTION_CLIPBOARD) @@ -1244,6 +1320,26 @@ gdk_win32_selection_add_targets (GdkWindow *owner, targets[i] == text_plain) continue; + /* files: Explorer takes them as CF_HDROP, and whether they were + * cut from Preferred DropEffect, made from the list of the + * clipboard of file managers when asked for */ + if (targets[i] == _text_uri_list) + { + g_hash_table_replace (_format_atom_table, + GINT_TO_POINTER (CF_HDROP), + targets[i]); + GDK_NOTE (DND, g_print ("... SetClipboardData(CF_HDROP,NULL)\n")); + SetClipboardData (CF_HDROP, NULL); + } + else if (targets[i] == _gnome_copied_files) + { + g_hash_table_replace (_format_atom_table, + GINT_TO_POINTER (_cf_preferred_drop_effect), + targets[i]); + GDK_NOTE (DND, g_print ("... SetClipboardData(Preferred DropEffect,NULL)\n")); + SetClipboardData (_cf_preferred_drop_effect, NULL); + } + target_name = gdk_atom_name (targets[i]); if (g_str_has_prefix (target_name, "text/plain;charset=")) @@ -1310,3 +1406,118 @@ _gdk_win32_selection_convert_to_dib (HGLOBAL hdata, return NULL; } + +/* The files of CF_HDROP (Explorer) as URIs, each followed by @separator */ +gchar * +_gdk_win32_hdrop_to_uri_list (HGLOBAL hdata, + const gchar *separator) +{ + HDROP hdrop = (HDROP) hdata; + GString *result = g_string_new (NULL); + UINT i, n; + + n = DragQueryFileW (hdrop, 0xFFFFFFFF, NULL, 0); + for (i = 0; i < n; i++) + { + UINT length = DragQueryFileW (hdrop, i, NULL, 0); + wchar_t *wpath = g_new0 (wchar_t, length + 1); + gchar *path, *uri; + + DragQueryFileW (hdrop, i, wpath, length + 1); + path = g_utf16_to_utf8 (wpath, -1, NULL, NULL, NULL); + uri = path ? g_filename_to_uri (path, NULL, NULL) : NULL; + if (uri) + { + g_string_append (result, uri); + g_string_append (result, separator); + } + g_free (uri); + g_free (path); + g_free (wpath); + } + + return g_string_free (result, FALSE); +} + +/* A list of URIs (text/uri-list), as rendered by the owner of the + * clipboard, as CF_HDROP for Explorer: the local files of it. Takes + * @hdata. */ +HGLOBAL +_gdk_win32_selection_convert_to_hdrop (HGLOBAL hdata) +{ + gchar *text, **uris; + GArray *paths; + HGLOBAL result = NULL; + gint i; + + text = g_strndup (GlobalLock (hdata), GlobalSize (hdata)); + GlobalUnlock (hdata); + GlobalFree (hdata); + + uris = g_uri_list_extract_uris (text); + g_free (text); + + paths = g_array_new (FALSE, FALSE, sizeof (wchar_t)); + for (i = 0; uris && uris[i]; i++) + { + gchar *path = g_filename_from_uri (uris[i], NULL, NULL); + gunichar2 *wpath; + glong length; + + if (path == NULL) + continue; + wpath = g_utf8_to_utf16 (path, -1, NULL, &length, NULL); + if (wpath) + g_array_append_vals (paths, wpath, length + 1); + g_free (wpath); + g_free (path); + } + g_strfreev (uris); + + if (paths->len > 0) + { + wchar_t zero = 0; + DROPFILES *drop; + + g_array_append_val (paths, zero); + result = GlobalAlloc (GMEM_MOVEABLE | GMEM_ZEROINIT, + sizeof (DROPFILES) + paths->len * sizeof (wchar_t)); + if (result) + { + drop = GlobalLock (result); + drop->pFiles = sizeof (DROPFILES); + drop->fWide = TRUE; + memcpy ((guchar *) drop + sizeof (DROPFILES), paths->data, paths->len * sizeof (wchar_t)); + GlobalUnlock (result); + } + } + g_array_free (paths, TRUE); + + return result; +} + +/* The clipboard of file managers ("cut" or "copy" and URIs) as the + * Preferred DropEffect of Explorer. Takes @hdata. */ +HGLOBAL +_gdk_win32_selection_convert_to_drop_effect (HGLOBAL hdata) +{ + gchar *text = g_strndup (GlobalLock (hdata), GlobalSize (hdata)); + HGLOBAL result; + DWORD effect; + + GlobalUnlock (hdata); + GlobalFree (hdata); + + effect = g_str_has_prefix (text, "cut") ? DROPEFFECT_MOVE : (DROPEFFECT_COPY | DROPEFFECT_LINK); + g_free (text); + + result = GlobalAlloc (GMEM_MOVEABLE, sizeof (DWORD)); + if (result) + { + DWORD *ptr = GlobalLock (result); + + *ptr = effect; + GlobalUnlock (result); + } + return result; +} diff --git a/gdk/win32/gdkwindow-win32.c b/gdk/win32/gdkwindow-win32.c index 1a21a1b67..ada0b5e80 100644 --- a/gdk/win32/gdkwindow-win32.c +++ b/gdk/win32/gdkwindow-win32.c @@ -679,17 +679,18 @@ _gdk_window_impl_new (GdkWindow *window, g_assert_not_reached (); } + /* in pixels of Windows (HiDPI) */ if (private->window_type != GDK_WINDOW_CHILD) { - rect.left = private->x; - rect.top = private->y; - rect.right = private->width + private->x; - rect.bottom = private->height + private->y; + rect.left = GDK_WIN32_SC (private->x); + rect.top = GDK_WIN32_SC (private->y); + rect.right = GDK_WIN32_SC (private->width + private->x); + rect.bottom = GDK_WIN32_SC (private->height + private->y); AdjustWindowRectEx (&rect, dwStyle, FALSE, dwExStyle); - real_x = private->x - offset_x; - real_y = private->y - offset_y; + real_x = GDK_WIN32_SC (private->x) - offset_x; + real_y = GDK_WIN32_SC (private->y) - offset_y; if (private->window_type == GDK_WINDOW_TOPLEVEL || private->window_type == GDK_WINDOW_DIALOG) @@ -711,11 +712,11 @@ _gdk_window_impl_new (GdkWindow *window, else { /* adjust position relative to real_parent */ - window_width = private->width; - window_height = private->height; + window_width = GDK_WIN32_SC (private->width); + window_height = GDK_WIN32_SC (private->height); /* use given position for initial placement, native coordinates */ - x = private->x + private->parent->abs_x - offset_x; - y = private->y + private->parent->abs_y - offset_y; + x = GDK_WIN32_SC (private->x + private->parent->abs_x) - offset_x; + y = GDK_WIN32_SC (private->y + private->parent->abs_y) - offset_y; } klass = RegisterGdkClass (private->window_type, impl->type_hint); @@ -796,6 +797,9 @@ _gdk_window_impl_new (GdkWindow *window, // if (!from_set_skip_taskbar_hint && private->window_type == GDK_WINDOW_TEMP) // gdk_window_set_skip_taskbar_hint (window, TRUE); + if (event_mask & GDK_TOUCH_MASK) + _gdk_win32_window_update_touch (window, TRUE); + if (attributes_mask & GDK_WA_CURSOR) gdk_window_set_cursor (window, attributes->cursor); } @@ -843,10 +847,10 @@ gdk_win32_window_foreign_new_for_display (GdkDisplay *display, ClientToScreen ((HWND) anid, &point); if (parent != GetDesktopWindow ()) ScreenToClient (parent, &point); - private->x = point.x; - private->y = point.y; - private->width = rect.right - rect.left; - private->height = rect.bottom - rect.top; + private->x = _gdk_win32_unscale (point.x); + private->y = _gdk_win32_unscale (point.y); + private->width = _gdk_win32_unscale_up (rect.right - rect.left); + private->height = _gdk_win32_unscale_up (rect.bottom - rect.top); private->window_type = GDK_WINDOW_FOREIGN; private->destroyed = FALSE; private->event_mask = GDK_ALL_EVENTS_MASK; /* XXX */ @@ -968,9 +972,10 @@ get_outer_rect (GdkWindow *window, gint height, RECT *rect) { + /* the size of GDK, the rectangle of Windows */ rect->left = rect->top = 0; - rect->right = width; - rect->bottom = height; + rect->right = GDK_WIN32_SC (width); + rect->bottom = GDK_WIN32_SC (height); _gdk_win32_adjust_client_rect (window, rect); } @@ -999,14 +1004,14 @@ adjust_for_gravity_hints (GdkWindow *window, case GDK_GRAVITY_CENTER: case GDK_GRAVITY_SOUTH: *x -= (outer_rect->right - outer_rect->left) / 2; - *x += obj->width / 2; + *x += GDK_WIN32_SC (obj->width) / 2; break; case GDK_GRAVITY_SOUTH_EAST: case GDK_GRAVITY_EAST: case GDK_GRAVITY_NORTH_EAST: *x -= outer_rect->right - outer_rect->left; - *x += obj->width; + *x += GDK_WIN32_SC (obj->width); break; case GDK_GRAVITY_STATIC: @@ -1023,14 +1028,14 @@ adjust_for_gravity_hints (GdkWindow *window, case GDK_GRAVITY_CENTER: case GDK_GRAVITY_EAST: *y -= (outer_rect->bottom - outer_rect->top) / 2; - *y += obj->height / 2; + *y += GDK_WIN32_SC (obj->height) / 2; break; case GDK_GRAVITY_SOUTH_WEST: case GDK_GRAVITY_SOUTH: case GDK_GRAVITY_SOUTH_EAST: *y -= outer_rect->bottom - outer_rect->top; - *y += obj->height; + *y += GDK_WIN32_SC (obj->height); break; case GDK_GRAVITY_STATIC: @@ -1153,7 +1158,7 @@ show_window_internal (GdkWindow *window, else { center_on_rect.left = 0; - center_on_rect.right = 0; + center_on_rect.top = 0; center_on_rect.right = GetSystemMetrics (SM_CXSCREEN); center_on_rect.bottom = GetSystemMetrics (SM_CYSCREEN); } @@ -1164,10 +1169,10 @@ show_window_internal (GdkWindow *window, { GdkWindowObject *owner = GDK_WINDOW_OBJECT (window_impl->transient_owner); /* Center on transient parent */ - center_on_rect.left = owner->x; - center_on_rect.top = owner->y; - center_on_rect.right = center_on_rect.left + owner->width; - center_on_rect.bottom = center_on_rect.top + owner->height; + center_on_rect.left = GDK_WIN32_ROOT_TO_SCREEN_X (owner->x); + center_on_rect.top = GDK_WIN32_ROOT_TO_SCREEN_Y (owner->y); + center_on_rect.right = center_on_rect.left + GDK_WIN32_SC (owner->width); + center_on_rect.bottom = center_on_rect.top + GDK_WIN32_SC (owner->height); _gdk_win32_adjust_client_rect (GDK_WINDOW (owner), ¢er_on_rect); center = TRUE; } @@ -1176,8 +1181,8 @@ show_window_internal (GdkWindow *window, { window_rect.left = 0; window_rect.top = 0; - window_rect.right = private->width; - window_rect.bottom = private->height; + window_rect.right = GDK_WIN32_SC (private->width); + window_rect.bottom = GDK_WIN32_SC (private->height); _gdk_win32_adjust_client_rect (window, &window_rect); x = center_on_rect.left + ((center_on_rect.right - center_on_rect.left) - (window_rect.right - window_rect.left)) / 2; @@ -1378,6 +1383,8 @@ gdk_win32_window_move (GdkWindow *window, get_outer_rect (window, private->width, private->height, &outer_rect); + x = GDK_WIN32_SC (x); + y = GDK_WIN32_SC (y); adjust_for_gravity_hints (window, &outer_rect, &x, &y); GDK_NOTE (MISC, g_print ("... SetWindowPos(%p,NULL,%d,%d,0,0," @@ -1481,6 +1488,8 @@ gdk_win32_window_move_resize_internal (GdkWindow *window, get_outer_rect (window, width, height, &outer_rect); + x = GDK_WIN32_SC (x); + y = GDK_WIN32_SC (y); adjust_for_gravity_hints (window, &outer_rect, &x, &y); GDK_NOTE (MISC, g_print ("... SetWindowPos(%p,NULL,%d,%d,%ld,%ld," @@ -1589,7 +1598,9 @@ gdk_win32_window_reparent (GdkWindow *window, GDK_WINDOW_HWND (new_parent))); API_CALL (MoveWindow, (GDK_WINDOW_HWND (window), - x, y, window_private->width, window_private->height, TRUE)); + GDK_WIN32_SC (x), GDK_WIN32_SC (y), + GDK_WIN32_SC (window_private->width), GDK_WIN32_SC (window_private->height), + TRUE)); /* From here on, we treat parents of type GDK_WINDOW_FOREIGN like * the root window @@ -1679,8 +1690,8 @@ erase_background (GdkWindow *window, * fetch the parent. (And if the same goes for the parent, fetch * the grandparent, etc.) */ - x_offset += ((GdkWindowObject *) window)->x; - y_offset += ((GdkWindowObject *) window)->y; + x_offset += GDK_WIN32_SC (((GdkWindowObject *) window)->x); + y_offset += GDK_WIN32_SC (((GdkWindowObject *) window)->y); window = GDK_WINDOW (((GdkWindowObject *) window)->parent); } @@ -1704,7 +1715,7 @@ erase_background (GdkWindow *window, GdkPixmapImplWin32 *pixmap_impl = GDK_PIXMAP_IMPL_WIN32 (GDK_PIXMAP_OBJECT (pixmap)->impl); if (x_offset == 0 && y_offset == 0 && - pixmap_impl->width <= 8 && pixmap_impl->height <= 8) + GDK_WIN32_SC (pixmap_impl->width) <= 8 && GDK_WIN32_SC (pixmap_impl->height) <= 8) { if (!(hbr = CreatePatternBrush (GDK_PIXMAP_HBITMAP (pixmap)))) WIN32_GDI_FAILED ("CreatePatternBrush"); @@ -1731,15 +1742,15 @@ erase_background (GdkWindow *window, x = -x_offset; while (x < rect.right) { - if (x + pixmap_impl->width >= rect.left) + if (x + GDK_WIN32_SC (pixmap_impl->width) >= rect.left) { y = -y_offset; while (y < rect.bottom) { - if (y + pixmap_impl->height >= rect.top) + if (y + GDK_WIN32_SC (pixmap_impl->height) >= rect.top) { if (!BitBlt (hdc, x, y, - pixmap_impl->width, pixmap_impl->height, + GDK_WIN32_SC (pixmap_impl->width), GDK_WIN32_SC (pixmap_impl->height), bgdc, 0, 0, SRCCOPY)) { WIN32_GDI_FAILED ("BitBlt"); @@ -1748,10 +1759,10 @@ erase_background (GdkWindow *window, return; } } - y += pixmap_impl->height; + y += GDK_WIN32_SC (pixmap_impl->height); } } - x += pixmap_impl->width; + x += GDK_WIN32_SC (pixmap_impl->width); } SelectObject (bgdc, oldbitmap); DeleteDC (bgdc); @@ -1786,7 +1797,8 @@ gdk_win32_window_clear_area (GdkWindow *window, "%dx%d@%+d%+d\n", GDK_WINDOW_HWND (window), width, height, x, y)); - IntersectClipRect (hdc, x, y, x + width, y + height); + IntersectClipRect (hdc, GDK_WIN32_SC (x), GDK_WIN32_SC (y), + GDK_WIN32_SC (x + width), GDK_WIN32_SC (y + height)); erase_background (window, hdc); GDI_CALL (ReleaseDC, (GDK_WINDOW_HWND (window), hdc)); } @@ -1794,14 +1806,15 @@ gdk_win32_window_clear_area (GdkWindow *window, { /* The background should be erased before the expose event is generated */ - IntersectClipRect (hdc, x, y, x + width, y + height); + IntersectClipRect (hdc, GDK_WIN32_SC (x), GDK_WIN32_SC (y), + GDK_WIN32_SC (x + width), GDK_WIN32_SC (y + height)); erase_background (window, hdc); GDI_CALL (ReleaseDC, (GDK_WINDOW_HWND (window), hdc)); - rect.left = x; - rect.right = x + width; - rect.top = y; - rect.bottom = y + height; + rect.left = GDK_WIN32_SC (x); + rect.right = GDK_WIN32_SC (x + width); + rect.top = GDK_WIN32_SC (y); + rect.bottom = GDK_WIN32_SC (y + height); GDI_CALL (InvalidateRect, (GDK_WINDOW_HWND (window), &rect, TRUE)); UpdateWindow (GDK_WINDOW_HWND (window)); @@ -2154,12 +2167,20 @@ gdk_window_set_transient_for (GdkWindow *window, GdkWindow *parent) { HWND window_id, parent_id; - GdkWindowImplWin32 *window_impl = GDK_WINDOW_IMPL_WIN32 (GDK_WINDOW_OBJECT (window)->impl); + GdkWindowImplWin32 *window_impl; GdkWindowImplWin32 *parent_impl = NULL; GSList *item; g_return_if_fail (GDK_IS_WINDOW (window)); + /* an offscreen window, or a child of one, has no HWND and no + * GdkWindowImplWin32 to keep the transient relationship in */ + if (!GDK_IS_WINDOW_IMPL_WIN32 (GDK_WINDOW_OBJECT (window)->impl) || + (parent != NULL && + !GDK_IS_WINDOW_IMPL_WIN32 (GDK_WINDOW_OBJECT (parent)->impl))) + return; + + window_impl = GDK_WINDOW_IMPL_WIN32 (GDK_WINDOW_OBJECT (window)->impl); window_id = GDK_WINDOW_HWND (window); parent_id = parent != NULL ? GDK_WINDOW_HWND (parent) : NULL; @@ -2492,14 +2513,15 @@ gdk_win32_window_get_geometry (GdkWindow *window, } } + /* in pixels of GDK */ if (x) - *x = rect.left; + *x = _gdk_win32_unscale (rect.left); if (y) - *y = rect.top; + *y = _gdk_win32_unscale (rect.top); if (width) - *width = rect.right - rect.left; + *width = _gdk_win32_unscale_up (rect.right - rect.left); if (height) - *height = rect.bottom - rect.top; + *height = _gdk_win32_unscale_up (rect.bottom - rect.top); if (depth) *depth = gdk_drawable_get_visual (window)->depth; @@ -2522,21 +2544,20 @@ gdk_win32_window_get_root_coords (GdkWindow *window, gint ty; POINT pt; - pt.x = x; - pt.y = y; + pt.x = 0; + pt.y = 0; ClientToScreen (GDK_WINDOW_HWND (window), &pt); - tx = pt.x; - ty = pt.y; + tx = GDK_WIN32_SCREEN_TO_ROOT_X (pt.x) + x; + ty = GDK_WIN32_SCREEN_TO_ROOT_Y (pt.y) + y; if (root_x) - *root_x = tx + _gdk_offset_x; + *root_x = tx; if (root_y) - *root_y = ty + _gdk_offset_y; + *root_y = ty; GDK_NOTE (MISC, g_print ("gdk_win32_window_get_root_coords: %p: %+d%+d %+d%+d\n", GDK_WINDOW_HWND (window), - x, y, - tx + _gdk_offset_x, ty + _gdk_offset_y)); + x, y, tx, ty)); return 1; } @@ -2636,6 +2657,15 @@ gdk_window_get_frame_extents (GdkWindow *window, rect->y = r.top + _gdk_offset_y; rect->width = r.right - r.left; rect->height = r.bottom - r.top; + { + /* in pixels of GDK */ + gint x2 = rect->x + rect->width, y2 = rect->y + rect->height; + + rect->x = _gdk_win32_unscale (rect->x); + rect->y = _gdk_win32_unscale (rect->y); + rect->width = _gdk_win32_unscale_up (x2) - rect->x; + rect->height = _gdk_win32_unscale_up (y2) - rect->y; + } GDK_NOTE (MISC, g_print ("gdk_window_get_frame_extents: %p: %ldx%ld@%+ld%+ld\n", GDK_WINDOW_HWND (window), @@ -2688,13 +2718,15 @@ gdk_window_win32_get_pointer (GdkWindow *window, GetCursorPos (&point); ScreenToClient (hwnd, &point); - *x = point.x; - *y = point.y; - if (window == _gdk_root) { - *x += _gdk_offset_x; - *y += _gdk_offset_y; + *x = GDK_WIN32_SCREEN_TO_ROOT_X (point.x); + *y = GDK_WIN32_SCREEN_TO_ROOT_Y (point.y); + } + else + { + *x = _gdk_win32_unscale (point.x); + *y = _gdk_win32_unscale (point.y); } hwndc = ChildWindowFromPoint (hwnd, point); @@ -2720,8 +2752,8 @@ _gdk_windowing_get_pointer (GdkDisplay *display, *screen = _gdk_screen; GetCursorPos (&point); - *x = point.x + _gdk_offset_x; - *y = point.y + _gdk_offset_y; + *x = GDK_WIN32_SCREEN_TO_ROOT_X (point.x); + *y = GDK_WIN32_SCREEN_TO_ROOT_Y (point.y); *mask = get_current_mask (); } @@ -2735,7 +2767,7 @@ gdk_display_warp_pointer (GdkDisplay *display, g_return_if_fail (display == _gdk_display); g_return_if_fail (screen == _gdk_screen); - SetCursorPos (x - _gdk_offset_x, y - _gdk_offset_y); + SetCursorPos (GDK_WIN32_ROOT_TO_SCREEN_X (x), GDK_WIN32_ROOT_TO_SCREEN_Y (y)); } static void @@ -2811,9 +2843,9 @@ _gdk_windowing_window_at_pointer (GdkDisplay *display, if (hwnd == NULL) { if (win_x) - *win_x = screen_pt.x + _gdk_offset_x; + *win_x = GDK_WIN32_SCREEN_TO_ROOT_X (screen_pt.x); if (win_y) - *win_y = screen_pt.y + _gdk_offset_y; + *win_y = GDK_WIN32_SCREEN_TO_ROOT_Y (screen_pt.y); return _gdk_root; } @@ -2823,9 +2855,9 @@ _gdk_windowing_window_at_pointer (GdkDisplay *display, if (window && (win_x || win_y)) { if (win_x) - *win_x = client_pt.x; + *win_x = _gdk_win32_unscale (client_pt.x); if (win_y) - *win_y = client_pt.y; + *win_y = _gdk_win32_unscale (client_pt.y); } GDK_NOTE (MISC, g_print ("_gdk_windowing_window_at_pointer: %+d%+d %p%s\n", @@ -2861,6 +2893,9 @@ gdk_win32_window_set_events (GdkWindow *window, * set it here, too. Not that I know or remember why it is * necessary, will have to test some day. */ + if ((impl->native_event_mask ^ event_mask) & GDK_TOUCH_MASK) + _gdk_win32_window_update_touch (window, (event_mask & GDK_TOUCH_MASK) != 0); + impl->native_event_mask = GDK_STRUCTURE_MASK | event_mask; } @@ -2875,7 +2910,7 @@ do_shape_combine_region (GdkWindow *window, _gdk_win32_adjust_client_rect (window, &rect); OffsetRgn (hrgn, -rect.left, -rect.top); - OffsetRgn (hrgn, x, y); + OffsetRgn (hrgn, GDK_WIN32_SC (x), GDK_WIN32_SC (y)); /* If this is a top-level window, add the title bar to the region */ if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_TOPLEVEL) @@ -3425,7 +3460,7 @@ gdk_window_begin_resize_drag (GdkWindow *window, } DefWindowProcW (GDK_WINDOW_HWND (window), WM_NCLBUTTONDOWN, winedge, - MAKELPARAM (root_x - _gdk_offset_x, root_y - _gdk_offset_y)); + MAKELPARAM (GDK_WIN32_ROOT_TO_SCREEN_X (root_x), GDK_WIN32_ROOT_TO_SCREEN_Y (root_y))); } void @@ -3455,7 +3490,7 @@ gdk_window_begin_move_drag (GdkWindow *window, gdk_display_pointer_ungrab (_gdk_display, 0); DefWindowProcW (GDK_WINDOW_HWND (window), WM_NCLBUTTONDOWN, HTCAPTION, - MAKELPARAM (root_x - _gdk_offset_x, root_y - _gdk_offset_y)); + MAKELPARAM (GDK_WIN32_ROOT_TO_SCREEN_X (root_x), GDK_WIN32_ROOT_TO_SCREEN_Y (root_y))); } @@ -3948,9 +3983,8 @@ gdk_window_set_opacity (GdkWindow *window, PFN_SetLayeredWindowAttributes setLayeredWindowAttributes = NULL; g_return_if_fail (GDK_IS_WINDOW (window)); - g_return_if_fail (WINDOW_IS_TOPLEVEL (window)); - if (GDK_WINDOW_DESTROYED (window)) + if (!WINDOW_IS_TOPLEVEL (window) || GDK_WINDOW_DESTROYED (window)) return; if (opacity < 0) @@ -4065,7 +4099,7 @@ _gdk_win32_window_queue_translation (GdkWindow *window, WIN32_API_FAILED ("CombineRgn"); else if (ret != NULLREGION) { - OffsetRgn (update, dx, dy); + OffsetRgn (update, GDK_WIN32_SC (dx), GDK_WIN32_SC (dy)); API_CALL (InvalidateRgn, (GDK_WINDOW_HWND (window), update, TRUE)); } DeleteObject (update); diff --git a/gdk/x11/Makefile.am b/gdk/x11/Makefile.am index 1169821f8..43574f1a5 100644 --- a/gdk/x11/Makefile.am +++ b/gdk/x11/Makefile.am @@ -42,6 +42,7 @@ libgdk_x11_la_SOURCES = \ gdkpixmap-x11.h \ gdkproperty-x11.c \ gdkscreen-x11.c \ + gdkscroll-x11.c \ gdkscreen-x11.h \ gdkselection-x11.c \ gdkspawn-x11.c \ diff --git a/gdk/x11/gdkapplaunchcontext-x11.c b/gdk/x11/gdkapplaunchcontext-x11.c index 51be6ce67..723ff4dcf 100644 --- a/gdk/x11/gdkapplaunchcontext-x11.c +++ b/gdk/x11/gdkapplaunchcontext-x11.c @@ -49,6 +49,9 @@ get_display_name (GFile *file, if (name == NULL) { name = g_file_get_basename (file); + if (name == NULL) + name = g_file_get_uri (file); + if (!g_utf8_validate (name, -1, NULL)) { tmp = name; @@ -175,10 +178,12 @@ free_startup_timeout (void *data) g_free (std); } +/* for the time a startup takes: not the wall clock, which may be set + * meanwhile */ static gint64 get_current_time_usec (void) { - return g_get_real_time (); + return g_get_monotonic_time (); } static gboolean diff --git a/gdk/x11/gdkasync.c b/gdk/x11/gdkasync.c index e72a96ef6..424cfd68d 100644 --- a/gdk/x11/gdkasync.c +++ b/gdk/x11/gdkasync.c @@ -620,7 +620,7 @@ get_child_info_handler (Display *dpy, if (rep->generic.type == X_Error) { state->child_has_error = TRUE; - if (rep->error.errorCode != BadDrawable || + if (rep->error.errorCode != BadDrawable && rep->error.errorCode != BadWindow) { state->have_error = TRUE; @@ -925,5 +925,21 @@ _gdk_x11_roundtrip_async (GdkDisplay *display, SyncHandle(); } +/* TRUE when Xlib has no events in its queue and no requests waiting + * to be sent: then only new data from the X server can bring events */ +gboolean +_gdk_x11_display_is_idle (Display *dpy) +{ + gboolean idle; + + LockDisplay (dpy); + idle = (dpy->qlen == 0 && + dpy->bufptr == dpy->buffer && + !(dpy->flags & XlibDisplayIOError)); + UnlockDisplay (dpy); + + return idle; +} + #define __GDK_ASYNC_C__ #include "gdkaliasdef.c" diff --git a/gdk/x11/gdkasync.h b/gdk/x11/gdkasync.h index 98fdbe4a1..9c5d99aa3 100644 --- a/gdk/x11/gdkasync.h +++ b/gdk/x11/gdkasync.h @@ -70,6 +70,8 @@ void _gdk_x11_roundtrip_async (GdkDisplay *display, GdkRoundTripCallback callback, gpointer data); +gboolean _gdk_x11_display_is_idle (Display *dpy); + G_END_DECLS #endif /* __GDK_ASYNC_H__ */ diff --git a/gdk/x11/gdkcolor-x11.c b/gdk/x11/gdkcolor-x11.c index f14650059..58e26d084 100644 --- a/gdk/x11/gdkcolor-x11.c +++ b/gdk/x11/gdkcolor-x11.c @@ -34,6 +34,9 @@ #include "gdkscreen-x11.h" #include "gdkalias.h" +#define MIN_SYNC_TIME 2 /* seconds between syncs of a colormap */ +#define NEVER_SYNCED G_MININT64 + typedef struct _GdkColormapPrivateX11 GdkColormapPrivateX11; typedef GdkColormapPrivateX11 GdkColormapPrivate; @@ -82,7 +85,7 @@ gdk_colormap_init (GdkColormap *colormap) private->screen = NULL; private->hash = NULL; - private->last_sync_time = 0; + private->last_sync_time = NEVER_SYNCED; private->info = NULL; colormap->size = 0; @@ -317,7 +320,6 @@ gdk_colormap_sync_direct_color (GdkColormap *colormap) g_free (xpalette); } -#define MIN_SYNC_TIME 2 static void gdk_colormap_sync (GdkColormap *colormap, @@ -331,8 +333,12 @@ gdk_colormap_sync (GdkColormap *colormap, if (private->screen->closed) return; - current_time = (gint64) time (NULL); - if (!force && ((current_time - private->last_sync_time) < MIN_SYNC_TIME)) + /* A time between two syncs: the monotonic clock, not time (), which + * on 32-bit systems has no answer after 2038 (and then never let the + * colormap be synced again) and jumps when the clock is set */ + current_time = g_get_monotonic_time () / G_USEC_PER_SEC; + if (!force && private->last_sync_time != NEVER_SYNCED && + current_time - private->last_sync_time < MIN_SYNC_TIME) return; private->last_sync_time = current_time; @@ -376,7 +382,7 @@ gdk_screen_get_system_colormap (GdkScreen *screen) private->private_val = FALSE; private->hash = NULL; - private->last_sync_time = 0; + private->last_sync_time = NEVER_SYNCED; private->info = NULL; colormap->colors = NULL; diff --git a/gdk/x11/gdkcursor-x11.c b/gdk/x11/gdkcursor-x11.c index 7d4f10103..0f9b9a7ed 100644 --- a/gdk/x11/gdkcursor-x11.c +++ b/gdk/x11/gdkcursor-x11.c @@ -654,8 +654,9 @@ gdk_x11_display_set_cursor_theme (GdkDisplay *display, theme_serial++; XcursorSetTheme (xdisplay, theme); + /* HiDPI: the size of the setting is in pixels of GDK */ if (size > 0) - XcursorSetDefaultSize (xdisplay, size); + XcursorSetDefaultSize (xdisplay, size * GDK_X11_DISPLAY_SCALE (display)); g_slist_foreach (cursor_cache, update_cursor, NULL); } @@ -722,10 +723,9 @@ create_cursor_image (GdkPixbuf *pixbuf, for (i = 0; i < width; i++) { *dest = (0xff << 24) | (src[0] << 16) | (src[1] << 8) | src[2]; + src += n_channels; + dest++; } - - src += n_channels; - dest++; } } else @@ -817,7 +817,20 @@ gdk_cursor_new_from_pixbuf (GdkDisplay *display, xcursor = None; else { - xcimage = create_cursor_image (pixbuf, x, y); + gint scale = GDK_X11_DISPLAY_SCALE (display); + + /* HiDPI: the picture's pixels as blocks of the X server's */ + if (scale > 1) + { + GdkPixbuf *big = gdk_pixbuf_scale_simple (pixbuf, + gdk_pixbuf_get_width (pixbuf) * scale, + gdk_pixbuf_get_height (pixbuf) * scale, + GDK_INTERP_NEAREST); + xcimage = create_cursor_image (big, x * scale + scale / 2, y * scale + scale / 2); + g_object_unref (big); + } + else + xcimage = create_cursor_image (pixbuf, x, y); xcursor = XcursorImageLoadCursor (GDK_DISPLAY_XDISPLAY (display), xcimage); XcursorImageDestroy (xcimage); } diff --git a/gdk/x11/gdkdisplay-x11.c b/gdk/x11/gdkdisplay-x11.c index 4e46981af..bec39cf86 100644 --- a/gdk/x11/gdkdisplay-x11.c +++ b/gdk/x11/gdkdisplay-x11.c @@ -136,6 +136,18 @@ _gdk_display_x11_init (GdkDisplayX11 *display) { } +/* Whether we run in a Flatpak sandbox */ +gboolean +_gdk_x11_running_in_sandbox (void) +{ + static gint in_sandbox = -1; + + if (in_sandbox < 0) + in_sandbox = g_file_test ("/.flatpak-info", G_FILE_TEST_EXISTS); + + return in_sandbox; +} + /** * gdk_display_open: * @display_name: the name of the display to open @@ -235,6 +247,8 @@ gdk_display_open (const gchar *display_name) display_x11->have_render = GDK_UNKNOWN; + _gdk_x11_scroll_init (display); + #ifdef HAVE_XFIXES if (XFixesQueryExtension (display_x11->xdisplay, &display_x11->xfixes_event_base, @@ -337,11 +351,16 @@ gdk_display_open (const gchar *display_name) if (sm_client_id) _gdk_windowing_display_set_sm_client_id (display, sm_client_id); - pid = getpid (); - XChangeProperty (display_x11->xdisplay, - display_x11->leader_window, - gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_PID"), - XA_CARDINAL, 32, PropModeReplace, (guchar *) & pid, 1); + /* Sandboxed, we are likely in a pid namespace, and our pid would + * only confuse the window manager (or make it kill another process) */ + if (!_gdk_x11_running_in_sandbox ()) + { + pid = getpid (); + XChangeProperty (display_x11->xdisplay, + display_x11->leader_window, + gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_PID"), + XA_CARDINAL, 32, PropModeReplace, (guchar *) & pid, 1); + } /* We don't yet know a valid time. */ display_x11->user_time = 0; @@ -692,6 +711,10 @@ gdk_display_beep (GdkDisplay *display) { g_return_if_fail (GDK_IS_DISPLAY (display)); + /* An untrusted client gets BadAccess for the bell */ + if (!GDK_DISPLAY_X11 (display)->trusted_client) + return; + #ifdef HAVE_XKB XkbBell (GDK_DISPLAY_XDISPLAY (display), None, 0, None); #else @@ -855,6 +878,10 @@ gdk_display_x11_finalize (GObject *object) } _gdk_x11_cursor_display_finalize (GDK_DISPLAY_OBJECT(display_x11)); + _gdk_x11_scroll_finalize (GDK_DISPLAY_OBJECT(display_x11)); + + /* Empty the translate/antiexpose queue */ + _gdk_x11_display_free_translate_queue (GDK_DISPLAY_OBJECT (display_x11)); /* Atom Hashtable */ g_hash_table_destroy (display_x11->atom_from_virtual); diff --git a/gdk/x11/gdkdisplay-x11.h b/gdk/x11/gdkdisplay-x11.h index 45f5834df..d9f20a2bf 100644 --- a/gdk/x11/gdkdisplay-x11.h +++ b/gdk/x11/gdkdisplay-x11.h @@ -37,6 +37,7 @@ G_BEGIN_DECLS typedef struct _GdkDisplayX11 GdkDisplayX11; typedef struct _GdkDisplayX11Class GdkDisplayX11Class; +typedef struct _GdkX11Scroll GdkX11Scroll; #define GDK_TYPE_DISPLAY_X11 (_gdk_display_x11_get_type()) #define GDK_DISPLAY_X11(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), GDK_TYPE_DISPLAY_X11, GdkDisplayX11)) @@ -155,6 +156,9 @@ struct _GdkDisplayX11 /* The offscreen window that has the pointer in it (if any) */ GdkWindow *active_offscreen_window; + + /* Smooth scrolling with XInput 2.1, NULL without */ + GdkX11Scroll *scroll; }; struct _GdkDisplayX11Class diff --git a/gdk/x11/gdkdnd-x11.c b/gdk/x11/gdkdnd-x11.c index 8c67c19f7..92c84347b 100644 --- a/gdk/x11/gdkdnd-x11.c +++ b/gdk/x11/gdkdnd-x11.c @@ -25,6 +25,7 @@ */ #include "config.h" +#include #include #include @@ -107,6 +108,33 @@ struct _GdkDragContextPrivateX11 { /* Forward declarations */ + +/* HiDPI: root coordinates of GDK and of the X server (the default + * screen's, on monitors of different scales piecewise) */ +static void +dnd_root_to_device (GdkDisplay *display, + gint x, + gint y, + gint *dx, + gint *dy) +{ + _gdk_x11_screen_root_to_device (gdk_display_get_default_screen (display), x, y, dx, dy); +} + +static void +dnd_device_to_root (GdkDisplay *display, + gint dx, + gint dy, + gint *x, + gint *y) +{ + gdouble rx, ry; + + _gdk_x11_screen_device_to_root (gdk_display_get_default_screen (display), dx, dy, &rx, &ry); + *x = (gint) floor (rx); + *y = (gint) floor (ry); +} + static GdkWindowCache *gdk_window_cache_get (GdkScreen *screen); static GdkWindowCache *gdk_window_cache_ref (GdkWindowCache *cache); static void gdk_window_cache_unref (GdkWindowCache *cache); @@ -263,12 +291,12 @@ gdk_drag_context_find (GdkDisplay *display, Window source_xid, Window dest_xid) { - GList *tmp_list = contexts; + GList *tmp_list; GdkDragContext *context; GdkDragContextPrivateX11 *private; Window context_dest_xid; - while (tmp_list) + for (tmp_list = contexts; tmp_list; tmp_list = tmp_list->next) { context = (GdkDragContext *)tmp_list->data; private = PRIVATE_DATA (context); @@ -288,8 +316,6 @@ gdk_drag_context_find (GdkDisplay *display, (GDK_DRAWABLE_XID (context->source_window) == source_xid))) && ((dest_xid == None) || (context_dest_xid == dest_xid))) return context; - - tmp_list = tmp_list->next; } return NULL; @@ -683,12 +709,12 @@ is_pointer_within_shape (GdkDisplay *display, child->shape = NULL; if (gdk_display_supports_shapes (display)) child->shape = _xwindow_get_shape (display_x11->xdisplay, - child->xid, ShapeBounding); + child->xid, ShapeBounding, 1); #ifdef ShapeInput input_shape = NULL; if (gdk_display_supports_input_shapes (display)) input_shape = _xwindow_get_shape (display_x11->xdisplay, - child->xid, ShapeInput); + child->xid, ShapeInput, 1); if (child->shape && input_shape) { @@ -1596,8 +1622,13 @@ motif_send_motion (GdkDragContext *context, { MOTIF_XCLIENT_BYTE (&xev, 0) = XmDRAG_MOTION; - MOTIF_XCLIENT_SHORT (&xev, 4) = x_root; - MOTIF_XCLIENT_SHORT (&xev, 5) = y_root; + { + gint dx, dy; + + dnd_root_to_device (display, x_root, y_root, &dx, &dy); + MOTIF_XCLIENT_SHORT (&xev, 4) = dx; + MOTIF_XCLIENT_SHORT (&xev, 5) = dy; + } private->drag_status = GDK_DRAG_STATUS_MOTION_WAIT; retval = FALSE; @@ -1630,8 +1661,13 @@ motif_send_drop (GdkDragContext *context, guint32 time) MOTIF_XCLIENT_SHORT (&xev, 1) = motif_dnd_get_flags (context); MOTIF_XCLIENT_LONG (&xev, 1) = time; - MOTIF_XCLIENT_SHORT (&xev, 4) = private->last_x; - MOTIF_XCLIENT_SHORT (&xev, 5) = private->last_y; + { + gint dx, dy; + + dnd_root_to_device (display, private->last_x, private->last_y, &dx, &dy); + MOTIF_XCLIENT_SHORT (&xev, 4) = dx; + MOTIF_XCLIENT_SHORT (&xev, 5) = dy; + } MOTIF_XCLIENT_LONG (&xev, 3) = private->motif_selection; MOTIF_XCLIENT_LONG (&xev, 4) = GDK_DRAWABLE_XID (context->source_window); @@ -1861,11 +1897,16 @@ motif_motion (GdkEvent *event, motif_dnd_translate_flags (display_x11->current_dest_drag, flags); - event->dnd.x_root = x_root; - event->dnd.y_root = y_root; + { + gint rx, ry; - private->last_x = x_root; - private->last_y = y_root; + dnd_device_to_root (GDK_DRAWABLE_DISPLAY (event->any.window), x_root, y_root, &rx, &ry); + event->dnd.x_root = rx; + event->dnd.y_root = ry; + } + + private->last_x = event->dnd.x_root; + private->last_y = event->dnd.y_root; private->drag_status = GDK_DRAG_STATUS_MOTION_WAIT; @@ -1934,8 +1975,13 @@ motif_drop_start (GdkEvent *event, event->dnd.type = GDK_DROP_START; event->dnd.context = new_context; event->dnd.time = timestamp; - event->dnd.x_root = x_root; - event->dnd.y_root = y_root; + { + gint rx, ry; + + dnd_device_to_root (GDK_DRAWABLE_DISPLAY (event->any.window), x_root, y_root, &rx, &ry); + event->dnd.x_root = rx; + event->dnd.y_root = ry; + } gdk_x11_window_set_user_time (event->any.window, timestamp); @@ -2572,7 +2618,12 @@ xdnd_send_motion (GdkDragContext *context, GDK_DRAWABLE_XID (context->dest_window); xev.xclient.data.l[0] = GDK_DRAWABLE_XID (context->source_window); xev.xclient.data.l[1] = 0; - xev.xclient.data.l[2] = (x_root << 16) | y_root; + { + gint dx, dy; + + dnd_root_to_device (display, x_root, y_root, &dx, &dy); + xev.xclient.data.l[2] = (dx << 16) | (dy & 0xffff); + } xev.xclient.data.l[3] = time; xev.xclient.data.l[4] = xdnd_action_to_atom (display, action); @@ -3064,11 +3115,16 @@ xdnd_position_filter (GdkXEvent *xev, if (!(PRIVATE_DATA (display_x11->current_dest_drag))->xdnd_have_actions) display_x11->current_dest_drag->actions = display_x11->current_dest_drag->suggested_action; - event->dnd.x_root = x_root; - event->dnd.y_root = y_root; + { + gint rx, ry; - (PRIVATE_DATA (display_x11->current_dest_drag))->last_x = x_root; - (PRIVATE_DATA (display_x11->current_dest_drag))->last_y = y_root; + dnd_device_to_root (display, x_root, y_root, &rx, &ry); + event->dnd.x_root = rx; + event->dnd.y_root = ry; + } + + (PRIVATE_DATA (display_x11->current_dest_drag))->last_x = event->dnd.x_root; + (PRIVATE_DATA (display_x11->current_dest_drag))->last_y = event->dnd.y_root; return GDK_FILTER_TRANSLATE; } @@ -3397,10 +3453,16 @@ gdk_drag_find_window_for_screen (GdkDragContext *context, window_cache = drag_context_find_window_cache (context, screen); - dest = get_client_window_at_coords (window_cache, - drag_window && GDK_WINDOW_IS_X11 (drag_window) ? - GDK_DRAWABLE_XID (drag_window) : None, - x_root, y_root); + /* the cache has the windows in pixels of the X server */ + { + gint dx, dy; + + _gdk_x11_screen_root_to_device (screen, x_root, y_root, &dx, &dy); + dest = get_client_window_at_coords (window_cache, + drag_window && GDK_WINDOW_IS_X11 (drag_window) ? + GDK_DRAWABLE_XID (drag_window) : None, + dx, dy); + } if (private->dest_xid != dest) { @@ -3795,8 +3857,11 @@ gdk_drag_status (GdkDragContext *context, if (need_coords) { - MOTIF_XCLIENT_SHORT (&xev, 4) = private->last_x; - MOTIF_XCLIENT_SHORT (&xev, 5) = private->last_y; + gint dx, dy; + + dnd_root_to_device (display, private->last_x, private->last_y, &dx, &dy); + MOTIF_XCLIENT_SHORT (&xev, 4) = dx; + MOTIF_XCLIENT_SHORT (&xev, 5) = dy; } else MOTIF_XCLIENT_LONG (&xev, 2) = 0; diff --git a/gdk/x11/gdkdrawable-x11.c b/gdk/x11/gdkdrawable-x11.c index d27a03ebb..c72a3c656 100644 --- a/gdk/x11/gdkdrawable-x11.c +++ b/gdk/x11/gdkdrawable-x11.c @@ -182,6 +182,7 @@ _gdk_drawable_impl_x11_class_init (GdkDrawableImplX11Class *klass) static void _gdk_drawable_impl_x11_init (GdkDrawableImplX11 *impl) { + impl->scale = 1; } static void @@ -236,7 +237,22 @@ _gdk_x11_drawable_update_size (GdkDrawable *drawable) int width, height; gdk_drawable_get_size (drawable, &width, &height); - cairo_xlib_surface_set_size (impl->cairo_surface, width, height); + cairo_xlib_surface_set_size (impl->cairo_surface, width * impl->scale, height * impl->scale); + } +} + +/* HiDPI: after the scale of the drawable changed */ +void +_gdk_x11_drawable_update_scale (GdkDrawable *drawable) +{ + GdkDrawableImplX11 *impl = GDK_DRAWABLE_IMPL_X11 (drawable); + + if (impl->cairo_surface) + { +#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE (1, 14, 0) + cairo_surface_set_device_scale (impl->cairo_surface, impl->scale, impl->scale); +#endif + _gdk_x11_drawable_update_size (drawable); } } @@ -367,19 +383,11 @@ gdk_x11_drawable_update_picture_clip (GdkDrawable *drawable, if (clip_region) { - GdkRegionBox *boxes = clip_region->rects; - gint n_boxes = clip_region->numRects; - XRectangle *rects = g_new (XRectangle, n_boxes); - int i; - - for (i=0; i < n_boxes; i++) - { - rects[i].x = CLAMP (boxes[i].x1 + gc->clip_x_origin, G_MINSHORT, G_MAXSHORT); - rects[i].y = CLAMP (boxes[i].y1 + gc->clip_y_origin, G_MINSHORT, G_MAXSHORT); - rects[i].width = CLAMP (boxes[i].x2 + gc->clip_x_origin, G_MINSHORT, G_MAXSHORT) - rects[i].x; - rects[i].height = CLAMP (boxes[i].y2 + gc->clip_y_origin, G_MINSHORT, G_MAXSHORT) - rects[i].y; - } + XRectangle *rects; + gint n_boxes; + _gdk_region_get_xrectangles (clip_region, gc->clip_x_origin, gc->clip_y_origin, + impl->scale, &rects, &n_boxes); XRenderSetPictureClipRectangles (xdisplay, picture, 0, 0, rects, n_boxes); @@ -395,8 +403,8 @@ gdk_x11_drawable_update_picture_clip (GdkDrawable *drawable, if (gc && (mask = _gdk_gc_get_clip_mask (gc))) { pa.clip_mask = GDK_PIXMAP_XID (mask); - pa.clip_x_origin = gc->clip_x_origin; - pa.clip_y_origin = gc->clip_y_origin; + pa.clip_x_origin = gc->clip_x_origin * impl->scale; + pa.clip_y_origin = gc->clip_y_origin * impl->scale; pa_mask |= CPClipXOrigin | CPClipYOrigin; } else @@ -452,15 +460,22 @@ gdk_x11_draw_rectangle (GdkDrawable *drawable, gint height) { GdkDrawableImplX11 *impl; + gint s, o; + GC xgc; impl = GDK_DRAWABLE_IMPL_X11 (drawable); + s = impl->scale; + xgc = GDK_GC_GET_XGC_SCALED (gc, s); if (filled) XFillRectangle (GDK_SCREEN_XDISPLAY (impl->screen), impl->xid, - GDK_GC_GET_XGC (gc), x, y, width, height); + xgc, x * s, y * s, width * s, height * s); else - XDrawRectangle (GDK_SCREEN_XDISPLAY (impl->screen), impl->xid, - GDK_GC_GET_XGC (gc), x, y, width, height); + { + o = GDK_GC_X11_THIN_OFFSET (gc, s); + XDrawRectangle (GDK_SCREEN_XDISPLAY (impl->screen), impl->xid, + xgc, x * s + o, y * s + o, width * s, height * s); + } } static void @@ -475,16 +490,22 @@ gdk_x11_draw_arc (GdkDrawable *drawable, gint angle2) { GdkDrawableImplX11 *impl; + gint s, o; + GC xgc; impl = GDK_DRAWABLE_IMPL_X11 (drawable); - + s = impl->scale; + xgc = GDK_GC_GET_XGC_SCALED (gc, s); if (filled) XFillArc (GDK_SCREEN_XDISPLAY (impl->screen), impl->xid, - GDK_GC_GET_XGC (gc), x, y, width, height, angle1, angle2); + xgc, x * s, y * s, width * s, height * s, angle1, angle2); else - XDrawArc (GDK_SCREEN_XDISPLAY (impl->screen), impl->xid, - GDK_GC_GET_XGC (gc), x, y, width, height, angle1, angle2); + { + o = GDK_GC_X11_THIN_OFFSET (gc, s); + XDrawArc (GDK_SCREEN_XDISPLAY (impl->screen), impl->xid, + xgc, x * s + o, y * s + o, width * s, height * s, angle1, angle2); + } } static void @@ -495,19 +516,22 @@ gdk_x11_draw_polygon (GdkDrawable *drawable, gint npoints) { XPoint *tmp_points; - gint tmp_npoints, i; + gint tmp_npoints, i, s, o; GdkDrawableImplX11 *impl; + GC xgc; impl = GDK_DRAWABLE_IMPL_X11 (drawable); - + s = impl->scale; + xgc = GDK_GC_GET_XGC_SCALED (gc, s); + o = filled ? 0 : GDK_GC_X11_THIN_OFFSET (gc, s); if (!filled && (points[0].x != points[npoints-1].x || points[0].y != points[npoints-1].y)) { tmp_npoints = npoints + 1; tmp_points = g_new (XPoint, tmp_npoints); - tmp_points[npoints].x = points[0].x; - tmp_points[npoints].y = points[0].y; + tmp_points[npoints].x = points[0].x * s + o; + tmp_points[npoints].y = points[0].y * s + o; } else { @@ -517,16 +541,16 @@ gdk_x11_draw_polygon (GdkDrawable *drawable, for (i=0; iscreen), impl->xid, - GDK_GC_GET_XGC (gc), tmp_points, tmp_npoints, Complex, CoordModeOrigin); + xgc, tmp_points, tmp_npoints, Complex, CoordModeOrigin); else XDrawLines (GDK_SCREEN_XDISPLAY (impl->screen), impl->xid, - GDK_GC_GET_XGC (gc), tmp_points, tmp_npoints, CoordModeOrigin); + xgc, tmp_points, tmp_npoints, CoordModeOrigin); g_free (tmp_points); } @@ -555,23 +579,26 @@ gdk_x11_draw_text (GdkDrawable *drawable, if (font->type == GDK_FONT_FONT) { XFontStruct *xfont = (XFontStruct *) GDK_FONT_XFONT (font); - XSetFont(xdisplay, GDK_GC_GET_XGC (gc), xfont->fid); + XSetFont(xdisplay, GDK_GC_GET_XGC_SCALED (gc, impl->scale), xfont->fid); if ((xfont->min_byte1 == 0) && (xfont->max_byte1 == 0)) { XDrawString (xdisplay, impl->xid, - GDK_GC_GET_XGC (gc), x, y, text, text_length); + GDK_GC_GET_XGC_SCALED (gc, impl->scale), x * impl->scale, y * impl->scale, + text, text_length); } else { XDrawString16 (xdisplay, impl->xid, - GDK_GC_GET_XGC (gc), x, y, (XChar2b *) text, text_length / 2); + GDK_GC_GET_XGC_SCALED (gc, impl->scale), x * impl->scale, y * impl->scale, + (XChar2b *) text, text_length / 2); } } else if (font->type == GDK_FONT_FONTSET) { XFontSet fontset = (XFontSet) GDK_FONT_XFONT (font); XmbDrawString (xdisplay, impl->xid, - fontset, GDK_GC_GET_XGC (gc), x, y, text, text_length); + fontset, GDK_GC_GET_XGC_SCALED (gc, impl->scale), + x * impl->scale, y * impl->scale, text, text_length); } else g_error("undefined font type\n"); @@ -597,11 +624,12 @@ gdk_x11_draw_text_wc (GdkDrawable *drawable, XFontStruct *xfont = (XFontStruct *) GDK_FONT_XFONT (font); gchar *text_8bit; gint i; - XSetFont(xdisplay, GDK_GC_GET_XGC (gc), xfont->fid); + XSetFont(xdisplay, GDK_GC_GET_XGC_SCALED (gc, impl->scale), xfont->fid); text_8bit = g_new (gchar, text_length); for (i=0; ixid, - GDK_GC_GET_XGC (gc), x, y, text_8bit, text_length); + GDK_GC_GET_XGC_SCALED (gc, impl->scale), x * impl->scale, y * impl->scale, + text_8bit, text_length); g_free (text_8bit); } else if (font->type == GDK_FONT_FONTSET) @@ -610,7 +638,8 @@ gdk_x11_draw_text_wc (GdkDrawable *drawable, { XwcDrawString (xdisplay, impl->xid, (XFontSet) GDK_FONT_XFONT (font), - GDK_GC_GET_XGC (gc), x, y, (wchar_t *)text, text_length); + GDK_GC_GET_XGC_SCALED (gc, impl->scale), x * impl->scale, y * impl->scale, + (wchar_t *)text, text_length); } else { @@ -620,7 +649,8 @@ gdk_x11_draw_text_wc (GdkDrawable *drawable, for (i=0; ixid, (XFontSet) GDK_FONT_XFONT (font), - GDK_GC_GET_XGC (gc), x, y, text_wchar, text_length); + GDK_GC_GET_XGC_SCALED (gc, impl->scale), x * impl->scale, y * impl->scale, + text_wchar, text_length); g_free (text_wchar); } } @@ -628,6 +658,104 @@ gdk_x11_draw_text_wc (GdkDrawable *drawable, g_error("undefined font type\n"); } +/* HiDPI: an image of the X server with each pixel of @src (x, y, width, + * height) as a block of @scale by @scale; NULL where it cannot be made */ +XImage * +_gdk_x11_ximage_scale_up (Display *xdisplay, + XImage *src, + gint x, + gint y, + gint width, + gint height, + gint scale) +{ + XImage *dest; + gint dw = width * scale, dh = height * scale, bpp = src->bits_per_pixel; + gint i, j, k; + + dest = XCreateImage (xdisplay, NULL, src->depth, src->format, 0, NULL, + dw, dh, src->bitmap_pad, 0); + if (!dest) + return NULL; + dest->data = g_try_malloc ((gsize) dest->bytes_per_line * dh); + if (!dest->data) + { + XDestroyImage (dest); + return NULL; + } + dest->byte_order = src->byte_order; + dest->bitmap_bit_order = src->bitmap_bit_order; + + if (src->format == ZPixmap && (bpp == 8 || bpp == 16 || bpp == 24 || bpp == 32)) + { + gint b = bpp / 8; + + for (j = 0; j < height; j++) + { + const guchar *in = (guchar *) src->data + (gsize) (y + j) * src->bytes_per_line + x * b; + guchar *out = (guchar *) dest->data + (gsize) j * scale * dest->bytes_per_line; + guchar *o = out; + + for (i = 0; i < width; i++, in += b) + for (k = 0; k < scale; k++, o += b) + memcpy (o, in, b); + for (k = 1; k < scale; k++) + memcpy (out + (gsize) k * dest->bytes_per_line, out, (gsize) dw * b); + } + } + else + { + for (j = 0; j < dh; j++) + for (i = 0; i < dw; i++) + XPutPixel (dest, i, j, XGetPixel (src, x + i / scale, y + j / scale)); + } + + return dest; +} + +/* A drawable of another scale: its pixels are read, made bigger or + * smaller, and put (pixmaps of GDK all have the scale of their screen, + * so this is rare) */ +static void +copy_rescaled (GdkDrawableImplX11 *src_impl, + GdkDrawableImplX11 *impl, + GdkGC *gc, + gint xsrc, + gint ysrc, + gint xdest, + gint ydest, + gint width, + gint height) +{ + Display *xdisplay = GDK_SCREEN_XDISPLAY (impl->screen); + gint ss = src_impl->scale, ds = impl->scale; + gint dw = width * ds, dh = height * ds, i, j; + XImage *from, *to; + + gdk_error_trap_push (); + from = XGetImage (xdisplay, src_impl->xid, xsrc * ss, ysrc * ss, width * ss, height * ss, + AllPlanes, ZPixmap); + gdk_error_trap_pop (); + if (!from) + return; + + to = XCreateImage (xdisplay, NULL, from->depth, ZPixmap, 0, NULL, dw, dh, + from->bitmap_pad, 0); + if (to) + to->data = g_try_malloc ((gsize) to->bytes_per_line * dh); + if (to && to->data) + { + for (j = 0; j < dh; j++) + for (i = 0; i < dw; i++) + XPutPixel (to, i, j, XGetPixel (from, i * ss / ds, j * ss / ds)); + XPutImage (xdisplay, impl->xid, GDK_GC_GET_XGC_SCALED (gc, ds), to, + 0, 0, xdest * ds, ydest * ds, dw, dh); + } + if (to) + XDestroyImage (to); + XDestroyImage (from); +} + static void gdk_x11_draw_drawable (GdkDrawable *drawable, GdkGC *gc, @@ -689,29 +817,26 @@ gdk_x11_draw_drawable (GdkDrawable *drawable, height = src_pixmap->height - ysrc; } - if (src_depth == 1) + if (width <= 0 || height <= 0) + return; + + if (src_depth != 1 && (dest_depth == 0 || src_depth != dest_depth)) { - XCopyArea (GDK_SCREEN_XDISPLAY (impl->screen), - src_impl->xid, - impl->xid, - GDK_GC_GET_XGC (gc), - xsrc, ysrc, - width, height, - xdest, ydest); - } - else if (dest_depth != 0 && src_depth == dest_depth) - { - XCopyArea (GDK_SCREEN_XDISPLAY (impl->screen), - src_impl->xid, - impl->xid, - GDK_GC_GET_XGC (gc), - xsrc, ysrc, - width, height, - xdest, ydest); + g_warning ("Attempt to draw a drawable with depth %d to a drawable with depth %d", + src_depth, dest_depth); + return; } + + if (src_impl->scale == impl->scale) + XCopyArea (GDK_SCREEN_XDISPLAY (impl->screen), + src_impl->xid, + impl->xid, + GDK_GC_GET_XGC_SCALED (gc, impl->scale), + xsrc * impl->scale, ysrc * impl->scale, + width * impl->scale, height * impl->scale, + xdest * impl->scale, ydest * impl->scale); else - g_warning ("Attempt to draw a drawable with depth %d to a drawable with depth %d", - src_depth, dest_depth); + copy_rescaled (src_impl, impl, gc, xsrc, ysrc, xdest, ydest, width, height); } static void @@ -724,6 +849,23 @@ gdk_x11_draw_points (GdkDrawable *drawable, impl = GDK_DRAWABLE_IMPL_X11 (drawable); + /* a point of GDK is a block of pixels of the X server */ + if (impl->scale > 1) + { + gint i, s = impl->scale; + XRectangle *rects = g_new (XRectangle, npoints); + + for (i = 0; i < npoints; i++) + { + rects[i].x = points[i].x * s; + rects[i].y = points[i].y * s; + rects[i].width = rects[i].height = s; + } + XFillRectangles (GDK_SCREEN_XDISPLAY (impl->screen), impl->xid, + GDK_GC_GET_XGC_SCALED (gc, s), rects, npoints); + g_free (rects); + return; + } /* We special-case npoints == 1, because X will merge multiple * consecutive XDrawPoint requests into a PolyPoint request @@ -732,7 +874,7 @@ gdk_x11_draw_points (GdkDrawable *drawable, { XDrawPoint (GDK_SCREEN_XDISPLAY (impl->screen), impl->xid, - GDK_GC_GET_XGC (gc), + GDK_GC_GET_XGC_SCALED (gc, 1), points[0].x, points[0].y); } else @@ -748,7 +890,7 @@ gdk_x11_draw_points (GdkDrawable *drawable, XDrawPoints (GDK_SCREEN_XDISPLAY (impl->screen), impl->xid, - GDK_GC_GET_XGC (gc), + GDK_GC_GET_XGC_SCALED (gc, 1), tmp_points, npoints, CoordModeOrigin); @@ -764,9 +906,13 @@ gdk_x11_draw_segments (GdkDrawable *drawable, gint nsegs) { GdkDrawableImplX11 *impl; + gint s, o; + GC xgc; impl = GDK_DRAWABLE_IMPL_X11 (drawable); - + s = impl->scale; + xgc = GDK_GC_GET_XGC_SCALED (gc, s); + o = GDK_GC_X11_THIN_OFFSET (gc, s); /* We special-case nsegs == 1, because X will merge multiple * consecutive XDrawLine requests into a PolySegment request @@ -774,8 +920,8 @@ gdk_x11_draw_segments (GdkDrawable *drawable, if (nsegs == 1) { XDrawLine (GDK_SCREEN_XDISPLAY (impl->screen), impl->xid, - GDK_GC_GET_XGC (gc), segs[0].x1, segs[0].y1, - segs[0].x2, segs[0].y2); + xgc, segs[0].x1 * s + o, segs[0].y1 * s + o, + segs[0].x2 * s + o, segs[0].y2 * s + o); } else { @@ -784,15 +930,15 @@ gdk_x11_draw_segments (GdkDrawable *drawable, for (i=0; iscreen), impl->xid, - GDK_GC_GET_XGC (gc), + xgc, tmp_segs, nsegs); g_free (tmp_segs); @@ -805,22 +951,25 @@ gdk_x11_draw_lines (GdkDrawable *drawable, GdkPoint *points, gint npoints) { - gint i; + gint i, s, o; XPoint *tmp_points = g_new (XPoint, npoints); GdkDrawableImplX11 *impl; + GC xgc; impl = GDK_DRAWABLE_IMPL_X11 (drawable); - + s = impl->scale; + xgc = GDK_GC_GET_XGC_SCALED (gc, s); + o = GDK_GC_X11_THIN_OFFSET (gc, s); for (i=0; iscreen), impl->xid, - GDK_GC_GET_XGC (gc), + xgc, tmp_points, npoints, CoordModeOrigin); @@ -842,15 +991,31 @@ gdk_x11_draw_image (GdkDrawable *drawable, impl = GDK_DRAWABLE_IMPL_X11 (drawable); + /* the image is in pixels of GDK: each becomes a block */ + if (impl->scale > 1) + { + Display *xdisplay = GDK_SCREEN_XDISPLAY (impl->screen); + gint s = impl->scale; + XImage *big = _gdk_x11_ximage_scale_up (xdisplay, GDK_IMAGE_XIMAGE (image), + xsrc, ysrc, width, height, s); + if (big) + { + XPutImage (xdisplay, impl->xid, GDK_GC_GET_XGC_SCALED (gc, s), big, + 0, 0, xdest * s, ydest * s, width * s, height * s); + XDestroyImage (big); + } + return; + } + #ifdef USE_SHM if (image->type == GDK_IMAGE_SHARED) XShmPutImage (GDK_SCREEN_XDISPLAY (impl->screen), impl->xid, - GDK_GC_GET_XGC (gc), GDK_IMAGE_XIMAGE (image), + GDK_GC_GET_XGC_SCALED (gc, 1), GDK_IMAGE_XIMAGE (image), xsrc, ysrc, xdest, ydest, width, height, False); else #endif XPutImage (GDK_SCREEN_XDISPLAY (impl->screen), impl->xid, - GDK_GC_GET_XGC (gc), GDK_IMAGE_XIMAGE (image), + GDK_GC_GET_XGC_SCALED (gc, 1), GDK_IMAGE_XIMAGE (image), xsrc, ysrc, xdest, ydest, width, height); } @@ -1270,6 +1435,26 @@ _gdk_x11_convert_to_format (guchar *src_buf, } } +/* HiDPI: the source pictures show each of their pixels as a block of + * @up by @up on the drawable, or as one where the pixbuf is in pixels of + * the X server already (up 1) */ +static void +set_upscale (Display *xdisplay, + Picture pict, + gint up) +{ + XTransform transform = {{ + { XDoubleToFixed (1), 0, 0 }, + { 0, XDoubleToFixed (1), 0 }, + { 0, 0, XDoubleToFixed (1) } }}; + + transform.matrix[2][2] = XDoubleToFixed (up); + XRenderSetPictureTransform (xdisplay, pict, &transform); + XRenderSetPictureFilter (xdisplay, pict, FilterNearest, NULL, 0); +} + +/* @dest_x, @dest_y in pixels of the X server; @width, @height in those + * of the source */ static void draw_with_images (GdkDrawable *drawable, GdkGC *gc, @@ -1281,32 +1466,35 @@ draw_with_images (GdkDrawable *drawable, gint dest_x, gint dest_y, gint width, - gint height) + gint height, + gint up) { - GdkScreen *screen = GDK_DRAWABLE_IMPL_X11 (drawable)->screen; + GdkDrawableImplX11 *impl = GDK_DRAWABLE_IMPL_X11 (drawable); + GdkScreen *screen = impl->screen; Display *xdisplay = GDK_SCREEN_XDISPLAY (screen); GdkImage *image; - GdkPixmap *pix; - GdkGC *pix_gc; + Pixmap pix; + GC pix_gc; Picture pict; Picture dest_pict; Picture mask = None; gint x0, y0; - pix = gdk_pixmap_new (gdk_screen_get_root_window (screen), width, height, 32); + pix = XCreatePixmap (xdisplay, GDK_SCREEN_XROOTWIN (screen), width, height, 32); + pix_gc = XCreateGC (xdisplay, pix, 0, NULL); - pict = XRenderCreatePicture (xdisplay, - GDK_PIXMAP_XID (pix), - format, 0, NULL); + pict = XRenderCreatePicture (xdisplay, pix, format, 0, NULL); if (mask_format) - mask = XRenderCreatePicture (xdisplay, - GDK_PIXMAP_XID (pix), - mask_format, 0, NULL); + mask = XRenderCreatePicture (xdisplay, pix, mask_format, 0, NULL); + if (up > 1) + { + set_upscale (xdisplay, pict, up); + if (mask) + set_upscale (xdisplay, mask, up); + } dest_pict = gdk_x11_drawable_get_picture (drawable); - pix_gc = _gdk_drawable_get_scratch_gc (pix, FALSE); - for (y0 = 0; y0 < height; y0 += GDK_SCRATCH_IMAGE_HEIGHT) { gint height1 = MIN (height - y0, GDK_SCRATCH_IMAGE_HEIGHT); @@ -1323,19 +1511,25 @@ draw_with_images (GdkDrawable *drawable, format_type, image->byte_order, width1, height1); - gdk_draw_image (pix, pix_gc, - image, xs0, ys0, x0, y0, width1, height1); +#ifdef USE_SHM + if (image->type == GDK_IMAGE_SHARED) + XShmPutImage (xdisplay, pix, pix_gc, GDK_IMAGE_XIMAGE (image), + xs0, ys0, x0, y0, width1, height1, False); + else +#endif + XPutImage (xdisplay, pix, pix_gc, GDK_IMAGE_XIMAGE (image), + xs0, ys0, x0, y0, width1, height1); } } XRenderComposite (xdisplay, PictOpOver, pict, mask, dest_pict, - 0, 0, 0, 0, dest_x, dest_y, width, height); + 0, 0, 0, 0, dest_x, dest_y, width * up, height * up); XRenderFreePicture (xdisplay, pict); if (mask) XRenderFreePicture (xdisplay, mask); - - g_object_unref (pix); + XFreeGC (xdisplay, pix_gc); + XFreePixmap (xdisplay, pix); } typedef struct _ShmPixmapInfo ShmPixmapInfo; @@ -1346,6 +1540,7 @@ struct _ShmPixmapInfo Pixmap pix; Picture pict; Picture mask; + gint up; /* the scale the pictures are transformed for */ }; static void @@ -1389,6 +1584,7 @@ get_shm_pixmap_for_image (Display *xdisplay, info = g_new (ShmPixmapInfo, 1); info->display = xdisplay; info->pix = *pix; + info->up = 1; info->pict = XRenderCreatePicture (xdisplay, info->pix, format, 0, NULL); @@ -1421,7 +1617,8 @@ draw_with_pixmaps (GdkDrawable *drawable, gint dest_x, gint dest_y, gint width, - gint height) + gint height, + gint up) { Display *xdisplay = GDK_SCREEN_XDISPLAY (GDK_DRAWABLE_IMPL_X11 (drawable)->screen); GdkImage *image; @@ -1447,14 +1644,28 @@ draw_with_pixmaps (GdkDrawable *drawable, if (!get_shm_pixmap_for_image (xdisplay, image, format, mask_format, &pix, &pict, &mask)) return FALSE; + /* the pictures stay with the image */ + { + ShmPixmapInfo *info = g_object_get_data (G_OBJECT (image), "gdk-x11-shm-pixmap"); + + if (info && info->up != up) + { + set_upscale (xdisplay, pict, up); + if (mask) + set_upscale (xdisplay, mask, up); + info->up = up; + } + } + _gdk_x11_convert_to_format (src_rgb + y0 * src_rowstride + 4 * x0, src_rowstride, (guchar *)image->mem + ys0 * image->bpl + xs0 * image->bpp, image->bpl, format_type, image->byte_order, width1, height1); XRenderComposite (xdisplay, PictOpOver, pict, mask, dest_pict, - xs0, ys0, xs0, ys0, x0 + dest_x, y0 + dest_y, - width1, height1); + xs0 * up, ys0 * up, xs0 * up, ys0 * up, + dest_x + x0 * up, dest_y + y0 * up, + width1 * up, height1 * up); } } @@ -1476,9 +1687,11 @@ gdk_x11_draw_pixbuf (GdkDrawable *drawable, gint x_dither, gint y_dither) { + GdkColormap *colormap = gdk_drawable_get_colormap (drawable); GdkX11FormatType format_type; XRenderPictFormat *format, *mask_format; - gint rowstride; + gint rowstride, s = GDK_DRAWABLE_IMPL_X11 (drawable)->scale, up = s; + GdkPixbuf *hires; #ifdef USE_SHM gboolean use_pixmaps = TRUE; #endif /* USE_SHM */ @@ -1489,7 +1702,8 @@ gdk_x11_draw_pixbuf (GdkDrawable *drawable, if (format_type == GDK_X11_FORMAT_NONE || !gdk_pixbuf_get_has_alpha (pixbuf) || gdk_drawable_get_depth (drawable) == 1 || - (dither == GDK_RGB_DITHER_MAX && gdk_drawable_get_depth (drawable) != 24) || + (colormap ? _gdk_rgb_prefers_own_blending (colormap, dither) + : dither == GDK_RGB_DITHER_MAX && gdk_drawable_get_depth (drawable) != 24) || gdk_x11_drawable_get_picture (drawable) == None) { GdkDrawable *wrapper = GDK_DRAWABLE_IMPL_X11 (drawable)->wrapper; @@ -1502,6 +1716,20 @@ gdk_x11_draw_pixbuf (GdkDrawable *drawable, gdk_x11_drawable_update_picture_clip (drawable, gc); + /* in pixels of the X server */ + hires = _gdk_pixbuf_get_hires (pixbuf, s); + if (hires) + { + pixbuf = hires; + src_x *= s; + src_y *= s; + width *= s; + height *= s; + up = 1; + } + dest_x *= s; + dest_y *= s; + rowstride = gdk_pixbuf_get_rowstride (pixbuf); #ifdef USE_SHM @@ -1511,7 +1739,7 @@ gdk_x11_draw_pixbuf (GdkDrawable *drawable, format_type, format, mask_format, gdk_pixbuf_get_pixels (pixbuf) + src_y * rowstride + src_x * 4, rowstride, - dest_x, dest_y, width, height)) + dest_x, dest_y, width, height, up)) use_pixmaps = FALSE; } @@ -1521,7 +1749,7 @@ gdk_x11_draw_pixbuf (GdkDrawable *drawable, format_type, format, mask_format, gdk_pixbuf_get_pixels (pixbuf) + src_y * rowstride + src_x * 4, rowstride, - dest_x, dest_y, width, height); + dest_x, dest_y, width, height, up); } static void @@ -1537,7 +1765,12 @@ _gdk_windowing_set_cairo_surface_size (cairo_surface_t *surface, int width, int height) { - cairo_xlib_surface_set_size (surface, width, height); + gdouble sx = 1, sy = 1; + +#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE (1, 14, 0) + cairo_surface_get_device_scale (surface, &sx, &sy); +#endif + cairo_xlib_surface_set_size (surface, width * sx, height * sy); } cairo_surface_t * @@ -1547,18 +1780,29 @@ _gdk_windowing_create_cairo_surface (GdkDrawable *drawable, { GdkDrawableImplX11 *impl = GDK_DRAWABLE_IMPL_X11 (drawable); GdkVisual *visual; + cairo_surface_t *surface = NULL; + gint s = impl->scale; + /* in pixels of the X server, drawn on in those of GDK */ visual = gdk_drawable_get_visual (drawable); if (visual) - return cairo_xlib_surface_create (GDK_SCREEN_XDISPLAY (impl->screen), - impl->xid, - GDK_VISUAL_XVISUAL (visual), - width, height); + surface = cairo_xlib_surface_create (GDK_SCREEN_XDISPLAY (impl->screen), + impl->xid, + GDK_VISUAL_XVISUAL (visual), + width * s, height * s); else if (gdk_drawable_get_depth (drawable) == 1) - return cairo_xlib_surface_create_for_bitmap (GDK_SCREEN_XDISPLAY (impl->screen), - impl->xid, - GDK_SCREEN_XSCREEN (impl->screen), - width, height); + surface = cairo_xlib_surface_create_for_bitmap (GDK_SCREEN_XDISPLAY (impl->screen), + impl->xid, + GDK_SCREEN_XSCREEN (impl->screen), + width * s, height * s); + if (surface) + { +#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE (1, 14, 0) + if (s > 1) + cairo_surface_set_device_scale (surface, s, s); +#endif + return surface; + } else { g_warning ("Using Cairo rendering requires the drawable argument to\n" @@ -1598,5 +1842,16 @@ gdk_x11_ref_cairo_surface (GdkDrawable *drawable) return impl->cairo_surface; } +gint +_gdk_windowing_drawable_get_scale (GdkDrawable *drawable) +{ + if (GDK_IS_WINDOW (drawable)) + drawable = ((GdkWindowObject *) drawable)->impl; + else if (GDK_IS_PIXMAP (drawable)) + drawable = ((GdkPixmapObject *) drawable)->impl; + + return GDK_IS_DRAWABLE_IMPL_X11 (drawable) ? GDK_DRAWABLE_IMPL_X11 (drawable)->scale : 1; +} + #define __GDK_DRAWABLE_X11_C__ #include "gdkaliasdef.c" diff --git a/gdk/x11/gdkdrawable-x11.h b/gdk/x11/gdkdrawable-x11.h index 2f82d667e..d6f2619a1 100644 --- a/gdk/x11/gdkdrawable-x11.h +++ b/gdk/x11/gdkdrawable-x11.h @@ -68,6 +68,10 @@ struct _GdkDrawableImplX11 Picture picture; cairo_surface_t *cairo_surface; + + /* HiDPI: pixels of the X server for one of GDK, in each direction; + * sizes and coordinates of GDK are multiplied by it for X */ + gint scale; }; struct _GdkDrawableImplX11Class @@ -90,6 +94,7 @@ void _gdk_x11_convert_to_format (guchar *src_buf, /* Note that the following take GdkDrawableImplX11, not the wrapper drawable */ void _gdk_x11_drawable_finish (GdkDrawable *drawable); void _gdk_x11_drawable_update_size (GdkDrawable *drawable); +void _gdk_x11_drawable_update_scale (GdkDrawable *drawable); GdkDrawable *gdk_x11_window_get_drawable_impl (GdkWindow *window); GdkDrawable *gdk_x11_pixmap_get_drawable_impl (GdkPixmap *pixmap); diff --git a/gdk/x11/gdkevents-x11.c b/gdk/x11/gdkevents-x11.c index b5d3df4fd..84adf6826 100644 --- a/gdk/x11/gdkevents-x11.c +++ b/gdk/x11/gdkevents-x11.c @@ -40,6 +40,7 @@ #include "xsettings-client.h" #include +#include #include "gdkinputprivate.h" #include "gdksettings.c" @@ -83,6 +84,11 @@ struct _GdkDisplaySource GdkDisplay *display; GPollFD event_poll_fd; + + /* how much xcb had read from the X server when an XPending() found + * no events (see gdk_event_prepare) */ + guint64 quiet_total_read; + gboolean quiet; }; struct _GdkEventTypeX11 @@ -185,6 +191,11 @@ _gdk_x11_events_init_screen (GdkScreen *screen) { GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (screen); + /* GDK_NO_XSETTINGS: the settings of the desktop are not read, to see + * what a program does without them (as Ardour's YDK has it) */ + if (g_getenv ("GDK_NO_XSETTINGS")) + return; + /* Keep a flag to avoid extra notifies that we don't need */ screen_x11->xsettings_in_init = TRUE; @@ -947,6 +958,7 @@ gdk_event_translate (GdkDisplay *display, GdkWindow *window; GdkWindowObject *window_private; + gint scale = 1; GdkWindow *filter_window; GdkWindowImplX11 *window_impl = NULL; gboolean return_val; @@ -976,6 +988,16 @@ gdk_event_translate (GdkDisplay *display, } } + /* XInput 2 motion stands for the core motion it hides */ + if (xevent->type == GenericEvent && display_x11->scroll) + { + XEvent motion; + + if (_gdk_x11_scroll_translate (display, xevent, &motion)) + return motion.type != 0 && !XFilterEvent (&motion, None) && + gdk_event_translate (display, event, &motion, return_exposes); + } + /* Find the GdkWindow that this event relates to. * Basically this means substructure events * are reported same as structure events @@ -989,6 +1011,46 @@ gdk_event_translate (GdkDisplay *display, if (window && !GDK_IS_WINDOW (window)) window = NULL; window_private = (GdkWindowObject *) window; + /* HiDPI: the X server's pixels of the window for one of GDK */ + scale = window && window_private->impl ? GDK_X11_WINDOW_SCALE (window) : 1; + + /* What gdk_window_get_origin() keeps (see gdkwindow-x11.c): events that + * can move windows make it ask the X server again, pointer events tell + * where their window is */ + switch (xevent->type) + { + case ConfigureNotify: + case ReparentNotify: + case MapNotify: + case UnmapNotify: + case GravityNotify: + case CirculateNotify: + case DestroyNotify: + _gdk_x11_window_root_coords_changed (); + break; + case MotionNotify: + if (window && xevent->xmotion.same_screen) + _gdk_x11_window_set_root_origin (window, + xevent->xmotion.x_root - xevent->xmotion.x, + xevent->xmotion.y_root - xevent->xmotion.y); + break; + case ButtonPress: + case ButtonRelease: + if (window && xevent->xbutton.same_screen) + _gdk_x11_window_set_root_origin (window, + xevent->xbutton.x_root - xevent->xbutton.x, + xevent->xbutton.y_root - xevent->xbutton.y); + break; + case EnterNotify: + case LeaveNotify: + if (window && xevent->xcrossing.same_screen) + _gdk_x11_window_set_root_origin (window, + xevent->xcrossing.x_root - xevent->xcrossing.x, + xevent->xcrossing.y_root - xevent->xcrossing.y); + break; + default: + break; + } /* We always run the filters for the window where the event * is delivered, not the window that it relates to @@ -1207,13 +1269,18 @@ gdk_event_translate (GdkDisplay *display, event->scroll.window = window; event->scroll.time = xevent->xbutton.time; - event->scroll.x = xevent->xbutton.x; - event->scroll.y = xevent->xbutton.y; - event->scroll.x_root = (gfloat)xevent->xbutton.x_root; - event->scroll.y_root = (gfloat)xevent->xbutton.y_root; + event->scroll.x = xevent->xbutton.x / (gdouble) scale; + event->scroll.y = xevent->xbutton.y / (gdouble) scale; + /* HiDPI: through the monitor of the window's toplevel */ + _gdk_x11_window_device_to_root (window, xevent->xbutton.x_root, xevent->xbutton.y_root, + &event->scroll.x_root, &event->scroll.y_root); event->scroll.state = (GdkModifierType) xevent->xbutton.state; event->scroll.device = display->core_pointer; + if (display_x11->scroll && + _gdk_x11_scroll_is_emulated (display, xevent->xbutton.time)) + ((GdkEventPrivate *) event)->flags |= GDK_EVENT_POINTER_EMULATED; + if (!set_screen_from_root (display, event, xevent->xbutton.root)) { return_val = FALSE; @@ -1223,13 +1290,18 @@ gdk_event_translate (GdkDisplay *display, break; default: + /* an implicit core grab, without XI_Motion, begins */ + if (display_x11->scroll) + _gdk_x11_scroll_reset (display, FALSE); + event->button.type = GDK_BUTTON_PRESS; event->button.window = window; event->button.time = xevent->xbutton.time; - event->button.x = xevent->xbutton.x; - event->button.y = xevent->xbutton.y; - event->button.x_root = (gfloat)xevent->xbutton.x_root; - event->button.y_root = (gfloat)xevent->xbutton.y_root; + event->button.x = xevent->xbutton.x / (gdouble) scale; + event->button.y = xevent->xbutton.y / (gdouble) scale; + /* HiDPI: through the monitor of the window's toplevel */ + _gdk_x11_window_device_to_root (window, xevent->xbutton.x_root, xevent->xbutton.y_root, + &event->button.x_root, &event->button.y_root); event->button.axes = NULL; event->button.state = (GdkModifierType) xevent->xbutton.state; event->button.button = xevent->xbutton.button; @@ -1268,13 +1340,17 @@ gdk_event_translate (GdkDisplay *display, break; } + if (display_x11->scroll) + _gdk_x11_scroll_reset (display, FALSE); + event->button.type = GDK_BUTTON_RELEASE; event->button.window = window; event->button.time = xevent->xbutton.time; - event->button.x = xevent->xbutton.x; - event->button.y = xevent->xbutton.y; - event->button.x_root = (gfloat)xevent->xbutton.x_root; - event->button.y_root = (gfloat)xevent->xbutton.y_root; + event->button.x = xevent->xbutton.x / (gdouble) scale; + event->button.y = xevent->xbutton.y / (gdouble) scale; + /* HiDPI: through the monitor of the window's toplevel */ + _gdk_x11_window_device_to_root (window, xevent->xbutton.x_root, xevent->xbutton.y_root, + &event->button.x_root, &event->button.y_root); event->button.axes = NULL; event->button.state = (GdkModifierType) xevent->xbutton.state; event->button.button = xevent->xbutton.button; @@ -1301,10 +1377,11 @@ gdk_event_translate (GdkDisplay *display, event->motion.type = GDK_MOTION_NOTIFY; event->motion.window = window; event->motion.time = xevent->xmotion.time; - event->motion.x = xevent->xmotion.x; - event->motion.y = xevent->xmotion.y; - event->motion.x_root = (gfloat)xevent->xmotion.x_root; - event->motion.y_root = (gfloat)xevent->xmotion.y_root; + event->motion.x = xevent->xmotion.x / (gdouble) scale; + event->motion.y = xevent->xmotion.y / (gdouble) scale; + /* HiDPI: through the monitor of the window's toplevel */ + _gdk_x11_window_device_to_root (window, xevent->xmotion.x_root, xevent->xmotion.y_root, + &event->motion.x_root, &event->motion.y_root); event->motion.axes = NULL; event->motion.state = (GdkModifierType) xevent->xmotion.state; event->motion.is_hint = xevent->xmotion.is_hint; @@ -1338,6 +1415,11 @@ gdk_event_translate (GdkDisplay *display, break; } + if (display_x11->scroll) + _gdk_x11_scroll_reset (display, + xevent->xcrossing.detail != NotifyInferior && + window_private->window_type != GDK_WINDOW_CHILD); + /* Handle focusing (in the case where no window manager is running */ if (toplevel && xevent->xcrossing.detail != NotifyInferior) { @@ -1366,10 +1448,11 @@ gdk_event_translate (GdkDisplay *display, event->crossing.subwindow = NULL; event->crossing.time = xevent->xcrossing.time; - event->crossing.x = xevent->xcrossing.x; - event->crossing.y = xevent->xcrossing.y; - event->crossing.x_root = xevent->xcrossing.x_root; - event->crossing.y_root = xevent->xcrossing.y_root; + event->crossing.x = xevent->xcrossing.x / (gdouble) scale; + event->crossing.y = xevent->xcrossing.y / (gdouble) scale; + /* HiDPI: through the monitor of the window's toplevel */ + _gdk_x11_window_device_to_root (window, xevent->xcrossing.x_root, xevent->xcrossing.y_root, + &event->crossing.x_root, &event->crossing.y_root); /* Translate the crossing mode into Gdk terms. */ @@ -1463,10 +1546,11 @@ gdk_event_translate (GdkDisplay *display, event->crossing.subwindow = NULL; event->crossing.time = xevent->xcrossing.time; - event->crossing.x = xevent->xcrossing.x; - event->crossing.y = xevent->xcrossing.y; - event->crossing.x_root = xevent->xcrossing.x_root; - event->crossing.y_root = xevent->xcrossing.y_root; + event->crossing.x = xevent->xcrossing.x / (gdouble) scale; + event->crossing.y = xevent->xcrossing.y / (gdouble) scale; + /* HiDPI: through the monitor of the window's toplevel */ + _gdk_x11_window_device_to_root (window, xevent->xcrossing.x_root, xevent->xcrossing.y_root, + &event->crossing.x_root, &event->crossing.y_root); /* Translate the crossing mode into Gdk terms. */ @@ -1664,6 +1748,7 @@ gdk_event_translate (GdkDisplay *display, expose_rect.y = xevent->xexpose.y; expose_rect.width = xevent->xexpose.width; expose_rect.height = xevent->xexpose.height; + _gdk_x11_unscale_rect (&expose_rect, scale); _gdk_window_process_expose (window, xevent->xexpose.serial, &expose_rect); return_val = FALSE; @@ -1689,6 +1774,7 @@ gdk_event_translate (GdkDisplay *display, expose_rect.y = xevent->xgraphicsexpose.y; expose_rect.width = xevent->xgraphicsexpose.width; expose_rect.height = xevent->xgraphicsexpose.height; + _gdk_x11_unscale_rect (&expose_rect, scale); if (return_exposes) { @@ -1882,8 +1968,8 @@ gdk_event_translate (GdkDisplay *display, : "")); if (window && GDK_WINDOW_TYPE (window) == GDK_WINDOW_ROOT) { - window_private->width = xevent->xconfigure.width; - window_private->height = xevent->xconfigure.height; + window_private->width = xevent->xconfigure.width / scale; + window_private->height = xevent->xconfigure.height / scale; _gdk_window_update_size (window); _gdk_x11_drawable_update_size (window_private->impl); @@ -1911,41 +1997,56 @@ gdk_event_translate (GdkDisplay *display, return_val = FALSE; else { + gint tx = xevent->xconfigure.x; + gint ty = xevent->xconfigure.y; + gint rescaled; + gdouble rx, ry; + event->configure.type = GDK_CONFIGURE; event->configure.window = window; - event->configure.width = xevent->xconfigure.width; - event->configure.height = xevent->xconfigure.height; if (!xevent->xconfigure.send_event && !xevent->xconfigure.override_redirect && !GDK_WINDOW_DESTROYED (window)) { - gint tx = 0; - gint ty = 0; Window child_window = 0; gdk_error_trap_push (); - if (XTranslateCoordinates (GDK_DRAWABLE_XDISPLAY (window), - GDK_DRAWABLE_XID (window), - screen_x11->xroot_window, - 0, 0, - &tx, &ty, - &child_window)) - { - event->configure.x = tx; - event->configure.y = ty; - } + if (!XTranslateCoordinates (GDK_DRAWABLE_XDISPLAY (window), + GDK_DRAWABLE_XID (window), + screen_x11->xroot_window, + 0, 0, + &tx, &ty, + &child_window)) + tx = ty = 0; gdk_error_trap_pop (); } + + /* HiDPI: on monitors of different scales the window takes the + * one of the monitor it is on now; resized by GDK it keeps its + * size in GDK's pixels */ + rescaled = _gdk_x11_window_update_scale (window, tx, ty, + xevent->xconfigure.width, + xevent->xconfigure.height); + scale = GDK_X11_WINDOW_SCALE (window); + if (rescaled == 1) + { + event->configure.width = window_private->width; + event->configure.height = window_private->height; + } else { - event->configure.x = xevent->xconfigure.x; - event->configure.y = xevent->xconfigure.y; + event->configure.width = _gdk_x11_unscale_up (xevent->xconfigure.width, scale); + event->configure.height = _gdk_x11_unscale_up (xevent->xconfigure.height, scale); } + + _gdk_x11_window_device_to_root (window, tx, ty, &rx, &ry); + event->configure.x = (gint) floor (rx); + event->configure.y = (gint) floor (ry); window_private->x = event->configure.x; window_private->y = event->configure.y; - window_private->width = xevent->xconfigure.width; - window_private->height = xevent->xconfigure.height; + window_private->width = event->configure.width; + window_private->height = event->configure.height; _gdk_window_update_size (window); _gdk_x11_drawable_update_size (window_private->impl); @@ -2367,9 +2468,83 @@ _gdk_events_queue (GdkDisplay *display) g_list_free_1 (node); gdk_event_free (event); } + + /* the smooth scroll of an XI_Motion comes after its motion, and + * a touch or touchpad gesture brings its events */ + if (xevent.type == GenericEvent && GDK_DISPLAY_X11 (display)->scroll) + while ((event = _gdk_x11_scroll_take_pending (display))) + _gdk_windowing_got_event (display, _gdk_event_queue_append (display, event), + event, xevent.xany.serial); } } +/* GLib asks every event source before it waits whether it has + * something, and some programs turn the main loop very often: Pale + * Moon and Firefox tens of thousands of times a second while there is + * work. For the X connection, XPending() answers that with two reads + * from the socket, which find nothing nearly every time - and need not + * look, as the poll() that follows watches the socket. What poll() + * cannot see is what has already been read: events Xlib or xcb queued + * while waiting for a reply, also of other code using xcb directly + * (cairo, Mesa). So XPending() is skipped while Xlib has nothing queued + * or unsent and xcb has read nothing from the socket since the last + * XPending() that found no events; xcb_total_read() counts that (libxcb + * 1.14). Weak references: used where the program has libX11-xcb + * loaded (Pale Moon, Firefox, programs with OpenGL), with no new + * dependency for GTK+; elsewhere every turn asks XPending() as before. */ +#if defined (__ELF__) && defined (__GNUC__) +#define HAVE_WEAK_XCB_TOTAL_READ 1 +struct xcb_connection_t; +extern struct xcb_connection_t *XGetXCBConnection (Display *dpy) __attribute__ ((weak)); +extern guint64 xcb_total_read (struct xcb_connection_t *c) __attribute__ ((weak)); +#endif + +static gboolean +gdk_display_source_total_read (GdkDisplaySource *source, + guint64 *total) +{ +#ifdef HAVE_WEAK_XCB_TOTAL_READ + struct xcb_connection_t *c; + + if (XGetXCBConnection == NULL || xcb_total_read == NULL) + return FALSE; + c = XGetXCBConnection (GDK_DISPLAY_XDISPLAY (source->display)); + if (c == NULL) + return FALSE; + *total = xcb_total_read (c); + return TRUE; +#else + return FALSE; +#endif +} + +static gboolean +gdk_display_source_is_quiet (GdkDisplaySource *source) +{ + guint64 total; + + return (source->quiet && + _gdk_x11_display_is_idle (GDK_DISPLAY_XDISPLAY (source->display)) && + gdk_display_source_total_read (source, &total) && + total == source->quiet_total_read); +} + +static gboolean +gdk_display_source_check_xpending (GdkDisplaySource *source) +{ + guint64 total = 0; + gboolean known, pending; + + /* counted before: whatever is read during or after the XPending(), + * here or in another thread, makes the next turn look again */ + known = gdk_display_source_total_read (source, &total); + pending = gdk_check_xpending (source->display); + source->quiet = known && !pending; + source->quiet_total_read = total; + + return pending; +} + static gboolean gdk_event_prepare (GSource *source, gint *timeout) @@ -2380,8 +2555,12 @@ gdk_event_prepare (GSource *source, GDK_THREADS_ENTER (); *timeout = -1; - retval = (_gdk_event_queue_find_first (display) != NULL || - gdk_check_xpending (display)); + if (_gdk_event_queue_find_first (display) != NULL) + retval = TRUE; + else if (gdk_display_source_is_quiet ((GdkDisplaySource *) source)) + retval = FALSE; + else + retval = gdk_display_source_check_xpending ((GdkDisplaySource *) source); GDK_THREADS_LEAVE (); @@ -2398,7 +2577,7 @@ gdk_event_check (GSource *source) if (display_source->event_poll_fd.revents & G_IO_IN) retval = (_gdk_event_queue_find_first (display_source->display) != NULL || - gdk_check_xpending (display_source->display)); + gdk_display_source_check_xpending (display_source)); else retval = FALSE; @@ -2683,9 +2862,11 @@ fetch_net_wm_check_window (GdkScreen *screen) g_return_if_fail (GDK_DISPLAY_X11 (display)->trusted_client); - now_sec = g_get_real_time () / G_USEC_PER_SEC; + now_sec = g_get_monotonic_time () / G_USEC_PER_SEC; - if (ABS (now_sec - screen_x11->last_wmspec_check_time) < 15) + /* 0: not checked yet, or to be checked again */ + if (screen_x11->last_wmspec_check_time != 0 && + ABS (now_sec - screen_x11->last_wmspec_check_time) < 15) return; /* we've checked recently */ screen_x11->last_wmspec_check_time = now_sec; @@ -2856,6 +3037,7 @@ gdk_x11_screen_supports_net_wm_hint (GdkScreen *screen, GdkScreenX11 *screen_x11; NetWmSupportedAtoms *supported_atoms; GdkDisplay *display; + Atom atom; g_return_val_if_fail (GDK_IS_SCREEN (screen), FALSE); @@ -2907,13 +3089,12 @@ gdk_x11_screen_supports_net_wm_hint (GdkScreen *screen, if (supported_atoms->atoms == NULL) return FALSE; - i = 0; - while (i < supported_atoms->n_atoms) - { - if (supported_atoms->atoms[i] == gdk_x11_atom_to_xatom_for_display (display, property)) - return TRUE; + atom = gdk_x11_atom_to_xatom_for_display (display, property); - ++i; + for (i = 0; i < supported_atoms->n_atoms; i++) + { + if (supported_atoms->atoms[i] == atom) + return TRUE; } return FALSE; @@ -2953,6 +3134,10 @@ gdk_xsettings_notify_cb (const char *name, if (screen_x11->xsettings_in_init) return; + /* HiDPI: the desktop's scale or resolution changed */ + if (strcmp (name, "Gdk/WindowScalingFactor") == 0 || strcmp (name, "Xft/DPI") == 0) + _gdk_x11_screen_update_scales (screen); + new_event.type = GDK_SETTING; new_event.setting.window = gdk_screen_get_root_window (screen); new_event.setting.send_event = FALSE; @@ -3018,11 +3203,82 @@ check_transform (const gchar *xsettings_name, * * Since: 2.2 **/ +static gboolean get_setting_raw (GdkScreen *screen, + const gchar *name, + GValue *value); + +/* HiDPI: fonts are drawn in pixels of GDK, so their resolution is that + * of the desktop over the scale (GNOME also says it as Gdk/UnscaledDPI); + * GDK_DPI_SCALE makes it bigger or smaller, as in GTK+ 3 */ +static gboolean +get_font_dpi (GdkScreen *screen, + GValue *value) +{ + GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (screen); + XSettingsSetting *setting = NULL; + const char *env = g_getenv ("GDK_DPI_SCALE"); + gdouble factor = env && *env ? g_ascii_strtod (env, NULL) : 1.0; + gint dpi = 0; + GValue tmp = { 0, }; + + if (screen_x11->window_scale > 1 && screen_x11->xsettings_client && + xsettings_client_get_setting (screen_x11->xsettings_client, "Gdk/UnscaledDPI", + &setting) == XSETTINGS_SUCCESS && + setting->type == XSETTINGS_TYPE_INT && setting->data.v_int > 0) + dpi = setting->data.v_int; + if (setting) + xsettings_setting_free (setting); + + if (dpi <= 0) + { + g_value_init (&tmp, G_TYPE_INT); + if (get_setting_raw (screen, "gtk-xft-dpi", &tmp) && g_value_get_int (&tmp) > 0) + { + dpi = g_value_get_int (&tmp); + /* a resolution made for the scale (192 for 2) is divided; one + * that is not (96 with GDK_SCALE=2 alone) is already right */ + if (dpi / screen_x11->window_scale >= 72 * 1024) + dpi /= screen_x11->window_scale; + } + g_value_unset (&tmp); + } + + if (factor <= 0) + factor = 1.0; + if (dpi <= 0) + { + if (factor == 1.0) + return FALSE; + dpi = 96 * 1024; + } + + dpi = dpi * factor; + g_value_init (&tmp, G_TYPE_INT); + g_value_set_int (&tmp, dpi); + g_value_transform (&tmp, value); + g_value_unset (&tmp); + + return TRUE; +} + gboolean gdk_screen_get_setting (GdkScreen *screen, const gchar *name, GValue *value) { + g_return_val_if_fail (GDK_IS_SCREEN (screen), FALSE); + + if (strcmp (name, "gtk-xft-dpi") == 0) + return get_font_dpi (screen, value); + + return get_setting_raw (screen, name, value); +} + +static gboolean +get_setting_raw (GdkScreen *screen, + const gchar *name, + GValue *value) +{ const char *xsettings_name = NULL; XSettingsResult result; @@ -3043,7 +3299,7 @@ gdk_screen_get_setting (GdkScreen *screen, break; } - if (!xsettings_name) + if (!xsettings_name || !screen_x11->xsettings_client) goto out; result = xsettings_client_get_setting (screen_x11->xsettings_client, diff --git a/gdk/x11/gdkgc-x11.c b/gdk/x11/gdkgc-x11.c index 11f610e90..36c74c007 100644 --- a/gdk/x11/gdkgc-x11.c +++ b/gdk/x11/gdkgc-x11.c @@ -42,7 +42,8 @@ typedef enum { static void gdk_x11_gc_values_to_xvalues (GdkGCValues *values, GdkGCValuesMask mask, XGCValues *xvalues, - unsigned long *xvalues_mask); + unsigned long *xvalues_mask, + gint scale); static void gdk_x11_gc_get_values (GdkGC *gc, GdkGCValues *values); @@ -82,6 +83,7 @@ gdk_gc_x11_finalize (GObject *object) GdkGCX11 *x11_gc = GDK_GC_X11 (object); XFreeGC (GDK_GC_XDISPLAY (x11_gc), GDK_GC_XGC (x11_gc)); + g_free (x11_gc->dashes); G_OBJECT_CLASS (_gdk_gc_x11_parent_class)->finalize (object); } @@ -112,6 +114,8 @@ _gdk_x11_gc_new (GdkDrawable *drawable, private->have_clip_mask = FALSE; private->screen = GDK_DRAWABLE_IMPL_X11 (drawable)->screen; + private->scale = GDK_DRAWABLE_IMPL_X11 (drawable)->scale; + private->line_width = (values_mask & GDK_GC_LINE_WIDTH) ? values->line_width : 0; private->depth = gdk_drawable_get_depth (drawable); @@ -137,7 +141,14 @@ _gdk_x11_gc_new (GdkDrawable *drawable, xvalues.graphics_exposures = False; xvalues_mask = GCFunction | GCFillStyle | GCArcMode | GCSubwindowMode | GCGraphicsExposures; - gdk_x11_gc_values_to_xvalues (values, values_mask, &xvalues, &xvalues_mask); + if (private->scale > 1) + { + xvalues.line_width = private->scale; + xvalues_mask |= GCLineWidth; + } + + gdk_x11_gc_values_to_xvalues (values, values_mask, &xvalues, &xvalues_mask, + private->scale); private->xgc = XCreateGC (GDK_GC_XDISPLAY (gc), GDK_DRAWABLE_IMPL_X11 (drawable)->xid, @@ -158,8 +169,19 @@ _gdk_x11_gc_flush (GdkGC *gc) GdkRegion *clip_region = _gdk_gc_get_clip_region (gc); if (!clip_region) - XSetClipOrigin (xdisplay, xgc, - gc->clip_x_origin, gc->clip_y_origin); + { + XSetClipOrigin (xdisplay, xgc, + gc->clip_x_origin * private->scale, + gc->clip_y_origin * private->scale); + private->clip_sent = FALSE; + } + /* drawing to a window inside the paint of a parent moves the + * clip origin there and back for every drawing; the server has + * the rectangles at that origin from the last one already */ + else if (private->clip_sent && + private->sent_clip_x == gc->clip_x_origin && + private->sent_clip_y == gc->clip_y_origin) + ; else { XRectangle *rectangles; @@ -168,6 +190,7 @@ _gdk_x11_gc_flush (GdkGC *gc) _gdk_region_get_xrectangles (clip_region, gc->clip_x_origin, gc->clip_y_origin, + private->scale, &rectangles, &n_rects); @@ -176,19 +199,80 @@ _gdk_x11_gc_flush (GdkGC *gc) n_rects, YXBanded); g_free (rectangles); + + private->clip_sent = TRUE; + private->sent_clip_x = gc->clip_x_origin; + private->sent_clip_y = gc->clip_y_origin; } } - if (private->dirty_mask & GDK_GC_DIRTY_TS) + if ((private->dirty_mask & GDK_GC_DIRTY_TS) && + !(private->ts_sent && + private->sent_ts_x == gc->ts_x_origin && + private->sent_ts_y == gc->ts_y_origin)) { XSetTSOrigin (xdisplay, xgc, - gc->ts_x_origin, gc->ts_y_origin); + gc->ts_x_origin * private->scale, + gc->ts_y_origin * private->scale); + private->ts_sent = TRUE; + private->sent_ts_x = gc->ts_x_origin; + private->sent_ts_y = gc->ts_y_origin; } private->dirty_mask = 0; return xgc; } +static gint +device_line_width (gint width, + gint scale) +{ + if (scale <= 1) + return width; + return width <= 1 ? scale : width * scale; +} + +static void +send_dashes (GdkGCX11 *private) +{ + gint i; + gchar *list; + + if (!private->dashes) + return; + + list = g_new (gchar, private->n_dashes); + for (i = 0; i < private->n_dashes; i++) + list[i] = CLAMP ((guint8) private->dashes[i] * private->scale, 1, 255); + XSetDashes (GDK_SCREEN_XDISPLAY (private->screen), private->xgc, + private->dash_offset * private->scale, list, private->n_dashes); + g_free (list); +} + +/* The X GC set for drawables of another scale: widths, dashes, the clip + * and the tile origin of the X server change with it */ +GC +_gdk_x11_gc_flush_scaled (GdkGC *gc, + gint scale) +{ + GdkGCX11 *private = GDK_GC_X11 (gc); + + if (private->scale != scale) + { + XGCValues xvalues; + + private->scale = scale; + xvalues.line_width = device_line_width (private->line_width, scale); + XChangeGC (GDK_GC_XDISPLAY (gc), private->xgc, GCLineWidth, &xvalues); + send_dashes (private); + private->dirty_mask |= GDK_GC_DIRTY_CLIP | GDK_GC_DIRTY_TS; + private->clip_sent = FALSE; + private->ts_sent = FALSE; + } + + return private->dirty_mask ? _gdk_x11_gc_flush (gc) : private->xgc; +} + static void gdk_x11_gc_get_values (GdkGC *gc, GdkGCValues *values) @@ -283,12 +367,13 @@ gdk_x11_gc_get_values (GdkGC *gc, xvalues.stipple); values->clip_mask = NULL; values->subwindow_mode = xvalues.subwindow_mode; - values->ts_x_origin = xvalues.ts_x_origin; - values->ts_y_origin = xvalues.ts_y_origin; - values->clip_x_origin = xvalues.clip_x_origin; - values->clip_y_origin = xvalues.clip_y_origin; + /* those of GDK, not of the X server */ + values->ts_x_origin = gc->ts_x_origin; + values->ts_y_origin = gc->ts_y_origin; + values->clip_x_origin = gc->clip_x_origin; + values->clip_y_origin = gc->clip_y_origin; values->graphics_exposures = xvalues.graphics_exposures; - values->line_width = xvalues.line_width; + values->line_width = GDK_GC_X11 (gc)->line_width; switch (xvalues.line_style) { @@ -365,14 +450,21 @@ gdk_x11_gc_set_values (GdkGC *gc, { x11_gc->have_clip_region = FALSE; x11_gc->have_clip_mask = values->clip_mask != NULL; + x11_gc->clip_sent = FALSE; } - gdk_x11_gc_values_to_xvalues (values, values_mask, &xvalues, &xvalues_mask); + if (values_mask & GDK_GC_LINE_WIDTH) + x11_gc->line_width = values->line_width; - XChangeGC (GDK_GC_XDISPLAY (gc), - GDK_GC_XGC (gc), - xvalues_mask, - &xvalues); + gdk_x11_gc_values_to_xvalues (values, values_mask, &xvalues, &xvalues_mask, + x11_gc->scale); + + /* origins alone only mark the GC for the next flush */ + if (xvalues_mask) + XChangeGC (GDK_GC_XDISPLAY (gc), + GDK_GC_XGC (gc), + xvalues_mask, + &xvalues); } static void @@ -381,18 +473,40 @@ gdk_x11_gc_set_dashes (GdkGC *gc, gint8 dash_list[], gint n) { + GdkGCX11 *x11_gc = GDK_GC_X11 (gc); + g_return_if_fail (GDK_IS_GC (gc)); g_return_if_fail (dash_list != NULL); - XSetDashes (GDK_GC_XDISPLAY (gc), GDK_GC_XGC (gc), - dash_offset, (char *)dash_list, n); + if (x11_gc->scale <= 1) + { + XSetDashes (GDK_GC_XDISPLAY (gc), GDK_GC_XGC (gc), + dash_offset, (char *)dash_list, n); + g_free (x11_gc->dashes); + x11_gc->dashes = NULL; + } + + /* kept for a scale of the X server */ + if (x11_gc->dashes != dash_list) + { + gint8 *copy = memcpy (g_new (gint8, n), dash_list, n); + + g_free (x11_gc->dashes); + x11_gc->dashes = copy; + } + x11_gc->n_dashes = n; + x11_gc->dash_offset = dash_offset; + + if (x11_gc->scale > 1) + send_dashes (x11_gc); } static void gdk_x11_gc_values_to_xvalues (GdkGCValues *values, GdkGCValuesMask mask, XGCValues *xvalues, - unsigned long *xvalues_mask) + unsigned long *xvalues_mask, + gint scale) { /* Optimization for the common case (gdk_gc_new()) */ if (values == NULL || mask == 0) @@ -549,7 +663,7 @@ gdk_x11_gc_values_to_xvalues (GdkGCValues *values, if (mask & GDK_GC_LINE_WIDTH) { - xvalues->line_width = values->line_width; + xvalues->line_width = device_line_width (values->line_width, scale); *xvalues_mask |= GCLineWidth; } if (mask & GDK_GC_LINE_STYLE) @@ -623,6 +737,7 @@ _gdk_windowing_gc_set_clip_region (GdkGC *gc, } x11_gc->have_clip_region = region != NULL; + x11_gc->clip_sent = FALSE; if (reset_origin) { @@ -646,6 +761,19 @@ _gdk_windowing_gc_copy (GdkGC *dst_gc, x11_dst_gc->dirty_mask = x11_src_gc->dirty_mask; x11_dst_gc->have_clip_region = x11_src_gc->have_clip_region; x11_dst_gc->have_clip_mask = x11_src_gc->have_clip_mask; + x11_dst_gc->clip_sent = x11_src_gc->clip_sent; + x11_dst_gc->sent_clip_x = x11_src_gc->sent_clip_x; + x11_dst_gc->sent_clip_y = x11_src_gc->sent_clip_y; + x11_dst_gc->ts_sent = x11_src_gc->ts_sent; + x11_dst_gc->sent_ts_x = x11_src_gc->sent_ts_x; + x11_dst_gc->sent_ts_y = x11_src_gc->sent_ts_y; + x11_dst_gc->scale = x11_src_gc->scale; + x11_dst_gc->line_width = x11_src_gc->line_width; + x11_dst_gc->dash_offset = x11_src_gc->dash_offset; + x11_dst_gc->n_dashes = x11_src_gc->n_dashes; + g_free (x11_dst_gc->dashes); + x11_dst_gc->dashes = x11_src_gc->dashes ? + memcpy (g_new (gint8, x11_src_gc->n_dashes), x11_src_gc->dashes, x11_src_gc->n_dashes) : NULL; } /** @@ -703,9 +831,18 @@ gdk_x11_gc_get_xgc (GdkGC *gc) gc_x11 = GDK_GC_X11 (gc); + /* drawing with the X GC directly gets the clip the GC has, without + * the one of the window it was last drawn to inside a paint */ + _gdk_gc_remove_kept_drawable_clip (gc); + if (gc_x11->dirty_mask) _gdk_x11_gc_flush (gc); + /* the caller may change the clip and the tile origin of the X GC + * itself: the next flush sends them again */ + gc_x11->clip_sent = FALSE; + gc_x11->ts_sent = FALSE; + return gc_x11->xgc; } diff --git a/gdk/x11/gdkgeometry-x11.c b/gdk/x11/gdkgeometry-x11.c index b6c5c9030..c68a80fa6 100644 --- a/gdk/x11/gdkgeometry-x11.c +++ b/gdk/x11/gdkgeometry-x11.c @@ -91,9 +91,10 @@ _gdk_window_move_resize_child (GdkWindow *window, _gdk_x11_window_tmp_unset_bg (window, TRUE); XMoveResizeWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window), - obj->x + obj->parent->abs_x, - obj->y + obj->parent->abs_y, - width, height); + (obj->x + obj->parent->abs_x) * GDK_X11_WINDOW_SCALE (window), + (obj->y + obj->parent->abs_y) * GDK_X11_WINDOW_SCALE (window), + width * GDK_X11_WINDOW_SCALE (window), + height * GDK_X11_WINDOW_SCALE (window)); _gdk_x11_window_tmp_reset_parent_bg (window); _gdk_x11_window_tmp_reset_bg (window, TRUE); } @@ -158,6 +159,19 @@ queue_item_free (GdkWindowQueueItem *item) g_free (item); } +void +_gdk_x11_display_free_translate_queue (GdkDisplay *display) +{ + GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display); + + if (display_x11->translate_queue) + { + g_queue_foreach (display_x11->translate_queue, (GFunc) queue_item_free, NULL); + g_queue_free (display_x11->translate_queue); + display_x11->translate_queue = NULL; + } +} + static void gdk_window_queue (GdkWindow *window, GdkWindowQueueItem *item) @@ -243,7 +257,7 @@ _gdk_x11_window_queue_translation (GdkWindow *window, serial from NextRequest in gdk_window_queue, i.e. the the serial for the XCopyArea, not the ones from flushing the gc. */ - _gdk_x11_gc_flush (gc); + _gdk_x11_gc_flush_scaled (gc, GDK_X11_WINDOW_SCALE (window)); gdk_window_queue (window, item); } diff --git a/gdk/x11/gdkimage-x11.c b/gdk/x11/gdkimage-x11.c index 65616271e..9c61e6e16 100644 --- a/gdk/x11/gdkimage-x11.c +++ b/gdk/x11/gdkimage-x11.c @@ -270,6 +270,13 @@ _gdk_image_new_for_depth (GdkScreen *screen, goto error; } + /* GdkImage has one byte order for bytes and bits; a server + * whose bitmap bit order differs gets an unshared image, + * which Xlib converts */ + if (private->ximage->bits_per_pixel == 1 && + private->ximage->bitmap_bit_order != private->ximage->byte_order) + goto error; + x_shm_info->shmid = shmget (IPC_PRIVATE, private->ximage->bytes_per_line * private->ximage->height, IPC_CREAT | 0600); @@ -335,6 +342,8 @@ _gdk_image_new_for_depth (GdkScreen *screen, case GDK_IMAGE_NORMAL: private->ximage = XCreateImage (screen_x11->xdisplay, xvisual, depth, ZPixmap, 0, NULL, width, height, 32, 0); + if (private->ximage->bits_per_pixel == 1) + private->ximage->bitmap_bit_order = private->ximage->byte_order; /* Use malloc, not g_malloc here, because X will call free() * on this data @@ -457,6 +466,73 @@ get_full_image (GdkDrawable *drawable, return image; } +/* HiDPI: the pixels of GDK, each the first of its block on the X server */ +static GdkImage * +copy_to_image_scaled (GdkDrawableImplX11 *impl, + GdkImage *image, + gint src_x, + gint src_y, + gint dest_x, + gint dest_y, + gint width, + gint height) +{ + GdkDrawable *drawable = GDK_DRAWABLE (impl); + Display *xdisplay = GDK_SCREEN_XDISPLAY (impl->screen); + gint s = impl->scale, i, j; + GdkRectangle req = { src_x, src_y, width, height }, avail = { 0, 0, 0, 0 }; + XImage *dev; + gboolean created = FALSE; + + gdk_drawable_get_size (impl->wrapper, &avail.width, &avail.height); + if (GDK_IS_WINDOW_IMPL_X11 (drawable)) + { + /* only what is on the screen can be read */ + GdkRectangle screen_rect; + Window child; + gint rx = 0, ry = 0; + + XTranslateCoordinates (xdisplay, impl->xid, GDK_SCREEN_XROOTWIN (impl->screen), + 0, 0, &rx, &ry, &child); + screen_rect.x = - _gdk_x11_unscale (rx, s); + screen_rect.y = - _gdk_x11_unscale (ry, s); + screen_rect.width = gdk_screen_get_width (impl->screen); + screen_rect.height = gdk_screen_get_height (impl->screen); + if (!gdk_rectangle_intersect (&avail, &screen_rect, &avail)) + return image; + } + if (!gdk_rectangle_intersect (&req, &avail, &req)) + return image; + + gdk_error_trap_push (); + dev = XGetImage (xdisplay, impl->xid, req.x * s, req.y * s, req.width * s, req.height * s, + AllPlanes, ZPixmap); + gdk_error_trap_pop (); + if (!dev) + return image; + + if (!image) + { + image = _gdk_image_new_for_depth (impl->screen, GDK_IMAGE_NORMAL, + gdk_drawable_get_visual (drawable), width, height, + gdk_drawable_get_depth (drawable)); + created = TRUE; + } + if (image) + { + XImage *ximage = PRIVATE_DATA (image)->ximage; + + for (j = 0; j < req.height; j++) + for (i = 0; i < req.width; i++) + XPutPixel (ximage, dest_x + req.x - src_x + i, dest_y + req.y - src_y + j, + XGetPixel (dev, i * s, j * s)); + } + XDestroyImage (dev); + (void) created; + + return image; +} + GdkImage* _gdk_x11_copy_to_image (GdkDrawable *drawable, GdkImage *image, @@ -497,6 +573,9 @@ _gdk_x11_copy_to_image (GdkDrawable *drawable, have_grab = FALSE; } \ } G_STMT_END + if (impl->scale > 1) + return copy_to_image_scaled (impl, image, src_x, src_y, dest_x, dest_y, width, height); + if (!image && !GDK_IS_WINDOW_IMPL_X11 (drawable)) return get_full_image (drawable, src_x, src_y, width, height); diff --git a/gdk/x11/gdkinput-x11.c b/gdk/x11/gdkinput-x11.c index bb908e355..35db0ebdf 100644 --- a/gdk/x11/gdkinput-x11.c +++ b/gdk/x11/gdkinput-x11.c @@ -25,6 +25,7 @@ */ #include "config.h" +#include #include "gdkinputprivate.h" #include "gdkinternals.h" #include "gdkx.h" @@ -86,10 +87,16 @@ _gdk_input_get_root_relative_geometry (GdkWindow *window, GDK_WINDOW_XROOTWIN (window), 0, 0, &x, &y, &child); - if (x_ret) - *x_ret = x; - if (y_ret) - *y_ret = y; + /* in root coordinates of GDK */ + { + gdouble rx, ry; + + _gdk_x11_window_device_to_root (window, x, y, &rx, &ry); + if (x_ret) + *x_ret = (gint) floor (rx); + if (y_ret) + *y_ret = (gint) floor (ry); + } } static GdkDevicePrivate * diff --git a/gdk/x11/gdkkeys-x11.c b/gdk/x11/gdkkeys-x11.c index 6479aa0ef..9a270e5de 100644 --- a/gdk/x11/gdkkeys-x11.c +++ b/gdk/x11/gdkkeys-x11.c @@ -86,6 +86,7 @@ struct _GdkKeymapX11 PangoDirection current_direction; guint sun_keypad : 1; guint have_direction : 1; + guint have_lock_state : 1; guint caps_lock_state : 1; guint current_serial; @@ -166,6 +167,7 @@ gdk_keymap_x11_init (GdkKeymapX11 *keymap) keymap->group_switch_mask = 0; keymap->lock_keysym = GDK_Caps_Lock; keymap->have_direction = FALSE; + keymap->have_lock_state = FALSE; keymap->current_serial = 0; #ifdef HAVE_XKB @@ -704,13 +706,17 @@ static gboolean update_lock_state (GdkKeymapX11 *keymap_x11, gint locked_mods) { + gboolean have_lock_state; gboolean caps_lock_state; + have_lock_state = keymap_x11->have_lock_state; caps_lock_state = keymap_x11->caps_lock_state; + keymap_x11->have_lock_state = TRUE; keymap_x11->caps_lock_state = (locked_mods & GDK_LOCK_MASK) != 0; - return caps_lock_state != keymap_x11->caps_lock_state; + return !have_lock_state + || caps_lock_state != keymap_x11->caps_lock_state; } /* keep this in sync with the XkbSelectEventDetails() call @@ -852,6 +858,19 @@ gdk_keymap_get_caps_lock_state (GdkKeymap *keymap) keymap_x11 = GDK_KEYMAP_X11 (keymap); +#ifdef HAVE_XKB + /* The lock state is otherwise only tracked from XkbStateNotify + * events, so query it explicitly the first time. + */ + if (KEYMAP_USE_XKB (keymap) && !keymap_x11->have_lock_state) + { + XkbStateRec state_rec; + + XkbGetState (KEYMAP_XDISPLAY (keymap), XkbUseCoreKbd, &state_rec); + update_lock_state (keymap_x11, state_rec.locked_mods); + } +#endif /* HAVE_XKB */ + return keymap_x11->caps_lock_state; } @@ -1238,6 +1257,7 @@ MyEnhancedXkbTranslateKeyCode(register XkbDescPtr xkb, int col,nKeyGroups; unsigned preserve,effectiveGroup; KeySym *syms; + int found_col = 0; if (mods_rtrn!=NULL) *mods_rtrn = 0; @@ -1270,7 +1290,7 @@ MyEnhancedXkbTranslateKeyCode(register XkbDescPtr xkb, break; } } - col= effectiveGroup*XkbKeyGroupsWidth(xkb,key); + found_col = col= effectiveGroup*XkbKeyGroupsWidth(xkb,key); type = XkbKeyKeyType(xkb,key,effectiveGroup); preserve= 0; @@ -1308,7 +1328,7 @@ MyEnhancedXkbTranslateKeyCode(register XkbDescPtr xkb, } if (!found && ((mods&type->mods.mask) == entry->mods.mask)) { - col+= entry->level; + found_col= col + entry->level; if (type->preserve) preserve= type->preserve[i].mask; @@ -1322,7 +1342,7 @@ MyEnhancedXkbTranslateKeyCode(register XkbDescPtr xkb, } if (keysym_rtrn!=NULL) - *keysym_rtrn= syms[col]; + *keysym_rtrn= syms[found_col]; if (mods_rtrn) { /* ---- Begin section modified for GDK ---- */ *mods_rtrn &= ~preserve; @@ -1354,7 +1374,7 @@ MyEnhancedXkbTranslateKeyCode(register XkbDescPtr xkb, /* ---- End stuff GDK adds to the original Xlib version ---- */ - return (syms[col] != NoSymbol); + return (syms[found_col] != NoSymbol); } #endif /* HAVE_XKB */ diff --git a/gdk/x11/gdkmain-x11.c b/gdk/x11/gdkmain-x11.c index 5c8a61fbb..4237f5ba3 100644 --- a/gdk/x11/gdkmain-x11.c +++ b/gdk/x11/gdkmain-x11.c @@ -665,6 +665,7 @@ void _gdk_region_get_xrectangles (const GdkRegion *region, gint x_offset, gint y_offset, + gint scale, XRectangle **rects, gint *n_rects) { @@ -674,10 +675,10 @@ _gdk_region_get_xrectangles (const GdkRegion *region, for (i = 0; i < region->numRects; i++) { - rectangles[i].x = CLAMP (boxes[i].x1 + x_offset, G_MINSHORT, G_MAXSHORT); - rectangles[i].y = CLAMP (boxes[i].y1 + y_offset, G_MINSHORT, G_MAXSHORT); - rectangles[i].width = CLAMP (boxes[i].x2 + x_offset, G_MINSHORT, G_MAXSHORT) - rectangles[i].x; - rectangles[i].height = CLAMP (boxes[i].y2 + y_offset, G_MINSHORT, G_MAXSHORT) - rectangles[i].y; + rectangles[i].x = CLAMP ((boxes[i].x1 + x_offset) * scale, G_MINSHORT, G_MAXSHORT); + rectangles[i].y = CLAMP ((boxes[i].y1 + y_offset) * scale, G_MINSHORT, G_MAXSHORT); + rectangles[i].width = CLAMP ((boxes[i].x2 + x_offset) * scale, G_MINSHORT, G_MAXSHORT) - rectangles[i].x; + rectangles[i].height = CLAMP ((boxes[i].y2 + y_offset) * scale, G_MINSHORT, G_MAXSHORT) - rectangles[i].y; } *rects = rectangles; diff --git a/gdk/x11/gdkpixmap-x11.c b/gdk/x11/gdkpixmap-x11.c index ec6fad76d..4307c0d27 100644 --- a/gdk/x11/gdkpixmap-x11.c +++ b/gdk/x11/gdkpixmap-x11.c @@ -136,6 +136,54 @@ gdk_pixmap_impl_x11_get_size (GdkDrawable *drawable, *height = GDK_PIXMAP_IMPL_X11 (drawable)->height; } +/* HiDPI: a pixmap is as many times bigger on the X server as the + * drawable it is made for (by default the screen's root window) */ +static gint +scale_of (GdkDrawable *drawable) +{ + /* for the root window the scale of the primary monitor (the root + * window has the smallest of all monitors) */ + if (GDK_IS_WINDOW (drawable) && GDK_WINDOW_TYPE (drawable) == GDK_WINDOW_ROOT) + return GDK_SCREEN_X11 (gdk_drawable_get_screen (drawable))->window_scale; + + return _gdk_windowing_drawable_get_scale (drawable); +} + +/* @xpixmap with the pixels of GDK made into blocks of the scale; the + * old one is freed */ +static Pixmap +scale_up_pixmap (Display *xdisplay, + Window xwindow, + Pixmap xpixmap, + gint width, + gint height, + gint depth, + gint scale) +{ + XImage *image, *big; + Pixmap result; + GC xgc; + + if (scale <= 1) + return xpixmap; + + image = XGetImage (xdisplay, xpixmap, 0, 0, width, height, AllPlanes, ZPixmap); + result = XCreatePixmap (xdisplay, xwindow, width * scale, height * scale, depth); + xgc = XCreateGC (xdisplay, result, 0, NULL); + big = image ? _gdk_x11_ximage_scale_up (xdisplay, image, 0, 0, width, height, scale) : NULL; + if (big) + { + XPutImage (xdisplay, result, xgc, big, 0, 0, 0, 0, width * scale, height * scale); + XDestroyImage (big); + } + if (image) + XDestroyImage (image); + XFreeGC (xdisplay, xgc); + XFreePixmap (xdisplay, xpixmap); + + return result; +} + GdkPixmap* _gdk_pixmap_new (GdkDrawable *drawable, gint width, @@ -172,9 +220,11 @@ _gdk_pixmap_new (GdkDrawable *drawable, draw_impl->wrapper = GDK_DRAWABLE (pixmap); draw_impl->screen = GDK_WINDOW_SCREEN (drawable); + draw_impl->scale = scale_of (drawable); draw_impl->xid = XCreatePixmap (GDK_PIXMAP_XDISPLAY (pixmap), GDK_WINDOW_XID (drawable), - width, height, depth); + width * draw_impl->scale, height * draw_impl->scale, + depth); pix_impl->is_foreign = FALSE; pix_impl->width = width; @@ -228,9 +278,12 @@ _gdk_bitmap_create_from_data (GdkDrawable *drawable, GDK_PIXMAP_OBJECT (pixmap)->depth = 1; draw_impl->screen = GDK_WINDOW_SCREEN (drawable); + draw_impl->scale = scale_of (drawable); draw_impl->xid = XCreateBitmapFromData (GDK_WINDOW_XDISPLAY (drawable), GDK_WINDOW_XID (drawable), (char *)data, width, height); + draw_impl->xid = scale_up_pixmap (GDK_WINDOW_XDISPLAY (drawable), GDK_WINDOW_XID (drawable), + draw_impl->xid, width, height, 1, draw_impl->scale); _gdk_xid_table_insert (GDK_WINDOW_DISPLAY (drawable), &GDK_PIXMAP_XID (pixmap), pixmap); @@ -281,10 +334,13 @@ _gdk_pixmap_create_from_data (GdkDrawable *drawable, GDK_PIXMAP_OBJECT (pixmap)->depth = depth; draw_impl->screen = GDK_DRAWABLE_SCREEN (drawable); + draw_impl->scale = scale_of (drawable); draw_impl->xid = XCreatePixmapFromBitmapData (GDK_WINDOW_XDISPLAY (drawable), GDK_WINDOW_XID (drawable), (char *)data, width, height, fg->pixel, bg->pixel, depth); + draw_impl->xid = scale_up_pixmap (GDK_WINDOW_XDISPLAY (drawable), GDK_WINDOW_XID (drawable), + draw_impl->xid, width, height, depth, draw_impl->scale); _gdk_xid_table_insert (GDK_WINDOW_DISPLAY (drawable), &GDK_PIXMAP_XID (pixmap), pixmap); @@ -387,10 +443,12 @@ gdk_pixmap_foreign_new_for_screen (GdkScreen *screen, draw_impl->screen = screen; draw_impl->xid = xpixmap; + /* sizes of the X server: in GDK's, a pixel of it is a block */ + draw_impl->scale = GDK_SCREEN_X11 (screen)->window_scale; pix_impl->is_foreign = TRUE; - pix_impl->width = width; - pix_impl->height = height; + pix_impl->width = MAX (width / draw_impl->scale, 1); + pix_impl->height = MAX (height / draw_impl->scale, 1); GDK_PIXMAP_OBJECT (pixmap)->depth = depth; _gdk_xid_table_insert (gdk_screen_get_display (screen), diff --git a/gdk/x11/gdkprivate-x11.h b/gdk/x11/gdkprivate-x11.h index a7754b024..790f9751c 100644 --- a/gdk/x11/gdkprivate-x11.h +++ b/gdk/x11/gdkprivate-x11.h @@ -60,6 +60,20 @@ struct _GdkGCX11 guint have_clip_region : 1; guint have_clip_mask : 1; guint depth : 8; + /* the clip rectangles and the tile origin last sent to the server, + * for flushes that would send the same again */ + guint clip_sent : 1; + guint ts_sent : 1; + gint sent_clip_x, sent_clip_y; + gint sent_ts_x, sent_ts_y; + + /* HiDPI: the scale of the drawables the X GC is set for, and the + * values of GDK it was set from */ + gint scale; + gint line_width; + gint dash_offset; + gint n_dashes; + gint8 *dashes; }; struct _GdkGCX11Class @@ -99,6 +113,7 @@ gint _gdk_send_xevent (GdkDisplay *display, GType _gdk_gc_x11_get_type (void); gboolean _gdk_x11_have_render (GdkDisplay *display); +gboolean _gdk_x11_running_in_sandbox (void); GdkGC *_gdk_x11_gc_new (GdkDrawable *drawable, GdkGCValues *values, @@ -124,8 +139,13 @@ void _gdk_window_process_expose (GdkWindow *window, gulong serial, GdkRectangle *area); +void _gdk_x11_window_root_coords_changed (void); +void _gdk_x11_window_set_root_origin (GdkWindow *window, + gint x, + gint y); gboolean _gdk_x11_window_queue_antiexpose (GdkWindow *window, GdkRegion *area); +void _gdk_x11_display_free_translate_queue (GdkDisplay *display); void _gdk_x11_window_queue_translation (GdkWindow *window, GdkGC *gc, GdkRegion *area, @@ -135,13 +155,17 @@ void _gdk_x11_window_queue_translation (GdkWindow *window, void _gdk_selection_window_destroyed (GdkWindow *window); gboolean _gdk_selection_filter_clear_event (XSelectionClearEvent *event); +/* in pixels of GDK for the scale (1: of the X server) */ GdkRegion* _xwindow_get_shape (Display *xdisplay, Window window, - gint shape_type); + gint shape_type, + gint scale); +/* the region, moved by the offset, in rectangles of the X server */ void _gdk_region_get_xrectangles (const GdkRegion *region, gint x_offset, gint y_offset, + gint scale, XRectangle **rects, gint *n_rects); @@ -160,6 +184,20 @@ gboolean _gdk_keymap_key_is_modifier (GdkKeymap *keymap, guint keycode); GC _gdk_x11_gc_flush (GdkGC *gc); +XImage *_gdk_x11_ximage_scale_up (Display *xdisplay, XImage *src, gint x, gint y, + gint width, gint height, gint scale); +GC _gdk_x11_gc_flush_scaled (GdkGC *gc, + gint scale); + +/* the X GC for drawing to a drawable of that scale */ +#define GDK_GC_GET_XGC_SCALED(gc, s) \ + (GDK_GC_X11 (gc)->dirty_mask || GDK_GC_X11 (gc)->scale != (s) \ + ? _gdk_x11_gc_flush_scaled ((gc), (s)) : GDK_GC_X11 (gc)->xgc) + +/* where a thin line of GDK goes through the middle of its pixels of the + * X server, with the GC's line as wide as they are */ +#define GDK_GC_X11_THIN_OFFSET(gc, s) \ + ((s) > 1 && GDK_GC_X11 (gc)->line_width <= 1 ? (s) / 2 : 0) void _gdk_x11_initialize_locale (void); @@ -195,6 +233,20 @@ gboolean _gdk_x11_get_xft_setting (GdkScreen *screen, const gchar *name, GValue *value); +void _gdk_x11_scroll_init (GdkDisplay *display); +void _gdk_x11_scroll_finalize (GdkDisplay *display); +void _gdk_x11_scroll_select (GdkWindow *window, + long xevent_mask, + gboolean touch); +void _gdk_x11_scroll_reset (GdkDisplay *display, + gboolean forget_device); +gboolean _gdk_x11_scroll_is_emulated (GdkDisplay *display, + guint32 time); +gboolean _gdk_x11_scroll_translate (GdkDisplay *display, + XEvent *xevent, + XEvent *motion); +GdkEvent *_gdk_x11_scroll_take_pending (GdkDisplay *display); + extern GdkDrawableClass _gdk_x11_drawable_class; extern gboolean _gdk_use_xshm; extern const int _gdk_nenvent_masks; @@ -216,4 +268,75 @@ extern gboolean _gdk_synchronize; #define GDK_GC_DISPLAY(gc) (GDK_SCREEN_DISPLAY (GDK_GC_X11(gc)->screen)) #define GDK_WINDOW_IS_X11(win) (GDK_IS_WINDOW_IMPL_X11 (((GdkWindowObject *)win)->impl)) +/* HiDPI: GDK's coordinates and those of the X server, which are scale + * times as many (see _gdk_x11_screen_new()) */ +#define GDK_X11_IMPL_SCALE(impl) (((GdkDrawableImplX11 *) (impl))->scale) +#define GDK_X11_WINDOW_SCALE(win) GDK_X11_IMPL_SCALE (((GdkWindowObject *) (win))->impl) +#define GDK_X11_SCREEN_SCALE(screen) (GDK_SCREEN_X11 (screen)->window_scale) + +/* HiDPI with monitors of different scales (GdkX11RootAnchor in + * gdkwindow-x11.h) */ +gboolean _gdk_x11_screen_has_mixed_scales (GdkScreen *screen); +gint _gdk_x11_screen_place (GdkScreen *screen, + gboolean device, + gint x, + gint y, + GdkX11RootAnchor *anchor); +void _gdk_x11_screen_device_to_root (GdkScreen *screen, + gdouble dx, + gdouble dy, + gdouble *x, + gdouble *y); +void _gdk_x11_screen_root_to_device (GdkScreen *screen, + gint x, + gint y, + gint *dx, + gint *dy); +void _gdk_x11_screen_rescale_windows (GdkScreen *screen); +void _gdk_x11_screen_update_scales (GdkScreen *screen); + +/* the same as seen from a window: through the monitor its toplevel is on */ +void _gdk_x11_window_device_to_root (GdkWindow *window, + gdouble dx, + gdouble dy, + gdouble *x, + gdouble *y); +void _gdk_x11_window_root_to_device (GdkWindow *window, + gint x, + gint y, + gint *dx, + gint *dy); +gint _gdk_x11_window_update_scale (GdkWindow *window, + gint dx, + gint dy, + gint dwidth, + gint dheight); +#define GDK_X11_DISPLAY_SCALE(display) \ + GDK_X11_SCREEN_SCALE (gdk_display_get_default_screen (display)) + +/* from the X server: rounded down, and for an end rounded up */ +static inline gint +_gdk_x11_unscale (gint value, gint scale) +{ + return value >= 0 ? value / scale : - ((- value + scale - 1) / scale); +} + +static inline gint +_gdk_x11_unscale_up (gint value, gint scale) +{ + return - _gdk_x11_unscale (- value, scale); +} + +/* a rectangle of the X server in GDK's pixels, all of it covered */ +static inline void +_gdk_x11_unscale_rect (GdkRectangle *rect, gint scale) +{ + gint x2 = rect->x + rect->width, y2 = rect->y + rect->height; + + rect->x = _gdk_x11_unscale (rect->x, scale); + rect->y = _gdk_x11_unscale (rect->y, scale); + rect->width = _gdk_x11_unscale_up (x2, scale) - rect->x; + rect->height = _gdk_x11_unscale_up (y2, scale) - rect->y; +} + #endif /* __GDK_PRIVATE_X11_H__ */ diff --git a/gdk/x11/gdkproperty-x11.c b/gdk/x11/gdkproperty-x11.c index 8d1ed21e6..47a337965 100644 --- a/gdk/x11/gdkproperty-x11.c +++ b/gdk/x11/gdkproperty-x11.c @@ -28,6 +28,7 @@ #include #include #include +#include #include "gdk.h" /* For gdk_error_trap_push/pop() */ #include "gdkx.h" @@ -524,6 +525,188 @@ gdk_x11_get_xatom_name (Atom xatom) return get_atom_name (gdk_x11_xatom_to_atom (xatom)); } +/* HiDPI: the properties of the window manager specification that hold + * sizes and positions are in pixels of the X server; programs give and + * read them through GDK in its own (panels set struts, pagers read the + * work area), so they are translated on the way: sizes by the scale of + * the window (for the root window the smallest of the screen), positions + * as root coordinates seen from the window (see + * _gdk_x11_window_root_to_device ()), struts from the edges of the + * screen. */ +typedef enum +{ + GEOMETRY_NONE, + GEOMETRY_SIZES, /* each value a size */ + GEOMETRY_STRUT, /* left, right, top, bottom */ + GEOMETRY_STRUT_PARTIAL, /* and where along the edges */ + GEOMETRY_ROOT_RECTS, /* x, y, width, height in root coordinates */ + GEOMETRY_ROOT_POINTS /* x, y in root coordinates */ +} GeometryKind; + +static GeometryKind +geometry_property_kind (GdkDisplay *display, + GdkWindow *window, + Atom xproperty, + Atom xtype, + gint format) +{ + static const struct { const char *name; GeometryKind kind; } props[] = { + { "_NET_WM_STRUT", GEOMETRY_STRUT }, + { "_NET_WM_STRUT_PARTIAL", GEOMETRY_STRUT_PARTIAL }, + { "_NET_WM_ICON_GEOMETRY", GEOMETRY_ROOT_RECTS }, + { "_NET_WORKAREA", GEOMETRY_ROOT_RECTS }, + { "_NET_DESKTOP_GEOMETRY", GEOMETRY_SIZES }, + { "_NET_DESKTOP_VIEWPORT", GEOMETRY_ROOT_POINTS }, + { "_NET_FRAME_EXTENTS", GEOMETRY_SIZES }, + { "_GTK_FRAME_EXTENTS", GEOMETRY_SIZES }, + { "_NET_WM_OPAQUE_REGION", GEOMETRY_SIZES }, + { "_KDE_NET_WM_FRAME_STRUT", GEOMETRY_SIZES }, + { "_NET_REQUEST_FRAME_EXTENTS", GEOMETRY_SIZES } + }; + gint i; + + if (format != 32 || xtype != XA_CARDINAL || !window || GDK_WINDOW_DESTROYED (window)) + return GEOMETRY_NONE; + + if (GDK_X11_WINDOW_SCALE (window) <= 1 && + !_gdk_x11_screen_has_mixed_scales (GDK_WINDOW_SCREEN (window))) + return GEOMETRY_NONE; + + for (i = 0; i < G_N_ELEMENTS (props); i++) + if (xproperty == gdk_x11_get_xatom_by_name_for_display (display, props[i].name)) + return props[i].kind; + + return GEOMETRY_NONE; +} + +/* a point of root coordinates, to the X server or back */ +static void +geometry_point (GdkWindow *window, + gboolean to_device, + long x, + long y, + long *rx, + long *ry) +{ + if (to_device) + { + gint dx, dy; + + _gdk_x11_window_root_to_device (window, x, y, &dx, &dy); + *rx = dx; + *ry = dy; + } + else + { + gdouble gx, gy; + + _gdk_x11_window_device_to_root (window, x, y, &gx, &gy); + *rx = (long) floor (gx); + *ry = (long) floor (gy); + } +} + +static void +translate_geometry (GdkWindow *window, + GeometryKind kind, + long *v, + gulong n, + gboolean to_device) +{ + GdkScreen *screen = GDK_WINDOW_SCREEN (window); + gint scale = GDK_X11_WINDOW_SCALE (window); + long w[2], h[2], x, y; + gulong i; + + /* the size of the screen in GDK's and in the X server's pixels */ + w[0] = gdk_screen_get_width (screen); + h[0] = gdk_screen_get_height (screen); + w[1] = WidthOfScreen (GDK_SCREEN_XSCREEN (screen)); + h[1] = HeightOfScreen (GDK_SCREEN_XSCREEN (screen)); + + switch (kind) + { + case GEOMETRY_NONE: + break; + + case GEOMETRY_SIZES: + for (i = 0; i < n; i++) + v[i] = to_device ? v[i] * scale : _gdk_x11_unscale (v[i], scale); + break; + + case GEOMETRY_STRUT_PARTIAL: + /* where along the edges: left and right y, top and bottom x; the + * ends are the last pixels */ + for (i = 4; i + 1 < n && i < 12; i += 2) + { + gboolean along_x = i >= 8; + long a, b; + + /* only for an edge that has a strut */ + if (!v[(i - 4) / 2]) + continue; + + geometry_point (window, to_device, along_x ? v[i] : 0, along_x ? 0 : v[i], &x, &y); + a = along_x ? x : y; + geometry_point (window, to_device, along_x ? v[i + 1] + 1 : 0, along_x ? 0 : v[i + 1] + 1, &x, &y); + b = (along_x ? x : y) - 1; + v[i] = a; + v[i + 1] = MAX (b, a); + } + /* fall through */ + + case GEOMETRY_STRUT: + { + gint from = to_device ? 0 : 1, to = to_device ? 1 : 0; + + if (n > 0 && v[0]) + { + geometry_point (window, to_device, v[0], 0, &x, &y); + v[0] = x; + } + if (n > 1 && v[1]) + { + geometry_point (window, to_device, w[from] - v[1], 0, &x, &y); + v[1] = w[to] - x; + } + if (n > 2 && v[2]) + { + geometry_point (window, to_device, 0, v[2], &x, &y); + v[2] = y; + } + if (n > 3 && v[3]) + { + geometry_point (window, to_device, 0, h[from] - v[3], &x, &y); + v[3] = h[to] - y; + } + } + break; + + case GEOMETRY_ROOT_RECTS: + for (i = 0; i + 3 < n; i += 4) + { + long x2, y2; + + geometry_point (window, to_device, v[i] + v[i + 2], v[i + 1] + v[i + 3], &x2, &y2); + geometry_point (window, to_device, v[i], v[i + 1], &x, &y); + v[i] = x; + v[i + 1] = y; + v[i + 2] = MAX (x2 - x, 0); + v[i + 3] = MAX (y2 - y, 0); + } + break; + + case GEOMETRY_ROOT_POINTS: + for (i = 0; i + 1 < n; i += 2) + { + geometry_point (window, to_device, v[i], v[i + 1], &x, &y); + v[i] = x; + v[i + 1] = y; + } + break; + } +} + gboolean gdk_property_get (GdkWindow *window, GdkAtom property, @@ -662,6 +845,12 @@ gdk_property_get (GdkWindow *window, memcpy (*data, ret_data, ret_length); if (actual_length) *actual_length = ret_length; + + if (ret_format == 32) + translate_geometry (window, + geometry_property_kind (display, window, xproperty, + ret_prop_type, ret_format), + (long *) *data, ret_nitems, FALSE); } } @@ -728,6 +917,18 @@ gdk_property_change (GdkWindow *window, format, mode, (guchar *)xatoms, nelements); g_free (xatoms); } + else if (geometry_property_kind (display, window, xproperty, xtype, format) != GEOMETRY_NONE) + { + long *scaled = g_new (long, MAX (nelements, 1)); + + memcpy (scaled, data, sizeof (long) * nelements); + translate_geometry (window, + geometry_property_kind (display, window, xproperty, xtype, format), + scaled, nelements, TRUE); + XChangeProperty (GDK_DISPLAY_XDISPLAY (display), xwindow, xproperty, + xtype, format, mode, (guchar *)scaled, nelements); + g_free (scaled); + } else XChangeProperty (GDK_DISPLAY_XDISPLAY (display), xwindow, xproperty, xtype, format, mode, (guchar *)data, nelements); diff --git a/gdk/x11/gdkscreen-x11.c b/gdk/x11/gdkscreen-x11.c index b0cf48029..12bc4a09f 100644 --- a/gdk/x11/gdkscreen-x11.c +++ b/gdk/x11/gdkscreen-x11.c @@ -25,6 +25,8 @@ #include #include +#include +#include #include #include "gdkscreen.h" @@ -32,6 +34,7 @@ #include "gdkdisplay.h" #include "gdkdisplay-x11.h" #include "gdkx.h" +#include "xsettings-client.h" #include "gdkalias.h" #include @@ -68,12 +71,15 @@ G_DEFINE_TYPE (GdkScreenX11, _gdk_screen_x11, GDK_TYPE_SCREEN) struct _GdkX11Monitor { - GdkRectangle geometry; + GdkRectangle geometry; /* in pixels of GDK (see scale_monitors ()) */ + GdkRectangle device; /* of the X server */ + gint scale; /* HiDPI: pixels of the X server per pixel of GDK */ XID output; int width_mm; int height_mm; char * output_name; char * manufacturer; + int dpi; /* the output's own, 0 for none */ }; static void @@ -98,6 +104,8 @@ _gdk_screen_x11_class_init (GdkScreenX11Class *klass) static void _gdk_screen_x11_init (GdkScreenX11 *screen) { + screen->window_scale = 1; + screen->root_scale = 1; } /** @@ -132,7 +140,7 @@ gdk_screen_get_width (GdkScreen *screen) { g_return_val_if_fail (GDK_IS_SCREEN (screen), 0); - return WidthOfScreen (GDK_SCREEN_X11 (screen)->xscreen); + return WidthOfScreen (GDK_SCREEN_X11 (screen)->xscreen) / GDK_SCREEN_X11 (screen)->root_scale; } /** @@ -150,7 +158,7 @@ gdk_screen_get_height (GdkScreen *screen) { g_return_val_if_fail (GDK_IS_SCREEN (screen), 0); - return HeightOfScreen (GDK_SCREEN_X11 (screen)->xscreen); + return HeightOfScreen (GDK_SCREEN_X11 (screen)->xscreen) / GDK_SCREEN_X11 (screen)->root_scale; } /** @@ -642,6 +650,7 @@ init_monitor_geometry (GdkX11Monitor *monitor, monitor->height_mm = -1; monitor->output_name = NULL; monitor->manufacturer = NULL; + monitor->dpi = 0; } static gboolean @@ -741,6 +750,8 @@ monitor_compare_function (GdkX11Monitor *monitor1, #endif #ifdef HAVE_RANDR15 +static int output_dpi (Display *dpy, RROutput output); + static gboolean init_randr15 (GdkScreen *screen) { @@ -752,6 +763,7 @@ init_randr15 (GdkScreen *screen) int i; GArray *monitors; XID primary_output = None; + gchar *primary_name = NULL; if (!display_x11->have_randr15) return FALSE; @@ -776,9 +788,27 @@ init_randr15 (GdkScreen *screen) monitor.width_mm = rr_monitors[i].mwidth; monitor.height_mm = rr_monitors[i].mheight; - monitor.output = rr_monitors[i].outputs[0]; + /* a monitor set by a client (xrandr --setmonitor) may have no + * output */ + monitor.output = rr_monitors[i].noutput > 0 ? rr_monitors[i].outputs[0] : None; + if (rr_monitors[i].name != None) + { + char *name = XGetAtomName (x11_screen->xdisplay, rr_monitors[i].name); + + if (name) + { + monitor.output_name = g_strdup (name); + XFree (name); + } + } + if (monitor.output != None) + monitor.dpi = output_dpi (x11_screen->xdisplay, monitor.output); if (rr_monitors[i].primary) - primary_output = monitor.output; + { + primary_output = monitor.output; + g_free (primary_name); + primary_name = g_strdup (monitor.output_name); + } g_array_append_val (monitors, monitor); } @@ -793,17 +823,58 @@ init_randr15 (GdkScreen *screen) for (i = 0; i < x11_screen->n_monitors; i++) { - if (x11_screen->monitors[i].output == primary_output) + if (primary_output != None + ? x11_screen->monitors[i].output == primary_output + : primary_name && g_strcmp0 (x11_screen->monitors[i].output_name, primary_name) == 0) { x11_screen->primary_monitor = i; break; } } + g_free (primary_name); + return x11_screen->n_monitors > 0; } #endif +#ifdef HAVE_RANDR +/* The resolution an output of the X server gives itself: the property + * "Xft.dpi" of RandR, as proposed for Xlibre (X11Libre/xserver#208), + * in dots per inch or, from 1024 on, in 1024ths of them as XSETTINGS + * has Xft/DPI; 0 where there is none */ +static int +output_dpi (Display *dpy, + RROutput output) +{ + Atom actual_type, prop = XInternAtom (dpy, "Xft.dpi", True); + int actual_format, dpi = 0; + unsigned long nitems, bytes_after; + unsigned char *data = NULL; + + if (prop == None) + return 0; + + if (XRRGetOutputProperty (dpy, output, prop, 0, 1, False, False, AnyPropertyType, + &actual_type, &actual_format, &nitems, &bytes_after, + &data) == Success && data && nitems >= 1) + { + if (actual_format == 32) + dpi = (int) ((long *) data)[0]; + else if (actual_format == 16) + dpi = ((short *) data)[0]; + else if (actual_type == XA_STRING || actual_format == 8) + dpi = atoi ((char *) data); + } + if (data) + XFree (data); + + if (dpi >= 1024 * 10) + dpi /= 1024; + return dpi > 0 && dpi < 2000 ? dpi : 0; +} +#endif + static gboolean init_randr13 (GdkScreen *screen) { @@ -832,8 +903,21 @@ init_randr13 (GdkScreen *screen) for (i = 0; i < resources->noutput; ++i) { - XRROutputInfo *output = - XRRGetOutputInfo (dpy, resources, resources->outputs[i]); + XRROutputInfo *output; + gint error; + + /* an output can go away before we ask about it; the X error + * this gives must not end the program */ + gdk_error_trap_push (); + output = XRRGetOutputInfo (dpy, resources, resources->outputs[i]); + error = gdk_error_trap_pop (); + + if (output == NULL || error) + { + if (output) + XRRFreeOutputInfo (output); + continue; + } /* Non RandR1.2 X driver have output name "default" */ randr12_compat |= !g_strcmp0 (output->name, "default"); @@ -847,7 +931,19 @@ init_randr13 (GdkScreen *screen) if (output->crtc) { GdkX11Monitor monitor; - XRRCrtcInfo *crtc = XRRGetCrtcInfo (dpy, resources, output->crtc); + XRRCrtcInfo *crtc; + + gdk_error_trap_push (); + crtc = XRRGetCrtcInfo (dpy, resources, output->crtc); + error = gdk_error_trap_pop (); + + if (crtc == NULL || error) + { + if (crtc) + XRRFreeCrtcInfo (crtc); + XRRFreeOutputInfo (output); + continue; + } monitor.geometry.x = crtc->x; monitor.geometry.y = crtc->y; @@ -860,6 +956,7 @@ init_randr13 (GdkScreen *screen) monitor.output_name = g_strdup (output->name); /* FIXME: need EDID parser */ monitor.manufacturer = NULL; + monitor.dpi = output_dpi (dpy, resources->outputs[i]); g_array_append_val (monitors, monitor); @@ -1036,7 +1133,8 @@ compare_monitor (GdkX11Monitor *m1, return FALSE; if (m1->width_mm != m2->width_mm || - m1->height_mm != m2->height_mm) + m1->height_mm != m2->height_mm || + m1->scale != m2->scale) return FALSE; if (g_strcmp0 (m1->output_name, m2->output_name) != 0) @@ -1112,6 +1210,390 @@ init_multihead (GdkScreen *screen) HeightOfScreen (screen_x11->xscreen)); } +/* HiDPI. GDK and GTK+ keep their coordinates in pixels of the old size; + * on a screen of high density each of them becomes window_scale pixels + * of the X server in each direction, and all is drawn at the resolution + * of the X server: sharp text, lines and icons in the same proportions + * (as GTK+ 3 does on X11). The scale comes, in this order, from + * + * - GDK_SCALE (as GTK+ 3; 1 turns it off), + * - XSETTINGS Gdk/WindowScalingFactor, which GNOME, KDE Plasma (also + * for Xwayland when it lets programs scale themselves), MATE, Xfce and + * Cinnamon set, + * - the resolution of the primary monitor, if the X server gives one + * for each output (Xlibre), + * - Xft/DPI of XSETTINGS or the resource Xft.dpi: 192 makes 2, 288 + * makes 3; what remains of a fraction stays with the fonts (144 keeps + * 1 with fonts of 144 dpi, as before). + * + * Programs that draw on their X windows themselves with the sizes of + * GDK (some browsers, video players) would draw too small; they keep + * scale 1, as do those named in GDK_UNSCALED_PROGRAMS (separated by + * colons). Without cairo 1.14 the scale is always 1. */ + +#define MAX_WINDOW_SCALE 8 + +static gint +scale_for_dpi (gdouble dpi) +{ + return CLAMP ((gint) floor (dpi / 96.0 + 0.25), 1, MAX_WINDOW_SCALE); +} + +static gboolean +read_xsetting_int (GdkScreenX11 *screen_x11, + const char *name, + gint *value) +{ + XSettingsClient *client; + XSettingsSetting *setting = NULL; + gboolean found = FALSE; + + if (g_getenv ("GDK_NO_XSETTINGS")) + return FALSE; + + /* the screen's own client once it has one */ + if (screen_x11->xsettings_client) + { + if (xsettings_client_get_setting (screen_x11->xsettings_client, name, &setting) == XSETTINGS_SUCCESS && + setting && setting->type == XSETTINGS_TYPE_INT) + { + *value = setting->data.v_int; + found = TRUE; + } + if (setting) + xsettings_setting_free (setting); + return found; + } + + client = xsettings_client_new (screen_x11->xdisplay, screen_x11->screen_num, + NULL, NULL, NULL); + if (!client) + return FALSE; + + if (xsettings_client_get_setting (client, name, &setting) == XSETTINGS_SUCCESS && + setting && setting->type == XSETTINGS_TYPE_INT) + { + *value = setting->data.v_int; + found = TRUE; + } + if (setting) + xsettings_setting_free (setting); + xsettings_client_destroy (client); + + return found; +} + +static gboolean +unscaled_program (void) +{ + static const char *const builtin[] = { + /* the browsers of Mozilla's code with GTK+ 2 draw on X themselves + * and scale by Xft.dpi on their own */ + "palemoon", "basilisk", "firefox", "firefox-bin", "seamonkey", + "thunderbird", "iceweasel", "icedove", "iceape", "waterfox", + "interlink", "borealis", "iceapc", + /* video in X windows of the size of GDK */ + "mplayer", "gmplayer", "gnome-mplayer", + NULL + }; + const char *prgname = g_get_prgname (); + const char *env = g_getenv ("GDK_UNSCALED_PROGRAMS"); + gchar *base; + gboolean unscaled = FALSE; + gint i; + + if (prgname == NULL) + return FALSE; + + base = g_path_get_basename (prgname); + for (i = 0; builtin[i] && !unscaled; i++) + unscaled = g_ascii_strcasecmp (base, builtin[i]) == 0; + if (!unscaled && env) + { + gchar **names = g_strsplit (env, ":", -1); + + for (i = 0; names[i] && !unscaled; i++) + unscaled = names[i][0] && g_ascii_strcasecmp (base, names[i]) == 0; + g_strfreev (names); + } + g_free (base); + + return unscaled; +} + +/* a scale for all monitors: GDK_SCALE, 1 for programs that draw on + * their own, else 0 (each monitor its own) */ +static gint +forced_scale (void) +{ +#if CAIRO_VERSION < CAIRO_VERSION_ENCODE (1, 14, 0) + return 1; +#else + const char *env = g_getenv ("GDK_SCALE"); + + if (env && *env && atoi (env) >= 1) + return MIN (atoi (env), MAX_WINDOW_SCALE); + + if (unscaled_program ()) + return 1; + + return 0; +#endif +} + +/* the scale of the whole screen where a monitor says nothing of its own */ +static gint +screen_wide_scale (GdkScreenX11 *screen_x11) +{ + const char *resource; + gint value; + + if (read_xsetting_int (screen_x11, "Gdk/WindowScalingFactor", &value) && value >= 1) + return MIN (value, MAX_WINDOW_SCALE); + + if (read_xsetting_int (screen_x11, "Xft/DPI", &value) && value > 0) + return scale_for_dpi (value / 1024.0); + + resource = XGetDefault (screen_x11->xdisplay, "Xft", "dpi"); + if (resource && g_ascii_strtod (resource, NULL) > 0) + return scale_for_dpi (g_ascii_strtod (resource, NULL)); + + return 1; +} + +/* GDK_MONITOR_SCALES: the scale of monitors, by name ("DP-1=2;HDMI-1=1") + * or in their order ("2,1"); 0 where it says nothing */ +static gint +env_monitor_scale (GdkScreenX11 *screen_x11, + gint num) +{ + const char *env = g_getenv ("GDK_MONITOR_SCALES"); + gchar **items; + gint i, scale = 0, pos = 0; + + if (!env || !*env) + return 0; + + items = g_strsplit_set (env, ",;:", -1); + for (i = 0; items[i]; i++) + { + gchar *eq = strchr (items[i], '='); + + g_strstrip (items[i]); + if (eq) + { + *eq = '\0'; + if (screen_x11->monitors[num].output_name && + g_ascii_strcasecmp (g_strstrip (items[i]), screen_x11->monitors[num].output_name) == 0) + scale = atoi (eq + 1); + } + else if (items[i][0]) + { + if (pos == num) + scale = atoi (items[i]); + pos++; + } + } + g_strfreev (items); + + return CLAMP (scale, 0, MAX_WINDOW_SCALE); +} + +/* HiDPI on several monitors: each monitor has its scale (GDK_MONITOR_SCALES, + * the resolution of its output on Xlibre, else the one of the screen), + * and a window takes the scale of the monitor it is on, changing it when it + * moves (see _gdk_x11_window_update_scale ()). Root coordinates of GDK + * are those of the X server divided by the smallest scale, root_scale; + * within a monitor of a larger scale they go on in its own pixels of GDK + * from the corner of the monitor, so that each monitor in GDK's pixels is + * as large as the windows on it see it (some coordinates between monitors + * are not on any). With one scale for all monitors this is the division + * by it, as before. */ +static void +compute_scales (GdkScreenX11 *screen_x11) +{ + gint forced = forced_scale (); + gint wide = forced ? forced : screen_wide_scale (screen_x11); + gint i, primary; + + screen_x11->root_scale = 0; + screen_x11->mixed_scales = FALSE; + + for (i = 0; i < screen_x11->n_monitors; i++) + { + GdkX11Monitor *m = &screen_x11->monitors[i]; + + if (forced) + m->scale = forced; + else if ((m->scale = env_monitor_scale (screen_x11, i)) > 0) + ; + else if (m->dpi > 0) + m->scale = scale_for_dpi (m->dpi); + else + m->scale = wide; + + if (i > 0 && m->scale != screen_x11->monitors[0].scale) + screen_x11->mixed_scales = TRUE; + if (screen_x11->root_scale == 0 || m->scale < screen_x11->root_scale) + screen_x11->root_scale = m->scale; + } + + if (screen_x11->root_scale == 0) + screen_x11->root_scale = wide; + + primary = screen_x11->primary_monitor; + screen_x11->window_scale = primary >= 0 && primary < screen_x11->n_monitors + ? screen_x11->monitors[primary].scale : screen_x11->root_scale; +} + +/* the monitors in pixels of GDK */ +static void +scale_monitors (GdkScreenX11 *screen_x11) +{ + gint i, s = screen_x11->root_scale; + + for (i = 0; i < screen_x11->n_monitors; i++) + { + GdkX11Monitor *m = &screen_x11->monitors[i]; + GdkRectangle *g = &m->geometry; + gint x2, y2; + + m->device = *g; + x2 = g->x + g->width; + y2 = g->y + g->height; + g->x /= s; + g->y /= s; + if (!screen_x11->mixed_scales) + { + g->width = x2 / s - g->x; + g->height = y2 / s - g->y; + } + else + { + g->width = m->device.width / m->scale; + g->height = m->device.height / m->scale; + } + } +} + +/* the monitor at a point of the X server (device) or of GDK, or the + * nearest */ +static GdkX11Monitor * +monitor_at (GdkScreenX11 *screen_x11, + gboolean device, + gint x, + gint y) +{ + GdkX11Monitor *best = NULL; + gint64 best_dist = G_MAXINT64; + gint i; + + for (i = 0; i < screen_x11->n_monitors; i++) + { + GdkX11Monitor *m = &screen_x11->monitors[i]; + GdkRectangle *r = device ? &m->device : &m->geometry; + gint64 dx = 0, dy = 0, dist; + + if (x < r->x) + dx = r->x - x; + else if (x >= r->x + r->width) + dx = x - (r->x + r->width - 1); + if (y < r->y) + dy = r->y - y; + else if (y >= r->y + r->height) + dy = y - (r->y + r->height - 1); + + dist = dx * dx + dy * dy; + if (dist < best_dist) + { + best = m; + best_dist = dist; + } + } + + return best; +} + +gboolean +_gdk_x11_screen_has_mixed_scales (GdkScreen *screen) +{ + return GDK_SCREEN_X11 (screen)->mixed_scales; +} + +/* the scale of the monitor at a point of the X server (@device) or of + * GDK, and how coordinates there become root coordinates of GDK */ +gint +_gdk_x11_screen_place (GdkScreen *screen, + gboolean device, + gint x, + gint y, + GdkX11RootAnchor *anchor) +{ + GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (screen); + GdkX11Monitor *m; + + if (!screen_x11->mixed_scales || + !(m = monitor_at (screen_x11, device, x, y))) + { + if (anchor) + anchor->dx = anchor->dy = anchor->lx = anchor->ly = 0; + return screen_x11->root_scale; + } + + if (anchor) + { + anchor->dx = m->device.x; + anchor->dy = m->device.y; + anchor->lx = m->geometry.x; + anchor->ly = m->geometry.y; + } + return m->scale; +} + +/* root coordinates of GDK for a point of the X server, and back */ +void +_gdk_x11_screen_device_to_root (GdkScreen *screen, + gdouble dx, + gdouble dy, + gdouble *x, + gdouble *y) +{ + GdkX11RootAnchor a; + gint s = _gdk_x11_screen_place (screen, TRUE, floor (dx), floor (dy), &a); + + if (x) + *x = a.lx + (dx - a.dx) / s; + if (y) + *y = a.ly + (dy - a.dy) / s; +} + +void +_gdk_x11_screen_root_to_device (GdkScreen *screen, + gint x, + gint y, + gint *dx, + gint *dy) +{ + GdkX11RootAnchor a; + gint s = _gdk_x11_screen_place (screen, FALSE, x, y, &a); + + if (dx) + *dx = a.dx + (x - a.lx) * s; + if (dy) + *dy = a.dy + (y - a.ly) * s; +} + +gint +_gdk_windowing_screen_get_monitor_scale (GdkScreen *screen, + gint monitor_num) +{ + GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (screen); + + if (monitor_num >= 0 && monitor_num < screen_x11->n_monitors) + return screen_x11->monitors[monitor_num].scale; + return screen_x11->window_scale; +} + GdkScreen * _gdk_x11_screen_new (GdkDisplay *display, gint screen_number) @@ -1135,6 +1617,9 @@ _gdk_x11_screen_new (GdkDisplay *display, init_multihead (screen); init_randr_support (screen); + compute_scales (screen_x11); + scale_monitors (screen_x11); + _gdk_visual_init (screen); _gdk_windowing_window_init (screen); @@ -1211,6 +1696,9 @@ process_monitors_change (GdkScreen *screen) gint primary_monitor; GdkX11Monitor *monitors; gboolean changed; + gint old_window_scale = screen_x11->window_scale; + gint old_root_scale = screen_x11->root_scale; + gboolean old_mixed = screen_x11->mixed_scales; primary_monitor = screen_x11->primary_monitor; n_monitors = screen_x11->n_monitors; @@ -1220,6 +1708,8 @@ process_monitors_change (GdkScreen *screen) screen_x11->monitors = NULL; init_multihead (screen); + compute_scales (screen_x11); + scale_monitors (screen_x11); changed = !compare_monitors (monitors, n_monitors, @@ -1228,10 +1718,34 @@ process_monitors_change (GdkScreen *screen) free_monitors (monitors, n_monitors); + /* HiDPI: windows take the scales the monitors have now; the fonts, + * whose resolution is over the scale, change with it */ + if (changed || old_window_scale != screen_x11->window_scale || + old_root_scale != screen_x11->root_scale || old_mixed != screen_x11->mixed_scales) + _gdk_x11_screen_rescale_windows (screen); + if (old_window_scale != screen_x11->window_scale) + { + GdkEvent event; + + memset (&event, 0, sizeof event); + event.type = GDK_SETTING; + event.setting.window = gdk_screen_get_root_window (screen); + event.setting.action = GDK_SETTING_ACTION_CHANGED; + event.setting.name = (char *) "gtk-xft-dpi"; + gdk_event_put (&event); + } + if (changed) g_signal_emit_by_name (screen, "monitors-changed"); } +/* HiDPI: the scale of the desktop (XSETTINGS) changed */ +void +_gdk_x11_screen_update_scales (GdkScreen *screen) +{ + process_monitors_change (screen); +} + void _gdk_x11_screen_size_changed (GdkScreen *screen, XEvent *event) diff --git a/gdk/x11/gdkscreen-x11.h b/gdk/x11/gdkscreen-x11.h index 7df8e0e7f..6460d822b 100644 --- a/gdk/x11/gdkscreen-x11.h +++ b/gdk/x11/gdkscreen-x11.h @@ -73,7 +73,7 @@ struct _GdkScreenX11 GdkVisualPrivate *system_visual; GdkVisualPrivate **visuals; gint nvisuals; - gint available_depths[7]; + gint available_depths[8]; gint navailable_depths; GdkVisualType available_types[6]; gint navailable_types; @@ -110,6 +110,13 @@ struct _GdkScreenX11 GdkAtom cm_selection_atom; gboolean is_composited; + + /* HiDPI: pixels of the X server for one of GDK (see compute_scales () + * in gdkscreen-x11.c): of the primary monitor, the smallest of all, which + * root coordinates have, and whether monitors differ */ + gint window_scale; + gint root_scale; + gboolean mixed_scales; }; struct _GdkScreenX11Class diff --git a/gdk/x11/gdkscroll-x11.c b/gdk/x11/gdkscroll-x11.c new file mode 100644 index 000000000..c158cbae5 --- /dev/null +++ b/gdk/x11/gdkscroll-x11.c @@ -0,0 +1,641 @@ +/* GDK - The GIMP Drawing Kit + * + * Smooth scrolling from the scroll valuators of XInput 2.1 + * + * High resolution wheels and touchpads move scroll valuators in small + * amounts; X makes the old wheel buttons 4 to 7 of them, one press a + * whole step. Selecting XI_Motion on a window brings the valuators, + * but no more core motion events there, so those are made here from + * the XI_Motion events, and everything else stays core events. + * + * Smooth scroll events are only made for the event handler of GTK+ + * and where a window asked for them with GDK_SMOOTH_SCROLL_MASK (see + * _gdk_event_smooth_scroll_wanted()). Nothing is kept per + * window. The display has one small record, made only when the + * server can do this. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + */ + +#include "config.h" + +#include + +#include "gdkx.h" +#include "gdkprivate-x11.h" +#include "gdkdisplay-x11.h" +#include "gdkinternals.h" +#include "gdkalias.h" + +#ifdef HAVE_XINPUT2 + +#include + +typedef struct +{ + gint number; /* the valuator, -1 for none */ + gdouble increment; /* how much of it a step of the wheel is */ + gdouble last; + gboolean valid; +} ScrollAxis; + +struct _GdkX11Scroll +{ + gint opcode; + gboolean touch; /* XInput 2.2: touches can be selected */ + gint sourceid; /* the device the axes belong to, 0 for none */ + ScrollAxis axis[2]; /* horizontal and vertical */ + guint32 smooth_time; /* when the last smooth event came */ + gboolean smooth_valid; + GQueue pending; /* the events made of the last XI event */ + gboolean gesture; /* XInput 2.4: touchpad gestures */ + gdouble pinch_scale; /* of the pinch going on, 0 for none */ + gdouble pinch_rest; + gdouble swipe_dx, swipe_dy; +}; + +static void +clear_pending (GdkX11Scroll *scroll) +{ + GdkEvent *event; + + while ((event = g_queue_pop_head (&scroll->pending))) + gdk_event_free (event); +} + +void +_gdk_x11_scroll_init (GdkDisplay *display) +{ + GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display); + int opcode, event, error, major = 2, minor = 4; + Status status; + + if (g_getenv ("GDK_CORE_DEVICE_EVENTS") || + !XQueryExtension (display_x11->xdisplay, "XInputExtension", &opcode, &event, &error)) + return; + + /* Clients that ask for 2.2 or more may ask again with another + * version, which other libraries in the program might */ + gdk_error_trap_push (); + status = XIQueryVersion (display_x11->xdisplay, &major, &minor); + if (gdk_error_trap_pop () || status != Success || major * 1000 + minor < 2001) + return; + + display_x11->scroll = g_new0 (GdkX11Scroll, 1); + display_x11->scroll->opcode = opcode; + display_x11->scroll->touch = major * 1000 + minor >= 2002; +#ifdef HAVE_XINPUT2_GESTURES + display_x11->scroll->gesture = major * 1000 + minor >= 2004; +#endif + display_x11->scroll->axis[0].number = -1; + display_x11->scroll->axis[1].number = -1; +} + +void +_gdk_x11_scroll_finalize (GdkDisplay *display) +{ + GdkX11Scroll *scroll = GDK_DISPLAY_X11 (display)->scroll; + + if (scroll) + clear_pending (scroll); + g_free (scroll); +} + +/* XI_Motion where the window takes core motion, without hints. The + * selection is for the master pointers, so XInput 1 devices stay. + * The touches of XInput 2.2 where a window asked for GDK_TOUCH_MASK: + * the X server then sends them instead of moving the pointer with the + * first finger there, which GDK does itself then (gdkwindow.c). */ +void +_gdk_x11_scroll_select (GdkWindow *window, + long xevent_mask, + gboolean touch) +{ + unsigned char bits[XIMaskLen (XI_LASTEVENT)] = { 0 }; + XIEventMask mask; + GdkX11Scroll *scroll = GDK_DISPLAY_X11 (GDK_WINDOW_DISPLAY (window))->scroll; + + if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_ROOT || + GDK_WINDOW_TYPE (window) == GDK_WINDOW_FOREIGN) + return; + + if ((xevent_mask & (PointerMotionMask | PointerMotionHintMask)) == PointerMotionMask) + XISetMask (bits, XI_Motion); + +#ifdef XI_TouchBegin + if (touch && scroll->touch) + { + XISetMask (bits, XI_TouchBegin); + XISetMask (bits, XI_TouchUpdate); + XISetMask (bits, XI_TouchEnd); + } +#endif + +#ifdef HAVE_XINPUT2_GESTURES + /* touchpad gestures where scroll events come, made into those and + * into the back and forward buttons (gdkevents.c) */ + if (scroll->gesture && (xevent_mask & ButtonPressMask)) + { + XISetMask (bits, XI_GesturePinchBegin); + XISetMask (bits, XI_GesturePinchUpdate); + XISetMask (bits, XI_GesturePinchEnd); + XISetMask (bits, XI_GestureSwipeBegin); + XISetMask (bits, XI_GestureSwipeUpdate); + XISetMask (bits, XI_GestureSwipeEnd); + } +#endif + + mask.deviceid = XIAllMasterDevices; + mask.mask_len = sizeof bits; + mask.mask = bits; + XISelectEvents (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window), &mask, 1); +} + +/* The valuators may have moved where no XI_Motion came here: outside, + * in other programs' windows inside ours, or under a core grab, which + * gets core events only. The next scroll starts afresh; when the + * pointer comes from outside, maybe with another device, the device + * is looked at again as well. */ +void +_gdk_x11_scroll_reset (GdkDisplay *display, + gboolean forget_device) +{ + GdkX11Scroll *scroll = GDK_DISPLAY_X11 (display)->scroll; + + scroll->axis[0].valid = FALSE; + scroll->axis[1].valid = FALSE; + if (forget_device) + scroll->sourceid = 0; +} + +/* A core press of buttons 4 to 7: was it made of a smooth event? */ +gboolean +_gdk_x11_scroll_is_emulated (GdkDisplay *display, + guint32 time) +{ + GdkX11Scroll *scroll = GDK_DISPLAY_X11 (display)->scroll; + + return scroll->smooth_valid && scroll->smooth_time == time; +} + +GdkEvent * +_gdk_x11_scroll_take_pending (GdkDisplay *display) +{ + GdkX11Scroll *scroll = GDK_DISPLAY_X11 (display)->scroll; + + return g_queue_pop_head (&scroll->pending); +} + +static void +find_axes (Display *xdisplay, + GdkX11Scroll *scroll, + gint sourceid) +{ + XIDeviceInfo *info; + gint n, i; + + scroll->sourceid = sourceid; + scroll->axis[0].number = -1; + scroll->axis[1].number = -1; + + gdk_error_trap_push (); + info = XIQueryDevice (xdisplay, sourceid, &n); + gdk_error_trap_pop (); + if (!info) + return; + + for (i = 0; i < info->num_classes; i++) + { + XIScrollClassInfo *class = (XIScrollClassInfo *) info->classes[i]; + ScrollAxis *axis; + + if (class->type != XIScrollClass || class->increment == 0) + continue; + + axis = &scroll->axis[class->scroll_type == XIScrollTypeVertical]; + axis->number = class->number; + axis->increment = class->increment; + axis->valid = FALSE; + } + + XIFreeDeviceInfo (info); +} + +static guint +core_state (XIDeviceEvent *ev) +{ + guint state = (ev->mods.effective & 0xff) | ((ev->group.effective & 0x3) << 13); + gint b; + + for (b = 1; b <= 5 && b < ev->buttons.mask_len * 8; b++) + if (XIMaskIsSet (ev->buttons.mask, b)) + state |= Button1Mask << (b - 1); + + return state; +} + +static GdkEvent * +smooth_event (GdkDisplay *display, + XIDeviceEvent *ev, + gdouble dx, + gdouble dy) +{ + GdkWindow *window; + GdkScreen *screen; + GdkEvent *event; + + /* Over a window inside that took no XI_Motion, such as another + * program's, the core steps go there and the smooth event would + * go past it */ + if (ev->child != None || !_gdk_event_smooth_scroll_wanted ()) + return NULL; + + window = gdk_window_lookup_for_display (display, ev->event); + screen = _gdk_x11_display_screen_for_xrootwin (display, ev->root); + if (!window || !GDK_IS_WINDOW (window) || GDK_WINDOW_DESTROYED (window) || !screen) + return NULL; + + event = gdk_event_new (GDK_SCROLL); + event->scroll.window = g_object_ref (window); + event->scroll.send_event = ev->send_event ? TRUE : FALSE; + event->scroll.time = ev->time; + /* in pixels of GDK */ + event->scroll.x = ev->event_x / GDK_X11_WINDOW_SCALE (window); + event->scroll.y = ev->event_y / GDK_X11_WINDOW_SCALE (window); + _gdk_x11_window_device_to_root (window, ev->root_x, ev->root_y, + &event->scroll.x_root, &event->scroll.y_root); + event->scroll.state = core_state (ev); + event->scroll.device = display->core_pointer; + gdk_event_set_screen (event, screen); + _gdk_event_set_scroll_deltas (event, dx, dy); + + return event; +} + +#ifdef XI_TouchBegin +/* A touch of XInput 2.2, for gdkwindow.c (proxy_touch_event()) */ +static GdkEvent * +touch_event (GdkDisplay *display, + XIDeviceEvent *ev) +{ + GdkWindow *window; + GdkScreen *screen; + GdkEvent *event; + GdkEventType type; + + switch (ev->evtype) + { + case XI_TouchBegin: + type = GDK_TOUCH_BEGIN; + break; + case XI_TouchUpdate: + type = GDK_TOUCH_UPDATE; + break; + case XI_TouchEnd: + type = GDK_TOUCH_END; + break; + default: + return NULL; + } + + window = gdk_window_lookup_for_display (display, ev->event); + screen = _gdk_x11_display_screen_for_xrootwin (display, ev->root); + if (!window || !GDK_IS_WINDOW (window) || GDK_WINDOW_DESTROYED (window) || !screen) + return NULL; + + event = gdk_event_new (type); + event->touch.window = g_object_ref (window); + event->touch.send_event = ev->send_event ? TRUE : FALSE; + event->touch.time = ev->time; + /* in pixels of GDK */ + event->touch.x = ev->event_x / GDK_X11_WINDOW_SCALE (window); + event->touch.y = ev->event_y / GDK_X11_WINDOW_SCALE (window); + _gdk_x11_window_device_to_root (window, ev->root_x, ev->root_y, + &event->touch.x_root, &event->touch.y_root); + event->touch.axes = NULL; + event->touch.state = core_state (ev); + /* the touch ids of X are never 0 */ + event->touch.sequence = GUINT_TO_POINTER (ev->detail); + event->touch.emulating_pointer = (ev->flags & XITouchEmulatingPointer) != 0; + event->touch.device = display->core_pointer; + gdk_event_set_screen (event, screen); + + return event; +} +#endif + +#ifdef HAVE_XINPUT2_GESTURES +/* A scroll event to make the events of a gesture from, or NULL where + * another program's window inside took no gestures */ +static GdkEvent * +gesture_template (GdkDisplay *display, + Window xwindow, + Window child, + Window root, + gdouble event_x, + gdouble event_y, + gdouble root_x, + gdouble root_y, + XIModifierState *mods, + XIGroupState *group, + Time time, + Bool send_event) +{ + GdkWindow *window; + GdkScreen *screen; + GdkEvent *event; + + if (child != None) + return NULL; + + window = gdk_window_lookup_for_display (display, xwindow); + screen = _gdk_x11_display_screen_for_xrootwin (display, root); + if (!window || !GDK_IS_WINDOW (window) || GDK_WINDOW_DESTROYED (window) || !screen) + return NULL; + + event = gdk_event_new (GDK_SCROLL); + event->scroll.window = g_object_ref (window); + event->scroll.send_event = send_event ? TRUE : FALSE; + event->scroll.time = time; + /* in pixels of GDK */ + event->scroll.x = event_x / GDK_X11_WINDOW_SCALE (window); + event->scroll.y = event_y / GDK_X11_WINDOW_SCALE (window); + _gdk_x11_window_device_to_root (window, root_x, root_y, + &event->scroll.x_root, &event->scroll.y_root); + event->scroll.state = (mods->effective & 0xff) | ((group->effective & 0x3) << 13); + event->scroll.direction = GDK_SCROLL_UP; + event->scroll.device = display->core_pointer; + gdk_event_set_screen (event, screen); + + return event; +} + +static void +queue_events (GdkX11Scroll *scroll, + GList *events) +{ + GList *l; + + for (l = events; l; l = l->next) + g_queue_push_tail (&scroll->pending, l->data); + g_list_free (events); +} + +/* Unaccelerated distance across (about 1/1000 inch) that makes a swipe + * go back or forward: some 8 mm */ +#define SWIPE_DISTANCE 300 + +static void +gesture_event (GdkDisplay *display, + GdkX11Scroll *scroll, + gint evtype, + gpointer data) +{ + XIGesturePinchEvent *pinch = data; + XIGestureSwipeEvent *swipe = data; + GdkEvent *template_event; + + switch (evtype) + { + case XI_GesturePinchBegin: + scroll->pinch_scale = 1; + scroll->pinch_rest = 0; + break; + + case XI_GesturePinchUpdate: + if (scroll->pinch_scale <= 0 || pinch->scale <= 0) + break; + template_event = gesture_template (display, pinch->event, pinch->child, pinch->root, + pinch->event_x, pinch->event_y, + pinch->root_x, pinch->root_y, + &pinch->mods, &pinch->group, + pinch->time, pinch->send_event); + if (template_event) + { + queue_events (scroll, _gdk_event_touchpad_pinch (template_event, + log (pinch->scale / scroll->pinch_scale), + &scroll->pinch_rest)); + gdk_event_free (template_event); + } + scroll->pinch_scale = pinch->scale; + break; + + case XI_GesturePinchEnd: + scroll->pinch_scale = 0; + break; + + case XI_GestureSwipeBegin: + scroll->swipe_dx = scroll->swipe_dy = 0; + break; + + case XI_GestureSwipeUpdate: + scroll->swipe_dx += swipe->delta_unaccel_x; + scroll->swipe_dy += swipe->delta_unaccel_y; + break; + + case XI_GestureSwipeEnd: + if ((swipe->flags & XIGestureSwipeEventCancelled) || + fabs (scroll->swipe_dx) < SWIPE_DISTANCE || + fabs (scroll->swipe_dx) < 2 * fabs (scroll->swipe_dy)) + break; + template_event = gesture_template (display, swipe->event, swipe->child, swipe->root, + swipe->event_x, swipe->event_y, + swipe->root_x, swipe->root_y, + &swipe->mods, &swipe->group, + swipe->time, swipe->send_event); + if (template_event) + { + queue_events (scroll, _gdk_event_touchpad_swipe (template_event, scroll->swipe_dx)); + gdk_event_free (template_event); + } + break; + } +} +#endif + +/* An XI_Motion becomes the core motion event that the window would + * have had, in @motion (type 0 for none), and maybe a smooth scroll + * event, which _gdk_x11_scroll_take_pending() then gives; a touch + * becomes a touch event, given the same way. + * Returns FALSE for other events. */ +gboolean +_gdk_x11_scroll_translate (GdkDisplay *display, + XEvent *xevent, + XEvent *motion) +{ + GdkX11Scroll *scroll = GDK_DISPLAY_X11 (display)->scroll; + XGenericEventCookie *cookie = &xevent->xcookie; + XIDeviceEvent *ev; + gdouble delta[2] = { 0, 0 }; + gboolean scrolled = FALSE, claimed; + GdkEvent *event; + gint i, k; + + motion->type = 0; + +#ifdef XI_TouchBegin + if (cookie->extension == scroll->opcode && + (cookie->evtype == XI_TouchBegin || cookie->evtype == XI_TouchUpdate || + cookie->evtype == XI_TouchEnd)) + { + claimed = XGetEventData (cookie->display, cookie); + if (!cookie->data) + return FALSE; + clear_pending (scroll); + event = touch_event (display, cookie->data); + if (event) + g_queue_push_tail (&scroll->pending, event); + if (claimed) + XFreeEventData (cookie->display, cookie); + return TRUE; + } +#endif + +#ifdef HAVE_XINPUT2_GESTURES + if (cookie->extension == scroll->opcode && + cookie->evtype >= XI_GesturePinchBegin && cookie->evtype <= XI_GestureSwipeEnd) + { + claimed = XGetEventData (cookie->display, cookie); + if (!cookie->data) + return FALSE; + clear_pending (scroll); + gesture_event (display, scroll, cookie->evtype, cookie->data); + if (claimed) + XFreeEventData (cookie->display, cookie); + return TRUE; + } +#endif + + if (cookie->extension != scroll->opcode || cookie->evtype != XI_Motion) + return FALSE; + + /* a filter of the program may have taken the data already */ + claimed = XGetEventData (cookie->display, cookie); + if (!cookie->data) + return FALSE; + + ev = cookie->data; + + /* Scroll valuators: anything past x and y on a new device */ + if (ev->sourceid != scroll->sourceid) + { + for (i = 2; i < ev->valuators.mask_len * 8; i++) + if (XIMaskIsSet (ev->valuators.mask, i)) + break; + if (i < ev->valuators.mask_len * 8) + find_axes (cookie->display, scroll, ev->sourceid); + } + + if (ev->sourceid == scroll->sourceid) + for (i = 0, k = 0; i < ev->valuators.mask_len * 8; i++) + { + gint a; + + if (!XIMaskIsSet (ev->valuators.mask, i)) + continue; + + for (a = 0; a < 2; a++) + if (scroll->axis[a].number == i) + { + gdouble value = ev->valuators.values[k]; + + /* a scroll that old wheel buttons made is already there */ + if (scroll->axis[a].valid && !(ev->flags & XIPointerEmulated)) + delta[a] = (value - scroll->axis[a].last) / scroll->axis[a].increment; + scrolled |= delta[a] != 0; + scroll->axis[a].last = value; + scroll->axis[a].valid = TRUE; + } + k++; + } + + /* X makes core motion of the events that have x or y */ + if (ev->valuators.mask_len > 0 && (ev->valuators.mask[0] & 3)) + { + XMotionEvent *m = &motion->xmotion; + + m->type = MotionNotify; + m->serial = ev->serial; + m->send_event = ev->send_event; + m->display = ev->display; + m->window = ev->event; + m->root = ev->root; + m->subwindow = ev->child; + m->time = ev->time; + m->x = floor (ev->event_x); + m->y = floor (ev->event_y); + m->x_root = floor (ev->root_x); + m->y_root = floor (ev->root_y); + m->state = core_state (ev); + m->is_hint = NotifyNormal; + m->same_screen = True; + } + + if (scrolled) + { + clear_pending (scroll); + event = smooth_event (display, ev, delta[0], delta[1]); + if (event) + { + g_queue_push_tail (&scroll->pending, event); + scroll->smooth_time = ev->time; + scroll->smooth_valid = TRUE; + } + } + + if (claimed) + XFreeEventData (cookie->display, cookie); + + return TRUE; +} + +#else /* !HAVE_XINPUT2 */ + +void +_gdk_x11_scroll_init (GdkDisplay *display) +{ +} + +void +_gdk_x11_scroll_finalize (GdkDisplay *display) +{ +} + +void +_gdk_x11_scroll_select (GdkWindow *window, + long xevent_mask, + gboolean touch) +{ +} + +void +_gdk_x11_scroll_reset (GdkDisplay *display, + gboolean forget_device) +{ +} + +gboolean +_gdk_x11_scroll_is_emulated (GdkDisplay *display, + guint32 time) +{ + return FALSE; +} + +GdkEvent * +_gdk_x11_scroll_take_pending (GdkDisplay *display) +{ + return NULL; +} + +gboolean +_gdk_x11_scroll_translate (GdkDisplay *display, + XEvent *xevent, + XEvent *motion) +{ + return FALSE; +} + +#endif diff --git a/gdk/x11/gdktestutils-x11.c b/gdk/x11/gdktestutils-x11.c index f53e2b3e5..f27af7366 100644 --- a/gdk/x11/gdktestutils-x11.c +++ b/gdk/x11/gdktestutils-x11.c @@ -20,6 +20,7 @@ #include #include #include +#include "gdkprivate-x11.h" #include "gdkalias.h" #include @@ -108,8 +109,9 @@ gdk_test_simulate_key (GdkWindow *window, priv = (GdkWindowObject *)window; /* Convert to impl coordinates */ - x = x + priv->abs_x; - y = y + priv->abs_y; + /* in pixels of the X server, in the middle of GDK's pixel */ + x = (x + priv->abs_x) * GDK_X11_WINDOW_SCALE (window) + GDK_X11_WINDOW_SCALE (window) / 2; + y = (y + priv->abs_y) * GDK_X11_WINDOW_SCALE (window) + GDK_X11_WINDOW_SCALE (window) / 2; xev.type = key_pressrelease == GDK_KEY_PRESS ? KeyPress : KeyRelease; xev.display = GDK_DRAWABLE_XDISPLAY (window); @@ -219,8 +221,9 @@ gdk_test_simulate_button (GdkWindow *window, priv = (GdkWindowObject *)window; /* Convert to impl coordinates */ - x = x + priv->abs_x; - y = y + priv->abs_y; + /* in pixels of the X server, in the middle of GDK's pixel */ + x = (x + priv->abs_x) * GDK_X11_WINDOW_SCALE (window) + GDK_X11_WINDOW_SCALE (window) / 2; + y = (y + priv->abs_y) * GDK_X11_WINDOW_SCALE (window) + GDK_X11_WINDOW_SCALE (window) / 2; xev.type = button_pressrelease == GDK_BUTTON_PRESS ? ButtonPress : ButtonRelease; xev.display = GDK_DRAWABLE_XDISPLAY (window); diff --git a/gdk/x11/gdkwindow-x11.c b/gdk/x11/gdkwindow-x11.c index 4421273f6..88f9325e7 100644 --- a/gdk/x11/gdkwindow-x11.c +++ b/gdk/x11/gdkwindow-x11.c @@ -56,6 +56,7 @@ #include #include #include +#include #include @@ -441,6 +442,8 @@ _gdk_windowing_window_init (GdkScreen * screen) draw_impl->screen = screen; draw_impl->xid = screen_x11->xroot_window; draw_impl->wrapper = GDK_DRAWABLE (private); + /* HiDPI: root coordinates are in pixels of the smallest scale */ + draw_impl->scale = screen_x11->root_scale; draw_impl->colormap = gdk_screen_get_system_colormap (screen); g_object_ref (draw_impl->colormap); @@ -451,8 +454,8 @@ _gdk_windowing_window_init (GdkScreen * screen) private->y = 0; private->abs_x = 0; private->abs_y = 0; - private->width = WidthOfScreen (screen_x11->xscreen); - private->height = HeightOfScreen (screen_x11->xscreen); + private->width = WidthOfScreen (screen_x11->xscreen) / draw_impl->scale; + private->height = HeightOfScreen (screen_x11->xscreen) / draw_impl->scale; private->viewable = TRUE; /* see init_randr_support() in gdkscreen-x11.c */ @@ -473,9 +476,12 @@ set_wm_protocols (GdkWindow *window) int n = 0; protocols[n++] = gdk_x11_get_xatom_by_name_for_display (display, "WM_DELETE_WINDOW"); - protocols[n++] = gdk_x11_get_xatom_by_name_for_display (display, "WM_TAKE_FOCUS"); protocols[n++] = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_PING"); + /* without input focus, "No Input" rather than "Globally Active" */ + if (((GdkWindowObject *) window)->accept_focus) + protocols[n++] = gdk_x11_get_xatom_by_name_for_display (display, "WM_TAKE_FOCUS"); + #ifdef HAVE_XSYNC if (GDK_DISPLAY_X11 (display)->use_sync) protocols[n++] = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_SYNC_REQUEST"); @@ -603,20 +609,25 @@ setup_toplevel_window (GdkWindow *window, * correct value??? */ size_hints.flags = PSize; - size_hints.width = obj->width; - size_hints.height = obj->height; + size_hints.width = obj->width * GDK_X11_WINDOW_SCALE (window); + size_hints.height = obj->height * GDK_X11_WINDOW_SCALE (window); XSetWMNormalHints (xdisplay, xid, &size_hints); /* This will set WM_CLIENT_MACHINE and WM_LOCALE_NAME */ XSetWMProperties (xdisplay, xid, NULL, NULL, NULL, 0, NULL, NULL, NULL); - pid = getpid (); - XChangeProperty (xdisplay, xid, - gdk_x11_get_xatom_by_name_for_display (screen_x11->display, "_NET_WM_PID"), - XA_CARDINAL, 32, - PropModeReplace, - (guchar *)&pid, 1); + /* Sandboxed, we are likely in a pid namespace, and our pid would + * only confuse the window manager (or make it kill another process) */ + if (!_gdk_x11_running_in_sandbox ()) + { + pid = getpid (); + XChangeProperty (xdisplay, xid, + gdk_x11_get_xatom_by_name_for_display (screen_x11->display, "_NET_WM_PID"), + XA_CARDINAL, 32, + PropModeReplace, + (guchar *)&pid, 1); + } leader_window = GDK_DISPLAY_X11 (screen_x11->display)->leader_window; if (!leader_window) @@ -666,6 +677,7 @@ _gdk_window_impl_new (GdkWindow *window, unsigned int class; const char *title; int i; + gint dx, dy; private = (GdkWindowObject *) window; @@ -678,6 +690,15 @@ _gdk_window_impl_new (GdkWindow *window, draw_impl->wrapper = GDK_DRAWABLE (window); draw_impl->screen = screen; + /* HiDPI: as the native window it is in, a toplevel as the monitor its + * middle is on */ + if (GDK_WINDOW_TYPE (real_parent) == GDK_WINDOW_ROOT) + draw_impl->scale = _gdk_x11_screen_place (screen, FALSE, + private->x + private->width / 2, + private->y + private->height / 2, + &impl->anchor); + else + draw_impl->scale = GDK_X11_WINDOW_SCALE (real_parent); xdisplay = screen_x11->xdisplay; xattributes_mask = 0; @@ -777,24 +798,36 @@ _gdk_window_impl_new (GdkWindow *window, g_object_ref (draw_impl->colormap); } - if (private->width > 32767 || - private->height > 32767) + if (private->width > 32767 / draw_impl->scale || + private->height > 32767 / draw_impl->scale) { g_warning ("Native Windows wider or taller than 32767 pixels are not supported"); - if (private->width > 32767) - private->width = 32767; - if (private->height > 32767) - private->height = 32767; + if (private->width > 32767 / draw_impl->scale) + private->width = 32767 / draw_impl->scale; + if (private->height > 32767 / draw_impl->scale) + private->height = 32767 / draw_impl->scale; + } + + if (GDK_WINDOW_TYPE (real_parent) == GDK_WINDOW_ROOT) + _gdk_x11_window_root_to_device (window, private->x, private->y, &dx, &dy); + else + { + dx = (private->x + private->parent->abs_x) * draw_impl->scale; + dy = (private->y + private->parent->abs_y) * draw_impl->scale; } xid = draw_impl->xid = XCreateWindow (xdisplay, xparent, - private->x + private->parent->abs_x, - private->y + private->parent->abs_y, - private->width, private->height, + dx, dy, + private->width * draw_impl->scale, + private->height * draw_impl->scale, 0, private->depth, class, xvisual, xattributes_mask, &xattributes); + if (GDK_DISPLAY_X11 (screen_x11->display)->scroll && + ((xattributes.event_mask & PointerMotionMask) || (event_mask & GDK_TOUCH_MASK))) + _gdk_x11_scroll_select (window, xattributes.event_mask, (event_mask & GDK_TOUCH_MASK) != 0); + g_object_ref (window); _gdk_xid_table_insert (screen_x11->display, &draw_impl->xid, window); @@ -955,11 +988,12 @@ gdk_x11_window_foreign_new_for_display (GdkDisplay *display, private->parent->children = g_list_prepend (private->parent->children, win); draw_impl->xid = window; + draw_impl->scale = GDK_X11_WINDOW_SCALE (private->parent); - private->x = attrs.x; - private->y = attrs.y; - private->width = attrs.width; - private->height = attrs.height; + private->x = _gdk_x11_unscale (attrs.x, draw_impl->scale); + private->y = _gdk_x11_unscale (attrs.y, draw_impl->scale); + private->width = _gdk_x11_unscale_up (attrs.width, draw_impl->scale); + private->height = _gdk_x11_unscale_up (attrs.height, draw_impl->scale); private->window_type = GDK_WINDOW_FOREIGN; private->destroyed = FALSE; @@ -1514,6 +1548,41 @@ gdk_window_x11_withdraw (GdkWindow *window) } } +static void set_window_scale (GdkWindow *window, gint scale, gboolean resize); + +/* HiDPI: a toplevel to be at root coordinates (@x, @y) of GDK, in + * @width x @height: its scale and anchor become those of the monitor its + * middle will be on; (@dx, @dy) of the X server; TRUE when the scale + * changed (the window has to be resized) */ +static gboolean +place_toplevel (GdkWindow *window, + gint x, + gint y, + gint width, + gint height, + gint *dx, + gint *dy) +{ + GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (((GdkWindowObject *) window)->impl); + GdkX11RootAnchor anchor; + gboolean changed = FALSE; + gint scale; + + scale = _gdk_x11_screen_place (GDK_WINDOW_SCREEN (window), FALSE, + x + width / 2, y + height / 2, &anchor); + impl->anchor = anchor; + if (scale != GDK_X11_IMPL_SCALE (impl) && + _gdk_x11_screen_has_mixed_scales (GDK_WINDOW_SCREEN (window))) + { + set_window_scale (window, scale, FALSE); + changed = TRUE; + } + + _gdk_x11_window_root_to_device (window, x, y, dx, dy); + + return changed; +} + static inline void window_x11_move (GdkWindow *window, gint x, @@ -1521,6 +1590,7 @@ window_x11_move (GdkWindow *window, { GdkWindowObject *private = (GdkWindowObject *) window; GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (private->impl); + _gdk_x11_window_root_coords_changed (); if (GDK_WINDOW_TYPE (private) == GDK_WINDOW_CHILD) { @@ -1530,9 +1600,17 @@ window_x11_move (GdkWindow *window, } else { - XMoveWindow (GDK_WINDOW_XDISPLAY (window), - GDK_WINDOW_XID (window), - x, y); + gint dx, dy; + + /* HiDPI: on a monitor of another scale, it takes that one */ + if (place_toplevel (window, x, y, private->width, private->height, &dx, &dy)) + XMoveResizeWindow (GDK_WINDOW_XDISPLAY (window), + GDK_WINDOW_XID (window), dx, dy, + MAX (private->width, 1) * GDK_X11_WINDOW_SCALE (window), + MAX (private->height, 1) * GDK_X11_WINDOW_SCALE (window)); + else + XMoveWindow (GDK_WINDOW_XDISPLAY (window), + GDK_WINDOW_XID (window), dx, dy); if (impl->override_redirect) { @@ -1548,6 +1626,7 @@ window_x11_resize (GdkWindow *window, gint height) { GdkWindowObject *private = (GdkWindowObject *) window; + _gdk_x11_window_root_coords_changed (); if (width < 1) width = 1; @@ -1567,7 +1646,8 @@ window_x11_resize (GdkWindow *window, XResizeWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window), - width, height); + width * GDK_X11_WINDOW_SCALE (window), + height * GDK_X11_WINDOW_SCALE (window)); if (impl->override_redirect) { @@ -1593,6 +1673,7 @@ window_x11_move_resize (GdkWindow *window, gint height) { GdkWindowObject *private = (GdkWindowObject *) window;; + _gdk_x11_window_root_coords_changed (); if (width < 1) width = 1; @@ -1609,9 +1690,13 @@ window_x11_move_resize (GdkWindow *window, { GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (private->impl); + gint sc, dx, dy; + + place_toplevel (window, x, y, width, height, &dx, &dy); + sc = GDK_X11_WINDOW_SCALE (window); XMoveResizeWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window), - x, y, width, height); + dx, dy, width * sc, height * sc); if (impl->override_redirect) { @@ -1659,6 +1744,7 @@ gdk_window_x11_reparent (GdkWindow *window, GdkWindowObject *window_private; GdkWindowObject *parent_private; GdkWindowImplX11 *impl; + _gdk_x11_window_root_coords_changed (); window_private = (GdkWindowObject*) window; parent_private = (GdkWindowObject*) new_parent; @@ -1669,7 +1755,8 @@ gdk_window_x11_reparent (GdkWindow *window, XReparentWindow (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window), GDK_WINDOW_XID (new_parent), - parent_private->abs_x + x, parent_private->abs_y + y); + (parent_private->abs_x + x) * GDK_X11_WINDOW_SCALE (window), + (parent_private->abs_y + y) * GDK_X11_WINDOW_SCALE (window)); _gdk_x11_window_tmp_reset_parent_bg (window); _gdk_x11_window_tmp_reset_bg (window, TRUE); @@ -1739,8 +1826,10 @@ gdk_window_x11_clear_region (GdkWindow *window, for (i = 0; i < n_rectangles; i++) XClearArea (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window), - rectangles[i].x, rectangles[i].y, - rectangles[i].width, rectangles[i].height, + rectangles[i].x * GDK_X11_WINDOW_SCALE (window), + rectangles[i].y * GDK_X11_WINDOW_SCALE (window), + rectangles[i].width * GDK_X11_WINDOW_SCALE (window), + rectangles[i].height * GDK_X11_WINDOW_SCALE (window), send_expose); g_free (rectangles); @@ -1976,22 +2065,22 @@ gdk_window_set_hints (GdkWindow *window, if (flags & GDK_HINT_POS) { size_hints.flags |= PPosition; - size_hints.x = x; - size_hints.y = y; + size_hints.x = x * GDK_X11_WINDOW_SCALE (window); + size_hints.y = y * GDK_X11_WINDOW_SCALE (window); } if (flags & GDK_HINT_MIN_SIZE) { size_hints.flags |= PMinSize; - size_hints.min_width = min_width; - size_hints.min_height = min_height; + size_hints.min_width = min_width * GDK_X11_WINDOW_SCALE (window); + size_hints.min_height = min_height * GDK_X11_WINDOW_SCALE (window); } if (flags & GDK_HINT_MAX_SIZE) { size_hints.flags |= PMaxSize; - size_hints.max_width = max_width; - size_hints.max_height = max_height; + size_hints.max_width = max_width * GDK_X11_WINDOW_SCALE (window); + size_hints.max_height = max_height * GDK_X11_WINDOW_SCALE (window); } /* FIXME: Would it be better to delete this property if @@ -2356,11 +2445,13 @@ gdk_window_set_geometry_hints (GdkWindow *window, GdkWindowHints geom_mask) { XSizeHints size_hints; + gint sc; if (GDK_WINDOW_DESTROYED (window) || !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window)) return; + sc = GDK_X11_WINDOW_SCALE (window); size_hints.flags = 0; if (geom_mask & GDK_HINT_POS) @@ -2387,29 +2478,29 @@ gdk_window_set_geometry_hints (GdkWindow *window, if (geom_mask & GDK_HINT_MIN_SIZE) { size_hints.flags |= PMinSize; - size_hints.min_width = geometry->min_width; - size_hints.min_height = geometry->min_height; + size_hints.min_width = geometry->min_width * sc; + size_hints.min_height = geometry->min_height * sc; } if (geom_mask & GDK_HINT_MAX_SIZE) { size_hints.flags |= PMaxSize; - size_hints.max_width = MAX (geometry->max_width, 1); - size_hints.max_height = MAX (geometry->max_height, 1); + size_hints.max_width = MAX (geometry->max_width, 1) * sc; + size_hints.max_height = MAX (geometry->max_height, 1) * sc; } if (geom_mask & GDK_HINT_BASE_SIZE) { size_hints.flags |= PBaseSize; - size_hints.base_width = geometry->base_width; - size_hints.base_height = geometry->base_height; + size_hints.base_width = geometry->base_width * sc; + size_hints.base_height = geometry->base_height * sc; } if (geom_mask & GDK_HINT_RESIZE_INC) { size_hints.flags |= PResizeInc; - size_hints.width_inc = geometry->width_inc; - size_hints.height_inc = geometry->height_inc; + size_hints.width_inc = geometry->width_inc * sc; + size_hints.height_inc = geometry->height_inc * sc; } if (geom_mask & GDK_HINT_ASPECT) @@ -2482,22 +2573,22 @@ gdk_window_get_geometry_hints (GdkWindow *window, if (size_hints->flags & PMinSize) { *geom_mask |= GDK_HINT_MIN_SIZE; - geometry->min_width = size_hints->min_width; - geometry->min_height = size_hints->min_height; + geometry->min_width = _gdk_x11_unscale_up (size_hints->min_width, GDK_X11_WINDOW_SCALE (window)); + geometry->min_height = _gdk_x11_unscale_up (size_hints->min_height, GDK_X11_WINDOW_SCALE (window)); } if (size_hints->flags & PMaxSize) { *geom_mask |= GDK_HINT_MAX_SIZE; - geometry->max_width = MAX (size_hints->max_width, 1); - geometry->max_height = MAX (size_hints->max_height, 1); + geometry->max_width = MAX (size_hints->max_width / GDK_X11_WINDOW_SCALE (window), 1); + geometry->max_height = MAX (size_hints->max_height / GDK_X11_WINDOW_SCALE (window), 1); } if (size_hints->flags & PResizeInc) { *geom_mask |= GDK_HINT_RESIZE_INC; - geometry->width_inc = size_hints->width_inc; - geometry->height_inc = size_hints->height_inc; + geometry->width_inc = MAX (size_hints->width_inc / GDK_X11_WINDOW_SCALE (window), 1); + geometry->height_inc = MAX (size_hints->height_inc / GDK_X11_WINDOW_SCALE (window), 1); } if (size_hints->flags & PAspect) @@ -2738,8 +2829,11 @@ void gdk_window_set_transient_for (GdkWindow *window, GdkWindow *parent) { + /* an offscreen window, or a child of one, has no X window to be + * transient for */ if (!GDK_WINDOW_DESTROYED (window) && !GDK_WINDOW_DESTROYED (parent) && - WINDOW_IS_TOPLEVEL_OR_FOREIGN (window)) + WINDOW_IS_TOPLEVEL_OR_FOREIGN (window) && + GDK_WINDOW_IS_X11 (parent)) XSetTransientForHint (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window), GDK_WINDOW_XID (parent)); @@ -2763,6 +2857,10 @@ gdk_window_x11_set_back_pixmap (GdkWindow *window, xpixmap = ParentRelative; else if (pixmap == GDK_NO_BG) xpixmap = None; + else if (_gdk_windowing_drawable_get_scale (pixmap) != GDK_X11_WINDOW_SCALE (window)) + /* HiDPI: the X server would tile its pixels in the wrong size; GDK + * paints the background itself anyway */ + xpixmap = None; else xpixmap = GDK_PIXMAP_XID (pixmap); @@ -2845,19 +2943,335 @@ gdk_window_x11_get_geometry (GdkWindow *window, GDK_WINDOW_XID (window), &root, &tx, &ty, &twidth, &theight, &tborder_width, &tdepth); + gint sc = GDK_X11_WINDOW_SCALE (window); + if (x) - *x = tx; + *x = _gdk_x11_unscale (tx, sc); if (y) - *y = ty; + *y = _gdk_x11_unscale (ty, sc); if (width) - *width = twidth; + *width = _gdk_x11_unscale_up (twidth, sc); if (height) - *height = theight; + *height = _gdk_x11_unscale_up (theight, sc); if (depth) *depth = tdepth; } } +/* Where native windows are on the screen. Asking the X server + * (XTranslateCoordinates) is a round trip, and programs ask often: + * Pale Moon and Firefox several times for every motion of the mouse. + * So the answer is kept per window, as long as nothing that can move + * windows has happened since: a ConfigureNotify (also the synthetic ones + * a window manager sends when it moves a frame), Reparent, Map, Unmap, + * Gravity, Circulate or DestroyNotify, or a move or reparent by GDK. + * Pointer events tell the position of their window, too, from their + * root and window coordinates. Half a second at most, for window + * managers that move frames without telling. */ +#define ROOT_ORIGIN_MAX_AGE (G_USEC_PER_SEC / 2) + +static guint root_coords_serial = 1; + +void +_gdk_x11_window_root_coords_changed (void) +{ + /* 0 is never current: it marks a failed lookup */ + if (++root_coords_serial == 0) + root_coords_serial = 1; +} + +void +_gdk_x11_window_set_root_origin (GdkWindow *window, + gint x, + gint y) +{ + GdkWindowObject *private = (GdkWindowObject *) window; + GdkWindowImplX11 *impl; + + if (!GDK_IS_WINDOW_IMPL_X11 (private->impl) || private->impl_window != private) + return; + impl = GDK_WINDOW_IMPL_X11 (private->impl); + impl->root_origin_x = x; + impl->root_origin_y = y; + impl->root_origin_serial = root_coords_serial; + impl->root_origin_time = g_get_monotonic_time (); +} + +/* HiDPI on monitors of different scales. The toplevel through whose + * monitor @window's points become root coordinates; NULL for the root + * window and foreign windows, which the screen maps */ +static GdkWindowImplX11 * +anchor_impl (GdkWindow *window) +{ + GdkWindowObject *top; + + if (!window) + return NULL; + + top = (GdkWindowObject *) gdk_window_get_toplevel (window); + if (!top || top->window_type == GDK_WINDOW_ROOT || + top->window_type == GDK_WINDOW_FOREIGN || + !GDK_IS_WINDOW_IMPL_X11 (top->impl)) + return NULL; + + return GDK_WINDOW_IMPL_X11 (top->impl); +} + +void +_gdk_x11_window_device_to_root (GdkWindow *window, + gdouble dx, + gdouble dy, + gdouble *x, + gdouble *y) +{ + GdkWindowImplX11 *impl = anchor_impl (window); + gint sc; + + if (!impl) + { + _gdk_x11_screen_device_to_root (window ? GDK_WINDOW_SCREEN (window) : gdk_screen_get_default (), + dx, dy, x, y); + return; + } + + sc = GDK_X11_IMPL_SCALE (impl); + if (x) + *x = impl->anchor.lx + (dx - impl->anchor.dx) / sc; + if (y) + *y = impl->anchor.ly + (dy - impl->anchor.dy) / sc; +} + +void +_gdk_x11_window_root_to_device (GdkWindow *window, + gint x, + gint y, + gint *dx, + gint *dy) +{ + GdkWindowImplX11 *impl = anchor_impl (window); + gint sc; + + if (!impl) + { + _gdk_x11_screen_root_to_device (window ? GDK_WINDOW_SCREEN (window) : gdk_screen_get_default (), + x, y, dx, dy); + return; + } + + sc = GDK_X11_IMPL_SCALE (impl); + if (dx) + *dx = impl->anchor.dx + (x - impl->anchor.lx) * sc; + if (dy) + *dy = impl->anchor.dy + (y - impl->anchor.ly) * sc; +} + +/* a size of the X server in a hint, from one scale to another */ +static int +rescale_hint (int value, gint from, gint to) +{ + gint64 v = (gint64) value / from * to; + + return v > G_MAXINT / 2 ? G_MAXINT / 2 : (int) v; +} + +/* the native windows in @private (not itself) to scale @scale */ +static void +rescale_native_children (GdkWindowObject *private, + gint scale) +{ + GList *l; + + for (l = private->children; l != NULL; l = l->next) + { + GdkWindowObject *child = l->data; + + if (child->impl_window == child && !child->destroyed && + GDK_IS_WINDOW_IMPL_X11 (child->impl) && + GDK_X11_IMPL_SCALE (child->impl) != scale) + { + GDK_X11_IMPL_SCALE (child->impl) = scale; + XMoveResizeWindow (GDK_WINDOW_XDISPLAY (child), GDK_WINDOW_XID (child), + (child->x + child->parent->abs_x) * scale, + (child->y + child->parent->abs_y) * scale, + MAX (child->width, 1) * scale, + MAX (child->height, 1) * scale); + _gdk_x11_drawable_update_scale (child->impl); + _gdk_window_reapply_shapes ((GdkWindow *) child); + } + + rescale_native_children (child, scale); + } +} + +/* a toplevel and the native windows in it to scale @scale; with @resize + * the X window becomes as large as it was in GDK's pixels */ +static void +set_window_scale (GdkWindow *window, + gint scale, + gboolean resize) +{ + GdkWindowObject *private = (GdkWindowObject *) window; + GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (private->impl); + Display *xdisplay = GDK_WINDOW_XDISPLAY (window); + gint old = GDK_X11_IMPL_SCALE (impl); + XSizeHints size_hints; + long supplied = 0; + + if (old == scale || GDK_WINDOW_DESTROYED (window)) + return; + + GDK_X11_IMPL_SCALE (impl) = scale; + _gdk_x11_drawable_update_scale (private->impl); + + /* the hints for the window manager in the new pixels */ + if (impl->toplevel && !impl->override_redirect && + XGetWMNormalHints (xdisplay, GDK_WINDOW_XID (window), &size_hints, &supplied)) + { + if (size_hints.flags & PMinSize) + { + size_hints.min_width = rescale_hint (size_hints.min_width, old, scale); + size_hints.min_height = rescale_hint (size_hints.min_height, old, scale); + } + if (size_hints.flags & PMaxSize) + { + size_hints.max_width = rescale_hint (size_hints.max_width, old, scale); + size_hints.max_height = rescale_hint (size_hints.max_height, old, scale); + } + if (size_hints.flags & PBaseSize) + { + size_hints.base_width = rescale_hint (size_hints.base_width, old, scale); + size_hints.base_height = rescale_hint (size_hints.base_height, old, scale); + } + if (size_hints.flags & PResizeInc) + { + size_hints.width_inc = MAX (rescale_hint (size_hints.width_inc, old, scale), 1); + size_hints.height_inc = MAX (rescale_hint (size_hints.height_inc, old, scale), 1); + } + XSetWMNormalHints (xdisplay, GDK_WINDOW_XID (window), &size_hints); + } + + if (resize) + XResizeWindow (xdisplay, GDK_WINDOW_XID (window), + MAX (private->width, 1) * scale, MAX (private->height, 1) * scale); + + _gdk_window_reapply_shapes (window); + rescale_native_children (private, scale); + _gdk_x11_window_root_coords_changed (); + gdk_window_invalidate_rect (window, NULL, TRUE); +} + +/* From a ConfigureNotify of a toplevel at (@dx, @dy) of the X server, of + * that size there: it takes the scale of the monitor its middle is on. + * 0 when the scale stays, 1 when it changed and the window keeps its + * size in GDK's pixels (GDK resized it), 2 when it changed and the + * window keeps the size of the X server (maximized or full screen, + * where the window manager decides the size). A window that would, + * grown or shrunk from its corner, no longer have its middle there keeps + * its scale, so that it does not go back and forth at the edge. */ +gint +_gdk_x11_window_update_scale (GdkWindow *window, + gint dx, + gint dy, + gint dwidth, + gint dheight) +{ + GdkWindowObject *private = (GdkWindowObject *) window; + GdkScreen *screen; + GdkWindowImplX11 *impl; + GdkX11RootAnchor anchor, after; + gboolean keep_device; + gint scale; + + if (!window || GDK_WINDOW_DESTROYED (window) || + private->window_type == GDK_WINDOW_CHILD || + private->window_type == GDK_WINDOW_ROOT || + private->window_type == GDK_WINDOW_FOREIGN || + !GDK_IS_WINDOW_IMPL_X11 (private->impl)) + return 0; + + screen = GDK_WINDOW_SCREEN (window); + impl = GDK_WINDOW_IMPL_X11 (private->impl); + + if (!_gdk_x11_screen_has_mixed_scales (screen)) + return 0; + + scale = _gdk_x11_screen_place (screen, TRUE, dx + dwidth / 2, dy + dheight / 2, &anchor); + + if (scale == GDK_X11_IMPL_SCALE (impl)) + { + if (memcmp (&anchor, &impl->anchor, sizeof anchor) != 0) + { + impl->anchor = anchor; + _gdk_x11_window_root_coords_changed (); + } + return 0; + } + + keep_device = (private->state & (GDK_WINDOW_STATE_MAXIMIZED | + GDK_WINDOW_STATE_FULLSCREEN)) != 0; + if (!keep_device && + (_gdk_x11_screen_place (screen, TRUE, + dx + MAX (private->width, 1) * scale / 2, + dy + MAX (private->height, 1) * scale / 2, + &after) != scale || + memcmp (&anchor, &after, sizeof anchor) != 0)) + return 0; + + impl->anchor = anchor; + set_window_scale (window, scale, !keep_device); + + return keep_device ? 2 : 1; +} + +/* after the monitors or their scales changed: the root window and each + * toplevel to the scale it has now */ +void +_gdk_x11_screen_rescale_windows (GdkScreen *screen) +{ + GdkWindowObject *root = (GdkWindowObject *) gdk_screen_get_root_window (screen); + GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (screen); + GList *toplevels, *l; + + if (root && GDK_IS_DRAWABLE_IMPL_X11 (root->impl)) + { + GDK_X11_IMPL_SCALE (root->impl) = screen_x11->root_scale; + root->width = WidthOfScreen (screen_x11->xscreen) / screen_x11->root_scale; + root->height = HeightOfScreen (screen_x11->xscreen) / screen_x11->root_scale; + _gdk_window_update_size ((GdkWindow *) root); + } + + toplevels = gdk_screen_get_toplevel_windows (screen); + for (l = toplevels; l != NULL; l = l->next) + { + GdkWindow *window = l->data; + GdkWindowObject *private = l->data; + GdkWindowImplX11 *impl; + Window child; + gint dx = 0, dy = 0, scale; + + if (GDK_WINDOW_DESTROYED (window) || private->window_type == GDK_WINDOW_FOREIGN || + !GDK_IS_WINDOW_IMPL_X11 (private->impl)) + continue; + impl = GDK_WINDOW_IMPL_X11 (private->impl); + + gdk_error_trap_push (); + XTranslateCoordinates (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window), + GDK_WINDOW_XROOTWIN (window), 0, 0, &dx, &dy, &child); + gdk_error_trap_pop (); + + scale = _gdk_x11_screen_place (screen, TRUE, + dx + private->width * GDK_X11_IMPL_SCALE (impl) / 2, + dy + private->height * GDK_X11_IMPL_SCALE (impl) / 2, + &impl->anchor); + set_window_scale (window, scale, + !(private->state & (GDK_WINDOW_STATE_MAXIMIZED | + GDK_WINDOW_STATE_FULLSCREEN))); + } + g_list_free (toplevels); + + _gdk_x11_window_root_coords_changed (); +} + static gint gdk_window_x11_get_root_coords (GdkWindow *window, gint x, @@ -2865,23 +3279,46 @@ gdk_window_x11_get_root_coords (GdkWindow *window, gint *root_x, gint *root_y) { - gint return_val; - Window child; - gint tx; - gint ty; + GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (((GdkWindowObject *) window)->impl); + gint64 now = g_get_monotonic_time (); - return_val = XTranslateCoordinates (GDK_WINDOW_XDISPLAY (window), - GDK_WINDOW_XID (window), - GDK_WINDOW_XROOTWIN (window), - x, y, &tx, &ty, - &child); + if (impl->root_origin_serial != root_coords_serial || + now - impl->root_origin_time > ROOT_ORIGIN_MAX_AGE) + { + Window child; + gint tx, ty; - if (root_x) - *root_x = tx; - if (root_y) - *root_y = ty; + if (!XTranslateCoordinates (GDK_WINDOW_XDISPLAY (window), + GDK_WINDOW_XID (window), + GDK_WINDOW_XROOTWIN (window), + 0, 0, &tx, &ty, + &child)) + { + impl->root_origin_serial = 0; + if (root_x) + *root_x = 0; + if (root_y) + *root_y = 0; + return FALSE; + } + impl->root_origin_x = tx; + impl->root_origin_y = ty; + impl->root_origin_serial = root_coords_serial; + impl->root_origin_time = now; + } - return return_val; + /* the origin is kept in pixels of the X server */ + { + gdouble rx, ry; + + _gdk_x11_window_device_to_root (window, impl->root_origin_x, impl->root_origin_y, &rx, &ry); + if (root_x) + *root_x = (gint) floor (rx) + x; + if (root_y) + *root_y = (gint) floor (ry) + y; + } + + return TRUE; } static gboolean @@ -2932,6 +3369,8 @@ gdk_window_x11_get_deskrelative_origin (GdkWindow *window, win, 0, 0, x, y, &root); + *x = _gdk_x11_unscale (*x, GDK_X11_WINDOW_SCALE (window)); + *y = _gdk_x11_unscale (*y, GDK_X11_WINDOW_SCALE (window)); return return_val; } @@ -3019,6 +3458,12 @@ gdk_window_get_frame_extents (GdkWindow *window, if (GDK_WINDOW_DESTROYED (private) || impl->override_redirect) return; + /* from here on in pixels of the X server */ + rect->x *= GDK_X11_WINDOW_SCALE (window); + rect->y *= GDK_X11_WINDOW_SCALE (window); + rect->width *= GDK_X11_WINDOW_SCALE (window); + rect->height *= GDK_X11_WINDOW_SCALE (window); + nvroots = 0; vroots = NULL; @@ -3130,6 +3575,18 @@ gdk_window_get_frame_extents (GdkWindow *window, XFree (vroots); gdk_error_trap_pop (); + + /* HiDPI: the frame through the monitor of the window */ + { + gdouble x1, y1, x2, y2; + + _gdk_x11_window_device_to_root (window, rect->x, rect->y, &x1, &y1); + _gdk_x11_window_device_to_root (window, rect->x + rect->width, rect->y + rect->height, &x2, &y2); + rect->x = (gint) floor (x1); + rect->y = (gint) floor (y1); + rect->width = (gint) ceil (x2) - rect->x; + rect->height = (gint) ceil (y2) - rect->y; + } } void @@ -3181,8 +3638,16 @@ _gdk_windowing_get_pointer (GdkDisplay *display, *screen = gdk_drawable_get_screen (gdk_root); } - *x = rootx; - *y = rooty; + { + GdkWindow *gdk_root = gdk_window_lookup_for_display (display, root); + gdouble rx = rootx, ry = rooty; + + /* HiDPI: through the monitor the pointer is on */ + if (gdk_root) + _gdk_x11_screen_device_to_root (gdk_drawable_get_screen (gdk_root), rootx, rooty, &rx, &ry); + *x = (gint) floor (rx); + *y = (gint) floor (ry); + } *mask = xmask; } @@ -3216,6 +3681,8 @@ gdk_window_x11_get_pointer (GdkWindow *window, if (child) return_val = gdk_window_lookup_for_display (GDK_WINDOW_DISPLAY (window), child) != NULL; } + winx = _gdk_x11_unscale (winx, GDK_X11_WINDOW_SCALE (window)); + winy = _gdk_x11_unscale (winy, GDK_X11_WINDOW_SCALE (window)); } else { @@ -3269,7 +3736,12 @@ gdk_display_warp_pointer (GdkDisplay *display, xdisplay = GDK_DISPLAY_XDISPLAY (display); dest = GDK_WINDOW_XWINDOW (gdk_screen_get_root_window (screen)); - XWarpPointer (xdisplay, None, dest, 0, 0, 0, 0, x, y); + { + gint dx, dy; + + _gdk_x11_screen_root_to_device (screen, x, y, &dx, &dy); + XWarpPointer (xdisplay, None, dest, 0, 0, 0, 0, dx, dy); + } } GdkWindow* @@ -3350,6 +3822,8 @@ _gdk_windowing_window_at_pointer (GdkDisplay *display, break; } gdk_window_get_geometry (window, NULL, NULL, &width, &height, NULL); + width *= GDK_X11_WINDOW_SCALE (window); + height *= GDK_X11_WINDOW_SCALE (window); if (winx >= 0 && winy >= 0 && winx < width && winy < height) { /* A childless toplevel, or below another window? */ @@ -3395,8 +3869,8 @@ _gdk_windowing_window_at_pointer (GdkDisplay *display, gdk_x11_display_ungrab (display); window = gdk_window_lookup_for_display (display, xwindow_last); - *win_x = window ? winx : -1; - *win_y = window ? winy : -1; + *win_x = window ? _gdk_x11_unscale (winx, GDK_X11_WINDOW_SCALE (window)) : -1; + *win_y = window ? _gdk_x11_unscale (winy, GDK_X11_WINDOW_SCALE (window)) : -1; if (mask) *mask = xmask; @@ -3445,6 +3919,9 @@ gdk_window_x11_set_events (GdkWindow *window, XSelectInput (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window), xevent_mask); + + if (GDK_DISPLAY_X11 (GDK_WINDOW_DISPLAY (window))->scroll) + _gdk_x11_scroll_select (window, xevent_mask, (event_mask & GDK_TOUCH_MASK) != 0); } } @@ -3538,7 +4015,7 @@ do_shape_combine_region (GdkWindow *window, XRectangle *xrects = NULL; _gdk_region_get_xrectangles (shape_region, - 0, 0, + 0, 0, GDK_X11_WINDOW_SCALE (window), &xrects, &n_rects); if (shape == ShapeBounding) @@ -3549,7 +4026,8 @@ do_shape_combine_region (GdkWindow *window, XShapeCombineRectangles (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window), shape, - offset_x, offset_y, + offset_x * GDK_X11_WINDOW_SCALE (window), + offset_y * GDK_X11_WINDOW_SCALE (window), xrects, n_rects, ShapeSet, YXBanded); @@ -3651,7 +4129,10 @@ gdk_window_set_accept_focus (GdkWindow *window, if (!GDK_WINDOW_DESTROYED (window) && WINDOW_IS_TOPLEVEL_OR_FOREIGN (window)) - update_wm_hints (window, FALSE); + { + update_wm_hints (window, FALSE); + set_wm_protocols (window); + } } } @@ -4665,7 +5146,8 @@ gdk_window_set_functions (GdkWindow *window, GdkRegion * _xwindow_get_shape (Display *xdisplay, Window window, - gint shape_type) + gint shape_type, + gint scale) { GdkRegion *shape; GdkRectangle *rl; @@ -4698,6 +5180,21 @@ _xwindow_get_shape (Display *xdisplay, return NULL; } + if (scale > 1) + { + /* in pixels of GDK, all that is partly in the shape */ + shape = gdk_region_new (); + for (i = 0; i < rn; i++) + { + GdkRectangle r = { xrl[i].x, xrl[i].y, xrl[i].width, xrl[i].height }; + + _gdk_x11_unscale_rect (&r, scale); + gdk_region_union_with_rect (shape, &r); + } + XFree (xrl); + return shape; + } + rl = g_new (GdkRectangle, rn); for (i = 0; i < rn; i++) { @@ -4736,7 +5233,8 @@ _gdk_windowing_get_shape_for_mask (GdkBitmap *mask) ShapeSet); region = _xwindow_get_shape (GDK_DISPLAY_XDISPLAY (display), - window, ShapeBounding); + window, ShapeBounding, + _gdk_windowing_drawable_get_scale (mask)); XDestroyWindow (GDK_DISPLAY_XDISPLAY (display), window); @@ -4749,7 +5247,8 @@ _gdk_windowing_window_get_shape (GdkWindow *window) if (!GDK_WINDOW_DESTROYED (window) && gdk_display_supports_shapes (GDK_WINDOW_DISPLAY (window))) return _xwindow_get_shape (GDK_WINDOW_XDISPLAY (window), - GDK_WINDOW_XID (window), ShapeBounding); + GDK_WINDOW_XID (window), ShapeBounding, + GDK_X11_WINDOW_SCALE (window)); return NULL; } @@ -4762,7 +5261,7 @@ _gdk_windowing_window_get_input_shape (GdkWindow *window) gdk_display_supports_input_shapes (GDK_WINDOW_DISPLAY (window))) return _xwindow_get_shape (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window), - ShapeInput); + ShapeInput, GDK_X11_WINDOW_SCALE (window)); #endif return NULL; @@ -4853,8 +5352,13 @@ wmspec_moveresize (GdkWindow *window, xclient.message_type = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_MOVERESIZE"); xclient.format = 32; - xclient.data.l[0] = root_x; - xclient.data.l[1] = root_y; + { + gint dx, dy; + + _gdk_x11_window_root_to_device (window, root_x, root_y, &dx, &dy); + xclient.data.l[0] = dx; + xclient.data.l[1] = dy; + } xclient.data.l[2] = direction; xclient.data.l[3] = 0; xclient.data.l[4] = 0; @@ -5157,9 +5661,14 @@ _gdk_moveresize_handle_event (XEvent *event) if (!moveresize_lookahead (mv_resize, event)) break; - update_pos (mv_resize, - event->xmotion.x_root, - event->xmotion.y_root); + { + /* HiDPI: in root coordinates of GDK */ + gdouble rx, ry; + + _gdk_x11_window_device_to_root (mv_resize->moveresize_window, + event->xmotion.x_root, event->xmotion.y_root, &rx, &ry); + update_pos (mv_resize, (gint) floor (rx), (gint) floor (ry)); + } /* This should never be triggered in normal cases, but in the * case where the drag started without an implicit grab being @@ -5172,9 +5681,14 @@ _gdk_moveresize_handle_event (XEvent *event) break; case ButtonRelease: - update_pos (mv_resize, - event->xbutton.x_root, - event->xbutton.y_root); + { + /* HiDPI: in root coordinates of GDK */ + gdouble rx, ry; + + _gdk_x11_window_device_to_root (mv_resize->moveresize_window, + event->xbutton.x_root, event->xbutton.y_root, &rx, &ry); + update_pos (mv_resize, (gint) floor (rx), (gint) floor (ry)); + } if (event->xbutton.button == mv_resize->moveresize_button) finish_drag (mv_resize); @@ -5333,6 +5847,9 @@ emulate_resize_drag (GdkWindow *window, { MoveResizeData *mv_resize = get_move_resize_data (GDK_WINDOW_DISPLAY (window), TRUE); + if (mv_resize->moveresize_window != NULL) + return; /* a drag is already going on */ + mv_resize->is_resize = TRUE; mv_resize->moveresize_button = button; mv_resize->resize_edge = edge; @@ -5363,6 +5880,9 @@ emulate_move_drag (GdkWindow *window, { MoveResizeData *mv_resize = get_move_resize_data (GDK_WINDOW_DISPLAY (window), TRUE); + if (mv_resize->moveresize_window != NULL) + return; /* a drag is already going on */ + mv_resize->is_resize = FALSE; mv_resize->moveresize_button = button; mv_resize->moveresize_x = root_x; @@ -5540,6 +6060,10 @@ _gdk_windowing_window_beep (GdkWindow *window) display = GDK_WINDOW_DISPLAY (window); + /* An untrusted client gets BadAccess for the bell */ + if (!GDK_DISPLAY_X11 (display)->trusted_client) + return; + #ifdef HAVE_XKB if (GDK_DISPLAY_X11 (display)->use_xkb) XkbBell (GDK_DISPLAY_XDISPLAY (display), diff --git a/gdk/x11/gdkwindow-x11.h b/gdk/x11/gdkwindow-x11.h index 69cca90c5..601f9d275 100644 --- a/gdk/x11/gdkwindow-x11.h +++ b/gdk/x11/gdkwindow-x11.h @@ -39,6 +39,14 @@ G_BEGIN_DECLS +/* HiDPI with monitors of different scales: root coordinates of GDK of a + * point of the X server on a monitor are l + (d - device) / scale */ +typedef struct +{ + gint dx, dy; /* the corner of the monitor in pixels of the X server */ + gint lx, ly; /* and in root coordinates of GDK */ +} GdkX11RootAnchor; + typedef struct _GdkToplevelX11 GdkToplevelX11; typedef struct _GdkWindowImplX11 GdkWindowImplX11; typedef struct _GdkWindowImplX11Class GdkWindowImplX11Class; @@ -66,6 +74,17 @@ struct _GdkWindowImplX11 guint override_redirect : 1; guint use_synchronized_configure : 1; + /* The position on the screen, kept for gdk_window_get_origin(), which + * would otherwise ask the X server each time (see get_root_coords) */ + gint root_origin_x; + gint root_origin_y; + guint root_origin_serial; + gint64 root_origin_time; + + /* HiDPI, of a toplevel on monitors of different scales: how its points + * become root coordinates (see _gdk_x11_window_device_to_root ()) */ + GdkX11RootAnchor anchor; + #if defined (HAVE_XCOMPOSITE) && defined(HAVE_XDAMAGE) && defined (HAVE_XFIXES) Damage damage; #endif diff --git a/gtk/Makefile.am b/gtk/Makefile.am index 31cc16730..09c849f11 100644 --- a/gtk/Makefile.am +++ b/gtk/Makefile.am @@ -224,6 +224,7 @@ gtk_public_h_sources = \ gtkfilechooser.h \ gtkfilechooserbutton.h \ gtkfilechooserdialog.h \ + gtkfilechoosernative.h \ gtkfilechooserwidget.h \ gtkfilefilter.h \ gtkfixed.h \ @@ -266,6 +267,7 @@ gtk_public_h_sources = \ gtkmisc.h \ gtkmodules.h \ gtkmountoperation.h \ + gtknativedialog.h \ gtknotebook.h \ gtkobject.h \ gtkoffscreenwindow.h \ @@ -386,9 +388,16 @@ gtk_private_h_sources = \ gtkfilechooserentry.h \ gtkfilechooserprivate.h \ gtkfilechoosersettings.h \ + gtkfilechoosernativeprivate.h \ + gtkemojichooser.h \ + gtkfilefilterprivate.h \ + gtknativedialogprivate.h \ gtkfilechooserutils.h \ + gtkfileoperation.h \ gtkfilesystem.h \ gtkfilesystemmodel.h \ + gtkfilethumbnail.h \ + gtktimeprivate.h \ gtkiconcache.h \ gtkimcontextsimpleseqs.h \ gtkintl.h \ @@ -483,14 +492,19 @@ gtk_base_c_sources = \ gtkfilechooserbutton.c \ gtkfilechooserdefault.c \ gtkfilechooserdialog.c \ + gtkfilechoosernative.c \ + gtkemojichooser.c \ + gtkfilechoosernativeportal.c \ gtkfilechooserembed.c \ gtkfilechooserentry.c \ gtkfilechoosersettings.c \ gtkfilechooserutils.c \ + gtkfileoperation.c \ gtkfilechooserwidget.c \ gtkfilefilter.c \ gtkfilesystem.c \ gtkfilesystemmodel.c \ + gtkfilethumbnail.c \ gtkfixed.c \ gtkfontbutton.c \ gtkfontsel.c \ @@ -538,6 +552,7 @@ gtk_base_c_sources = \ gtkmnemonichash.c \ gtkmodules.c \ gtkmountoperation.c \ + gtknativedialog.c \ gtknotebook.c \ gtkobject.c \ gtkoffscreenwindow.c \ @@ -741,12 +756,14 @@ gtk_use_x11_c_sources = \ gtktrayicon-x11.c \ gtkmountoperation-x11.c gtk_use_win32_c_sources = \ + gtkfilechoosernativewin32.c \ gtkplug-win32.c \ gtksocket-win32.c \ gtkwin32embed.c \ gtkwin32embedwidget.c \ gtkmountoperation-stub.c gtk_use_quartz_c_sources = \ + gtkfilechoosernativequartz.c \ gtksearchenginequartz.c \ gtkplug-stub.c \ gtksocket-stub.c \ @@ -834,7 +851,38 @@ MAINTAINERCLEANFILES = $(gtk_built_sources) $(stamp_files) $(GENERATED_ICONS) st EXTRA_HEADERS = EXTRA_DIST += $(gtk_private_h_sources) $(gtk_extra_sources) EXTRA_DIST += $(gtk_built_sources) -EXTRA_DIST += $(STOCK_ICONS) +EXTRA_DIST += $(STOCK_ICONS) stock-icons/render-sizes.py + +# the data of the emoji chooser, from GTK+ 3 +emojidir = $(datadir)/gtk-2.0/emoji +emoji_DATA = \ + emoji/bn.data \ + emoji/da.data \ + emoji/de.data \ + emoji/en.data \ + emoji/es.data \ + emoji/et.data \ + emoji/fi.data \ + emoji/fr.data \ + emoji/hi.data \ + emoji/hu.data \ + emoji/it.data \ + emoji/ja.data \ + emoji/ko.data \ + emoji/lt.data \ + emoji/ms.data \ + emoji/nb.data \ + emoji/nl.data \ + emoji/pl.data \ + emoji/pt.data \ + emoji/ru.data \ + emoji/sv.data \ + emoji/th.data \ + emoji/uk.data \ + emoji/vi.data \ + emoji/zh.data + +EXTRA_DIST += $(emoji_DATA) emoji/README # # rules to generate built sources @@ -926,7 +974,7 @@ libgtk_quartz_2_0_la_LDFLAGS = $(libtool_opts) libgtk_directfb_2_0_la_LDFLAGS = $(libtool_opts) libgtk_x11_2_0_la_LIBADD = $(libadd) -libgtk_win32_2_0_la_LIBADD = $(libadd) -lole32 -lgdi32 -lcomdlg32 -lwinspool -lcomctl32 +libgtk_win32_2_0_la_LIBADD = $(libadd) -lole32 -lgdi32 -lcomdlg32 -lwinspool -lcomctl32 -lshell32 -lmpr libgtk_quartz_2_0_la_LIBADD = $(libadd) libgtk_directfb_2_0_la_LIBADD = $(libadd) @@ -1389,39 +1437,564 @@ STOCK_ICONS = \ stock-icons/48/dialog-information.png \ stock-icons/48/dialog-password.png \ stock-icons/48/dialog-question.png \ - stock-icons/48/dialog-warning.png + stock-icons/48/dialog-warning.png \ + stock-icons/16/audio-volume-high.png \ + stock-icons/16/audio-volume-low.png \ + stock-icons/16/audio-volume-medium.png \ + stock-icons/16/audio-volume-muted.png \ + stock-icons/16/dialog-error.png \ + stock-icons/16/dialog-password.png \ + stock-icons/16/dialog-question.png \ + stock-icons/16/dialog-warning.png \ + stock-icons/16/gtk-apply.png \ + stock-icons/16/gtk-cancel.png \ + stock-icons/16/gtk-dnd-multiple.png \ + stock-icons/16/gtk-dnd.png \ + stock-icons/16/gtk-no.png \ + stock-icons/16/gtk-ok.png \ + stock-icons/16/gtk-yes.png \ + stock-icons/18/application-exit.png \ + stock-icons/18/audio-volume-high.png \ + stock-icons/18/audio-volume-low.png \ + stock-icons/18/audio-volume-medium.png \ + stock-icons/18/audio-volume-muted.png \ + stock-icons/18/dialog-error.png \ + stock-icons/18/dialog-information.png \ + stock-icons/18/dialog-password.png \ + stock-icons/18/dialog-question.png \ + stock-icons/18/dialog-warning.png \ + stock-icons/18/document-new.png \ + stock-icons/18/document-open-recent.png \ + stock-icons/18/document-open.png \ + stock-icons/18/document-print-preview.png \ + stock-icons/18/document-print.png \ + stock-icons/18/document-properties.png \ + stock-icons/18/document-revert-ltr.png \ + stock-icons/18/document-revert-rtl.png \ + stock-icons/18/document-save-as.png \ + stock-icons/18/drive-harddisk.png \ + stock-icons/18/edit-clear.png \ + stock-icons/18/edit-copy.png \ + stock-icons/18/edit-cut.png \ + stock-icons/18/edit-delete.png \ + stock-icons/18/edit-find-replace.png \ + stock-icons/18/edit-find.png \ + stock-icons/18/edit-paste.png \ + stock-icons/18/edit-redo-ltr.png \ + stock-icons/18/edit-redo-rtl.png \ + stock-icons/18/edit-select-all.png \ + stock-icons/18/edit-undo-ltr.png \ + stock-icons/18/edit-undo-rtl.png \ + stock-icons/18/folder.png \ + stock-icons/18/format-indent-less-ltr.png \ + stock-icons/18/format-indent-less-rtl.png \ + stock-icons/18/format-indent-more-ltr.png \ + stock-icons/18/format-indent-more-rtl.png \ + stock-icons/18/format-justify-center.png \ + stock-icons/18/format-justify-fill.png \ + stock-icons/18/format-justify-left.png \ + stock-icons/18/format-justify-right.png \ + stock-icons/18/format-text-bold.png \ + stock-icons/18/format-text-italic.png \ + stock-icons/18/format-text-strikethrough.png \ + stock-icons/18/format-text-underline.png \ + stock-icons/18/go-bottom.png \ + stock-icons/18/go-down.png \ + stock-icons/18/go-first-ltr.png \ + stock-icons/18/go-home.png \ + stock-icons/18/go-jump-ltr.png \ + stock-icons/18/go-jump-rtl.png \ + stock-icons/18/go-last-ltr.png \ + stock-icons/18/go-next-ltr.png \ + stock-icons/18/go-previous-ltr.png \ + stock-icons/18/go-top.png \ + stock-icons/18/go-up.png \ + stock-icons/18/gtk-apply.png \ + stock-icons/18/gtk-cancel.png \ + stock-icons/18/gtk-caps-lock-warning.png \ + stock-icons/18/gtk-color-picker.png \ + stock-icons/18/gtk-connect.png \ + stock-icons/18/gtk-convert.png \ + stock-icons/18/gtk-disconnect.png \ + stock-icons/18/gtk-dnd-multiple.png \ + stock-icons/18/gtk-dnd.png \ + stock-icons/18/gtk-edit.png \ + stock-icons/18/gtk-font.png \ + stock-icons/18/gtk-index.png \ + stock-icons/18/gtk-no.png \ + stock-icons/18/gtk-ok.png \ + stock-icons/18/gtk-orientation-landscape.png \ + stock-icons/18/gtk-orientation-portrait.png \ + stock-icons/18/gtk-orientation-reverse-landscape.png \ + stock-icons/18/gtk-orientation-reverse-portrait.png \ + stock-icons/18/gtk-page-setup.png \ + stock-icons/18/gtk-preferences.png \ + stock-icons/18/gtk-select-color.png \ + stock-icons/18/gtk-select-font.png \ + stock-icons/18/gtk-undelete-ltr.png \ + stock-icons/18/gtk-undelete-rtl.png \ + stock-icons/18/gtk-yes.png \ + stock-icons/18/help-about.png \ + stock-icons/18/help-contents.png \ + stock-icons/18/image-missing.png \ + stock-icons/18/list-add.png \ + stock-icons/18/list-remove.png \ + stock-icons/18/media-floppy.png \ + stock-icons/18/media-optical.png \ + stock-icons/18/media-playback-pause.png \ + stock-icons/18/media-playback-start-ltr.png \ + stock-icons/18/media-playback-start-rtl.png \ + stock-icons/18/media-playback-stop.png \ + stock-icons/18/media-record.png \ + stock-icons/18/media-seek-backward-ltr.png \ + stock-icons/18/media-seek-forward-ltr.png \ + stock-icons/18/media-skip-backward-ltr.png \ + stock-icons/18/media-skip-forward-ltr.png \ + stock-icons/18/network-idle.png \ + stock-icons/18/printer-error.png \ + stock-icons/18/printer-info.png \ + stock-icons/18/printer-paused.png \ + stock-icons/18/printer-warning.png \ + stock-icons/18/process-stop.png \ + stock-icons/18/system-run.png \ + stock-icons/18/text-x-generic.png \ + stock-icons/18/tools-check-spelling.png \ + stock-icons/18/view-fullscreen.png \ + stock-icons/18/view-refresh.png \ + stock-icons/18/view-restore.png \ + stock-icons/18/view-sort-ascending.png \ + stock-icons/18/view-sort-descending.png \ + stock-icons/18/window-close.png \ + stock-icons/18/zoom-fit-best.png \ + stock-icons/18/zoom-in.png \ + stock-icons/18/zoom-original.png \ + stock-icons/18/zoom-out.png \ + stock-icons/20/application-exit.png \ + stock-icons/20/audio-volume-high.png \ + stock-icons/20/audio-volume-low.png \ + stock-icons/20/audio-volume-medium.png \ + stock-icons/20/audio-volume-muted.png \ + stock-icons/20/dialog-error.png \ + stock-icons/20/dialog-information.png \ + stock-icons/20/dialog-password.png \ + stock-icons/20/dialog-question.png \ + stock-icons/20/dialog-warning.png \ + stock-icons/20/document-new.png \ + stock-icons/20/document-open-recent.png \ + stock-icons/20/document-open.png \ + stock-icons/20/document-print-preview.png \ + stock-icons/20/document-print.png \ + stock-icons/20/document-properties.png \ + stock-icons/20/document-revert-ltr.png \ + stock-icons/20/document-revert-rtl.png \ + stock-icons/20/document-save-as.png \ + stock-icons/20/drive-harddisk.png \ + stock-icons/20/edit-clear.png \ + stock-icons/20/edit-copy.png \ + stock-icons/20/edit-cut.png \ + stock-icons/20/edit-delete.png \ + stock-icons/20/edit-find-replace.png \ + stock-icons/20/edit-find.png \ + stock-icons/20/edit-paste.png \ + stock-icons/20/edit-redo-ltr.png \ + stock-icons/20/edit-redo-rtl.png \ + stock-icons/20/edit-select-all.png \ + stock-icons/20/edit-undo-ltr.png \ + stock-icons/20/edit-undo-rtl.png \ + stock-icons/20/folder.png \ + stock-icons/20/format-indent-less-ltr.png \ + stock-icons/20/format-indent-less-rtl.png \ + stock-icons/20/format-indent-more-ltr.png \ + stock-icons/20/format-indent-more-rtl.png \ + stock-icons/20/format-justify-center.png \ + stock-icons/20/format-justify-fill.png \ + stock-icons/20/format-justify-left.png \ + stock-icons/20/format-justify-right.png \ + stock-icons/20/format-text-bold.png \ + stock-icons/20/format-text-italic.png \ + stock-icons/20/format-text-strikethrough.png \ + stock-icons/20/format-text-underline.png \ + stock-icons/20/go-bottom.png \ + stock-icons/20/go-down.png \ + stock-icons/20/go-first-ltr.png \ + stock-icons/20/go-home.png \ + stock-icons/20/go-jump-ltr.png \ + stock-icons/20/go-jump-rtl.png \ + stock-icons/20/go-last-ltr.png \ + stock-icons/20/go-next-ltr.png \ + stock-icons/20/go-previous-ltr.png \ + stock-icons/20/go-top.png \ + stock-icons/20/go-up.png \ + stock-icons/20/gtk-caps-lock-warning.png \ + stock-icons/20/gtk-color-picker.png \ + stock-icons/20/gtk-connect.png \ + stock-icons/20/gtk-convert.png \ + stock-icons/20/gtk-disconnect.png \ + stock-icons/20/gtk-dnd-multiple.png \ + stock-icons/20/gtk-dnd.png \ + stock-icons/20/gtk-edit.png \ + stock-icons/20/gtk-font.png \ + stock-icons/20/gtk-index.png \ + stock-icons/20/gtk-orientation-landscape.png \ + stock-icons/20/gtk-orientation-portrait.png \ + stock-icons/20/gtk-orientation-reverse-landscape.png \ + stock-icons/20/gtk-orientation-reverse-portrait.png \ + stock-icons/20/gtk-page-setup.png \ + stock-icons/20/gtk-preferences.png \ + stock-icons/20/gtk-select-color.png \ + stock-icons/20/gtk-select-font.png \ + stock-icons/20/gtk-undelete-ltr.png \ + stock-icons/20/gtk-undelete-rtl.png \ + stock-icons/20/help-about.png \ + stock-icons/20/help-contents.png \ + stock-icons/20/image-missing.png \ + stock-icons/20/list-add.png \ + stock-icons/20/list-remove.png \ + stock-icons/20/media-floppy.png \ + stock-icons/20/media-optical.png \ + stock-icons/20/media-playback-pause.png \ + stock-icons/20/media-playback-start-ltr.png \ + stock-icons/20/media-playback-start-rtl.png \ + stock-icons/20/media-playback-stop.png \ + stock-icons/20/media-record.png \ + stock-icons/20/media-seek-backward-ltr.png \ + stock-icons/20/media-seek-forward-ltr.png \ + stock-icons/20/media-skip-backward-ltr.png \ + stock-icons/20/media-skip-forward-ltr.png \ + stock-icons/20/network-idle.png \ + stock-icons/20/printer-error.png \ + stock-icons/20/printer-info.png \ + stock-icons/20/printer-paused.png \ + stock-icons/20/printer-warning.png \ + stock-icons/20/process-stop.png \ + stock-icons/20/system-run.png \ + stock-icons/20/text-x-generic.png \ + stock-icons/20/tools-check-spelling.png \ + stock-icons/20/view-fullscreen.png \ + stock-icons/20/view-refresh.png \ + stock-icons/20/view-restore.png \ + stock-icons/20/view-sort-ascending.png \ + stock-icons/20/view-sort-descending.png \ + stock-icons/20/zoom-fit-best.png \ + stock-icons/20/zoom-in.png \ + stock-icons/20/zoom-original.png \ + stock-icons/20/zoom-out.png \ + stock-icons/24/dialog-error.png \ + stock-icons/24/dialog-password.png \ + stock-icons/24/dialog-question.png \ + stock-icons/24/dialog-warning.png \ + stock-icons/24/gtk-apply.png \ + stock-icons/24/gtk-cancel.png \ + stock-icons/24/gtk-dnd-multiple.png \ + stock-icons/24/gtk-dnd.png \ + stock-icons/24/gtk-no.png \ + stock-icons/24/gtk-ok.png \ + stock-icons/24/gtk-yes.png \ + stock-icons/32/application-exit.png \ + stock-icons/32/audio-volume-high.png \ + stock-icons/32/audio-volume-low.png \ + stock-icons/32/audio-volume-medium.png \ + stock-icons/32/audio-volume-muted.png \ + stock-icons/32/dialog-error.png \ + stock-icons/32/dialog-information.png \ + stock-icons/32/dialog-password.png \ + stock-icons/32/dialog-question.png \ + stock-icons/32/dialog-warning.png \ + stock-icons/32/document-new.png \ + stock-icons/32/document-open-recent.png \ + stock-icons/32/document-open.png \ + stock-icons/32/document-print-preview.png \ + stock-icons/32/document-print.png \ + stock-icons/32/document-properties.png \ + stock-icons/32/document-revert-ltr.png \ + stock-icons/32/document-revert-rtl.png \ + stock-icons/32/document-save-as.png \ + stock-icons/32/drive-harddisk.png \ + stock-icons/32/edit-clear.png \ + stock-icons/32/edit-copy.png \ + stock-icons/32/edit-cut.png \ + stock-icons/32/edit-delete.png \ + stock-icons/32/edit-find-replace.png \ + stock-icons/32/edit-find.png \ + stock-icons/32/edit-paste.png \ + stock-icons/32/edit-redo-ltr.png \ + stock-icons/32/edit-redo-rtl.png \ + stock-icons/32/edit-select-all.png \ + stock-icons/32/edit-undo-ltr.png \ + stock-icons/32/edit-undo-rtl.png \ + stock-icons/32/folder.png \ + stock-icons/32/format-indent-less-ltr.png \ + stock-icons/32/format-indent-less-rtl.png \ + stock-icons/32/format-indent-more-ltr.png \ + stock-icons/32/format-indent-more-rtl.png \ + stock-icons/32/format-justify-center.png \ + stock-icons/32/format-justify-fill.png \ + stock-icons/32/format-justify-left.png \ + stock-icons/32/format-justify-right.png \ + stock-icons/32/format-text-bold.png \ + stock-icons/32/format-text-italic.png \ + stock-icons/32/format-text-strikethrough.png \ + stock-icons/32/format-text-underline.png \ + stock-icons/32/go-bottom.png \ + stock-icons/32/go-down.png \ + stock-icons/32/go-first-ltr.png \ + stock-icons/32/go-home.png \ + stock-icons/32/go-jump-ltr.png \ + stock-icons/32/go-jump-rtl.png \ + stock-icons/32/go-last-ltr.png \ + stock-icons/32/go-next-ltr.png \ + stock-icons/32/go-previous-ltr.png \ + stock-icons/32/go-top.png \ + stock-icons/32/go-up.png \ + stock-icons/32/gtk-apply.png \ + stock-icons/32/gtk-cancel.png \ + stock-icons/32/gtk-caps-lock-warning.png \ + stock-icons/32/gtk-color-picker.png \ + stock-icons/32/gtk-connect.png \ + stock-icons/32/gtk-convert.png \ + stock-icons/32/gtk-disconnect.png \ + stock-icons/32/gtk-edit.png \ + stock-icons/32/gtk-font.png \ + stock-icons/32/gtk-index.png \ + stock-icons/32/gtk-no.png \ + stock-icons/32/gtk-ok.png \ + stock-icons/32/gtk-orientation-landscape.png \ + stock-icons/32/gtk-orientation-portrait.png \ + stock-icons/32/gtk-orientation-reverse-landscape.png \ + stock-icons/32/gtk-orientation-reverse-portrait.png \ + stock-icons/32/gtk-page-setup.png \ + stock-icons/32/gtk-preferences.png \ + stock-icons/32/gtk-select-color.png \ + stock-icons/32/gtk-select-font.png \ + stock-icons/32/gtk-undelete-ltr.png \ + stock-icons/32/gtk-undelete-rtl.png \ + stock-icons/32/gtk-yes.png \ + stock-icons/32/help-about.png \ + stock-icons/32/help-contents.png \ + stock-icons/32/image-missing.png \ + stock-icons/32/list-add.png \ + stock-icons/32/list-remove.png \ + stock-icons/32/media-floppy.png \ + stock-icons/32/media-optical.png \ + stock-icons/32/media-playback-pause.png \ + stock-icons/32/media-playback-start-ltr.png \ + stock-icons/32/media-playback-start-rtl.png \ + stock-icons/32/media-playback-stop.png \ + stock-icons/32/media-record.png \ + stock-icons/32/media-seek-backward-ltr.png \ + stock-icons/32/media-seek-forward-ltr.png \ + stock-icons/32/media-skip-backward-ltr.png \ + stock-icons/32/media-skip-forward-ltr.png \ + stock-icons/32/network-idle.png \ + stock-icons/32/printer-error.png \ + stock-icons/32/printer-info.png \ + stock-icons/32/printer-paused.png \ + stock-icons/32/printer-warning.png \ + stock-icons/32/process-stop.png \ + stock-icons/32/system-run.png \ + stock-icons/32/text-x-generic.png \ + stock-icons/32/tools-check-spelling.png \ + stock-icons/32/view-fullscreen.png \ + stock-icons/32/view-refresh.png \ + stock-icons/32/view-restore.png \ + stock-icons/32/view-sort-ascending.png \ + stock-icons/32/view-sort-descending.png \ + stock-icons/32/window-close.png \ + stock-icons/32/zoom-fit-best.png \ + stock-icons/32/zoom-in.png \ + stock-icons/32/zoom-original.png \ + stock-icons/32/zoom-out.png \ + stock-icons/48/application-exit.png \ + stock-icons/48/audio-volume-high.png \ + stock-icons/48/audio-volume-low.png \ + stock-icons/48/audio-volume-medium.png \ + stock-icons/48/audio-volume-muted.png \ + stock-icons/48/document-new.png \ + stock-icons/48/document-open-recent.png \ + stock-icons/48/document-open.png \ + stock-icons/48/document-print-preview.png \ + stock-icons/48/document-print.png \ + stock-icons/48/document-properties.png \ + stock-icons/48/document-revert-ltr.png \ + stock-icons/48/document-revert-rtl.png \ + stock-icons/48/document-save-as.png \ + stock-icons/48/drive-harddisk.png \ + stock-icons/48/edit-clear.png \ + stock-icons/48/edit-copy.png \ + stock-icons/48/edit-cut.png \ + stock-icons/48/edit-delete.png \ + stock-icons/48/edit-find-replace.png \ + stock-icons/48/edit-find.png \ + stock-icons/48/edit-paste.png \ + stock-icons/48/edit-redo-ltr.png \ + stock-icons/48/edit-redo-rtl.png \ + stock-icons/48/edit-select-all.png \ + stock-icons/48/edit-undo-ltr.png \ + stock-icons/48/edit-undo-rtl.png \ + stock-icons/48/folder.png \ + stock-icons/48/format-indent-less-ltr.png \ + stock-icons/48/format-indent-less-rtl.png \ + stock-icons/48/format-indent-more-ltr.png \ + stock-icons/48/format-indent-more-rtl.png \ + stock-icons/48/format-justify-center.png \ + stock-icons/48/format-justify-fill.png \ + stock-icons/48/format-justify-left.png \ + stock-icons/48/format-justify-right.png \ + stock-icons/48/format-text-bold.png \ + stock-icons/48/format-text-italic.png \ + stock-icons/48/format-text-strikethrough.png \ + stock-icons/48/format-text-underline.png \ + stock-icons/48/go-bottom.png \ + stock-icons/48/go-down.png \ + stock-icons/48/go-first-ltr.png \ + stock-icons/48/go-home.png \ + stock-icons/48/go-jump-ltr.png \ + stock-icons/48/go-jump-rtl.png \ + stock-icons/48/go-last-ltr.png \ + stock-icons/48/go-next-ltr.png \ + stock-icons/48/go-previous-ltr.png \ + stock-icons/48/go-top.png \ + stock-icons/48/go-up.png \ + stock-icons/48/gtk-apply.png \ + stock-icons/48/gtk-cancel.png \ + stock-icons/48/gtk-caps-lock-warning.png \ + stock-icons/48/gtk-color-picker.png \ + stock-icons/48/gtk-connect.png \ + stock-icons/48/gtk-convert.png \ + stock-icons/48/gtk-disconnect.png \ + stock-icons/48/gtk-dnd-multiple.png \ + stock-icons/48/gtk-dnd.png \ + stock-icons/48/gtk-edit.png \ + stock-icons/48/gtk-font.png \ + stock-icons/48/gtk-index.png \ + stock-icons/48/gtk-no.png \ + stock-icons/48/gtk-ok.png \ + stock-icons/48/gtk-orientation-landscape.png \ + stock-icons/48/gtk-orientation-portrait.png \ + stock-icons/48/gtk-orientation-reverse-landscape.png \ + stock-icons/48/gtk-orientation-reverse-portrait.png \ + stock-icons/48/gtk-page-setup.png \ + stock-icons/48/gtk-preferences.png \ + stock-icons/48/gtk-select-color.png \ + stock-icons/48/gtk-select-font.png \ + stock-icons/48/gtk-undelete-ltr.png \ + stock-icons/48/gtk-undelete-rtl.png \ + stock-icons/48/gtk-yes.png \ + stock-icons/48/help-about.png \ + stock-icons/48/help-contents.png \ + stock-icons/48/image-missing.png \ + stock-icons/48/list-add.png \ + stock-icons/48/list-remove.png \ + stock-icons/48/media-floppy.png \ + stock-icons/48/media-optical.png \ + stock-icons/48/media-playback-pause.png \ + stock-icons/48/media-playback-start-ltr.png \ + stock-icons/48/media-playback-start-rtl.png \ + stock-icons/48/media-playback-stop.png \ + stock-icons/48/media-record.png \ + stock-icons/48/media-seek-backward-ltr.png \ + stock-icons/48/media-seek-forward-ltr.png \ + stock-icons/48/media-skip-backward-ltr.png \ + stock-icons/48/media-skip-forward-ltr.png \ + stock-icons/48/network-idle.png \ + stock-icons/48/printer-error.png \ + stock-icons/48/printer-info.png \ + stock-icons/48/printer-paused.png \ + stock-icons/48/printer-warning.png \ + stock-icons/48/process-stop.png \ + stock-icons/48/system-run.png \ + stock-icons/48/text-x-generic.png \ + stock-icons/48/tools-check-spelling.png \ + stock-icons/48/view-fullscreen.png \ + stock-icons/48/view-refresh.png \ + stock-icons/48/view-restore.png \ + stock-icons/48/view-sort-ascending.png \ + stock-icons/48/view-sort-descending.png \ + stock-icons/48/window-close.png \ + stock-icons/48/zoom-fit-best.png \ + stock-icons/48/zoom-in.png \ + stock-icons/48/zoom-original.png \ + stock-icons/48/zoom-out.png GENERATED_ICONS = \ stock-icons/16/go-previous-rtl.png \ - stock-icons/16/go-next-rtl.png \ + stock-icons/16/go-next-rtl.png \ stock-icons/16/go-first-rtl.png \ - stock-icons/16/go-last-rtl.png \ - stock-icons/16/media-seek-forward-rtl.png \ - stock-icons/16/media-skip-forward-rtl.png \ - stock-icons/16/media-skip-backward-rtl.png \ - stock-icons/16/media-seek-backward-rtl.png \ + stock-icons/16/go-last-rtl.png \ + stock-icons/16/media-seek-forward-rtl.png \ + stock-icons/16/media-skip-forward-rtl.png \ + stock-icons/16/media-skip-backward-rtl.png \ + stock-icons/16/media-seek-backward-rtl.png \ stock-icons/16/document-save.png \ stock-icons/16/folder-remote.png \ - stock-icons/16/user-home.png \ + stock-icons/16/user-home.png \ stock-icons/16/user-desktop.png \ + stock-icons/18/go-previous-rtl.png \ + stock-icons/18/go-next-rtl.png \ + stock-icons/18/go-first-rtl.png \ + stock-icons/18/go-last-rtl.png \ + stock-icons/18/media-seek-forward-rtl.png \ + stock-icons/18/media-skip-forward-rtl.png \ + stock-icons/18/media-skip-backward-rtl.png \ + stock-icons/18/media-seek-backward-rtl.png \ + stock-icons/18/document-save.png \ + stock-icons/18/folder-remote.png \ + stock-icons/18/user-home.png \ + stock-icons/18/user-desktop.png \ + stock-icons/20/go-previous-rtl.png \ + stock-icons/20/go-next-rtl.png \ + stock-icons/20/go-first-rtl.png \ + stock-icons/20/go-last-rtl.png \ + stock-icons/20/media-seek-forward-rtl.png \ + stock-icons/20/media-skip-forward-rtl.png \ + stock-icons/20/media-skip-backward-rtl.png \ + stock-icons/20/media-seek-backward-rtl.png \ + stock-icons/20/document-save.png \ + stock-icons/20/folder-remote.png \ + stock-icons/20/user-home.png \ + stock-icons/20/user-desktop.png \ stock-icons/24/go-previous-rtl.png \ - stock-icons/24/go-next-rtl.png \ + stock-icons/24/go-next-rtl.png \ stock-icons/24/go-first-rtl.png \ - stock-icons/24/go-last-rtl.png \ - stock-icons/24/media-seek-forward-rtl.png \ - stock-icons/24/media-skip-forward-rtl.png \ - stock-icons/24/media-skip-backward-rtl.png \ - stock-icons/24/media-seek-backward-rtl.png \ + stock-icons/24/go-last-rtl.png \ + stock-icons/24/media-seek-forward-rtl.png \ + stock-icons/24/media-skip-forward-rtl.png \ + stock-icons/24/media-skip-backward-rtl.png \ + stock-icons/24/media-seek-backward-rtl.png \ stock-icons/24/document-save.png \ stock-icons/24/folder-remote.png \ - stock-icons/24/user-home.png \ - stock-icons/24/user-desktop.png + stock-icons/24/user-home.png \ + stock-icons/24/user-desktop.png \ + stock-icons/32/go-previous-rtl.png \ + stock-icons/32/go-next-rtl.png \ + stock-icons/32/go-first-rtl.png \ + stock-icons/32/go-last-rtl.png \ + stock-icons/32/media-seek-forward-rtl.png \ + stock-icons/32/media-skip-forward-rtl.png \ + stock-icons/32/media-skip-backward-rtl.png \ + stock-icons/32/media-seek-backward-rtl.png \ + stock-icons/32/document-save.png \ + stock-icons/32/folder-remote.png \ + stock-icons/32/user-home.png \ + stock-icons/32/user-desktop.png \ + stock-icons/48/go-previous-rtl.png \ + stock-icons/48/go-next-rtl.png \ + stock-icons/48/go-first-rtl.png \ + stock-icons/48/go-last-rtl.png \ + stock-icons/48/media-seek-forward-rtl.png \ + stock-icons/48/media-skip-forward-rtl.png \ + stock-icons/48/media-skip-backward-rtl.png \ + stock-icons/48/media-seek-backward-rtl.png \ + stock-icons/48/document-save.png \ + stock-icons/48/folder-remote.png \ + stock-icons/48/user-home.png \ + stock-icons/48/user-desktop.png # need to copy the icons so that we can replace the generated ones with # symlinks, even in the readonly srcdir case stamp-icons: $(STOCK_ICONS) if [ ! -d stock-icons ]; then \ - for d in 16 20 24 32 48; do \ + for d in 16 18 20 24 32 48; do \ mkdir -p stock-icons/$$d; \ done; \ for f in $(STOCK_ICONS); do \ @@ -1429,7 +2002,7 @@ stamp-icons: $(STOCK_ICONS) done; \ chmod -R u+w stock-icons; \ fi && \ - for i in 16 24; do \ + for i in 16 18 20 24 32 48; do \ (cd stock-icons/$$i \ && $(RM) document-save.png \ && $(LN_S) media-floppy.png document-save.png \ diff --git a/gtk/emoji/README b/gtk/emoji/README new file mode 100644 index 000000000..ea283e419 --- /dev/null +++ b/gtk/emoji/README @@ -0,0 +1,9 @@ +Emoji data of the emoji chooser (gtkemojichooser.c) + +The files are those of GTK+ 3.24 (gtk/emoji in its sources), one per +language: a GVariant of the type a(ausasu) - the code points (0 where a +skin tone may go), the name, the keywords and the group of each emoji. +GTK+ made them with its convert-emoji tool from emojibase +(https://github.com/milesj/emojibase, MIT licence), whose data comes +from the Unicode CLDR. They are installed to $(datadir)/gtk-2.0/emoji +and mapped only when the chooser is first opened. diff --git a/gtk/emoji/bn.data b/gtk/emoji/bn.data new file mode 100644 index 000000000..8dd157280 Binary files /dev/null and b/gtk/emoji/bn.data differ diff --git a/gtk/emoji/da.data b/gtk/emoji/da.data new file mode 100644 index 000000000..ff7cba157 Binary files /dev/null and b/gtk/emoji/da.data differ diff --git a/gtk/emoji/de.data b/gtk/emoji/de.data new file mode 100644 index 000000000..dae2f1628 Binary files /dev/null and b/gtk/emoji/de.data differ diff --git a/gtk/emoji/en.data b/gtk/emoji/en.data new file mode 100644 index 000000000..0987227f3 Binary files /dev/null and b/gtk/emoji/en.data differ diff --git a/gtk/emoji/es.data b/gtk/emoji/es.data new file mode 100644 index 000000000..784723ddb Binary files /dev/null and b/gtk/emoji/es.data differ diff --git a/gtk/emoji/et.data b/gtk/emoji/et.data new file mode 100644 index 000000000..c50864450 Binary files /dev/null and b/gtk/emoji/et.data differ diff --git a/gtk/emoji/fi.data b/gtk/emoji/fi.data new file mode 100644 index 000000000..d4e1e2899 Binary files /dev/null and b/gtk/emoji/fi.data differ diff --git a/gtk/emoji/fr.data b/gtk/emoji/fr.data new file mode 100644 index 000000000..57552a7a6 Binary files /dev/null and b/gtk/emoji/fr.data differ diff --git a/gtk/emoji/hi.data b/gtk/emoji/hi.data new file mode 100644 index 000000000..8ed962383 Binary files /dev/null and b/gtk/emoji/hi.data differ diff --git a/gtk/emoji/hu.data b/gtk/emoji/hu.data new file mode 100644 index 000000000..f46486f5e Binary files /dev/null and b/gtk/emoji/hu.data differ diff --git a/gtk/emoji/it.data b/gtk/emoji/it.data new file mode 100644 index 000000000..2ca532907 Binary files /dev/null and b/gtk/emoji/it.data differ diff --git a/gtk/emoji/ja.data b/gtk/emoji/ja.data new file mode 100644 index 000000000..f852efa7c Binary files /dev/null and b/gtk/emoji/ja.data differ diff --git a/gtk/emoji/ko.data b/gtk/emoji/ko.data new file mode 100644 index 000000000..284144e47 Binary files /dev/null and b/gtk/emoji/ko.data differ diff --git a/gtk/emoji/lt.data b/gtk/emoji/lt.data new file mode 100644 index 000000000..dc3e20d81 Binary files /dev/null and b/gtk/emoji/lt.data differ diff --git a/gtk/emoji/ms.data b/gtk/emoji/ms.data new file mode 100644 index 000000000..75b91f926 Binary files /dev/null and b/gtk/emoji/ms.data differ diff --git a/gtk/emoji/nb.data b/gtk/emoji/nb.data new file mode 100644 index 000000000..cfaac2435 Binary files /dev/null and b/gtk/emoji/nb.data differ diff --git a/gtk/emoji/nl.data b/gtk/emoji/nl.data new file mode 100644 index 000000000..b5d9da85f Binary files /dev/null and b/gtk/emoji/nl.data differ diff --git a/gtk/emoji/pl.data b/gtk/emoji/pl.data new file mode 100644 index 000000000..102a4829e Binary files /dev/null and b/gtk/emoji/pl.data differ diff --git a/gtk/emoji/pt.data b/gtk/emoji/pt.data new file mode 100644 index 000000000..b3acdce59 Binary files /dev/null and b/gtk/emoji/pt.data differ diff --git a/gtk/emoji/ru.data b/gtk/emoji/ru.data new file mode 100644 index 000000000..5ccb3565f Binary files /dev/null and b/gtk/emoji/ru.data differ diff --git a/gtk/emoji/sv.data b/gtk/emoji/sv.data new file mode 100644 index 000000000..510427ba8 Binary files /dev/null and b/gtk/emoji/sv.data differ diff --git a/gtk/emoji/th.data b/gtk/emoji/th.data new file mode 100644 index 000000000..b6463531d Binary files /dev/null and b/gtk/emoji/th.data differ diff --git a/gtk/emoji/uk.data b/gtk/emoji/uk.data new file mode 100644 index 000000000..3d554bce9 Binary files /dev/null and b/gtk/emoji/uk.data differ diff --git a/gtk/emoji/vi.data b/gtk/emoji/vi.data new file mode 100644 index 000000000..7af91dbae Binary files /dev/null and b/gtk/emoji/vi.data differ diff --git a/gtk/emoji/zh.data b/gtk/emoji/zh.data new file mode 100644 index 000000000..66d6f696f Binary files /dev/null and b/gtk/emoji/zh.data differ diff --git a/gtk/gtk.h b/gtk/gtk.h index 94e0b61f9..8ba2502f6 100644 --- a/gtk/gtk.h +++ b/gtk/gtk.h @@ -88,6 +88,7 @@ #include #include #include +#include #include #include #include @@ -128,6 +129,7 @@ #include #include #include +#include #include #include #include diff --git a/gtk/gtk.symbols b/gtk/gtk.symbols index 0a3b6b71f..d913c2681 100644 --- a/gtk/gtk.symbols +++ b/gtk/gtk.symbols @@ -40,7 +40,7 @@ gtk_about_dialog_set_name gtk_about_dialog_get_program_name gtk_about_dialog_set_program_name gtk_about_dialog_get_translator_credits -gtk_about_dialog_get_type G_GNUC_CONST +gtk_about_dialog_get_type gtk_about_dialog_get_version gtk_about_dialog_get_website gtk_about_dialog_get_website_label @@ -82,7 +82,7 @@ gtk_accel_group_disconnect gtk_accel_group_disconnect_key gtk_accel_group_find gtk_accel_group_from_accel_closure -gtk_accel_group_get_type G_GNUC_CONST +gtk_accel_group_get_type gtk_accel_group_get_is_locked gtk_accel_group_get_modifier_mask gtk_accel_group_lock @@ -98,7 +98,7 @@ gtk_accel_group_unlock #if IN_FILE(__GTK_ACCEL_LABEL_C__) gtk_accel_label_get_accel_widget gtk_accel_label_get_accel_width -gtk_accel_label_get_type G_GNUC_CONST +gtk_accel_label_get_type gtk_accel_label_new gtk_accel_label_refetch gtk_accel_label_set_accel_closure @@ -114,7 +114,7 @@ gtk_accel_map_change_entry gtk_accel_map_foreach gtk_accel_map_foreach_unfiltered gtk_accel_map_get -gtk_accel_map_get_type G_GNUC_CONST +gtk_accel_map_get_type #ifndef _WIN64 gtk_accel_map_load PRIVATE #endif @@ -139,7 +139,7 @@ gtk_accel_map_unlock_path #if IN_HEADER(__GTK_ACCESSIBLE_H__) #if IN_FILE(__GTK_ACCESSIBLE_C__) gtk_accessible_connect_widget_destroyed -gtk_accessible_get_type G_GNUC_CONST +gtk_accessible_get_type gtk_accessible_get_widget gtk_accessible_set_widget #endif @@ -180,7 +180,7 @@ gtk_action_get_sensitive gtk_action_get_short_label gtk_action_get_stock_id gtk_action_get_tooltip -gtk_action_get_type G_GNUC_CONST +gtk_action_get_type gtk_action_get_visible gtk_action_get_visible_horizontal gtk_action_get_visible_vertical @@ -221,7 +221,7 @@ gtk_action_group_add_toggle_actions_full gtk_action_group_get_action gtk_action_group_get_name gtk_action_group_get_sensitive -gtk_action_group_get_type G_GNUC_CONST +gtk_action_group_get_type gtk_action_group_get_visible gtk_action_group_list_actions gtk_action_group_new @@ -238,7 +238,7 @@ gtk_action_group_translate_string #if IN_FILE(__GTK_ACTIVATABLE_C__) gtk_activatable_do_set_related_action gtk_activatable_get_related_action -gtk_activatable_get_type G_GNUC_CONST +gtk_activatable_get_type gtk_activatable_get_use_action_appearance gtk_activatable_sync_action_properties gtk_activatable_set_related_action @@ -251,7 +251,7 @@ gtk_activatable_set_use_action_appearance gtk_adjustment_changed gtk_adjustment_clamp_page gtk_adjustment_configure -gtk_adjustment_get_type G_GNUC_CONST +gtk_adjustment_get_type gtk_adjustment_get_value gtk_adjustment_get_lower gtk_adjustment_get_upper @@ -272,7 +272,7 @@ gtk_adjustment_value_changed #if IN_HEADER(__GTK_ALIGNMENT_H__) #if IN_FILE(__GTK_ALIGNMENT_C__) gtk_alignment_get_padding -gtk_alignment_get_type G_GNUC_CONST +gtk_alignment_get_type gtk_alignment_new gtk_alignment_set gtk_alignment_set_padding @@ -282,7 +282,7 @@ gtk_alignment_set_padding #if IN_HEADER(__GTK_ASSISTANT_H__) #if IN_FILE(__GTK_ASSISTANT_C__) -gtk_assistant_get_type G_GNUC_CONST +gtk_assistant_get_type gtk_assistant_new gtk_assistant_get_current_page gtk_assistant_set_current_page @@ -311,129 +311,129 @@ gtk_assistant_commit #if IN_HEADER(__GTK_TYPE_BUILTINS_H__) #if IN_FILE(__GTK_TYPE_BUILTINS_C__) -gtk_pack_direction_get_type G_GNUC_CONST -gtk_ui_manager_item_type_get_type G_GNUC_CONST -gtk_spin_button_update_policy_get_type G_GNUC_CONST -gtk_notebook_tab_get_type G_GNUC_CONST -gtk_number_up_layout_get_type G_GNUC_CONST -gtk_anchor_type_get_type G_GNUC_CONST -gtk_arg_flags_get_type G_GNUC_CONST -gtk_arrow_type_get_type G_GNUC_CONST -gtk_arrow_placement_get_type G_GNUC_CONST -gtk_assistant_page_type_get_type G_GNUC_CONST -gtk_attach_options_get_type G_GNUC_CONST -gtk_builder_error_get_type G_GNUC_CONST -gtk_button_action_get_type G_GNUC_CONST -gtk_buttons_type_get_type G_GNUC_CONST -gtk_calendar_display_options_get_type G_GNUC_CONST -gtk_cell_renderer_mode_get_type G_GNUC_CONST -gtk_cell_renderer_state_get_type G_GNUC_CONST +gtk_pack_direction_get_type +gtk_ui_manager_item_type_get_type +gtk_spin_button_update_policy_get_type +gtk_notebook_tab_get_type +gtk_number_up_layout_get_type +gtk_anchor_type_get_type +gtk_arg_flags_get_type +gtk_arrow_type_get_type +gtk_arrow_placement_get_type +gtk_assistant_page_type_get_type +gtk_attach_options_get_type +gtk_builder_error_get_type +gtk_button_action_get_type +gtk_buttons_type_get_type +gtk_calendar_display_options_get_type +gtk_cell_renderer_mode_get_type +gtk_cell_renderer_state_get_type gtk_cell_renderer_accel_mode_get_type -gtk_corner_type_get_type G_GNUC_CONST -gtk_debug_flag_get_type G_GNUC_CONST -gtk_delete_type_get_type G_GNUC_CONST -gtk_dest_defaults_get_type G_GNUC_CONST -gtk_drag_result_get_type G_GNUC_CONST -gtk_clist_drag_pos_get_type G_GNUC_CONST -gtk_dialog_flags_get_type G_GNUC_CONST -gtk_direction_type_get_type G_GNUC_CONST -gtk_entry_icon_position_get_type G_GNUC_CONST -gtk_expander_style_get_type G_GNUC_CONST -gtk_file_chooser_action_get_type G_GNUC_CONST -gtk_file_chooser_confirmation_get_type G_GNUC_CONST -gtk_file_filter_flags_get_type G_GNUC_CONST -gtk_icon_view_drop_position_get_type G_GNUC_CONST -gtk_sensitivity_type_get_type G_GNUC_CONST -gtk_window_type_get_type G_GNUC_CONST -gtk_wrap_mode_get_type G_GNUC_CONST -gtk_widget_flags_get_type G_GNUC_CONST -gtk_widget_help_type_get_type G_GNUC_CONST -gtk_window_position_get_type G_GNUC_CONST -gtk_tree_view_column_sizing_get_type G_GNUC_CONST -gtk_tree_view_drop_position_get_type G_GNUC_CONST -gtk_button_box_style_get_type G_GNUC_CONST -gtk_cell_type_get_type G_GNUC_CONST -gtk_ctree_expander_style_get_type G_GNUC_CONST -gtk_ctree_expansion_type_get_type G_GNUC_CONST -gtk_ctree_line_style_get_type G_GNUC_CONST -gtk_ctree_pos_get_type G_GNUC_CONST -gtk_curve_type_get_type G_GNUC_CONST -gtk_icon_lookup_flags_get_type G_GNUC_CONST -gtk_image_type_get_type G_GNUC_CONST -gtk_im_preedit_style_get_type G_GNUC_CONST -gtk_im_status_style_get_type G_GNUC_CONST -gtk_justification_get_type G_GNUC_CONST -gtk_match_type_get_type G_GNUC_CONST -gtk_menu_direction_type_get_type G_GNUC_CONST -gtk_message_type_get_type G_GNUC_CONST -gtk_metric_type_get_type G_GNUC_CONST -gtk_movement_step_get_type G_GNUC_CONST -gtk_orientation_get_type G_GNUC_CONST -gtk_pack_type_get_type G_GNUC_CONST -gtk_page_orientation_get_type G_GNUC_CONST -gtk_print_operation_result_get_type G_GNUC_CONST -gtk_print_pages_get_type G_GNUC_CONST -gtk_print_quality_get_type G_GNUC_CONST -gtk_print_status_get_type G_GNUC_CONST -gtk_page_set_get_type G_GNUC_CONST -gtk_path_priority_type_get_type G_GNUC_CONST -gtk_path_type_get_type G_GNUC_CONST -gtk_policy_type_get_type G_GNUC_CONST -gtk_position_type_get_type G_GNUC_CONST -gtk_preview_type_get_type G_GNUC_CONST -gtk_print_duplex_get_type G_GNUC_CONST -gtk_print_error_get_type G_GNUC_CONST -gtk_recent_filter_flags_get_type G_GNUC_CONST -gtk_print_operation_action_get_type G_GNUC_CONST -gtk_private_flags_get_type G_GNUC_CONST -gtk_progress_bar_orientation_get_type G_GNUC_CONST -gtk_progress_bar_style_get_type G_GNUC_CONST -gtk_rc_flags_get_type G_GNUC_CONST -gtk_rc_token_type_get_type G_GNUC_CONST -gtk_recent_chooser_error_get_type G_GNUC_CONST -gtk_recent_manager_error_get_type G_GNUC_CONST -gtk_recent_sort_type_get_type G_GNUC_CONST -gtk_unit_get_type G_GNUC_CONST -gtk_relief_style_get_type G_GNUC_CONST -gtk_resize_mode_get_type G_GNUC_CONST -gtk_response_type_get_type G_GNUC_CONST -gtk_scroll_step_get_type G_GNUC_CONST -gtk_scroll_type_get_type G_GNUC_CONST -gtk_selection_mode_get_type G_GNUC_CONST -gtk_shadow_type_get_type G_GNUC_CONST -gtk_side_type_get_type G_GNUC_CONST -gtk_signal_run_type_get_type G_GNUC_CONST -gtk_size_group_mode_get_type G_GNUC_CONST -gtk_sort_type_get_type G_GNUC_CONST -gtk_spin_type_get_type G_GNUC_CONST -gtk_state_type_get_type G_GNUC_CONST -gtk_submenu_direction_get_type G_GNUC_CONST -gtk_submenu_placement_get_type G_GNUC_CONST -gtk_target_flags_get_type G_GNUC_CONST -gtk_text_direction_get_type G_GNUC_CONST -gtk_text_buffer_target_info_get_type G_GNUC_CONST -gtk_text_search_flags_get_type G_GNUC_CONST -gtk_text_window_type_get_type G_GNUC_CONST -gtk_tool_palette_drag_targets_get_type G_GNUC_CONST -gtk_tree_model_flags_get_type G_GNUC_CONST -gtk_tree_view_mode_get_type G_GNUC_CONST -gtk_tree_view_grid_lines_get_type G_GNUC_CONST -gtk_update_type_get_type G_GNUC_CONST -gtk_visibility_get_type G_GNUC_CONST -gtk_object_flags_get_type G_GNUC_CONST -gtk_accel_flags_get_type G_GNUC_CONST -gtk_icon_size_get_type G_GNUC_CONST -gtk_file_chooser_error_get_type G_GNUC_CONST -gtk_icon_theme_error_get_type G_GNUC_CONST -gtk_toolbar_child_type_get_type G_GNUC_CONST -gtk_toolbar_space_style_get_type G_GNUC_CONST -gtk_toolbar_style_get_type G_GNUC_CONST +gtk_corner_type_get_type +gtk_debug_flag_get_type +gtk_delete_type_get_type +gtk_dest_defaults_get_type +gtk_drag_result_get_type +gtk_clist_drag_pos_get_type +gtk_dialog_flags_get_type +gtk_direction_type_get_type +gtk_entry_icon_position_get_type +gtk_expander_style_get_type +gtk_file_chooser_action_get_type +gtk_file_chooser_confirmation_get_type +gtk_file_filter_flags_get_type +gtk_icon_view_drop_position_get_type +gtk_sensitivity_type_get_type +gtk_window_type_get_type +gtk_wrap_mode_get_type +gtk_widget_flags_get_type +gtk_widget_help_type_get_type +gtk_window_position_get_type +gtk_tree_view_column_sizing_get_type +gtk_tree_view_drop_position_get_type +gtk_button_box_style_get_type +gtk_cell_type_get_type +gtk_ctree_expander_style_get_type +gtk_ctree_expansion_type_get_type +gtk_ctree_line_style_get_type +gtk_ctree_pos_get_type +gtk_curve_type_get_type +gtk_icon_lookup_flags_get_type +gtk_image_type_get_type +gtk_im_preedit_style_get_type +gtk_im_status_style_get_type +gtk_justification_get_type +gtk_match_type_get_type +gtk_menu_direction_type_get_type +gtk_message_type_get_type +gtk_metric_type_get_type +gtk_movement_step_get_type +gtk_orientation_get_type +gtk_pack_type_get_type +gtk_page_orientation_get_type +gtk_print_operation_result_get_type +gtk_print_pages_get_type +gtk_print_quality_get_type +gtk_print_status_get_type +gtk_page_set_get_type +gtk_path_priority_type_get_type +gtk_path_type_get_type +gtk_policy_type_get_type +gtk_position_type_get_type +gtk_preview_type_get_type +gtk_print_duplex_get_type +gtk_print_error_get_type +gtk_recent_filter_flags_get_type +gtk_print_operation_action_get_type +gtk_private_flags_get_type +gtk_progress_bar_orientation_get_type +gtk_progress_bar_style_get_type +gtk_rc_flags_get_type +gtk_rc_token_type_get_type +gtk_recent_chooser_error_get_type +gtk_recent_manager_error_get_type +gtk_recent_sort_type_get_type +gtk_unit_get_type +gtk_relief_style_get_type +gtk_resize_mode_get_type +gtk_response_type_get_type +gtk_scroll_step_get_type +gtk_scroll_type_get_type +gtk_selection_mode_get_type +gtk_shadow_type_get_type +gtk_side_type_get_type +gtk_signal_run_type_get_type +gtk_size_group_mode_get_type +gtk_sort_type_get_type +gtk_spin_type_get_type +gtk_state_type_get_type +gtk_submenu_direction_get_type +gtk_submenu_placement_get_type +gtk_target_flags_get_type +gtk_text_direction_get_type +gtk_text_buffer_target_info_get_type +gtk_text_search_flags_get_type +gtk_text_window_type_get_type +gtk_tool_palette_drag_targets_get_type +gtk_tree_model_flags_get_type +gtk_tree_view_mode_get_type +gtk_tree_view_grid_lines_get_type +gtk_update_type_get_type +gtk_visibility_get_type +gtk_object_flags_get_type +gtk_accel_flags_get_type +gtk_icon_size_get_type +gtk_file_chooser_error_get_type +gtk_icon_theme_error_get_type +gtk_toolbar_child_type_get_type +gtk_toolbar_space_style_get_type +gtk_toolbar_style_get_type #endif #endif #if IN_HEADER(__GTK_ARROW_H__) #if IN_FILE(__GTK_ARROW_C__) -gtk_arrow_get_type G_GNUC_CONST +gtk_arrow_get_type gtk_arrow_new gtk_arrow_set #endif @@ -441,7 +441,7 @@ gtk_arrow_set #if IN_HEADER(__GTK_ASPECT_FRAME_H__) #if IN_FILE(__GTK_ASPECT_FRAME_C__) -gtk_aspect_frame_get_type G_GNUC_CONST +gtk_aspect_frame_get_type gtk_aspect_frame_new gtk_aspect_frame_set #endif @@ -470,7 +470,7 @@ gtk_binding_set_new #if IN_HEADER(__GTK_BIN_H__) #if IN_FILE(__GTK_BIN_C__) gtk_bin_get_child -gtk_bin_get_type G_GNUC_CONST +gtk_bin_get_type #endif #endif @@ -478,7 +478,7 @@ gtk_bin_get_type G_GNUC_CONST #if IN_FILE(__GTK_BOX_C__) gtk_box_get_homogeneous gtk_box_get_spacing -gtk_box_get_type G_GNUC_CONST +gtk_box_get_type gtk_box_pack_end gtk_box_pack_start #ifndef GTK_DISABLE_DEPRECATED @@ -502,7 +502,7 @@ gtk_buildable_custom_tag_end gtk_buildable_custom_finished gtk_buildable_get_internal_child gtk_buildable_get_name -gtk_buildable_get_type G_GNUC_CONST +gtk_buildable_get_type gtk_buildable_parser_finished gtk_buildable_set_name gtk_buildable_set_buildable_property @@ -519,7 +519,7 @@ gtk_builder_error_quark gtk_builder_get_object gtk_builder_get_objects gtk_builder_get_translation_domain -gtk_builder_get_type G_GNUC_CONST +gtk_builder_get_type gtk_builder_get_type_from_name gtk_builder_new gtk_builder_set_translation_domain @@ -540,7 +540,7 @@ gtk_button_box_get_child_size #endif gtk_button_box_get_child_secondary gtk_button_box_get_layout -gtk_button_box_get_type G_GNUC_CONST +gtk_button_box_get_type gtk_button_box_set_child_secondary gtk_button_box_set_layout #endif @@ -559,7 +559,7 @@ gtk_button_get_image gtk_button_get_image_position gtk_button_get_label gtk_button_get_relief -gtk_button_get_type G_GNUC_CONST +gtk_button_get_type gtk_button_get_use_stock gtk_button_get_use_underline #ifndef GTK_DISABLE_DEPRECATED @@ -596,7 +596,7 @@ gtk_calendar_get_date gtk_calendar_get_detail_height_rows gtk_calendar_get_detail_width_chars gtk_calendar_get_display_options -gtk_calendar_get_type G_GNUC_CONST +gtk_calendar_get_type gtk_calendar_mark_day gtk_calendar_new gtk_calendar_select_day @@ -612,7 +612,7 @@ gtk_calendar_unmark_day #if IN_HEADER(__GTK_CELL_EDITABLE_H__) #if IN_FILE(__GTK_CELL_EDITABLE_C__) gtk_cell_editable_editing_done -gtk_cell_editable_get_type G_GNUC_CONST +gtk_cell_editable_get_type gtk_cell_editable_remove_widget gtk_cell_editable_start_editing #endif @@ -623,7 +623,7 @@ gtk_cell_editable_start_editing gtk_cell_layout_add_attribute gtk_cell_layout_clear gtk_cell_layout_clear_attributes -gtk_cell_layout_get_type G_GNUC_CONST +gtk_cell_layout_get_type gtk_cell_layout_pack_end gtk_cell_layout_pack_start gtk_cell_layout_get_cells @@ -644,7 +644,7 @@ gtk_cell_renderer_get_fixed_size gtk_cell_renderer_get_padding gtk_cell_renderer_get_sensitive gtk_cell_renderer_get_size -gtk_cell_renderer_get_type G_GNUC_CONST +gtk_cell_renderer_get_type gtk_cell_renderer_get_visible gtk_cell_renderer_render gtk_cell_renderer_set_alignment @@ -659,49 +659,49 @@ gtk_cell_renderer_stop_editing #if IN_HEADER(__GTK_CELL_RENDERER_ACCEL_H__) #if IN_FILE(__GTK_CELL_RENDERER_ACCEL_C__) -gtk_cell_renderer_accel_get_type G_GNUC_CONST +gtk_cell_renderer_accel_get_type gtk_cell_renderer_accel_new #endif #endif #if IN_HEADER(__GTK_CELL_RENDERER_COMBO_H__) #if IN_FILE(__GTK_CELL_RENDERER_COMBO_C__) -gtk_cell_renderer_combo_get_type G_GNUC_CONST +gtk_cell_renderer_combo_get_type gtk_cell_renderer_combo_new #endif #endif #if IN_HEADER(__GTK_CELL_RENDERER_PIXBUF_H__) #if IN_FILE(__GTK_CELL_RENDERER_PIXBUF_C__) -gtk_cell_renderer_pixbuf_get_type G_GNUC_CONST +gtk_cell_renderer_pixbuf_get_type gtk_cell_renderer_pixbuf_new #endif #endif #if IN_HEADER(__GTK_CELL_RENDERER_SPIN_H__) #if IN_FILE(__GTK_CELL_RENDERER_SPIN_C__) -gtk_cell_renderer_spin_get_type G_GNUC_CONST +gtk_cell_renderer_spin_get_type gtk_cell_renderer_spin_new #endif #endif #if IN_HEADER(__GTK_CELL_RENDERER_SPINNER_H__) #if IN_FILE(__GTK_CELL_RENDERER_SPINNER_C__) -gtk_cell_renderer_spinner_get_type G_GNUC_CONST +gtk_cell_renderer_spinner_get_type gtk_cell_renderer_spinner_new #endif #endif #if IN_HEADER(__GTK_CELL_RENDERER_PROGRESS_H__) #if IN_FILE(__GTK_CELL_RENDERER_PROGRESS_C__) -gtk_cell_renderer_progress_get_type G_GNUC_CONST +gtk_cell_renderer_progress_get_type gtk_cell_renderer_progress_new #endif #endif #if IN_HEADER(__GTK_CELL_RENDERER_TEXT_H__) #if IN_FILE(__GTK_CELL_RENDERER_TEXT_C__) -gtk_cell_renderer_text_get_type G_GNUC_CONST +gtk_cell_renderer_text_get_type gtk_cell_renderer_text_new gtk_cell_renderer_text_set_fixed_height_from_font #endif @@ -712,7 +712,7 @@ gtk_cell_renderer_text_set_fixed_height_from_font gtk_cell_renderer_toggle_get_activatable gtk_cell_renderer_toggle_get_active gtk_cell_renderer_toggle_get_radio -gtk_cell_renderer_toggle_get_type G_GNUC_CONST +gtk_cell_renderer_toggle_get_type gtk_cell_renderer_toggle_new gtk_cell_renderer_toggle_set_activatable gtk_cell_renderer_toggle_set_active @@ -728,7 +728,7 @@ gtk_cell_view_get_cell_renderers gtk_cell_view_get_displayed_row gtk_cell_view_get_model gtk_cell_view_get_size_of_row -gtk_cell_view_get_type G_GNUC_CONST +gtk_cell_view_get_type gtk_cell_view_new gtk_cell_view_new_with_markup gtk_cell_view_new_with_pixbuf @@ -741,7 +741,7 @@ gtk_cell_view_set_model #if IN_HEADER(__GTK_CHECK_BUTTON_H__) #if IN_FILE(__GTK_CHECK_BUTTON_C__) -gtk_check_button_get_type G_GNUC_CONST +gtk_check_button_get_type gtk_check_button_new gtk_check_button_new_with_label gtk_check_button_new_with_mnemonic @@ -753,7 +753,7 @@ gtk_check_button_new_with_mnemonic gtk_check_menu_item_get_active gtk_check_menu_item_get_draw_as_radio gtk_check_menu_item_get_inconsistent -gtk_check_menu_item_get_type G_GNUC_CONST +gtk_check_menu_item_get_type gtk_check_menu_item_new gtk_check_menu_item_new_with_label gtk_check_menu_item_new_with_mnemonic @@ -774,7 +774,7 @@ gtk_clipboard_get gtk_clipboard_get_display gtk_clipboard_get_for_display gtk_clipboard_get_owner -gtk_clipboard_get_type G_GNUC_CONST +gtk_clipboard_get_type gtk_clipboard_request_contents gtk_clipboard_request_image gtk_clipboard_request_rich_text @@ -827,7 +827,7 @@ gtk_clist_get_row_style gtk_clist_get_selectable gtk_clist_get_selection_info gtk_clist_get_text -gtk_clist_get_type G_GNUC_CONST +gtk_clist_get_type gtk_clist_get_vadjustment gtk_clist_insert gtk_clist_moveto @@ -887,7 +887,7 @@ gtk_clist_unselect_row gtk_color_button_get_alpha gtk_color_button_get_color gtk_color_button_get_title -gtk_color_button_get_type G_GNUC_CONST +gtk_color_button_get_type gtk_color_button_get_use_alpha gtk_color_button_new gtk_color_button_new_with_color @@ -906,7 +906,7 @@ gtk_color_selection_get_has_opacity_control gtk_color_selection_get_has_palette gtk_color_selection_get_previous_alpha gtk_color_selection_get_previous_color -gtk_color_selection_get_type G_GNUC_CONST +gtk_color_selection_get_type gtk_color_selection_is_adjusting gtk_color_selection_new gtk_color_selection_palette_from_string @@ -929,7 +929,7 @@ gtk_color_selection_set_previous_color #if IN_HEADER(__GTK_COLOR_SELECTION_DIALOG_H__) #if IN_FILE(__GTK_COLOR_SELECTION_DIALOG_C__) -gtk_color_selection_dialog_get_type G_GNUC_CONST +gtk_color_selection_dialog_get_type gtk_color_selection_dialog_new gtk_color_selection_dialog_get_color_selection #endif @@ -952,7 +952,7 @@ gtk_combo_box_get_row_separator_func gtk_combo_box_get_row_span_column gtk_combo_box_get_button_sensitivity gtk_combo_box_get_title -gtk_combo_box_get_type G_GNUC_CONST +gtk_combo_box_get_type gtk_combo_box_get_wrap_width gtk_combo_box_insert_text gtk_combo_box_new @@ -983,7 +983,7 @@ gtk_combo_box_set_wrap_width #if IN_FILE(__GTK_COMBO_BOX_TEXT_C__) gtk_combo_box_text_append_text gtk_combo_box_text_get_active_text -gtk_combo_box_text_get_type G_GNUC_CONST +gtk_combo_box_text_get_type gtk_combo_box_text_insert_text gtk_combo_box_text_new gtk_combo_box_text_new_with_entry @@ -996,7 +996,7 @@ gtk_combo_box_text_remove #if IN_FILE(__GTK_COMBO_BOX_ENTRY_C__) #ifndef GTK_DISABLE_DEPRECATED gtk_combo_box_entry_get_text_column -gtk_combo_box_entry_get_type G_GNUC_CONST +gtk_combo_box_entry_get_type gtk_combo_box_entry_new gtk_combo_box_entry_new_text gtk_combo_box_entry_new_with_model @@ -1009,7 +1009,7 @@ gtk_combo_box_entry_set_text_column #if IN_FILE(__GTK_SMART_COMBO_C__) #ifndef GTK_DISABLE_DEPRECATED gtk_combo_disable_activate -gtk_combo_get_type G_GNUC_CONST +gtk_combo_get_type gtk_combo_new gtk_combo_set_case_sensitive gtk_combo_set_item_string @@ -1048,7 +1048,7 @@ gtk_container_get_focus_child gtk_container_get_focus_hadjustment gtk_container_get_focus_vadjustment gtk_container_get_resize_mode -gtk_container_get_type G_GNUC_CONST +gtk_container_get_type gtk_container_propagate_expose gtk_container_remove gtk_container_resize_children @@ -1080,7 +1080,7 @@ gtk_ctree_find_by_row_data gtk_ctree_find_by_row_data_custom gtk_ctree_find_node_ptr gtk_ctree_get_node_info -gtk_ctree_get_type G_GNUC_CONST +gtk_ctree_get_type gtk_ctree_insert_gnode gtk_ctree_insert_node gtk_ctree_is_ancestor @@ -1098,7 +1098,7 @@ gtk_ctree_node_get_row_data gtk_ctree_node_get_row_style gtk_ctree_node_get_selectable gtk_ctree_node_get_text -gtk_ctree_node_get_type G_GNUC_CONST +gtk_ctree_node_get_type gtk_ctree_node_is_visible gtk_ctree_node_moveto gtk_ctree_node_nth @@ -1141,7 +1141,7 @@ gtk_ctree_unselect_recursive #if IN_HEADER(__GTK_CURVE_H__) #if IN_FILE(__GTK_CURVE_C__) #ifndef GTK_DISABLE_DEPRECATED -gtk_curve_get_type G_GNUC_CONST +gtk_curve_get_type gtk_curve_get_vector gtk_curve_new gtk_curve_reset @@ -1171,7 +1171,7 @@ gtk_dialog_get_action_area gtk_dialog_get_content_area gtk_dialog_get_widget_for_response gtk_dialog_get_response_for_widget -gtk_dialog_get_type G_GNUC_CONST +gtk_dialog_get_type gtk_dialog_new gtk_dialog_new_with_buttons gtk_dialog_response @@ -1233,7 +1233,7 @@ gtk_drag_unhighlight #if IN_HEADER(__GTK_STATUS_ICON_H__) #if IN_FILE(__GTK_STATUS_ICON_C__) -gtk_status_icon_get_type G_GNUC_CONST +gtk_status_icon_get_type gtk_status_icon_new gtk_status_icon_new_from_pixbuf gtk_status_icon_new_from_file @@ -1332,12 +1332,12 @@ gtk_paint_vline gtk_border_new G_GNUC_MALLOC gtk_border_copy gtk_border_free -gtk_border_get_type G_GNUC_CONST +gtk_border_get_type gtk_style_apply_default_background gtk_style_attach gtk_style_copy gtk_style_detach -gtk_style_get_type G_GNUC_CONST +gtk_style_get_type gtk_style_lookup_icon_set gtk_style_lookup_color gtk_style_new @@ -1352,7 +1352,7 @@ gtk_style_get #if IN_HEADER(__GTK_DRAWING_AREA_H__) #if IN_FILE(__GTK_DRAWING_AREA_C__) -gtk_drawing_area_get_type G_GNUC_CONST +gtk_drawing_area_get_type gtk_drawing_area_new #ifndef GTK_DISABLE_DEPRECATED gtk_drawing_area_size @@ -1370,7 +1370,7 @@ gtk_editable_get_chars gtk_editable_get_editable gtk_editable_get_position gtk_editable_get_selection_bounds -gtk_editable_get_type G_GNUC_CONST +gtk_editable_get_type gtk_editable_insert_text gtk_editable_paste_clipboard gtk_editable_select_region @@ -1381,6 +1381,12 @@ gtk_editable_set_position #if IN_HEADER(__GTK_ENTRY_H__) #if IN_FILE(__GTK_ENTRY_C__) +gtk_entry_get_input_hints +gtk_entry_get_input_purpose +gtk_entry_get_placeholder_text +gtk_entry_set_input_hints +gtk_entry_set_input_purpose +gtk_entry_set_placeholder_text gtk_entry_get_activates_default gtk_entry_get_alignment gtk_entry_get_buffer @@ -1409,7 +1415,7 @@ gtk_entry_get_progress_fraction gtk_entry_get_progress_pulse_step gtk_entry_get_text gtk_entry_get_text_length -gtk_entry_get_type G_GNUC_CONST +gtk_entry_get_type gtk_entry_get_visibility gtk_entry_get_width_chars gtk_entry_get_text_window @@ -1470,7 +1476,7 @@ gtk_entry_completion_get_popup_completion gtk_entry_completion_get_popup_set_width gtk_entry_completion_get_popup_single_match gtk_entry_completion_get_text_column -gtk_entry_completion_get_type G_GNUC_CONST +gtk_entry_completion_get_type gtk_entry_completion_insert_action_markup gtk_entry_completion_insert_action_text gtk_entry_completion_insert_prefix @@ -1489,7 +1495,7 @@ gtk_entry_completion_set_text_column #if IN_HEADER(__GTK_ENTRY_BUFFER_H__) #if IN_FILE(__GTK_ENTRY_BUFFER_C__) -gtk_entry_buffer_get_type G_GNUC_CONST +gtk_entry_buffer_get_type gtk_entry_buffer_new gtk_entry_buffer_get_bytes gtk_entry_buffer_get_length @@ -1507,7 +1513,7 @@ gtk_entry_buffer_emit_deleted_text #if IN_HEADER(__GTK_EVENT_BOX_H__) #if IN_FILE(__GTK_EVENT_BOX_C__) gtk_event_box_get_above_child -gtk_event_box_get_type G_GNUC_CONST +gtk_event_box_get_type gtk_event_box_get_visible_window gtk_event_box_new gtk_event_box_set_above_child @@ -1522,7 +1528,7 @@ gtk_expander_get_label gtk_expander_get_label_fill gtk_expander_get_label_widget gtk_expander_get_spacing -gtk_expander_get_type G_GNUC_CONST +gtk_expander_get_type gtk_expander_get_use_markup gtk_expander_get_use_underline gtk_expander_new @@ -1590,7 +1596,7 @@ gtk_file_chooser_set_do_overwrite_confirmation gtk_file_chooser_get_do_overwrite_confirmation gtk_file_chooser_set_create_folders gtk_file_chooser_get_create_folders -gtk_file_chooser_get_type G_GNUC_CONST +gtk_file_chooser_get_type gtk_file_chooser_get_uri gtk_file_chooser_get_uris gtk_file_chooser_get_use_preview_label @@ -1659,7 +1665,7 @@ gtk_file_chooser_unselect_uri #if IN_HEADER(__GTK_FILE_CHOOSER_DIALOG_H__) #if IN_FILE(__GTK_FILE_CHOOSER_DIALOG_C__) -gtk_file_chooser_dialog_get_type G_GNUC_CONST +gtk_file_chooser_dialog_get_type gtk_file_chooser_dialog_new #ifndef GTK_DISABLE_DEPRECATED gtk_file_chooser_dialog_new_with_backend @@ -1667,9 +1673,37 @@ gtk_file_chooser_dialog_new_with_backend #endif #endif +#if IN_HEADER(__GTK_FILE_CHOOSER_NATIVE_H__) +#if IN_FILE(__GTK_FILE_CHOOSER_NATIVE_C__) +gtk_file_chooser_native_get_accept_label +gtk_file_chooser_native_get_cancel_label +gtk_file_chooser_native_get_type +gtk_file_chooser_native_new +gtk_file_chooser_native_set_accept_label +gtk_file_chooser_native_set_cancel_label +#endif +#endif + +#if IN_HEADER(__GTK_NATIVE_DIALOG_H__) +#if IN_FILE(__GTK_NATIVE_DIALOG_C__) +gtk_native_dialog_destroy +gtk_native_dialog_get_modal +gtk_native_dialog_get_title +gtk_native_dialog_get_transient_for +gtk_native_dialog_get_type +gtk_native_dialog_get_visible +gtk_native_dialog_hide +gtk_native_dialog_run +gtk_native_dialog_set_modal +gtk_native_dialog_set_title +gtk_native_dialog_set_transient_for +gtk_native_dialog_show +#endif +#endif + #if IN_HEADER(__GTK_FILE_CHOOSER_WIDGET_H__) #if IN_FILE(__GTK_FILE_CHOOSER_WIDGET_C__) -gtk_file_chooser_widget_get_type G_GNUC_CONST +gtk_file_chooser_widget_get_type gtk_file_chooser_widget_new #ifndef GTK_DISABLE_DEPRECATED gtk_file_chooser_widget_new_with_backend @@ -1680,7 +1714,7 @@ gtk_file_chooser_widget_new_with_backend #if IN_HEADER(__GTK_FILE_CHOOSER_BUTTON_H__) #if IN_FILE(__GTK_FILE_CHOOSER_BUTTON_C__) gtk_file_chooser_button_get_title -gtk_file_chooser_button_get_type G_GNUC_CONST +gtk_file_chooser_button_get_type gtk_file_chooser_button_get_width_chars gtk_file_chooser_button_new #ifndef GTK_DISABLE_DEPRECATED @@ -1703,9 +1737,11 @@ gtk_file_filter_add_pixbuf_formats gtk_file_filter_filter gtk_file_filter_get_name gtk_file_filter_get_needed -gtk_file_filter_get_type G_GNUC_CONST +gtk_file_filter_get_type gtk_file_filter_new +gtk_file_filter_new_from_gvariant gtk_file_filter_set_name +gtk_file_filter_to_gvariant #endif #endif @@ -1726,7 +1762,7 @@ gtk_file_selection_get_selections PRIVATE gtk_file_selection_get_selections_utf8 #endif gtk_file_selection_get_select_multiple -gtk_file_selection_get_type G_GNUC_CONST +gtk_file_selection_get_type gtk_file_selection_hide_fileop_buttons gtk_file_selection_new #ifndef _WIN64 @@ -1743,7 +1779,7 @@ gtk_file_selection_show_fileop_buttons #if IN_HEADER(__GTK_FIXED_H__) #if IN_FILE(__GTK_FIXED_C__) -gtk_fixed_get_type G_GNUC_CONST +gtk_fixed_get_type gtk_fixed_move gtk_fixed_new gtk_fixed_put @@ -1760,7 +1796,7 @@ gtk_font_button_get_font_name gtk_font_button_get_show_size gtk_font_button_get_show_style gtk_font_button_get_title -gtk_font_button_get_type G_GNUC_CONST +gtk_font_button_get_type gtk_font_button_get_use_font gtk_font_button_get_use_size gtk_font_button_new @@ -1781,7 +1817,7 @@ gtk_font_selection_dialog_get_font_name gtk_font_selection_dialog_get_font_selection gtk_font_selection_dialog_get_ok_button gtk_font_selection_dialog_get_preview_text -gtk_font_selection_dialog_get_type G_GNUC_CONST +gtk_font_selection_dialog_get_type gtk_font_selection_dialog_new gtk_font_selection_dialog_set_font_name gtk_font_selection_dialog_set_preview_text @@ -1800,7 +1836,7 @@ gtk_font_selection_get_preview_text gtk_font_selection_get_size gtk_font_selection_get_size_entry gtk_font_selection_get_size_list -gtk_font_selection_get_type G_GNUC_CONST +gtk_font_selection_get_type gtk_font_selection_new gtk_font_selection_set_font_name gtk_font_selection_set_preview_text @@ -1813,7 +1849,7 @@ gtk_frame_get_label gtk_frame_get_label_align gtk_frame_get_label_widget gtk_frame_get_shadow_type -gtk_frame_get_type G_GNUC_CONST +gtk_frame_get_type gtk_frame_new gtk_frame_set_label gtk_frame_set_label_align @@ -1825,7 +1861,7 @@ gtk_frame_set_shadow_type #if IN_HEADER(__GTK_GAMMA_CURVE_H__) #if IN_FILE(__GTK_GAMMA_CURVE_C__) #ifndef GTK_DISABLE_DEPRECATED -gtk_gamma_curve_get_type G_GNUC_CONST +gtk_gamma_curve_get_type gtk_gamma_curve_new #endif #endif @@ -1844,7 +1880,7 @@ gtk_handle_box_get_handle_position gtk_handle_box_get_shadow_type gtk_handle_box_get_snap_edge gtk_handle_box_get_child_detached -gtk_handle_box_get_type G_GNUC_CONST +gtk_handle_box_get_type gtk_handle_box_new gtk_handle_box_set_handle_position gtk_handle_box_set_shadow_type @@ -1854,7 +1890,7 @@ gtk_handle_box_set_snap_edge #if IN_HEADER(__GTK_HBOX_H__) #if IN_FILE(__GTK_HBOX_C__) -gtk_hbox_get_type G_GNUC_CONST +gtk_hbox_get_type gtk_hbox_new #endif #endif @@ -1862,7 +1898,7 @@ gtk_hbox_new #if IN_HEADER(__GTK_HBUTTON_BOX_H__) #if IN_FILE(__GTK_HBUTTON_BOX_C__) gtk_hbutton_box_new -gtk_hbutton_box_get_type G_GNUC_CONST +gtk_hbutton_box_get_type #ifndef GTK_DISABLE_DEPRECATED gtk_hbutton_box_get_layout_default gtk_hbutton_box_get_spacing_default @@ -1874,7 +1910,7 @@ gtk_hbutton_box_set_spacing_default #if IN_HEADER(__GTK_HPANED_H__) #if IN_FILE(__GTK_HPANED_C__) -gtk_hpaned_get_type G_GNUC_CONST +gtk_hpaned_get_type gtk_hpaned_new #endif #endif @@ -1882,7 +1918,7 @@ gtk_hpaned_new #if IN_HEADER(__GTK_HRULER_H__) #if IN_FILE(__GTK_HRULER_C__) #ifndef GTK_DISABLE_DEPRECATED -gtk_hruler_get_type G_GNUC_CONST +gtk_hruler_get_type gtk_hruler_new #endif #endif @@ -1890,7 +1926,7 @@ gtk_hruler_new #if IN_HEADER(__GTK_HSCALE_H__) #if IN_FILE(__GTK_HSCALE_C__) -gtk_hscale_get_type G_GNUC_CONST +gtk_hscale_get_type gtk_hscale_new gtk_hscale_new_with_range #endif @@ -1898,14 +1934,14 @@ gtk_hscale_new_with_range #if IN_HEADER(__GTK_HSCROLLBAR_H__) #if IN_FILE(__GTK_HSCROLLBAR_C__) -gtk_hscrollbar_get_type G_GNUC_CONST +gtk_hscrollbar_get_type gtk_hscrollbar_new #endif #endif #if IN_HEADER(__GTK_HSEPARATOR_H__) #if IN_FILE(__GTK_HSEPARATOR_C__) -gtk_hseparator_get_type G_GNUC_CONST +gtk_hseparator_get_type gtk_hseparator_new #endif #endif @@ -1914,7 +1950,7 @@ gtk_hseparator_new #if IN_FILE(__GTK_HSV_C__) gtk_hsv_get_color gtk_hsv_get_metrics -gtk_hsv_get_type G_GNUC_CONST +gtk_hsv_get_type gtk_hsv_is_adjusting gtk_hsv_new gtk_hsv_set_color @@ -1928,7 +1964,7 @@ gtk_rgb_to_hsv #if IN_FILE(__GTK_ICON_FACTORY_C__) gtk_icon_factory_add gtk_icon_factory_add_default -gtk_icon_factory_get_type G_GNUC_CONST +gtk_icon_factory_get_type gtk_icon_factory_lookup gtk_icon_factory_lookup_default gtk_icon_factory_new @@ -1942,7 +1978,7 @@ gtk_icon_size_register_alias gtk_icon_set_add_source gtk_icon_set_copy gtk_icon_set_get_sizes -gtk_icon_set_get_type G_GNUC_CONST +gtk_icon_set_get_type gtk_icon_set_new gtk_icon_set_new_from_pixbuf gtk_icon_set_ref @@ -1964,7 +2000,7 @@ gtk_icon_source_get_size gtk_icon_source_get_size_wildcarded gtk_icon_source_get_state gtk_icon_source_get_state_wildcarded -gtk_icon_source_get_type G_GNUC_CONST +gtk_icon_source_get_type gtk_icon_source_new gtk_icon_source_set_direction gtk_icon_source_set_direction_wildcarded @@ -1999,7 +2035,7 @@ gtk_icon_info_get_filename PRIVATE #ifdef G_OS_WIN32 gtk_icon_info_get_filename_utf8 #endif -gtk_icon_info_get_type G_GNUC_CONST +gtk_icon_info_get_type gtk_icon_info_load_icon gtk_icon_info_set_raw_coordinates gtk_icon_theme_add_builtin_icon @@ -2020,7 +2056,7 @@ gtk_icon_theme_get_search_path PRIVATE #ifdef G_OS_WIN32 gtk_icon_theme_get_search_path_utf8 #endif -gtk_icon_theme_get_type G_GNUC_CONST +gtk_icon_theme_get_type gtk_icon_theme_has_icon gtk_icon_theme_list_contexts gtk_icon_theme_list_icons @@ -2068,7 +2104,7 @@ gtk_icon_view_get_selected_items gtk_icon_view_get_selection_mode gtk_icon_view_get_spacing gtk_icon_view_get_text_column -gtk_icon_view_get_type G_GNUC_CONST +gtk_icon_view_get_type gtk_icon_view_get_visible_range gtk_icon_view_item_activated gtk_icon_view_new @@ -2132,7 +2168,7 @@ gtk_image_get_pixmap gtk_image_get_stock gtk_image_get_gicon gtk_image_get_storage_type -gtk_image_get_type G_GNUC_CONST +gtk_image_get_type gtk_image_new gtk_image_new_from_animation #ifndef _WIN64 @@ -2170,7 +2206,7 @@ gtk_image_set_pixel_size #if IN_FILE(__GTK_IMAGE_MENU_ITEM_C__) gtk_image_menu_item_get_always_show_image gtk_image_menu_item_get_image -gtk_image_menu_item_get_type G_GNUC_CONST +gtk_image_menu_item_get_type gtk_image_menu_item_get_use_stock gtk_image_menu_item_new gtk_image_menu_item_new_from_stock @@ -2191,7 +2227,7 @@ gtk_im_context_focus_in gtk_im_context_focus_out gtk_im_context_get_preedit_string gtk_im_context_get_surrounding -gtk_im_context_get_type G_GNUC_CONST +gtk_im_context_get_type gtk_im_context_reset gtk_im_context_set_client_window gtk_im_context_set_cursor_location @@ -2203,7 +2239,7 @@ gtk_im_context_set_use_preedit #if IN_HEADER(__GTK_IM_CONTEXT_SIMPLE_H__) #if IN_FILE(__GTK_IM_CONTEXT_SIMPLE_C__) gtk_im_context_simple_add_table -gtk_im_context_simple_get_type G_GNUC_CONST +gtk_im_context_simple_get_type gtk_im_context_simple_new #endif #endif @@ -2213,7 +2249,7 @@ gtk_im_context_simple_new gtk_im_multicontext_append_menuitems gtk_im_multicontext_get_context_id gtk_im_multicontext_set_context_id -gtk_im_multicontext_get_type G_GNUC_CONST +gtk_im_multicontext_get_type gtk_im_multicontext_new #endif #endif @@ -2221,7 +2257,7 @@ gtk_im_multicontext_new #if IN_HEADER(__GTK_INVISIBLE_H__) #if IN_FILE(__GTK_INVISIBLE_C__) gtk_invisible_get_screen -gtk_invisible_get_type G_GNUC_CONST +gtk_invisible_get_type gtk_invisible_new gtk_invisible_new_for_screen gtk_invisible_set_screen @@ -2230,7 +2266,7 @@ gtk_invisible_set_screen #if IN_HEADER(__GTK_ITEM_H__) #if IN_FILE(__GTK_ITEM_C__) -gtk_item_get_type G_GNUC_CONST +gtk_item_get_type #ifndef GTK_DISABLE_DEPRECATED gtk_item_deselect gtk_item_select @@ -2256,7 +2292,7 @@ gtk_item_factory_from_path gtk_item_factory_from_widget gtk_item_factory_get_item gtk_item_factory_get_item_by_action -gtk_item_factory_get_type G_GNUC_CONST +gtk_item_factory_get_type gtk_item_factory_get_widget gtk_item_factory_get_widget_by_action gtk_item_factory_new @@ -2292,7 +2328,7 @@ gtk_label_get_selectable gtk_label_get_selection_bounds gtk_label_get_single_line_mode gtk_label_get_text -gtk_label_get_type G_GNUC_CONST +gtk_label_get_type gtk_label_get_use_markup gtk_label_get_use_underline gtk_label_get_width_chars @@ -2329,7 +2365,7 @@ gtk_label_get_track_visited_links gtk_layout_get_bin_window gtk_layout_get_hadjustment gtk_layout_get_size -gtk_layout_get_type G_GNUC_CONST +gtk_layout_get_type gtk_layout_get_vadjustment gtk_layout_move gtk_layout_new @@ -2346,7 +2382,7 @@ gtk_layout_thaw #if IN_HEADER(__GTK_LINK_BUTTON_H__) #if IN_FILE(__GTK_LINK_BUTTON_C__) -gtk_link_button_get_type G_GNUC_CONST +gtk_link_button_get_type gtk_link_button_new gtk_link_button_new_with_label gtk_link_button_get_uri @@ -2368,7 +2404,7 @@ gtk_list_clear_items gtk_list_end_drag_selection gtk_list_end_selection gtk_list_extend_selection -gtk_list_get_type G_GNUC_CONST +gtk_list_get_type gtk_list_insert_items gtk_list_new gtk_list_prepend_items @@ -2396,7 +2432,7 @@ gtk_list_unselect_item #if IN_FILE(__GTK_LIST_ITEM_C__) #ifndef GTK_DISABLE_DEPRECATED gtk_list_item_deselect -gtk_list_item_get_type G_GNUC_CONST +gtk_list_item_get_type gtk_list_item_new gtk_list_item_new_with_label gtk_list_item_select @@ -2408,7 +2444,7 @@ gtk_list_item_select #if IN_FILE(__GTK_LIST_STORE_C__) gtk_list_store_append gtk_list_store_clear -gtk_list_store_get_type G_GNUC_CONST +gtk_list_store_get_type gtk_list_store_insert gtk_list_store_insert_after gtk_list_store_insert_before @@ -2492,7 +2528,7 @@ gtk_main_quit #if IN_HEADER(__GTK_INPUTDIALOG_H__) #if IN_FILE(__GTK_INPUTDIALOG_C__) #ifndef GTK_DISABLE_DEPRECATED -gtk_input_dialog_get_type G_GNUC_CONST +gtk_input_dialog_get_type gtk_input_dialog_new #endif #endif @@ -2531,9 +2567,26 @@ gtk_marshal_VOID__UINT_STRING #endif #endif +/* in gtkmisc.c, without aliases: for programs built against 2.24.32 */ +#if IN_HEADER(__GTK_MARSHAL_COMPAT_H__) +#if IN_FILE(__GTK_MARSHAL_COMPAT_C__) +#ifndef GTK_DISABLE_DEPRECATED +gtk_marshal_VOID__BOOLEAN +gtk_marshal_VOID__BOXED +gtk_marshal_VOID__ENUM +gtk_marshal_VOID__INT +gtk_marshal_VOID__OBJECT +gtk_marshal_VOID__POINTER +gtk_marshal_VOID__STRING +gtk_marshal_VOID__UINT +gtk_marshal_VOID__VOID +#endif +#endif +#endif + #if IN_HEADER(__GTK_MENU_BAR_H__) #if IN_FILE(__GTK_MENU_BAR_C__) -gtk_menu_bar_get_type G_GNUC_CONST +gtk_menu_bar_get_type gtk_menu_bar_new gtk_menu_bar_get_child_pack_direction gtk_menu_bar_set_child_pack_direction @@ -2556,7 +2609,7 @@ gtk_menu_get_for_attach_widget gtk_menu_get_reserve_toggle_size gtk_menu_get_tearoff_state gtk_menu_get_title -gtk_menu_get_type G_GNUC_CONST +gtk_menu_get_type gtk_menu_new gtk_menu_popdown gtk_menu_popup @@ -2581,7 +2634,7 @@ gtk_menu_item_get_accel_path gtk_menu_item_get_label gtk_menu_item_get_right_justified gtk_menu_item_get_submenu -gtk_menu_item_get_type G_GNUC_CONST +gtk_menu_item_get_type gtk_menu_item_get_use_underline gtk_menu_item_new gtk_menu_item_new_with_label @@ -2607,7 +2660,7 @@ gtk_menu_shell_append gtk_menu_shell_cancel gtk_menu_shell_deactivate gtk_menu_shell_deselect -gtk_menu_shell_get_type G_GNUC_CONST +gtk_menu_shell_get_type gtk_menu_shell_insert gtk_menu_shell_prepend gtk_menu_shell_select_first @@ -2620,7 +2673,7 @@ gtk_menu_shell_get_take_focus #if IN_HEADER(__GTK_MENU_TOOL_BUTTON_H__) #if IN_FILE(__GTK_MENU_TOOL_BUTTON_C__) gtk_menu_tool_button_get_menu -gtk_menu_tool_button_get_type G_GNUC_CONST +gtk_menu_tool_button_get_type gtk_menu_tool_button_new gtk_menu_tool_button_new_from_stock #ifndef GTK_DISABLE_DEPRECATED @@ -2637,7 +2690,7 @@ gtk_menu_tool_button_set_menu gtk_message_dialog_format_secondary_markup G_GNUC_PRINTF(2,3) gtk_message_dialog_format_secondary_text G_GNUC_PRINTF(2,3) gtk_message_dialog_get_message_area -gtk_message_dialog_get_type G_GNUC_CONST +gtk_message_dialog_get_type gtk_message_dialog_new G_GNUC_PRINTF(5,6) gtk_message_dialog_new_with_markup G_GNUC_PRINTF(5,6) gtk_message_dialog_set_markup @@ -2650,7 +2703,7 @@ gtk_message_dialog_get_image #if IN_FILE(__GTK_MISC_C__) gtk_misc_get_alignment gtk_misc_get_padding -gtk_misc_get_type G_GNUC_CONST +gtk_misc_get_type gtk_misc_set_alignment gtk_misc_set_padding #endif @@ -2658,7 +2711,7 @@ gtk_misc_set_padding #if IN_HEADER(__GTK_MOUNT_OPERATION_H__) #if IN_FILE(__GTK_MOUNT_OPERATION_C__) -gtk_mount_operation_get_type G_GNUC_CONST +gtk_mount_operation_get_type gtk_mount_operation_new gtk_mount_operation_is_showing gtk_mount_operation_set_parent @@ -2683,7 +2736,7 @@ gtk_notebook_get_show_tabs gtk_notebook_get_tab_label gtk_notebook_get_tab_label_text gtk_notebook_get_tab_pos -gtk_notebook_get_type G_GNUC_CONST +gtk_notebook_get_type gtk_notebook_insert_page gtk_notebook_insert_page_menu gtk_notebook_new @@ -2763,13 +2816,13 @@ gtk_object_set_user_data gtk_object_sink #endif gtk_object_destroy -gtk_object_get_type G_GNUC_CONST +gtk_object_get_type #endif #endif #if IN_HEADER(__GTK_OFFSCREEN_WINDOW_H__) #if IN_FILE(__GTK_OFFSCREEN_WINDOW_C__) -gtk_offscreen_window_get_type G_GNUC_CONST +gtk_offscreen_window_get_type gtk_offscreen_window_new gtk_offscreen_window_get_pixmap gtk_offscreen_window_get_pixbuf @@ -2779,7 +2832,7 @@ gtk_offscreen_window_get_pixbuf #if IN_HEADER(__GTK_ORIENTABLE_H__) #if IN_FILE(__GTK_ORIENTABLE_C__) gtk_orientable_get_orientation -gtk_orientable_get_type G_GNUC_CONST +gtk_orientable_get_type gtk_orientable_set_orientation #endif #endif @@ -2788,7 +2841,7 @@ gtk_orientable_set_orientation #if IN_FILE(__GTK_OLD_EDITABLE_C__) gtk_old_editable_changed gtk_old_editable_claim_selection -gtk_old_editable_get_type G_GNUC_CONST +gtk_old_editable_get_type #endif #endif @@ -2796,7 +2849,7 @@ gtk_old_editable_get_type G_GNUC_CONST #if IN_FILE(__GTK_OPTION_MENU_C__) gtk_option_menu_get_history gtk_option_menu_get_menu -gtk_option_menu_get_type G_GNUC_CONST +gtk_option_menu_get_type gtk_option_menu_new gtk_option_menu_remove_menu gtk_option_menu_set_history @@ -2812,7 +2865,7 @@ gtk_paned_get_child1 gtk_paned_get_child2 gtk_paned_get_handle_window gtk_paned_get_position -gtk_paned_get_type G_GNUC_CONST +gtk_paned_get_type gtk_paned_pack1 gtk_paned_pack2 gtk_paned_set_position @@ -2824,7 +2877,7 @@ gtk_paned_compute_position #if IN_HEADER(__GTK_PATH_BAR_H__) #if IN_FILE(__GTK_PATH_BAR_C__) -gtk_path_bar_get_type G_GNUC_CONST +gtk_path_bar_get_type #endif #endif @@ -2832,7 +2885,7 @@ gtk_path_bar_get_type G_GNUC_CONST #if IN_FILE(__GTK_PIXMAP_C__) #ifndef GTK_DISABLE_DEPRECATED gtk_pixmap_get -gtk_pixmap_get_type G_GNUC_CONST +gtk_pixmap_get_type gtk_pixmap_new gtk_pixmap_set gtk_pixmap_set_build_insensitive @@ -2847,7 +2900,7 @@ gtk_plug_construct_for_display gtk_plug_get_id gtk_plug_get_embedded gtk_plug_get_socket_window -gtk_plug_get_type G_GNUC_CONST +gtk_plug_get_type gtk_plug_new gtk_plug_new_for_display #endif @@ -2859,7 +2912,7 @@ gtk_plug_new_for_display gtk_preview_draw_row gtk_preview_get_cmap gtk_preview_get_info -gtk_preview_get_type G_GNUC_CONST +gtk_preview_get_type gtk_preview_get_visual gtk_preview_new gtk_preview_put @@ -2878,7 +2931,7 @@ gtk_preview_uninit #if IN_HEADER(__GTK_PAGE_SETUP_H__) #if IN_FILE(__GTK_PAGE_SETUP_C__) -gtk_page_setup_get_type G_GNUC_CONST +gtk_page_setup_get_type gtk_page_setup_new gtk_page_setup_new_from_file gtk_page_setup_new_from_key_file @@ -2910,7 +2963,7 @@ gtk_page_setup_get_page_height #if IN_HEADER(__GTK_PAGE_SETUP_UNIX_DIALOG_H__) #if IN_FILE(__GTK_PAGE_SETUP_UNIX_DIALOG_C__) #ifdef G_OS_UNIX -gtk_page_setup_unix_dialog_get_type G_GNUC_CONST +gtk_page_setup_unix_dialog_get_type gtk_page_setup_unix_dialog_new gtk_page_setup_unix_dialog_set_page_setup gtk_page_setup_unix_dialog_get_page_setup @@ -2922,7 +2975,7 @@ gtk_page_setup_unix_dialog_get_print_settings #if IN_HEADER(__GTK_PAPER_SIZE_H__) #if IN_FILE(__GTK_PAPER_SIZE_C__) -gtk_paper_size_get_type G_GNUC_CONST +gtk_paper_size_get_type gtk_paper_size_new gtk_paper_size_new_from_ppd gtk_paper_size_new_custom @@ -2950,7 +3003,7 @@ gtk_paper_size_get_default #if IN_HEADER(__GTK_CUSTOM_PAPER_UNIX_DIALOG_H__) #if IN_FILE(__GTK_CUSTOM_PAPER_UNIX_DIALOG_C__) #ifdef G_OS_UNIX -gtk_custom_paper_unix_dialog_get_type G_GNUC_CONST +gtk_custom_paper_unix_dialog_get_type #endif #endif #endif @@ -2959,7 +3012,7 @@ gtk_custom_paper_unix_dialog_get_type G_GNUC_CONST #if IN_FILE(__GTK_PRINT_BACKEND_C__) #ifdef G_OS_UNIX gtk_print_backend_error_quark -gtk_print_backend_get_type G_GNUC_CONST +gtk_print_backend_get_type gtk_print_backend_add_printer gtk_print_backend_remove_printer gtk_print_backend_set_list_done @@ -2976,7 +3029,7 @@ gtk_print_backend_set_password #if IN_HEADER(__GTK_PRINT_CONTEXT_H__) #if IN_FILE(__GTK_PRINT_CONTEXT_C__) -gtk_print_context_get_type G_GNUC_CONST +gtk_print_context_get_type gtk_print_context_get_cairo_context gtk_print_context_get_page_setup gtk_print_context_get_width @@ -2994,7 +3047,7 @@ gtk_print_context_set_cairo_context #if IN_HEADER(__GTK_PRINTER_H__) #if IN_FILE(__GTK_PRINTER_C__) #ifdef G_OS_UNIX -gtk_printer_get_type G_GNUC_CONST +gtk_printer_get_type gtk_printer_get_backend gtk_printer_get_name gtk_printer_get_description @@ -3013,7 +3066,7 @@ gtk_printer_request_details gtk_printer_get_capabilities gtk_printer_get_hard_margins gtk_enumerate_printers -gtk_print_capabilities_get_type G_GNUC_CONST +gtk_print_capabilities_get_type #endif #endif #endif @@ -3065,7 +3118,7 @@ gtk_printer_option_get_activates_default #if IN_HEADER(__GTK_PRINTER_OPTION_SET_H__) #if IN_FILE(__GTK_PRINTER_OPTION_SET_C__) #ifdef G_OS_UNIX -gtk_printer_option_set_get_type G_GNUC_CONST +gtk_printer_option_set_get_type gtk_printer_option_set_new gtk_printer_option_set_add gtk_printer_option_set_lookup @@ -3081,7 +3134,7 @@ gtk_printer_option_set_foreach_in_group #if IN_HEADER(__GTK_PRINTER_OPTION_WIDGET_H__) #if IN_FILE(__GTK_PRINTER_OPTION_WIDGET_C__) #ifdef G_OS_UNIX -gtk_printer_option_widget_get_type G_GNUC_CONST +gtk_printer_option_widget_get_type gtk_printer_option_widget_new gtk_printer_option_widget_set_source gtk_printer_option_widget_has_external_label @@ -3094,7 +3147,7 @@ gtk_printer_option_widget_get_value #if IN_HEADER(__GTK_PRINT_JOB_H__) #if IN_FILE(__GTK_PRINT_JOB_C__) #ifdef G_OS_UNIX -gtk_print_job_get_type G_GNUC_CONST +gtk_print_job_get_type gtk_print_job_new gtk_print_job_get_settings gtk_print_job_get_printer @@ -3120,7 +3173,7 @@ gtk_print_job_set_status #if IN_HEADER(__GTK_PRINT_OPERATION_H__) #if IN_FILE(__GTK_PRINT_OPERATION_C__) gtk_print_error_quark -gtk_print_operation_get_type G_GNUC_CONST +gtk_print_operation_get_type gtk_print_operation_new gtk_print_operation_set_allow_async gtk_print_operation_set_default_page_setup @@ -3183,7 +3236,7 @@ gtk_print_run_page_setup_dialog_async #if IN_HEADER(__GTK_PRINT_SETTINGS_H__) #if IN_FILE(__GTK_PRINT_SETTINGS_C__) -gtk_print_settings_get_type G_GNUC_CONST +gtk_print_settings_get_type gtk_print_settings_new gtk_print_settings_new_from_file gtk_print_settings_new_from_key_file @@ -3264,7 +3317,7 @@ gtk_print_settings_set_output_bin #if IN_HEADER(__GTK_PRINT_UNIX_DIALOG_H__) #if IN_FILE(__GTK_PRINT_UNIX_DIALOG_C__) #ifdef G_OS_UNIX -gtk_print_unix_dialog_get_type G_GNUC_CONST +gtk_print_unix_dialog_get_type gtk_print_unix_dialog_new gtk_print_unix_dialog_set_page_setup gtk_print_unix_dialog_get_page_setup @@ -3305,7 +3358,7 @@ gtk_progress_bar_get_orientation gtk_progress_bar_get_pulse_step gtk_progress_bar_get_text gtk_progress_bar_get_ellipsize -gtk_progress_bar_get_type G_GNUC_CONST +gtk_progress_bar_get_type gtk_progress_bar_new #ifndef GTK_DISABLE_DEPRECATED gtk_progress_bar_new_with_adjustment @@ -3332,7 +3385,7 @@ gtk_progress_get_current_percentage gtk_progress_get_current_text gtk_progress_get_percentage_from_value gtk_progress_get_text_from_value -gtk_progress_get_type G_GNUC_CONST +gtk_progress_get_type gtk_progress_get_value gtk_progress_set_activity_mode gtk_progress_set_adjustment @@ -3349,7 +3402,7 @@ gtk_progress_set_value #if IN_FILE(__GTK_RADIO_ACTION_C__) gtk_radio_action_get_current_value gtk_radio_action_get_group -gtk_radio_action_get_type G_GNUC_CONST +gtk_radio_action_get_type gtk_radio_action_new gtk_radio_action_set_current_value gtk_radio_action_set_group @@ -3359,7 +3412,7 @@ gtk_radio_action_set_group #if IN_HEADER(__GTK_RADIO_BUTTON_H__) #if IN_FILE(__GTK_RADIO_BUTTON_C__) gtk_radio_button_get_group -gtk_radio_button_get_type G_GNUC_CONST +gtk_radio_button_get_type gtk_radio_button_new gtk_radio_button_new_from_widget gtk_radio_button_new_with_label @@ -3373,7 +3426,7 @@ gtk_radio_button_set_group #if IN_HEADER(__GTK_RADIO_MENU_ITEM_H__) #if IN_FILE(__GTK_RADIO_MENU_ITEM_C__) gtk_radio_menu_item_get_group -gtk_radio_menu_item_get_type G_GNUC_CONST +gtk_radio_menu_item_get_type gtk_radio_menu_item_new gtk_radio_menu_item_new_from_widget gtk_radio_menu_item_new_with_label @@ -3387,7 +3440,7 @@ gtk_radio_menu_item_set_group #if IN_HEADER(__GTK_RADIO_TOOL_BUTTON_H__) #if IN_FILE(__GTK_RADIO_TOOL_BUTTON_C__) gtk_radio_tool_button_get_group -gtk_radio_tool_button_get_type G_GNUC_CONST +gtk_radio_tool_button_get_type gtk_radio_tool_button_new gtk_radio_tool_button_new_from_stock gtk_radio_tool_button_new_from_widget @@ -3409,7 +3462,7 @@ gtk_range_get_restrict_to_fill_level gtk_range_get_show_fill_level gtk_range_get_slider_range gtk_range_get_slider_size_fixed -gtk_range_get_type G_GNUC_CONST +gtk_range_get_type #ifndef GTK_DISABLE_DEPRECATED gtk_range_get_update_policy #endif @@ -3480,7 +3533,7 @@ gtk_rc_set_default_files PRIVATE gtk_rc_set_default_files_utf8 #endif gtk_rc_style_copy -gtk_rc_style_get_type G_GNUC_CONST +gtk_rc_style_get_type gtk_rc_style_new #ifndef GTK_DISABLE_DEPRECATED gtk_rc_style_ref @@ -3491,7 +3544,7 @@ gtk_rc_style_unref #if IN_HEADER(__GTK_RECENT_ACTION_H__) #if IN_FILE(__GTK_RECENT_ACTION_C__) -gtk_recent_action_get_type G_GNUC_CONST +gtk_recent_action_get_type gtk_recent_action_new gtk_recent_action_new_for_manager gtk_recent_action_set_show_numbers @@ -3536,14 +3589,14 @@ gtk_recent_chooser_remove_filter gtk_recent_chooser_list_filters gtk_recent_chooser_set_filter gtk_recent_chooser_get_filter -gtk_recent_chooser_get_type G_GNUC_CONST +gtk_recent_chooser_get_type gtk_recent_chooser_error_quark #endif #endif #if IN_HEADER(__GTK_RECENT_CHOOSER_DIALOG_H__) #if IN_FILE(__GTK_RECENT_CHOOSER_DIALOG_C__) -gtk_recent_chooser_dialog_get_type G_GNUC_CONST +gtk_recent_chooser_dialog_get_type gtk_recent_chooser_dialog_new G_GNUC_NULL_TERMINATED gtk_recent_chooser_dialog_new_for_manager G_GNUC_NULL_TERMINATED #endif @@ -3551,7 +3604,7 @@ gtk_recent_chooser_dialog_new_for_manager G_GNUC_NULL_TERMINATED #if IN_HEADER(__GTK_RECENT_CHOOSER_MENU_H__) #if IN_FILE(__GTK_RECENT_CHOOSER_MENU_C__) -gtk_recent_chooser_menu_get_type G_GNUC_CONST +gtk_recent_chooser_menu_get_type gtk_recent_chooser_menu_new gtk_recent_chooser_menu_new_for_manager gtk_recent_chooser_menu_get_show_numbers @@ -3561,7 +3614,7 @@ gtk_recent_chooser_menu_set_show_numbers #if IN_HEADER(__GTK_RECENT_CHOOSER_WIDGET_H__) #if IN_FILE(__GTK_RECENT_CHOOSER_WIDGET_C__) -gtk_recent_chooser_widget_get_type G_GNUC_CONST +gtk_recent_chooser_widget_get_type gtk_recent_chooser_widget_new gtk_recent_chooser_widget_new_for_manager #endif @@ -3569,7 +3622,7 @@ gtk_recent_chooser_widget_new_for_manager #if IN_HEADER(__GTK_RECENT_FILTER_H__) #if IN_FILE(__GTK_RECENT_FILTER_C__) -gtk_recent_filter_get_type G_GNUC_CONST +gtk_recent_filter_get_type gtk_recent_filter_new gtk_recent_filter_set_name gtk_recent_filter_get_name @@ -3588,7 +3641,7 @@ gtk_recent_filter_filter #if IN_HEADER(__GTK_RECENT_MANAGER_H__) #if IN_FILE(__GTK_RECENT_MANAGER_C__) gtk_recent_manager_error_quark -gtk_recent_manager_get_type G_GNUC_CONST +gtk_recent_manager_get_type gtk_recent_manager_new gtk_recent_manager_get_items gtk_recent_manager_get_default @@ -3605,7 +3658,7 @@ gtk_recent_manager_move_item gtk_recent_manager_set_limit gtk_recent_manager_get_limit gtk_recent_manager_purge_items -gtk_recent_info_get_type G_GNUC_CONST +gtk_recent_info_get_type gtk_recent_info_ref gtk_recent_info_unref gtk_recent_info_get_uri @@ -3613,10 +3666,14 @@ gtk_recent_info_get_display_name gtk_recent_info_get_description gtk_recent_info_get_mime_type gtk_recent_info_get_added +gtk_recent_info_get_added_unix gtk_recent_info_get_modified +gtk_recent_info_get_modified_unix gtk_recent_info_get_visited +gtk_recent_info_get_visited_unix gtk_recent_info_get_private_hint gtk_recent_info_get_application_info +gtk_recent_info_get_application_info_unix gtk_recent_info_get_applications G_GNUC_MALLOC gtk_recent_info_last_application G_GNUC_MALLOC gtk_recent_info_has_application @@ -3677,7 +3734,7 @@ gtk_ruler_draw_pos gtk_ruler_draw_ticks gtk_ruler_get_metric gtk_ruler_get_range -gtk_ruler_get_type G_GNUC_CONST +gtk_ruler_get_type gtk_ruler_set_metric gtk_ruler_set_range #endif @@ -3690,7 +3747,7 @@ gtk_scale_get_digits gtk_scale_get_draw_value gtk_scale_get_layout gtk_scale_get_layout_offsets -gtk_scale_get_type G_GNUC_CONST +gtk_scale_get_type gtk_scale_get_value_pos gtk_scale_set_digits gtk_scale_set_draw_value @@ -3702,7 +3759,7 @@ gtk_scale_clear_marks #if IN_HEADER(__GTK_SCALE_BUTTON_H__) #if IN_FILE(__GTK_SCALE_BUTTON_C__) -gtk_scale_button_get_type G_GNUC_CONST +gtk_scale_button_get_type gtk_scale_button_get_value gtk_scale_button_new gtk_scale_button_set_icons @@ -3721,7 +3778,7 @@ gtk_scale_button_get_popup #if IN_HEADER(__GTK_SCROLLBAR_H__) #if IN_FILE(__GTK_SCROLLBAR_C__) -gtk_scrollbar_get_type G_GNUC_CONST +gtk_scrollbar_get_type #endif #endif @@ -3730,14 +3787,16 @@ gtk_scrollbar_get_type G_GNUC_CONST gtk_scrolled_window_add_with_viewport gtk_scrolled_window_get_hadjustment gtk_scrolled_window_get_hscrollbar +gtk_scrolled_window_get_kinetic_scrolling gtk_scrolled_window_get_placement gtk_scrolled_window_get_policy gtk_scrolled_window_get_shadow_type -gtk_scrolled_window_get_type G_GNUC_CONST +gtk_scrolled_window_get_type gtk_scrolled_window_get_vadjustment gtk_scrolled_window_get_vscrollbar gtk_scrolled_window_new gtk_scrolled_window_set_hadjustment +gtk_scrolled_window_set_kinetic_scrolling gtk_scrolled_window_set_placement gtk_scrolled_window_set_policy gtk_scrolled_window_set_shadow_type @@ -3765,7 +3824,7 @@ gtk_selection_data_get_length gtk_selection_data_get_pixbuf gtk_selection_data_get_targets gtk_selection_data_get_text -gtk_selection_data_get_type G_GNUC_CONST +gtk_selection_data_get_type gtk_selection_data_get_uris gtk_selection_data_set gtk_selection_data_set_pixbuf @@ -3789,7 +3848,7 @@ gtk_target_list_add_table gtk_target_list_add_text_targets gtk_target_list_add_uri_targets gtk_target_list_find -gtk_target_list_get_type G_GNUC_CONST +gtk_target_list_get_type gtk_target_list_new gtk_target_list_ref gtk_target_list_remove @@ -3801,13 +3860,13 @@ gtk_target_table_free #if IN_HEADER(__GTK_SEPARATOR_H__) #if IN_FILE(__GTK_SEPARATOR_C__) -gtk_separator_get_type G_GNUC_CONST +gtk_separator_get_type #endif #endif #if IN_HEADER(__GTK_SEPARATOR_MENU_ITEM_H__) #if IN_FILE(__GTK_SEPARATOR_MENU_ITEM_C__) -gtk_separator_menu_item_get_type G_GNUC_CONST +gtk_separator_menu_item_get_type gtk_separator_menu_item_new #endif #endif @@ -3815,7 +3874,7 @@ gtk_separator_menu_item_new #if IN_HEADER(__GTK_SEPARATOR_TOOL_ITEM_H__) #if IN_FILE(__GTK_SEPARATOR_TOOL_ITEM_C__) gtk_separator_tool_item_get_draw -gtk_separator_tool_item_get_type G_GNUC_CONST +gtk_separator_tool_item_get_type gtk_separator_tool_item_new gtk_separator_tool_item_set_draw #endif @@ -3825,7 +3884,7 @@ gtk_separator_tool_item_set_draw #if IN_FILE(__GTK_SETTINGS_C__) gtk_settings_get_default gtk_settings_get_for_screen -gtk_settings_get_type G_GNUC_CONST +gtk_settings_get_type gtk_settings_install_property gtk_settings_install_property_parser gtk_settings_set_double_property @@ -3863,7 +3922,7 @@ gtk_signal_newv gtk_size_group_add_widget gtk_size_group_get_ignore_hidden gtk_size_group_get_mode -gtk_size_group_get_type G_GNUC_CONST +gtk_size_group_get_type gtk_size_group_get_widgets gtk_size_group_new gtk_size_group_remove_widget @@ -3883,7 +3942,7 @@ gtk_show_uri gtk_socket_add_id gtk_socket_get_id gtk_socket_get_plug_window -gtk_socket_get_type G_GNUC_CONST +gtk_socket_get_type gtk_socket_new #ifndef GTK_DISABLE_DEPRECATED gtk_socket_steal @@ -3900,7 +3959,7 @@ gtk_spin_button_get_increments gtk_spin_button_get_numeric gtk_spin_button_get_range gtk_spin_button_get_snap_to_ticks -gtk_spin_button_get_type G_GNUC_CONST +gtk_spin_button_get_type gtk_spin_button_get_update_policy gtk_spin_button_get_value gtk_spin_button_get_value_as_int @@ -3923,7 +3982,7 @@ gtk_spin_button_update #if IN_HEADER(__GTK_SPINNER_H__) #if IN_FILE(__GTK_SPINNER_C__) -gtk_spinner_get_type G_GNUC_CONST +gtk_spinner_get_type gtk_spinner_new gtk_spinner_start gtk_spinner_stop @@ -3935,7 +3994,7 @@ gtk_spinner_stop gtk_statusbar_get_context_id gtk_statusbar_get_has_resize_grip gtk_statusbar_get_message_area -gtk_statusbar_get_type G_GNUC_CONST +gtk_statusbar_get_type gtk_statusbar_new gtk_statusbar_pop gtk_statusbar_push @@ -3949,7 +4008,7 @@ gtk_statusbar_set_has_resize_grip #if IN_FILE(__GTK_STOCK_C__) gtk_stock_add gtk_stock_add_static -gtk_stock_item_get_type G_GNUC_CONST +gtk_stock_item_get_type gtk_stock_item_copy gtk_stock_item_free gtk_stock_list_ids @@ -3968,7 +4027,7 @@ gtk_table_get_default_row_spacing gtk_table_get_homogeneous gtk_table_get_row_spacing gtk_table_get_size -gtk_table_get_type G_GNUC_CONST +gtk_table_get_type gtk_table_new gtk_table_resize gtk_table_set_col_spacing @@ -3981,7 +4040,7 @@ gtk_table_set_row_spacings #if IN_HEADER(__GTK_TEAROFF_MENU_ITEM_H__) #if IN_FILE(__GTK_TEAROFF_MENU_ITEM_C__) -gtk_tearoff_menu_item_get_type G_GNUC_CONST +gtk_tearoff_menu_item_get_type gtk_tearoff_menu_item_new #endif #endif @@ -3990,13 +4049,13 @@ gtk_tearoff_menu_item_new #if IN_FILE(__GTK_TEXT_TAG_C__) gtk_text_attributes_copy gtk_text_attributes_copy_values -gtk_text_attributes_get_type G_GNUC_CONST +gtk_text_attributes_get_type gtk_text_attributes_new gtk_text_attributes_ref gtk_text_attributes_unref gtk_text_tag_event gtk_text_tag_get_priority -gtk_text_tag_get_type G_GNUC_CONST +gtk_text_tag_get_type gtk_text_tag_new gtk_text_tag_set_priority #endif @@ -4007,7 +4066,7 @@ gtk_text_tag_set_priority gtk_text_tag_table_add gtk_text_tag_table_foreach gtk_text_tag_table_get_size -gtk_text_tag_table_get_type G_GNUC_CONST +gtk_text_tag_table_get_type gtk_text_tag_table_lookup gtk_text_tag_table_new gtk_text_tag_table_remove @@ -4021,7 +4080,7 @@ gtk_text_forward_delete gtk_text_freeze gtk_text_get_length gtk_text_get_point -gtk_text_get_type G_GNUC_CONST +gtk_text_get_type gtk_text_insert gtk_text_new gtk_text_set_adjustments @@ -4074,7 +4133,7 @@ gtk_text_buffer_get_slice gtk_text_buffer_get_start_iter gtk_text_buffer_get_tag_table gtk_text_buffer_get_text -gtk_text_buffer_get_type G_GNUC_CONST +gtk_text_buffer_get_type gtk_text_buffer_insert gtk_text_buffer_insert_at_cursor gtk_text_buffer_insert_child_anchor @@ -4176,7 +4235,7 @@ gtk_text_iter_get_slice gtk_text_iter_get_tags gtk_text_iter_get_text gtk_text_iter_get_toggled_tags -gtk_text_iter_get_type G_GNUC_CONST +gtk_text_iter_get_type gtk_text_iter_get_visible_line_index gtk_text_iter_get_visible_line_offset gtk_text_iter_get_visible_slice @@ -4222,7 +4281,7 @@ gtk_text_layout_get_line_display gtk_text_layout_get_lines gtk_text_layout_get_line_yrange gtk_text_layout_get_size -gtk_text_layout_get_type G_GNUC_CONST +gtk_text_layout_get_type gtk_text_layout_invalidate gtk_text_layout_invalidate_cursors gtk_text_layout_is_valid @@ -4254,7 +4313,7 @@ gtk_text_layout_wrap_loop_start #if IN_HEADER(__GTK_TEXT_CHILD_H__) #if IN_FILE(__GTK_TEXT_CHILD_C__) gtk_text_child_anchor_get_deleted -gtk_text_child_anchor_get_type G_GNUC_CONST +gtk_text_child_anchor_get_type gtk_text_child_anchor_get_widgets gtk_text_child_anchor_new #endif @@ -4288,7 +4347,7 @@ gtk_text_mark_get_buffer gtk_text_mark_get_deleted gtk_text_mark_get_left_gravity gtk_text_mark_get_name -gtk_text_mark_get_type G_GNUC_CONST +gtk_text_mark_get_type gtk_text_mark_get_visible #endif #endif @@ -4301,6 +4360,10 @@ gtk_text_mark_set_visible #if IN_HEADER(__GTK_TEXT_VIEW_H__) #if IN_FILE(__GTK_TEXT_VIEW_C__) +gtk_text_view_get_input_hints +gtk_text_view_get_input_purpose +gtk_text_view_set_input_hints +gtk_text_view_set_input_purpose gtk_text_view_add_child_at_anchor gtk_text_view_add_child_in_window gtk_text_view_backward_display_line @@ -4329,7 +4392,7 @@ gtk_text_view_get_pixels_below_lines gtk_text_view_get_pixels_inside_wrap gtk_text_view_get_right_margin gtk_text_view_get_tabs -gtk_text_view_get_type G_GNUC_CONST +gtk_text_view_get_type gtk_text_view_get_vadjustment gtk_text_view_get_visible_rect gtk_text_view_get_window @@ -4370,13 +4433,13 @@ gtk_text_view_window_to_buffer_coords #if IN_FILE(__GTK_THEMES_C__) gtk_theme_engine_create_rc_style gtk_theme_engine_get -gtk_theme_engine_get_type G_GNUC_CONST +gtk_theme_engine_get_type #endif #endif #if IN_HEADER(__GTK_TIPS_QUERY_H__) #if IN_FILE(__GTK_TIPS_QUERY_C__) -gtk_tips_query_get_type G_GNUC_CONST +gtk_tips_query_get_type gtk_tips_query_new gtk_tips_query_set_caller gtk_tips_query_set_labels @@ -4389,7 +4452,7 @@ gtk_tips_query_stop_query #if IN_FILE(__GTK_TOGGLE_ACTION_C__) gtk_toggle_action_get_active gtk_toggle_action_get_draw_as_radio -gtk_toggle_action_get_type G_GNUC_CONST +gtk_toggle_action_get_type gtk_toggle_action_new gtk_toggle_action_set_active gtk_toggle_action_set_draw_as_radio @@ -4402,7 +4465,7 @@ gtk_toggle_action_toggled gtk_toggle_button_get_active gtk_toggle_button_get_inconsistent gtk_toggle_button_get_mode -gtk_toggle_button_get_type G_GNUC_CONST +gtk_toggle_button_get_type gtk_toggle_button_new gtk_toggle_button_new_with_label gtk_toggle_button_new_with_mnemonic @@ -4416,7 +4479,7 @@ gtk_toggle_button_toggled #if IN_HEADER(__GTK_TOGGLE_TOOL_BUTTON_H__) #if IN_FILE(__GTK_TOGGLE_TOOL_BUTTON_C__) gtk_toggle_tool_button_get_active -gtk_toggle_tool_button_get_type G_GNUC_CONST +gtk_toggle_tool_button_get_type gtk_toggle_tool_button_new gtk_toggle_tool_button_new_from_stock gtk_toggle_tool_button_set_active @@ -4457,7 +4520,7 @@ gtk_toolbar_get_style #ifndef GTK_DISABLE_DEPRECATED gtk_toolbar_get_tooltips #endif -gtk_toolbar_get_type G_GNUC_CONST +gtk_toolbar_get_type gtk_toolbar_insert gtk_toolbar_new gtk_toolbar_set_drop_highlight_item @@ -4475,7 +4538,7 @@ gtk_toolbar_unset_style #if IN_HEADER(__GTK_TOOL_SHELL_H__) #if IN_FILE(__GTK_TOOL_SHELL_C__) -gtk_tool_shell_get_type G_GNUC_CONST +gtk_tool_shell_get_type gtk_tool_shell_get_ellipsize_mode gtk_tool_shell_get_icon_size gtk_tool_shell_get_orientation @@ -4495,7 +4558,7 @@ gtk_tool_button_get_icon_widget gtk_tool_button_get_label gtk_tool_button_get_label_widget gtk_tool_button_get_stock_id -gtk_tool_button_get_type G_GNUC_CONST +gtk_tool_button_get_type gtk_tool_button_get_use_underline gtk_tool_button_new gtk_tool_button_new_from_stock @@ -4522,7 +4585,7 @@ gtk_tool_item_get_text_alignment gtk_tool_item_get_text_orientation gtk_tool_item_get_text_size_group gtk_tool_item_get_toolbar_style -gtk_tool_item_get_type G_GNUC_CONST +gtk_tool_item_get_type gtk_tool_item_get_use_drag_window gtk_tool_item_get_visible_horizontal gtk_tool_item_get_visible_vertical @@ -4547,7 +4610,7 @@ gtk_tool_item_toolbar_reconfigured #if IN_HEADER(__GTK_TOOL_ITEM_GROUP_H__) #if IN_FILE(__GTK_TOOL_ITEM_GROUP_C__) -gtk_tool_item_group_get_type G_GNUC_CONST +gtk_tool_item_group_get_type gtk_tool_item_group_new gtk_tool_item_group_set_label gtk_tool_item_group_set_label_widget @@ -4570,7 +4633,7 @@ gtk_tool_item_group_get_collapsed #if IN_HEADER(__GTK_TOOL_PALETTE_H__) #if IN_FILE(__GTK_TOOL_PALETTE_C__) -gtk_tool_palette_get_type G_GNUC_CONST +gtk_tool_palette_get_type gtk_tool_palette_new gtk_tool_palette_set_group_position gtk_tool_palette_set_exclusive @@ -4598,7 +4661,7 @@ gtk_tool_palette_get_drag_target_group G_GNUC_CONST #if IN_HEADER(__GTK_TOOLTIP_H__) #if IN_FILE(__GTK_TOOLTIP_C__) -gtk_tooltip_get_type G_GNUC_CONST +gtk_tooltip_get_type gtk_tooltip_set_custom gtk_tooltip_set_icon gtk_tooltip_set_icon_from_stock @@ -4619,7 +4682,7 @@ gtk_tooltips_disable gtk_tooltips_enable gtk_tooltips_force_window gtk_tooltips_get_info_from_tip_window -gtk_tooltips_get_type G_GNUC_CONST +gtk_tooltips_get_type gtk_tooltips_new gtk_tooltips_set_delay gtk_tooltips_set_tip @@ -4630,7 +4693,7 @@ gtk_tooltips_set_tip #if IN_HEADER(__GTK_TRAY_ICON_H__) #if IN_FILE(__GTK_TRAY_ICON_X11_C__) #ifndef G_OS_WIN32 -gtk_tray_icon_get_type G_GNUC_CONST +gtk_tray_icon_get_type #endif #endif #endif @@ -4640,7 +4703,7 @@ gtk_tray_icon_get_type G_GNUC_CONST gtk_tree_append gtk_tree_child_position gtk_tree_clear_items -gtk_tree_get_type G_GNUC_CONST +gtk_tree_get_type gtk_tree_insert gtk_tree_prepend gtk_tree_remove_item @@ -4659,11 +4722,11 @@ gtk_tree_new #if IN_HEADER(__GTK_TREE_DND_H__) #if IN_FILE(__GTK_TREE_DND_C__) gtk_tree_drag_dest_drag_data_received -gtk_tree_drag_dest_get_type G_GNUC_CONST +gtk_tree_drag_dest_get_type gtk_tree_drag_dest_row_drop_possible gtk_tree_drag_source_drag_data_delete gtk_tree_drag_source_drag_data_get -gtk_tree_drag_source_get_type G_GNUC_CONST +gtk_tree_drag_source_get_type gtk_tree_drag_source_row_draggable gtk_tree_get_row_drag_data gtk_tree_set_row_drag_data @@ -4675,7 +4738,7 @@ gtk_tree_set_row_drag_data gtk_tree_item_collapse gtk_tree_item_deselect gtk_tree_item_expand -gtk_tree_item_get_type G_GNUC_CONST +gtk_tree_item_get_type gtk_tree_item_new gtk_tree_item_new_with_label gtk_tree_item_remove_subtree @@ -4688,7 +4751,7 @@ gtk_tree_item_set_subtree #if IN_FILE(__GTK_TREE_MODEL_C__) gtk_tree_iter_copy gtk_tree_iter_free -gtk_tree_iter_get_type G_GNUC_CONST +gtk_tree_iter_get_type gtk_tree_model_foreach gtk_tree_model_get gtk_tree_model_get_column_type @@ -4699,7 +4762,7 @@ gtk_tree_model_get_iter_from_string gtk_tree_model_get_n_columns gtk_tree_model_get_path gtk_tree_model_get_string_from_iter -gtk_tree_model_get_type G_GNUC_CONST +gtk_tree_model_get_type gtk_tree_model_get_valist gtk_tree_model_get_value gtk_tree_model_iter_children @@ -4723,7 +4786,7 @@ gtk_tree_path_free gtk_tree_path_get_depth gtk_tree_path_get_indices gtk_tree_path_get_indices_with_depth -gtk_tree_path_get_type G_GNUC_CONST +gtk_tree_path_get_type gtk_tree_path_is_ancestor gtk_tree_path_is_descendant gtk_tree_path_new @@ -4740,7 +4803,7 @@ gtk_tree_row_reference_deleted gtk_tree_row_reference_free gtk_tree_row_reference_get_model gtk_tree_row_reference_get_path -gtk_tree_row_reference_get_type G_GNUC_CONST +gtk_tree_row_reference_get_type gtk_tree_row_reference_inserted gtk_tree_row_reference_new gtk_tree_row_reference_new_proxy @@ -4757,7 +4820,7 @@ gtk_tree_model_sort_convert_child_path_to_path gtk_tree_model_sort_convert_iter_to_child_iter gtk_tree_model_sort_convert_path_to_child_path gtk_tree_model_sort_get_model -gtk_tree_model_sort_get_type G_GNUC_CONST +gtk_tree_model_sort_get_type gtk_tree_model_sort_iter_is_valid gtk_tree_model_sort_new_with_model gtk_tree_model_sort_reset_default_sort_func @@ -4772,7 +4835,7 @@ gtk_tree_model_filter_convert_child_path_to_path gtk_tree_model_filter_convert_iter_to_child_iter gtk_tree_model_filter_convert_path_to_child_path gtk_tree_model_filter_get_model -gtk_tree_model_filter_get_type G_GNUC_CONST +gtk_tree_model_filter_get_type gtk_tree_model_filter_new gtk_tree_model_filter_refilter gtk_tree_model_filter_set_modify_func @@ -4789,7 +4852,7 @@ gtk_tree_selection_get_select_function gtk_tree_selection_get_selected gtk_tree_selection_get_selected_rows gtk_tree_selection_get_tree_view -gtk_tree_selection_get_type G_GNUC_CONST +gtk_tree_selection_get_type gtk_tree_selection_get_user_data gtk_tree_selection_iter_is_selected gtk_tree_selection_path_is_selected @@ -4810,7 +4873,7 @@ gtk_tree_selection_unselect_range #if IN_HEADER(__GTK_TREE_SORTABLE_H__) #if IN_FILE(__GTK_TREE_SORTABLE_C__) gtk_tree_sortable_get_sort_column_id -gtk_tree_sortable_get_type G_GNUC_CONST +gtk_tree_sortable_get_type gtk_tree_sortable_has_default_sort_func gtk_tree_sortable_set_default_sort_func gtk_tree_sortable_set_sort_column_id @@ -4823,7 +4886,7 @@ gtk_tree_sortable_sort_column_changed #if IN_FILE(__GTK_TREE_STORE_C__) gtk_tree_store_append gtk_tree_store_clear -gtk_tree_store_get_type G_GNUC_CONST +gtk_tree_store_get_type gtk_tree_store_insert gtk_tree_store_insert_after gtk_tree_store_insert_before @@ -4877,7 +4940,7 @@ gtk_tree_view_column_get_sort_order gtk_tree_view_column_get_spacing gtk_tree_view_column_get_title gtk_tree_view_column_get_tree_view -gtk_tree_view_column_get_type G_GNUC_CONST +gtk_tree_view_column_get_type gtk_tree_view_column_get_visible gtk_tree_view_column_get_widget gtk_tree_view_column_get_width @@ -4957,7 +5020,7 @@ gtk_tree_view_get_selection gtk_tree_view_get_show_expanders gtk_tree_view_get_tooltip_column gtk_tree_view_get_tooltip_context -gtk_tree_view_get_type G_GNUC_CONST +gtk_tree_view_get_type gtk_tree_view_get_vadjustment gtk_tree_view_get_visible_range gtk_tree_view_get_visible_rect @@ -5018,7 +5081,7 @@ gtk_tree_view_columns_autosize #if IN_HEADER(__GTK_TYPE_UTILS_H__) #if IN_FILE(__GTK_TYPE_UTILS_C__) -gtk_identifier_get_type G_GNUC_CONST +gtk_identifier_get_type #ifndef GTK_DISABLE_DEPRECATED gtk_type_enum_find_value gtk_type_enum_get_values @@ -5048,7 +5111,7 @@ gtk_ui_manager_get_action gtk_ui_manager_get_action_groups gtk_ui_manager_get_add_tearoffs gtk_ui_manager_get_toplevels -gtk_ui_manager_get_type G_GNUC_CONST +gtk_ui_manager_get_type gtk_ui_manager_get_ui gtk_ui_manager_get_widget gtk_ui_manager_insert_action_group @@ -5062,7 +5125,7 @@ gtk_ui_manager_set_add_tearoffs #if IN_HEADER(__GTK_VBOX_H__) #if IN_FILE(__GTK_VBOX_C__) -gtk_vbox_get_type G_GNUC_CONST +gtk_vbox_get_type gtk_vbox_new #endif #endif @@ -5075,7 +5138,7 @@ gtk_vbutton_box_get_spacing_default gtk_vbutton_box_set_layout_default gtk_vbutton_box_set_spacing_default #endif -gtk_vbutton_box_get_type G_GNUC_CONST +gtk_vbutton_box_get_type gtk_vbutton_box_new #endif #endif @@ -5084,7 +5147,7 @@ gtk_vbutton_box_new #if IN_FILE(__GTK_VIEWPORT_C__) gtk_viewport_get_hadjustment gtk_viewport_get_shadow_type -gtk_viewport_get_type G_GNUC_CONST +gtk_viewport_get_type gtk_viewport_get_vadjustment gtk_viewport_get_bin_window gtk_viewport_get_view_window @@ -5097,14 +5160,14 @@ gtk_viewport_set_vadjustment #if IN_HEADER(__GTK_VOLUME_BUTTON_H__) #if IN_FILE(__GTK_VOLUME_BUTTON_C__) -gtk_volume_button_get_type G_GNUC_CONST +gtk_volume_button_get_type gtk_volume_button_new #endif #endif #if IN_HEADER(__GTK_VPANED_H__) #if IN_FILE(__GTK_VPANED_C__) -gtk_vpaned_get_type G_GNUC_CONST +gtk_vpaned_get_type gtk_vpaned_new #endif #endif @@ -5112,7 +5175,7 @@ gtk_vpaned_new #if IN_HEADER(__GTK_VRULER_H__) #if IN_FILE(__GTK_VRULER_C__) #ifndef GTK_DISABLE_DEPRECATED -gtk_vruler_get_type G_GNUC_CONST +gtk_vruler_get_type gtk_vruler_new #endif #endif @@ -5120,7 +5183,7 @@ gtk_vruler_new #if IN_HEADER(__GTK_VSCALE_H__) #if IN_FILE(__GTK_VSCALE_C__) -gtk_vscale_get_type G_GNUC_CONST +gtk_vscale_get_type gtk_vscale_new gtk_vscale_new_with_range #endif @@ -5128,14 +5191,14 @@ gtk_vscale_new_with_range #if IN_HEADER(__GTK_VSCROLLBAR_H__) #if IN_FILE(__GTK_VSCROLLBAR_C__) -gtk_vscrollbar_get_type G_GNUC_CONST +gtk_vscrollbar_get_type gtk_vscrollbar_new #endif #endif #if IN_HEADER(__GTK_VSEPARATOR_H__) #if IN_FILE(__GTK_VSEPARATOR_C__) -gtk_vseparator_get_type G_GNUC_CONST +gtk_vseparator_get_type gtk_vseparator_new #endif #endif @@ -5144,7 +5207,7 @@ gtk_vseparator_new #if IN_FILE(__GTK_WIDGET_C__) gtk_requisition_copy gtk_requisition_free -gtk_requisition_get_type G_GNUC_CONST +gtk_requisition_get_type gtk_widget_activate gtk_widget_is_composited gtk_widget_add_accelerator @@ -5206,7 +5269,7 @@ gtk_widget_get_tooltip_markup gtk_widget_get_tooltip_text gtk_widget_get_tooltip_window gtk_widget_get_toplevel -gtk_widget_get_type G_GNUC_CONST +gtk_widget_get_type gtk_widget_get_visible gtk_widget_get_visual gtk_widget_grab_default @@ -5367,11 +5430,11 @@ gtk_window_get_skip_taskbar_hint gtk_window_get_urgency_hint gtk_window_get_title gtk_window_get_transient_for -gtk_window_get_type G_GNUC_CONST +gtk_window_get_type gtk_window_get_type_hint gtk_window_get_window_type gtk_window_group_add_window -gtk_window_group_get_type G_GNUC_CONST +gtk_window_group_get_type gtk_window_group_new gtk_window_group_remove_window gtk_window_group_list_windows @@ -5461,14 +5524,14 @@ gtk_window_unstick #if IN_HEADER(__GTK_WIN32_EMBED_WIDGET_H__) #if IN_FILE(__GTK_WIN32_EMBED_WIDGET_C__) #ifdef G_OS_WIN32 -gtk_win32_embed_widget_get_type G_GNUC_CONST +gtk_win32_embed_widget_get_type #endif #endif #endif #if IN_HEADER(__GTK_INFO_BAR_H__) #if IN_FILE(__GTK_INFO_BAR_C__) -gtk_info_bar_get_type G_GNUC_CONST +gtk_info_bar_get_type gtk_info_bar_new gtk_info_bar_new_with_buttons gtk_info_bar_get_action_area diff --git a/gtk/gtkaboutdialog.c b/gtk/gtkaboutdialog.c index b4f6e401c..9cac0c49f 100644 --- a/gtk/gtkaboutdialog.c +++ b/gtk/gtkaboutdialog.c @@ -188,6 +188,8 @@ static void gtk_about_dialog_set_property (GObject guint prop_id, const GValue *value, GParamSpec *pspec); +static void gtk_about_dialog_realize (GtkWidget *widget); +static void gtk_about_dialog_unrealize (GtkWidget *widget); static void gtk_about_dialog_show (GtkWidget *widge); static void update_name_version (GtkAboutDialog *about); static GtkIconSet * icon_set_new_from_pixbufs (GList *pixbufs); @@ -293,6 +295,8 @@ gtk_about_dialog_class_init (GtkAboutDialogClass *klass) object_class->finalize = gtk_about_dialog_finalize; widget_class->show = gtk_about_dialog_show; + widget_class->realize = gtk_about_dialog_realize; + widget_class->unrealize = gtk_about_dialog_unrealize; klass->activate_link = gtk_about_dialog_activate_link; @@ -583,8 +587,8 @@ gtk_about_dialog_init (GtkAboutDialog *about) priv->documenters = NULL; priv->artists = NULL; - priv->hand_cursor = gdk_cursor_new (GDK_HAND2); - priv->regular_cursor = gdk_cursor_new (GDK_XTERM); + priv->hand_cursor = NULL; + priv->regular_cursor = NULL; priv->hovering_over_link = FALSE; priv->wrap_license = FALSE; @@ -699,12 +703,44 @@ gtk_about_dialog_finalize (GObject *object) g_slist_foreach (priv->visited_links, (GFunc)g_free, NULL); g_slist_free (priv->visited_links); - gdk_cursor_unref (priv->hand_cursor); - gdk_cursor_unref (priv->regular_cursor); - G_OBJECT_CLASS (gtk_about_dialog_parent_class)->finalize (object); } +/* The cursors must belong to the display the dialog is on, not to the + * default display, so create them on realize. + */ +static void +gtk_about_dialog_realize (GtkWidget *widget) +{ + GtkAboutDialogPrivate *priv = (GtkAboutDialogPrivate *)GTK_ABOUT_DIALOG (widget)->private_data; + GdkDisplay *display; + + GTK_WIDGET_CLASS (gtk_about_dialog_parent_class)->realize (widget); + + display = gtk_widget_get_display (widget); + priv->hand_cursor = gdk_cursor_new_for_display (display, GDK_HAND2); + priv->regular_cursor = gdk_cursor_new_for_display (display, GDK_XTERM); +} + +static void +gtk_about_dialog_unrealize (GtkWidget *widget) +{ + GtkAboutDialogPrivate *priv = (GtkAboutDialogPrivate *)GTK_ABOUT_DIALOG (widget)->private_data; + + if (priv->hand_cursor) + { + gdk_cursor_unref (priv->hand_cursor); + priv->hand_cursor = NULL; + } + if (priv->regular_cursor) + { + gdk_cursor_unref (priv->regular_cursor); + priv->regular_cursor = NULL; + } + + GTK_WIDGET_CLASS (gtk_about_dialog_parent_class)->unrealize (widget); +} + static void gtk_about_dialog_set_property (GObject *object, guint prop_id, @@ -2085,14 +2121,14 @@ text_view_new (GtkAboutDialog *about, r1 = strstr (q0, "http://"); if (r1) { - r2 = strpbrk (r1, " \n\t"); + r2 = strpbrk (r1, " \n\t>"); if (!r2) r2 = strchr (r1, '\0'); } else r2 = NULL; - if (r1 && r2 && (!q1 || !q2 || (r1 < q1))) + if (r1 && r2 && (!q1 || !q2 || (r1 <= q1 + 1))) { q1 = r1; q2 = r2; diff --git a/gtk/gtkaboutdialog.h b/gtk/gtkaboutdialog.h index 3b61866f3..6d6c8cab2 100644 --- a/gtk/gtkaboutdialog.h +++ b/gtk/gtkaboutdialog.h @@ -70,7 +70,7 @@ struct _GtkAboutDialogClass void (*_gtk_reserved3) (void); }; -GType gtk_about_dialog_get_type (void) G_GNUC_CONST; +GType gtk_about_dialog_get_type (void); GtkWidget *gtk_about_dialog_new (void); void gtk_show_about_dialog (GtkWindow *parent, const gchar *first_property_name, diff --git a/gtk/gtkaccelgroup.c b/gtk/gtkaccelgroup.c index 07f81e36e..7d74dc4aa 100644 --- a/gtk/gtkaccelgroup.c +++ b/gtk/gtkaccelgroup.c @@ -1258,12 +1258,16 @@ gtk_accelerator_parse (const gchar *accelerator, } else { - gchar last_ch; - - last_ch = *accelerator; - while (last_ch && last_ch != '>') + /* skip an unknown modifier, up to and including its '>'; + * without one, stop at the end of the string rather than + * reading past it */ + while (len > 0 && *accelerator != '>') + { + accelerator += 1; + len -= 1; + } + if (len > 0) { - last_ch = *accelerator; accelerator += 1; len -= 1; } diff --git a/gtk/gtkaccelgroup.h b/gtk/gtkaccelgroup.h index 14652f18b..a3b374e2b 100644 --- a/gtk/gtkaccelgroup.h +++ b/gtk/gtkaccelgroup.h @@ -119,7 +119,7 @@ struct _GtkAccelKey /* -- Accelerator Groups --- */ -GType gtk_accel_group_get_type (void) G_GNUC_CONST; +GType gtk_accel_group_get_type (void); GtkAccelGroup* gtk_accel_group_new (void); gboolean gtk_accel_group_get_is_locked (GtkAccelGroup *accel_group); GdkModifierType diff --git a/gtk/gtkaccellabel.c b/gtk/gtkaccellabel.c index 231b092d0..31287e30c 100644 --- a/gtk/gtkaccellabel.c +++ b/gtk/gtkaccellabel.c @@ -572,16 +572,34 @@ gtk_accel_label_get_string (GtkAccelLabel *accel_label) } /* Underscores in key names are better displayed as spaces - * E.g., Page_Up should be "Page Up" + * E.g., Page_Up should be "Page Up". + * + * Some keynames also have prefixes that are not suitable + * for display, e.g XF86AudioMute, so strip those out, too. + * + * This function is only called on untranslated keynames, + * so no need to be UTF-8 safe. */ static void -substitute_underscores (char *str) +append_without_underscores (GString *s, + const gchar *str) { - char *p; + const gchar *p; - for (p = str; *p; p++) - if (*p == '_') - *p = ' '; + if (g_str_has_prefix (str, "XF86")) + p = str + 4; + else if (g_str_has_prefix (str, "ISO_")) + p = str + 4; + else + p = str; + + for ( ; *p; p++) + { + if (*p == '_') + g_string_append_c (s, ' '); + else + g_string_append_c (s, *p); + } } /* On Mac, if the key has symbolic representation (e.g. arrow keys), @@ -808,10 +826,7 @@ _gtk_accel_label_class_get_accelerator_label (GtkAccelLabelClass *klass, const gchar *str; str = g_dpgettext2 (GETTEXT_PACKAGE, "keyboard label", tmp); if (str == tmp) - { - g_string_append (gstring, tmp); - substitute_underscores (gstring->str); - } + append_without_underscores (gstring, tmp); else g_string_append (gstring, str); } diff --git a/gtk/gtkaccellabel.h b/gtk/gtkaccellabel.h index ef9f6b6e5..8dfe0e7b1 100644 --- a/gtk/gtkaccellabel.h +++ b/gtk/gtkaccellabel.h @@ -94,7 +94,7 @@ struct _GtkAccelLabelClass #define gtk_accel_label_accelerator_width gtk_accel_label_get_accel_width #endif /* GTK_DISABLE_DEPRECATED */ -GType gtk_accel_label_get_type (void) G_GNUC_CONST; +GType gtk_accel_label_get_type (void); GtkWidget* gtk_accel_label_new (const gchar *string); GtkWidget* gtk_accel_label_get_accel_widget (GtkAccelLabel *accel_label); guint gtk_accel_label_get_accel_width (GtkAccelLabel *accel_label); diff --git a/gtk/gtkaccelmap.h b/gtk/gtkaccelmap.h index 19b573da0..663884488 100644 --- a/gtk/gtkaccelmap.h +++ b/gtk/gtkaccelmap.h @@ -82,7 +82,7 @@ void gtk_accel_map_foreach_unfiltered (gpointer data, GtkAccelMapForeach foreach_func); /* --- notification --- */ -GType gtk_accel_map_get_type (void) G_GNUC_CONST; +GType gtk_accel_map_get_type (void); GtkAccelMap *gtk_accel_map_get (void); diff --git a/gtk/gtkaccessible.h b/gtk/gtkaccessible.h index f538af429..1e8ac0a8b 100644 --- a/gtk/gtkaccessible.h +++ b/gtk/gtkaccessible.h @@ -66,7 +66,7 @@ struct _GtkAccessibleClass void (*_gtk_reserved4) (void); }; -GType gtk_accessible_get_type (void) G_GNUC_CONST; +GType gtk_accessible_get_type (void); void gtk_accessible_set_widget (GtkAccessible *accessible, GtkWidget *widget); diff --git a/gtk/gtkaction.h b/gtk/gtkaction.h index 2fe85e635..f13cbe96f 100644 --- a/gtk/gtkaction.h +++ b/gtk/gtkaction.h @@ -85,7 +85,7 @@ struct _GtkActionClass void (*_gtk_reserved4) (void); }; -GType gtk_action_get_type (void) G_GNUC_CONST; +GType gtk_action_get_type (void); GtkAction *gtk_action_new (const gchar *name, const gchar *label, const gchar *tooltip, diff --git a/gtk/gtkactiongroup.h b/gtk/gtkactiongroup.h index 05a90edd6..1e97bf609 100644 --- a/gtk/gtkactiongroup.h +++ b/gtk/gtkactiongroup.h @@ -108,7 +108,7 @@ struct _GtkRadioActionEntry gint value; }; -GType gtk_action_group_get_type (void) G_GNUC_CONST; +GType gtk_action_group_get_type (void); GtkActionGroup *gtk_action_group_new (const gchar *name); const gchar *gtk_action_group_get_name (GtkActionGroup *action_group); gboolean gtk_action_group_get_sensitive (GtkActionGroup *action_group); diff --git a/gtk/gtkactivatable.h b/gtk/gtkactivatable.h index 94114923c..6d9279ca9 100644 --- a/gtk/gtkactivatable.h +++ b/gtk/gtkactivatable.h @@ -66,7 +66,7 @@ struct _GtkActivatableIface }; -GType gtk_activatable_get_type (void) G_GNUC_CONST; +GType gtk_activatable_get_type (void); void gtk_activatable_sync_action_properties (GtkActivatable *activatable, GtkAction *action); diff --git a/gtk/gtkadjustment.h b/gtk/gtkadjustment.h index f79179bbc..a03741271 100644 --- a/gtk/gtkadjustment.h +++ b/gtk/gtkadjustment.h @@ -75,7 +75,7 @@ struct _GtkAdjustmentClass }; -GType gtk_adjustment_get_type (void) G_GNUC_CONST; +GType gtk_adjustment_get_type (void); GtkObject* gtk_adjustment_new (gdouble value, gdouble lower, gdouble upper, diff --git a/gtk/gtkalignment.h b/gtk/gtkalignment.h index 086a2f4bc..c1e5067c1 100644 --- a/gtk/gtkalignment.h +++ b/gtk/gtkalignment.h @@ -65,7 +65,7 @@ struct _GtkAlignmentClass }; -GType gtk_alignment_get_type (void) G_GNUC_CONST; +GType gtk_alignment_get_type (void); GtkWidget* gtk_alignment_new (gfloat xalign, gfloat yalign, gfloat xscale, diff --git a/gtk/gtkarrow.h b/gtk/gtkarrow.h index a0ef78a72..a451400b9 100644 --- a/gtk/gtkarrow.h +++ b/gtk/gtkarrow.h @@ -63,7 +63,7 @@ struct _GtkArrowClass }; -GType gtk_arrow_get_type (void) G_GNUC_CONST; +GType gtk_arrow_get_type (void); GtkWidget* gtk_arrow_new (GtkArrowType arrow_type, GtkShadowType shadow_type); void gtk_arrow_set (GtkArrow *arrow, diff --git a/gtk/gtkaspectframe.h b/gtk/gtkaspectframe.h index c149477f0..af820d166 100644 --- a/gtk/gtkaspectframe.h +++ b/gtk/gtkaspectframe.h @@ -66,7 +66,7 @@ struct _GtkAspectFrameClass }; -GType gtk_aspect_frame_get_type (void) G_GNUC_CONST; +GType gtk_aspect_frame_get_type (void); GtkWidget* gtk_aspect_frame_new (const gchar *label, gfloat xalign, gfloat yalign, diff --git a/gtk/gtkassistant.c b/gtk/gtkassistant.c index 5928c3d9d..f07e7789f 100644 --- a/gtk/gtkassistant.c +++ b/gtk/gtkassistant.c @@ -612,6 +612,10 @@ set_current_page (GtkAssistant *assistant, set_assistant_sidebar_image (assistant); g_signal_emit (assistant, signals [PREPARE], 0, priv->current_page->page); + /* do not continue if the prepare signal handler has already changed the + * current page */ + if (priv->current_page != page) + return; if (gtk_widget_get_visible (priv->current_page->page) && gtk_widget_get_mapped (GTK_WIDGET (assistant))) { diff --git a/gtk/gtkassistant.h b/gtk/gtkassistant.h index 0de0856b0..59f1b69bd 100644 --- a/gtk/gtkassistant.h +++ b/gtk/gtkassistant.h @@ -119,7 +119,7 @@ struct _GtkAssistantClass */ typedef gint (*GtkAssistantPageFunc) (gint current_page, gpointer data); -GType gtk_assistant_get_type (void) G_GNUC_CONST; +GType gtk_assistant_get_type (void); GtkWidget *gtk_assistant_new (void); gint gtk_assistant_get_current_page (GtkAssistant *assistant); void gtk_assistant_set_current_page (GtkAssistant *assistant, diff --git a/gtk/gtkbbox.h b/gtk/gtkbbox.h index 32799ca1e..92e59789f 100644 --- a/gtk/gtkbbox.h +++ b/gtk/gtkbbox.h @@ -65,7 +65,7 @@ struct _GtkButtonBoxClass }; -GType gtk_button_box_get_type (void) G_GNUC_CONST; +GType gtk_button_box_get_type (void); GtkButtonBoxStyle gtk_button_box_get_layout (GtkButtonBox *widget); void gtk_button_box_set_layout (GtkButtonBox *widget, diff --git a/gtk/gtkbin.h b/gtk/gtkbin.h index 1366f7bed..72fe30a8b 100644 --- a/gtk/gtkbin.h +++ b/gtk/gtkbin.h @@ -61,7 +61,7 @@ struct _GtkBinClass }; -GType gtk_bin_get_type (void) G_GNUC_CONST; +GType gtk_bin_get_type (void); GtkWidget *gtk_bin_get_child (GtkBin *bin); diff --git a/gtk/gtkbox.h b/gtk/gtkbox.h index 6967687cd..ead2ba7dc 100644 --- a/gtk/gtkbox.h +++ b/gtk/gtkbox.h @@ -101,7 +101,7 @@ struct _GtkBoxChild }; #endif -GType gtk_box_get_type (void) G_GNUC_CONST; +GType gtk_box_get_type (void); GtkWidget* _gtk_box_new (GtkOrientation orientation, gboolean homogeneous, gint spacing); diff --git a/gtk/gtkbuildable.h b/gtk/gtkbuildable.h index 78a46173d..67fd41c66 100644 --- a/gtk/gtkbuildable.h +++ b/gtk/gtkbuildable.h @@ -133,7 +133,7 @@ struct _GtkBuildableIface }; -GType gtk_buildable_get_type (void) G_GNUC_CONST; +GType gtk_buildable_get_type (void); void gtk_buildable_set_name (GtkBuildable *buildable, const gchar *name); diff --git a/gtk/gtkbuilder.c b/gtk/gtkbuilder.c index af374215a..9c6462464 100644 --- a/gtk/gtkbuilder.c +++ b/gtk/gtkbuilder.c @@ -329,6 +329,15 @@ gtk_builder_get_parameters (GtkBuilder *builder, g_type_class_unref (oclass); } +static const gchar * +object_get_name (GObject *object) +{ + if (GTK_IS_BUILDABLE (object)) + return gtk_buildable_get_name (GTK_BUILDABLE (object)); + else + return g_object_get_data (object, "gtk-builder-name"); +} + static GObject * gtk_builder_get_internal_child (GtkBuilder *builder, ObjectInfo *info, @@ -349,7 +358,7 @@ gtk_builder_get_internal_child (GtkBuilder *builder, GTK_NOTE (BUILDER, g_print ("Trying to get internal child %s from %s\n", childname, - gtk_buildable_get_name (GTK_BUILDABLE (info->object)))); + object_get_name (info->object))); if (GTK_IS_BUILDABLE (info->object)) obj = gtk_buildable_get_internal_child (GTK_BUILDABLE (info->object), @@ -581,8 +590,7 @@ _gtk_builder_add (GtkBuilder *builder, if (!child_info->parent) { - g_warning ("%s: Not adding, No parent", - gtk_buildable_get_name (GTK_BUILDABLE (object))); + g_warning ("%s: Not adding, No parent", object_get_name (object)); return; } @@ -592,9 +600,7 @@ _gtk_builder_add (GtkBuilder *builder, g_assert (GTK_IS_BUILDABLE (parent)); GTK_NOTE (BUILDER, - g_print ("adding %s to %s\n", - gtk_buildable_get_name (GTK_BUILDABLE (object)), - gtk_buildable_get_name (GTK_BUILDABLE (parent)))); + g_print ("adding %s to %s\n", object_get_name (object), object_get_name (parent))); gtk_buildable_add_child (GTK_BUILDABLE (parent), builder, object, child_info->type); @@ -1215,7 +1221,7 @@ gtk_builder_value_from_string (GtkBuilder *builder, gunichar c; g_value_init (value, G_TYPE_UINT); c = g_utf8_get_char_validated (string, strlen (string)); - if (c > 0) + if (c != 0 && c != (gunichar)-1 && c != (gunichar)-2) g_value_set_uint (value, c); return TRUE; } diff --git a/gtk/gtkbuilder.h b/gtk/gtkbuilder.h index 513d98756..6a60f0e9a 100644 --- a/gtk/gtkbuilder.h +++ b/gtk/gtkbuilder.h @@ -91,7 +91,7 @@ typedef void (*GtkBuilderConnectFunc) (GtkBuilder *builder, GConnectFlags flags, gpointer user_data); -GType gtk_builder_get_type (void) G_GNUC_CONST; +GType gtk_builder_get_type (void); GtkBuilder* gtk_builder_new (void); guint gtk_builder_add_from_file (GtkBuilder *builder, diff --git a/gtk/gtkbutton.h b/gtk/gtkbutton.h index 7ffb0c745..2c8a207ba 100644 --- a/gtk/gtkbutton.h +++ b/gtk/gtkbutton.h @@ -88,7 +88,7 @@ struct _GtkButtonClass }; -GType gtk_button_get_type (void) G_GNUC_CONST; +GType gtk_button_get_type (void); GtkWidget* gtk_button_new (void); GtkWidget* gtk_button_new_with_label (const gchar *label); GtkWidget* gtk_button_new_from_stock (const gchar *stock_id); diff --git a/gtk/gtkcalendar.c b/gtk/gtkcalendar.c index 2e453db04..514e12d3d 100644 --- a/gtk/gtkcalendar.c +++ b/gtk/gtkcalendar.c @@ -54,6 +54,7 @@ #include "gtkmarshalers.h" #include "gtktooltip.h" #include "gtkprivate.h" +#include "gtktimeprivate.h" #include "gdk/gdkkeysyms.h" #include "gtkalias.h" @@ -766,7 +767,7 @@ gtk_calendar_init (GtkCalendar *calendar) } /* Set defaults */ - now_dt = g_date_time_new_now_local (); + now_dt = _gtk_date_time_new_now_local (); if (now_dt) { calendar->month = g_date_time_get_month (now_dt) - 1; @@ -3177,6 +3178,11 @@ gtk_calendar_scroll (GtkWidget *widget, { GtkCalendar *calendar = GTK_CALENDAR (widget); + /* a pinch on a touchpad (Ctrl with the wheel) is for programs that + * zoom, not for scrolling here */ + if (gdk_event_get_touchpad_emulated ((GdkEvent *) event)) + return FALSE; + if (event->direction == GDK_SCROLL_UP) { if (!gtk_widget_has_focus (widget)) diff --git a/gtk/gtkcalendar.h b/gtk/gtkcalendar.h index 722e0b8b8..3fccdff57 100644 --- a/gtk/gtkcalendar.h +++ b/gtk/gtkcalendar.h @@ -156,7 +156,7 @@ struct _GtkCalendarClass }; -GType gtk_calendar_get_type (void) G_GNUC_CONST; +GType gtk_calendar_get_type (void); GtkWidget* gtk_calendar_new (void); gboolean gtk_calendar_select_month (GtkCalendar *calendar, diff --git a/gtk/gtkcelleditable.h b/gtk/gtkcelleditable.h index 9d5a6332e..39bd5a0b2 100644 --- a/gtk/gtkcelleditable.h +++ b/gtk/gtkcelleditable.h @@ -51,7 +51,7 @@ struct _GtkCellEditableIface }; -GType gtk_cell_editable_get_type (void) G_GNUC_CONST; +GType gtk_cell_editable_get_type (void); void gtk_cell_editable_start_editing (GtkCellEditable *cell_editable, GdkEvent *event); diff --git a/gtk/gtkcelllayout.h b/gtk/gtkcelllayout.h index 828105c9e..e1f257ef4 100644 --- a/gtk/gtkcelllayout.h +++ b/gtk/gtkcelllayout.h @@ -75,7 +75,7 @@ struct _GtkCellLayoutIface GList* (* get_cells) (GtkCellLayout *cell_layout); }; -GType gtk_cell_layout_get_type (void) G_GNUC_CONST; +GType gtk_cell_layout_get_type (void); void gtk_cell_layout_pack_start (GtkCellLayout *cell_layout, GtkCellRenderer *cell, gboolean expand); diff --git a/gtk/gtkcellrenderer.c b/gtk/gtkcellrenderer.c index 154e05251..4758bb829 100644 --- a/gtk/gtkcellrenderer.c +++ b/gtk/gtkcellrenderer.c @@ -812,7 +812,7 @@ gtk_cell_renderer_set_padding (GtkCellRenderer *cell, gint ypad) { g_return_if_fail (GTK_IS_CELL_RENDERER (cell)); - g_return_if_fail (xpad >= 0 && xpad >= 0); + g_return_if_fail (xpad >= 0 && ypad >= 0); if ((xpad != cell->xpad) || (ypad != cell->ypad)) { diff --git a/gtk/gtkcellrenderer.h b/gtk/gtkcellrenderer.h index c4831f960..bc70c0844 100644 --- a/gtk/gtkcellrenderer.h +++ b/gtk/gtkcellrenderer.h @@ -122,7 +122,7 @@ struct _GtkCellRendererClass void (*_gtk_reserved2) (void); }; -GType gtk_cell_renderer_get_type (void) G_GNUC_CONST; +GType gtk_cell_renderer_get_type (void); void gtk_cell_renderer_get_size (GtkCellRenderer *cell, GtkWidget *widget, diff --git a/gtk/gtkcellrendereraccel.c b/gtk/gtkcellrendereraccel.c index c812ba981..1d2504a03 100644 --- a/gtk/gtkcellrendereraccel.c +++ b/gtk/gtkcellrendereraccel.c @@ -424,12 +424,24 @@ grab_key_callback (GtkWidget *widget, accel_mods = event->state; - _gtk_translate_keyboard_accel_state (gdk_keymap_get_for_display (display), - event->hardware_keycode, - event->state, - gtk_accelerator_get_default_mod_mask (), - event->group, - &keyval, NULL, NULL, &consumed_modifiers); + if (event->keyval == GDK_KEY_Sys_Req && + (accel_mods & GDK_MOD1_MASK) != 0) + { + /* HACK: we don't want to use SysRq as a keybinding (but we do + * want Alt+Print), so we avoid translation from Alt+Print to SysRq + */ + keyval = GDK_KEY_Print; + consumed_modifiers = 0; + } + else + { + _gtk_translate_keyboard_accel_state (gdk_keymap_get_for_display (display), + event->hardware_keycode, + event->state, + gtk_accelerator_get_default_mod_mask (), + event->group, + &keyval, NULL, NULL, &consumed_modifiers); + } accel_key = gdk_keyval_to_lower (keyval); if (accel_key == GDK_ISO_Left_Tab) diff --git a/gtk/gtkcellrendereraccel.h b/gtk/gtkcellrendereraccel.h index 905882a94..7353b1d0c 100644 --- a/gtk/gtkcellrendereraccel.h +++ b/gtk/gtkcellrendereraccel.h @@ -82,7 +82,7 @@ struct _GtkCellRendererAccelClass void (*_gtk_reserved4) (void); }; -GType gtk_cell_renderer_accel_get_type (void) G_GNUC_CONST; +GType gtk_cell_renderer_accel_get_type (void); GtkCellRenderer *gtk_cell_renderer_accel_new (void); diff --git a/gtk/gtkcellrenderercombo.h b/gtk/gtkcellrenderercombo.h index acd2109ff..2975cb9c0 100644 --- a/gtk/gtkcellrenderercombo.h +++ b/gtk/gtkcellrenderercombo.h @@ -56,7 +56,7 @@ struct _GtkCellRendererComboClass GtkCellRendererTextClass parent; }; -GType gtk_cell_renderer_combo_get_type (void) G_GNUC_CONST; +GType gtk_cell_renderer_combo_get_type (void); GtkCellRenderer *gtk_cell_renderer_combo_new (void); G_END_DECLS diff --git a/gtk/gtkcellrendererpixbuf.h b/gtk/gtkcellrendererpixbuf.h index 581d6a692..05d390ea6 100644 --- a/gtk/gtkcellrendererpixbuf.h +++ b/gtk/gtkcellrendererpixbuf.h @@ -61,7 +61,7 @@ struct _GtkCellRendererPixbufClass void (*_gtk_reserved4) (void); }; -GType gtk_cell_renderer_pixbuf_get_type (void) G_GNUC_CONST; +GType gtk_cell_renderer_pixbuf_get_type (void); GtkCellRenderer *gtk_cell_renderer_pixbuf_new (void); diff --git a/gtk/gtkcellrendererprogress.h b/gtk/gtkcellrendererprogress.h index b9043cfa8..d95362ad0 100644 --- a/gtk/gtkcellrendererprogress.h +++ b/gtk/gtkcellrendererprogress.h @@ -66,7 +66,7 @@ struct _GtkCellRendererProgressClass void (*_gtk_reserved4) (void); }; -GType gtk_cell_renderer_progress_get_type (void) G_GNUC_CONST; +GType gtk_cell_renderer_progress_get_type (void); GtkCellRenderer* gtk_cell_renderer_progress_new (void); G_END_DECLS diff --git a/gtk/gtkcellrendererspinner.h b/gtk/gtkcellrendererspinner.h index 7a9dc276b..17c0febb7 100644 --- a/gtk/gtkcellrendererspinner.h +++ b/gtk/gtkcellrendererspinner.h @@ -59,7 +59,7 @@ struct _GtkCellRendererSpinnerClass void (*_gtk_reserved4) (void); }; -GType gtk_cell_renderer_spinner_get_type (void) G_GNUC_CONST; +GType gtk_cell_renderer_spinner_get_type (void); GtkCellRenderer *gtk_cell_renderer_spinner_new (void); G_END_DECLS diff --git a/gtk/gtkcellrenderertext.c b/gtk/gtkcellrenderertext.c index 9d4d110c5..78d97de32 100644 --- a/gtk/gtkcellrenderertext.c +++ b/gtk/gtkcellrenderertext.c @@ -19,6 +19,7 @@ #include "config.h" #include +#include #include "gtkcellrenderertext.h" #include "gtkeditable.h" #include "gtkentry.h" @@ -1357,28 +1358,214 @@ add_attr (PangoAttrList *attr_list, pango_attr_list_insert (attr_list, attr); } -static PangoLayout* -get_layout (GtkCellRendererText *celltext, - GtkWidget *widget, - gboolean will_render, - GtkCellRendererState flags) +/* The laid out text of a cell. Measuring and drawing a cell used to + * build and shape a new PangoLayout each time; now the layouts are kept + * per widget, so text that is measured and then drawn, or drawn again, + * is shaped once. An entry is good as long as the widget's PangoContext + * is unchanged and nobody else changed the layout. + */ +typedef struct { - PangoAttrList *attr_list; + guint hash; + gchar *text; + PangoAttrList *attrs; + guint single_paragraph : 1; + PangoEllipsizeMode ellipsize; + PangoWrapMode wrap; + PangoAlignment align; + gint width; /* asked for when measuring, -1 for none */ PangoLayout *layout; + guint serial; /* of @layout after our last change */ + PangoRectangle rect; /* pixel extents at @width */ + /* in the cache: the next entry with the same bucket, and the + * neighbours in the order of use, -1 for none */ + gint16 bucket_next; + gint16 lru_prev, lru_next; +} CellLayout; + +#if PANGO_VERSION_CHECK (1, 46, 0) +#define CELL_LAYOUT_CACHE +#define layout_serial(layout) pango_layout_get_serial (layout) +#else +#define layout_serial(layout) 0 +#endif + +#ifdef CELL_LAYOUT_CACHE + +/* Enough for three or four text columns of the rows a list shows; the + * layout of a short text takes about 1.5 KB. The least recently used + * goes first; all go when the widget is unmapped. The entries are + * found through buckets by hash, so a lookup does not compare with + * every entry. */ +#define CELL_LAYOUTS 128 +#define CELL_BUCKETS 64 + +typedef struct +{ + PangoContext *context; /* not a reference: the widget holds one */ + guint context_serial; + guint n, size; /* the array grows to CELL_LAYOUTS */ + CellLayout *entries; + gint16 buckets[CELL_BUCKETS]; + gint16 lru_head, lru_tail; /* most and least recently used */ +} CellLayoutCache; + +static GQuark cell_layout_quark; + +#endif + +/* Frees what @cl holds; the links of a cache entry stay */ +static void +cell_layout_clear (CellLayout *cl) +{ + g_free (cl->text); + cl->text = NULL; + if (cl->attrs) + pango_attr_list_unref (cl->attrs); + cl->attrs = NULL; + if (cl->layout) + g_object_unref (cl->layout); + cl->layout = NULL; +} + +#ifdef CELL_LAYOUT_CACHE + +static void +cell_layout_cache_free (gpointer data) +{ + CellLayoutCache *cache = data; + guint i; + + for (i = 0; i < cache->n; i++) + cell_layout_clear (&cache->entries[i]); + g_free (cache->entries); + g_slice_free (CellLayoutCache, cache); +} + +static void +cell_layout_cache_drop (GtkWidget *widget) +{ + g_object_set_qdata (G_OBJECT (widget), cell_layout_quark, NULL); +} + +/* The cache of the widget (data of the widget, since the layouts hold + * the context), emptied when its context changed */ +static CellLayoutCache * +cell_layout_cache_get (GtkWidget *widget) +{ + PangoContext *context = gtk_widget_get_pango_context (widget); + CellLayoutCache *cache; + guint serial = pango_context_get_serial (context); + guint i; + + if (!cell_layout_quark) + cell_layout_quark = g_quark_from_static_string ("gtk-cell-renderer-text-layouts"); + + cache = g_object_get_qdata (G_OBJECT (widget), cell_layout_quark); + if (cache && (cache->context != context || cache->context_serial != serial)) + { + g_object_set_qdata (G_OBJECT (widget), cell_layout_quark, NULL); + cache = NULL; + } + if (!cache) + { + static GQuark hooked_quark; + + if (!hooked_quark) + hooked_quark = g_quark_from_static_string ("gtk-cell-renderer-text-unmap-hooked"); + if (!g_object_get_qdata (G_OBJECT (widget), hooked_quark)) + { + g_signal_connect (widget, "unmap", G_CALLBACK (cell_layout_cache_drop), NULL); + g_object_set_qdata (G_OBJECT (widget), hooked_quark, GINT_TO_POINTER (1)); + } + + cache = g_slice_new0 (CellLayoutCache); + cache->context = context; + cache->context_serial = serial; + for (i = 0; i < CELL_BUCKETS; i++) + cache->buckets[i] = -1; + cache->lru_head = cache->lru_tail = -1; + g_object_set_qdata_full (G_OBJECT (widget), cell_layout_quark, + cache, cell_layout_cache_free); + } + + return cache; +} + +static void +cell_layout_lru_unlink (CellLayoutCache *cache, + gint i) +{ + CellLayout *e = &cache->entries[i]; + + if (e->lru_prev >= 0) + cache->entries[e->lru_prev].lru_next = e->lru_next; + else + cache->lru_head = e->lru_next; + if (e->lru_next >= 0) + cache->entries[e->lru_next].lru_prev = e->lru_prev; + else + cache->lru_tail = e->lru_prev; +} + +static void +cell_layout_lru_push (CellLayoutCache *cache, + gint i) +{ + CellLayout *e = &cache->entries[i]; + + e->lru_prev = -1; + e->lru_next = cache->lru_head; + if (cache->lru_head >= 0) + cache->entries[cache->lru_head].lru_prev = i; + else + cache->lru_tail = i; + cache->lru_head = i; +} + +static void +cell_layout_lru_touch (CellLayoutCache *cache, + gint i) +{ + if (cache->lru_head == i) + return; + cell_layout_lru_unlink (cache, i); + cell_layout_lru_push (cache, i); +} + +static void +cell_layout_bucket_remove (CellLayoutCache *cache, + gint i) +{ + gint16 *link = &cache->buckets[cache->entries[i].hash % CELL_BUCKETS]; + + while (*link != i) + link = &cache->entries[*link].bucket_next; + *link = cache->entries[i].bucket_next; +} + +#endif + +/* The layout of the cell as it is now, from the cache or made in + * @scratch. Give it back with cell_layout_release(). */ +static CellLayout * +cell_layout_get (GtkCellRendererText *celltext, + GtkWidget *widget, + gboolean will_render, + GtkCellRendererState flags, + CellLayout *scratch) +{ + GtkCellRendererTextPrivate *priv = GTK_CELL_RENDERER_TEXT_GET_PRIVATE (celltext); + const gchar *text = celltext->text ? celltext->text : ""; + PangoAttrList *attr_list; PangoUnderline uline; - GtkCellRendererTextPrivate *priv; - - priv = GTK_CELL_RENDERER_TEXT_GET_PRIVATE (celltext); - - layout = gtk_widget_create_pango_layout (widget, celltext->text); + CellLayout key, *cl; if (celltext->extra_attrs) attr_list = pango_attr_list_copy (celltext->extra_attrs); else attr_list = pango_attr_list_new (); - pango_layout_set_single_paragraph_mode (layout, priv->single_paragraph); - if (will_render) { /* Add options that affect appearance but not size */ @@ -1440,48 +1627,120 @@ get_layout (GtkCellRendererText *celltext, if (celltext->rise_set) add_attr (attr_list, pango_attr_rise_new (celltext->rise)); - if (priv->ellipsize_set) - pango_layout_set_ellipsize (layout, priv->ellipsize); - else - pango_layout_set_ellipsize (layout, PANGO_ELLIPSIZE_NONE); - + memset (&key, 0, sizeof (key)); + key.single_paragraph = priv->single_paragraph; + key.ellipsize = priv->ellipsize_set ? priv->ellipsize : PANGO_ELLIPSIZE_NONE; if (priv->wrap_width != -1) { - pango_layout_set_width (layout, priv->wrap_width * PANGO_SCALE); - pango_layout_set_wrap (layout, priv->wrap_mode); + key.width = priv->wrap_width * PANGO_SCALE; + key.wrap = priv->wrap_mode; } else { - pango_layout_set_width (layout, -1); - pango_layout_set_wrap (layout, PANGO_WRAP_CHAR); + key.width = -1; + key.wrap = PANGO_WRAP_CHAR; } - if (priv->align_set) - pango_layout_set_alignment (layout, priv->align); + key.align = priv->align; + else if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL) + key.align = PANGO_ALIGN_RIGHT; else - { - PangoAlignment align; + key.align = PANGO_ALIGN_LEFT; + key.hash = g_str_hash (text) ^ (key.width * 31) ^ + (key.ellipsize << 2) ^ (key.wrap << 5) ^ (key.align << 7) ^ key.single_paragraph; - if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL) - align = PANGO_ALIGN_RIGHT; - else - align = PANGO_ALIGN_LEFT; + cl = scratch; - pango_layout_set_alignment (layout, align); - } +#ifdef CELL_LAYOUT_CACHE + { + CellLayoutCache *cache = cell_layout_cache_get (widget); + gint i, victim; - pango_layout_set_attributes (layout, attr_list); + for (i = cache->buckets[key.hash % CELL_BUCKETS]; i >= 0; i = cache->entries[i].bucket_next) + { + CellLayout *e = &cache->entries[i]; - pango_attr_list_unref (attr_list); + if (e->hash == key.hash && + e->width == key.width && + e->ellipsize == key.ellipsize && + e->wrap == key.wrap && + e->align == key.align && + e->single_paragraph == key.single_paragraph && + strcmp (e->text, text) == 0 && + pango_attr_list_equal (e->attrs, attr_list)) + { + cell_layout_lru_touch (cache, i); + if (layout_serial (e->layout) == e->serial) + { + pango_attr_list_unref (attr_list); + return e; + } + /* changed behind our back: make it again, in its place */ + cell_layout_clear (e); + cl = e; + goto make; + } + } + if (cache->n < CELL_LAYOUTS) + { + if (cache->n == cache->size) + { + cache->size = MAX (8, 2 * cache->size); + cache->entries = g_renew (CellLayout, cache->entries, cache->size); + } + victim = cache->n++; + memset (&cache->entries[victim], 0, sizeof (CellLayout)); + cell_layout_lru_push (cache, victim); + } + else + { + victim = cache->lru_tail; + cell_layout_bucket_remove (cache, victim); + cell_layout_clear (&cache->entries[victim]); + cell_layout_lru_touch (cache, victim); + } + cache->entries[victim].bucket_next = cache->buckets[key.hash % CELL_BUCKETS]; + cache->buckets[key.hash % CELL_BUCKETS] = victim; + cl = &cache->entries[victim]; + } + make: +#endif - return layout; + cl->hash = key.hash; + cl->text = g_strdup (text); + cl->attrs = attr_list; + cl->single_paragraph = key.single_paragraph; + cl->ellipsize = key.ellipsize; + cl->wrap = key.wrap; + cl->align = key.align; + cl->width = key.width; + + cl->layout = gtk_widget_create_pango_layout (widget, celltext->text); + pango_layout_set_single_paragraph_mode (cl->layout, cl->single_paragraph); + pango_layout_set_ellipsize (cl->layout, cl->ellipsize); + pango_layout_set_width (cl->layout, cl->width); + pango_layout_set_wrap (cl->layout, cl->wrap); + pango_layout_set_alignment (cl->layout, cl->align); + pango_layout_set_attributes (cl->layout, attr_list); + pango_layout_get_pixel_extents (cl->layout, NULL, &cl->rect); + cl->serial = layout_serial (cl->layout); + + return cl; +} + +static void +cell_layout_release (CellLayout *cl, + CellLayout *scratch) +{ + if (cl == scratch) + cell_layout_clear (scratch); } static void get_size (GtkCellRenderer *cell, GtkWidget *widget, GdkRectangle *cell_area, - PangoLayout *layout, + const PangoRectangle *text_rect, gint *x_offset, gint *y_offset, gint *width, @@ -1532,12 +1791,17 @@ get_size (GtkCellRenderer *cell, return; } - if (layout) - g_object_ref (layout); + if (text_rect) + rect = *text_rect; else - layout = get_layout (celltext, widget, FALSE, 0); + { + CellLayout scratch, *cl; - pango_layout_get_pixel_extents (layout, NULL, &rect); + memset (&scratch, 0, sizeof (scratch)); + cl = cell_layout_get (celltext, widget, FALSE, 0, &scratch); + rect = cl->rect; + cell_layout_release (cl, &scratch); + } if (height) *height = cell->ypad * 2 + rect.height; @@ -1551,7 +1815,7 @@ get_size (GtkCellRenderer *cell, PangoFontMetrics *metrics; gint char_width; - context = pango_layout_get_context (layout); + context = gtk_widget_get_pango_context (widget); metrics = pango_context_get_metrics (context, widget->style->font_desc, pango_context_get_language (context)); char_width = pango_font_metrics_get_approximate_char_width (metrics); @@ -1588,8 +1852,6 @@ get_size (GtkCellRenderer *cell, if (x_offset) *x_offset = 0; if (y_offset) *y_offset = 0; } - - g_object_unref (layout); } @@ -1617,16 +1879,18 @@ gtk_cell_renderer_text_render (GtkCellRenderer *cell, { GtkCellRendererText *celltext = (GtkCellRendererText *) cell; - PangoLayout *layout; + CellLayout scratch, *cl; GtkStateType state; gint x_offset; gint y_offset; + gint width; GtkCellRendererTextPrivate *priv; priv = GTK_CELL_RENDERER_TEXT_GET_PRIVATE (cell); - layout = get_layout (celltext, widget, TRUE, flags); - get_size (cell, widget, cell_area, layout, &x_offset, &y_offset, NULL, NULL); + memset (&scratch, 0, sizeof (scratch)); + cl = cell_layout_get (celltext, widget, TRUE, flags, &scratch); + get_size (cell, widget, cell_area, &cl->rect, &x_offset, &y_offset, NULL, NULL); if (!cell->sensitive) { @@ -1674,10 +1938,14 @@ gtk_cell_renderer_text_render (GtkCellRenderer *cell, } if (priv->ellipsize_set && priv->ellipsize != PANGO_ELLIPSIZE_NONE) - pango_layout_set_width (layout, - (cell_area->width - x_offset - 2 * cell->xpad) * PANGO_SCALE); - else if (priv->wrap_width == -1) - pango_layout_set_width (layout, -1); + width = (cell_area->width - x_offset - 2 * cell->xpad) * PANGO_SCALE; + else + width = cl->width; + if (pango_layout_get_width (cl->layout) != width) + { + pango_layout_set_width (cl->layout, width); + cl->serial = layout_serial (cl->layout); + } gtk_paint_layout (widget->style, window, @@ -1688,9 +1956,9 @@ gtk_cell_renderer_text_render (GtkCellRenderer *cell, "cellrenderertext", cell_area->x + x_offset + cell->xpad, cell_area->y + y_offset + cell->ypad, - layout); + cl->layout); - g_object_unref (layout); + cell_layout_release (cl, &scratch); } static void diff --git a/gtk/gtkcellrenderertext.h b/gtk/gtkcellrenderertext.h index 1156bf382..21ad88f49 100644 --- a/gtk/gtkcellrenderertext.h +++ b/gtk/gtkcellrenderertext.h @@ -93,7 +93,7 @@ struct _GtkCellRendererTextClass void (*_gtk_reserved4) (void); }; -GType gtk_cell_renderer_text_get_type (void) G_GNUC_CONST; +GType gtk_cell_renderer_text_get_type (void); GtkCellRenderer *gtk_cell_renderer_text_new (void); void gtk_cell_renderer_text_set_fixed_height_from_font (GtkCellRendererText *renderer, diff --git a/gtk/gtkcellrenderertoggle.h b/gtk/gtkcellrenderertoggle.h index d6145e6a5..60989f75c 100644 --- a/gtk/gtkcellrenderertoggle.h +++ b/gtk/gtkcellrenderertoggle.h @@ -64,7 +64,7 @@ struct _GtkCellRendererToggleClass void (*_gtk_reserved4) (void); }; -GType gtk_cell_renderer_toggle_get_type (void) G_GNUC_CONST; +GType gtk_cell_renderer_toggle_get_type (void); GtkCellRenderer *gtk_cell_renderer_toggle_new (void); gboolean gtk_cell_renderer_toggle_get_radio (GtkCellRendererToggle *toggle); diff --git a/gtk/gtkcellview.h b/gtk/gtkcellview.h index 1835c7a1c..5e943f373 100644 --- a/gtk/gtkcellview.h +++ b/gtk/gtkcellview.h @@ -54,7 +54,7 @@ struct _GtkCellViewClass GtkWidgetClass parent_class; }; -GType gtk_cell_view_get_type (void) G_GNUC_CONST; +GType gtk_cell_view_get_type (void); GtkWidget *gtk_cell_view_new (void); GtkWidget *gtk_cell_view_new_with_text (const gchar *text); GtkWidget *gtk_cell_view_new_with_markup (const gchar *markup); diff --git a/gtk/gtkcheckbutton.h b/gtk/gtkcheckbutton.h index 8b1a9aa0d..3ff627f2b 100644 --- a/gtk/gtkcheckbutton.h +++ b/gtk/gtkcheckbutton.h @@ -68,7 +68,7 @@ struct _GtkCheckButtonClass }; -GType gtk_check_button_get_type (void) G_GNUC_CONST; +GType gtk_check_button_get_type (void); GtkWidget* gtk_check_button_new (void); GtkWidget* gtk_check_button_new_with_label (const gchar *label); GtkWidget* gtk_check_button_new_with_mnemonic (const gchar *label); diff --git a/gtk/gtkcheckmenuitem.h b/gtk/gtkcheckmenuitem.h index 5e0ecba8a..651f235a4 100644 --- a/gtk/gtkcheckmenuitem.h +++ b/gtk/gtkcheckmenuitem.h @@ -74,7 +74,7 @@ struct _GtkCheckMenuItemClass }; -GType gtk_check_menu_item_get_type (void) G_GNUC_CONST; +GType gtk_check_menu_item_get_type (void); GtkWidget* gtk_check_menu_item_new (void); GtkWidget* gtk_check_menu_item_new_with_label (const gchar *label); diff --git a/gtk/gtkclipboard-quartz.c b/gtk/gtkclipboard-quartz.c index b8bc78fb0..e1bd5a05d 100644 --- a/gtk/gtkclipboard-quartz.c +++ b/gtk/gtkclipboard-quartz.c @@ -111,7 +111,10 @@ static GtkClipboard *clipboard_peek (GdkDisplay *display, memset (&selection_data, 0, sizeof (GtkSelectionData)); selection_data.selection = clipboard->selection; - selection_data.target = gdk_quartz_pasteboard_type_to_atom_libgtk_only (type); + /* the Finder takes files of NSFilenamesPboardType */ + selection_data.target = [type isEqualToString:NSFilenamesPboardType] + ? gdk_atom_intern_static_string ("text/uri-list") + : gdk_quartz_pasteboard_type_to_atom_libgtk_only (type); selection_data.display = gdk_display_get_default (); selection_data.length = -1; @@ -122,8 +125,14 @@ static GtkClipboard *clipboard_peek (GdkDisplay *display, clipboard->user_data); if (selection_data.length >= 0) - _gtk_quartz_set_selection_data_for_pasteboard (clipboard->pasteboard, - &selection_data); + { + if ([type isEqualToString:NSFilenamesPboardType]) + _gtk_quartz_set_filenames_for_pasteboard (clipboard->pasteboard, + &selection_data); + else + _gtk_quartz_set_selection_data_for_pasteboard (clipboard->pasteboard, + &selection_data); + } g_free (selection_data.data); } @@ -335,7 +344,6 @@ gtk_clipboard_set_contents (GtkClipboard *clipboard, gpointer user_data, gboolean have_owner) { - GtkClipboardOwner *owner; NSSet *types; NSAutoreleasePool *pool; @@ -365,32 +373,45 @@ gtk_clipboard_set_contents (GtkClipboard *clipboard, pool = [[NSAutoreleasePool alloc] init]; types = _gtk_quartz_target_entries_to_pasteboard_types (targets, n_targets); + /* files for the Finder too, as file managers put them there; the set + * is a mutable one, made for us */ + if (_gtk_quartz_targets_are_files (targets, n_targets)) + [(NSMutableSet *) types addObject:NSFilenamesPboardType]; /* call declareTypes before setting the clipboard members because * declareTypes might clear the clipboard */ if (user_data && user_data == clipboard->user_data) { - owner = [clipboard->owner retain]; - - owner->setting_same_owner = TRUE; + clipboard->owner->setting_same_owner = TRUE; clipboard->change_count = [clipboard->pasteboard declareTypes: [types allObjects] - owner: owner]; - owner->setting_same_owner = FALSE; + owner: clipboard->owner]; + clipboard->owner->setting_same_owner = FALSE; } else { - owner = [[GtkClipboardOwner alloc] initWithClipboard:clipboard]; + GtkClipboardOwner *new_owner; + /* We do not set the new owner on clipboard->owner immediately, + * because declareTypes could (but not always does -- see also the + * comment at pasteboardChangedOwner above) cause clipboard_unset + * to be called, which releases clipboard->owner. + */ + new_owner = [[GtkClipboardOwner alloc] initWithClipboard:clipboard]; clipboard->change_count = [clipboard->pasteboard declareTypes: [types allObjects] - owner: owner]; + owner: new_owner]; + + /* In case pasteboardChangedOwner was not triggered, check to see + * whether the previous owner still needs to be released. + */ + if (clipboard->owner) + [clipboard->owner release]; + clipboard->owner = new_owner; } - [owner release]; [types release]; [pool release]; - clipboard->owner = owner; clipboard->user_data = user_data; clipboard->have_owner = have_owner; if (have_owner) @@ -480,6 +501,8 @@ clipboard_unset (GtkClipboard *clipboard) g_free (clipboard->storable_targets); clipboard->storable_targets = NULL; + if (clipboard->owner) + [clipboard->owner release]; clipboard->owner = NULL; clipboard->get_func = NULL; clipboard->clear_func = NULL; diff --git a/gtk/gtkclipboard.c b/gtk/gtkclipboard.c index 132d21f62..c8657dea9 100644 --- a/gtk/gtkclipboard.c +++ b/gtk/gtkclipboard.c @@ -233,7 +233,7 @@ gtk_clipboard_finalize (GObject *object) if (clipboard->store_timeout != 0) g_source_remove (clipboard->store_timeout); - if (clipboard->notify_signal_id != 0) + if (clipboard_widget != NULL && clipboard->notify_signal_id != 0) g_signal_handler_disconnect (clipboard_widget, clipboard->notify_signal_id); g_free (clipboard->storable_targets); @@ -1784,6 +1784,7 @@ gtk_clipboard_wait_for_targets (GtkClipboard *clipboard, if (gdk_display_supports_selection_notification (gtk_clipboard_get_display (clipboard))) { + g_free (clipboard->cached_targets); clipboard->n_cached_targets = tmp_n_targets; clipboard->cached_targets = _gtk_memdup2 (tmp_targets, tmp_n_targets * sizeof (GdkAtom)); @@ -1923,6 +1924,7 @@ static gboolean gtk_clipboard_store_timeout (GtkClipboard *clipboard) { g_main_loop_quit (clipboard->store_loop); + clipboard->store_timeout = 0; return FALSE; } @@ -2049,8 +2051,11 @@ gtk_clipboard_store (GtkClipboard *clipboard) g_main_loop_unref (clipboard->store_loop); clipboard->store_loop = NULL; - g_source_remove (clipboard->store_timeout); - clipboard->store_timeout = 0; + if (clipboard->store_timeout != 0) + { + g_source_remove (clipboard->store_timeout); + clipboard->store_timeout = 0; + } g_signal_handler_disconnect (clipboard_widget, clipboard->notify_signal_id); clipboard->notify_signal_id = 0; diff --git a/gtk/gtkclipboard.h b/gtk/gtkclipboard.h index bead067f3..ff399c496 100644 --- a/gtk/gtkclipboard.h +++ b/gtk/gtkclipboard.h @@ -67,7 +67,7 @@ typedef void (* GtkClipboardGetFunc) (GtkClipboard *clipboard, typedef void (* GtkClipboardClearFunc) (GtkClipboard *clipboard, gpointer user_data_or_owner); -GType gtk_clipboard_get_type (void) G_GNUC_CONST; +GType gtk_clipboard_get_type (void); GtkClipboard *gtk_clipboard_get_for_display (GdkDisplay *display, GdkAtom selection); diff --git a/gtk/gtkclist.h b/gtk/gtkclist.h index 7409ac35a..cc66d5c0f 100644 --- a/gtk/gtkclist.h +++ b/gtk/gtkclist.h @@ -440,7 +440,7 @@ struct _GtkCell } u; }; -GType gtk_clist_get_type (void) G_GNUC_CONST; +GType gtk_clist_get_type (void); /* create a new GtkCList */ GtkWidget* gtk_clist_new (gint columns); diff --git a/gtk/gtkcolorbutton.c b/gtk/gtkcolorbutton.c index e50f46c1b..d63779705 100644 --- a/gtk/gtkcolorbutton.c +++ b/gtk/gtkcolorbutton.c @@ -361,12 +361,15 @@ gtk_color_button_drag_data_received (GtkWidget *widget, gtk_widget_queue_draw (color_button->priv->draw_area); + /* a handler of color-set may destroy the button */ + g_object_ref (color_button); g_signal_emit (color_button, color_button_signals[COLOR_SET], 0); g_object_freeze_notify (G_OBJECT (color_button)); g_object_notify (G_OBJECT (color_button), "color"); g_object_notify (G_OBJECT (color_button), "alpha"); g_object_thaw_notify (G_OBJECT (color_button)); + g_object_unref (color_button); } static void @@ -550,12 +553,15 @@ dialog_ok_clicked (GtkWidget *widget, gtk_widget_queue_draw (color_button->priv->draw_area); + /* a handler of color-set may destroy the button */ + g_object_ref (color_button); g_signal_emit (color_button, color_button_signals[COLOR_SET], 0); g_object_freeze_notify (G_OBJECT (color_button)); g_object_notify (G_OBJECT (color_button), "color"); g_object_notify (G_OBJECT (color_button), "alpha"); g_object_thaw_notify (G_OBJECT (color_button)); + g_object_unref (color_button); } static gboolean diff --git a/gtk/gtkcolorbutton.h b/gtk/gtkcolorbutton.h index c16220734..b5117058c 100644 --- a/gtk/gtkcolorbutton.h +++ b/gtk/gtkcolorbutton.h @@ -80,7 +80,7 @@ struct _GtkColorButtonClass { }; -GType gtk_color_button_get_type (void) G_GNUC_CONST; +GType gtk_color_button_get_type (void); GtkWidget *gtk_color_button_new (void); GtkWidget *gtk_color_button_new_with_color (const GdkColor *color); void gtk_color_button_set_color (GtkColorButton *color_button, diff --git a/gtk/gtkcolorsel.h b/gtk/gtkcolorsel.h index 4d71f19f6..b5e0e2d74 100644 --- a/gtk/gtkcolorsel.h +++ b/gtk/gtkcolorsel.h @@ -79,7 +79,7 @@ struct _GtkColorSelectionClass /* ColorSelection */ -GType gtk_color_selection_get_type (void) G_GNUC_CONST; +GType gtk_color_selection_get_type (void); GtkWidget *gtk_color_selection_new (void); gboolean gtk_color_selection_get_has_opacity_control (GtkColorSelection *colorsel); void gtk_color_selection_set_has_opacity_control (GtkColorSelection *colorsel, diff --git a/gtk/gtkcolorseldialog.h b/gtk/gtkcolorseldialog.h index 9cc70b897..edb667607 100644 --- a/gtk/gtkcolorseldialog.h +++ b/gtk/gtkcolorseldialog.h @@ -72,7 +72,7 @@ struct _GtkColorSelectionDialogClass /* ColorSelectionDialog */ -GType gtk_color_selection_dialog_get_type (void) G_GNUC_CONST; +GType gtk_color_selection_dialog_get_type (void); GtkWidget* gtk_color_selection_dialog_new (const gchar *title); GtkWidget* gtk_color_selection_dialog_get_color_selection (GtkColorSelectionDialog *colorsel); diff --git a/gtk/gtkcombo.h b/gtk/gtkcombo.h index d8680a645..615cd8b9c 100644 --- a/gtk/gtkcombo.h +++ b/gtk/gtkcombo.h @@ -84,7 +84,7 @@ struct _GtkComboClass { void (*_gtk_reserved4) (void); }; -GType gtk_combo_get_type (void) G_GNUC_CONST; +GType gtk_combo_get_type (void); GtkWidget* gtk_combo_new (void); /* the text in the entry must be or not be in the list */ diff --git a/gtk/gtkcombobox.c b/gtk/gtkcombobox.c index 2a554b2a9..cb19f3571 100644 --- a/gtk/gtkcombobox.c +++ b/gtk/gtkcombobox.c @@ -2921,6 +2921,11 @@ gtk_combo_box_scroll_event (GtkWidget *widget, GtkTreeIter iter; GtkTreeIter new_iter; + /* a pinch on a touchpad (Ctrl with the wheel) is for programs that + * zoom, not for scrolling here */ + if (gdk_event_get_touchpad_emulated ((GdkEvent *) event)) + return FALSE; + if (!gtk_combo_box_get_active_iter (combo_box, &iter)) return TRUE; @@ -4063,6 +4068,9 @@ gtk_combo_box_list_button_released (GtkWidget *widget, gboolean ret; GtkTreePath *path = NULL; GtkTreeIter iter; + GtkTreeViewColumn *column; + gint x; + GdkRectangle cell_area; GtkComboBox *combo_box = GTK_COMBO_BOX (data); GtkComboBoxPrivate *priv = combo_box->priv; @@ -4107,15 +4115,24 @@ gtk_combo_box_list_button_released (GtkWidget *widget, return FALSE; } - /* select something cool */ + /* Determine which row was clicked and which column therein */ ret = gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (priv->tree_view), event->x, event->y, - &path, - NULL, NULL, NULL); + &path, &column, + &x, NULL); if (!ret) return TRUE; /* clicked outside window? */ + /* Don’t select/close after clicking row’s expander. cell_area excludes that */ + gtk_tree_view_get_cell_area (GTK_TREE_VIEW (priv->tree_view), + path, column, &cell_area); + if (x < cell_area.x || x >= cell_area.x + cell_area.width) + { + gtk_tree_path_free (path); + return TRUE; + } + gtk_tree_model_get_iter (priv->model, &iter, path); /* Use iter before popdown, as mis-users like GtkFileChooserButton alter the @@ -4292,13 +4309,14 @@ gtk_combo_box_list_select_func (GtkTreeSelection *selection, NULL); if (cell_visible && cell_sensitive) - break; + { + sensitive = TRUE; + break; + } cell = cell->next; } g_list_free (cells); - - sensitive = cell_sensitive; } return sensitive; diff --git a/gtk/gtkcombobox.h b/gtk/gtkcombobox.h index 56dd9e6de..55b6aa2df 100644 --- a/gtk/gtkcombobox.h +++ b/gtk/gtkcombobox.h @@ -67,7 +67,7 @@ struct _GtkComboBoxClass /* construction */ -GType gtk_combo_box_get_type (void) G_GNUC_CONST; +GType gtk_combo_box_get_type (void); GtkWidget *gtk_combo_box_new (void); GtkWidget *gtk_combo_box_new_with_entry (void); GtkWidget *gtk_combo_box_new_with_model (GtkTreeModel *model); diff --git a/gtk/gtkcomboboxentry.h b/gtk/gtkcomboboxentry.h index c4099445d..00b589d58 100644 --- a/gtk/gtkcomboboxentry.h +++ b/gtk/gtkcomboboxentry.h @@ -62,7 +62,7 @@ struct _GtkComboBoxEntryClass }; -GType gtk_combo_box_entry_get_type (void) G_GNUC_CONST; +GType gtk_combo_box_entry_get_type (void); GtkWidget *gtk_combo_box_entry_new (void); GtkWidget *gtk_combo_box_entry_new_with_model (GtkTreeModel *model, gint text_column); diff --git a/gtk/gtkcomboboxtext.c b/gtk/gtkcomboboxtext.c index 999988211..2eedce2fd 100644 --- a/gtk/gtkcomboboxtext.c +++ b/gtk/gtkcomboboxtext.c @@ -151,8 +151,9 @@ typedef struct { GObject *object; const gchar *domain; + GString *string; + gchar *context; - gchar *string; guint translatable : 1; guint is_text : 1; @@ -211,23 +212,8 @@ item_text (GMarkupParseContext *context, return; string = g_strndup (text, text_len); - - if (data->translatable && text_len) - { - gchar *translated; - - /* FIXME: This will not use the domain set in the .ui file, - * since the parser is not telling the builder about the domain. - * However, it will work for gtk_builder_set_translation_domain() calls. - */ - translated = _gtk_builder_parser_translate (data->domain, - data->context, - string); - g_free (string); - string = translated; - } - - data->string = string; + g_string_append (data->string, string); + g_free (string); } static void @@ -239,14 +225,30 @@ item_end_element (GMarkupParseContext *context, ItemParserData *data = (ItemParserData*)user_data; /* Append the translated strings */ - if (data->string) - gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (data->object), data->string); + if (data->string->len) + { + if (data->translatable) + { + gchar *translated; + + /* FIXME: This will not use the domain set in the .ui file, + * since the parser is not telling the builder about the domain. + * However, it will work for gtk_builder_set_translation_domain() calls. + */ + translated = _gtk_builder_parser_translate (data->domain, + data->context, + data->string->str); + g_string_set_size (data->string, 0); + g_string_append (data->string, translated); + } + + gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (data->object), data->string->str); + } data->translatable = FALSE; + g_string_set_size (data->string, 0); g_free (data->context); - g_free (data->string); data->context = NULL; - data->string = NULL; data->is_text = FALSE; } @@ -277,6 +279,7 @@ gtk_combo_box_text_buildable_custom_tag_start (GtkBuildable *buildable, parser_data->builder = g_object_ref (builder); parser_data->object = G_OBJECT (g_object_ref (buildable)); parser_data->domain = gtk_builder_get_translation_domain (builder); + parser_data->string = g_string_new (""); *parser = item_parser; *data = parser_data; return TRUE; @@ -302,6 +305,7 @@ gtk_combo_box_text_buildable_custom_finished (GtkBuildable *buildable, g_object_unref (data->object); g_object_unref (data->builder); + g_string_free (data->string, TRUE); g_slice_free (ItemParserData, data); } } diff --git a/gtk/gtkcomboboxtext.h b/gtk/gtkcomboboxtext.h index 4158a2b73..957e26691 100644 --- a/gtk/gtkcomboboxtext.h +++ b/gtk/gtkcomboboxtext.h @@ -57,7 +57,7 @@ struct _GtkComboBoxTextClass void (*_gtk_reserved4) (void); }; -GType gtk_combo_box_text_get_type (void) G_GNUC_CONST; +GType gtk_combo_box_text_get_type (void); GtkWidget* gtk_combo_box_text_new (void); GtkWidget* gtk_combo_box_text_new_with_entry (void); void gtk_combo_box_text_append_text (GtkComboBoxText *combo_box, diff --git a/gtk/gtkcontainer.c b/gtk/gtkcontainer.c index e4c98c8c2..f1a2579b6 100644 --- a/gtk/gtkcontainer.c +++ b/gtk/gtkcontainer.c @@ -777,8 +777,7 @@ gtk_container_child_set_valist (GtkContainer *container, G_OBJECT_TYPE_NAME (container)); break; } - g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec)); - G_VALUE_COLLECT (&value, var_args, 0, &error); + G_VALUE_COLLECT_INIT (&value, G_PARAM_SPEC_VALUE_TYPE (pspec), var_args, 0, &error); if (error) { g_warning ("%s: %s", G_STRLOC, error); @@ -2758,6 +2757,15 @@ gtk_container_propagate_expose (GtkContainer *container, !gtk_widget_get_has_window (child) && (child->window == event->window)) { + GdkRectangle extents; + + /* a child away from the exposed area needs no event made; where + * it draws counts, with its draw border (the underlines of the + * mnemonics of labels) and its children */ + gdk_region_get_clipbox (event->region, &extents); + if (!_gtk_widget_draws_in_area (child, &extents)) + return; + child_event = gdk_event_new (GDK_EXPOSE); child_event->expose = *event; g_object_ref (child_event->expose.window); diff --git a/gtk/gtkcontainer.h b/gtk/gtkcontainer.h index 7c845e724..19242940e 100644 --- a/gtk/gtkcontainer.h +++ b/gtk/gtkcontainer.h @@ -104,7 +104,7 @@ struct _GtkContainerClass /* Application-level methods */ -GType gtk_container_get_type (void) G_GNUC_CONST; +GType gtk_container_get_type (void); void gtk_container_set_border_width (GtkContainer *container, guint border_width); guint gtk_container_get_border_width (GtkContainer *container); diff --git a/gtk/gtkctree.h b/gtk/gtkctree.h index 167c9fe02..634d886b4 100644 --- a/gtk/gtkctree.h +++ b/gtk/gtkctree.h @@ -172,7 +172,7 @@ struct _GtkCTreeNode { * Creation, insertion, deletion * ***********************************************************/ -GType gtk_ctree_get_type (void) G_GNUC_CONST; +GType gtk_ctree_get_type (void); GtkWidget * gtk_ctree_new_with_titles (gint columns, gint tree_column, gchar *titles[]); @@ -436,7 +436,7 @@ void gtk_ctree_sort_recursive (GtkCTree *ctree, * no-op's for the copy and free routines. It is defined in order to * provide type information for the signal arguments */ -GType gtk_ctree_node_get_type (void) G_GNUC_CONST; +GType gtk_ctree_node_get_type (void); G_END_DECLS diff --git a/gtk/gtkcurve.h b/gtk/gtkcurve.h index 68ee716ed..29426dcd5 100644 --- a/gtk/gtkcurve.h +++ b/gtk/gtkcurve.h @@ -85,7 +85,7 @@ struct _GtkCurveClass }; -GType gtk_curve_get_type (void) G_GNUC_CONST; +GType gtk_curve_get_type (void); GtkWidget* gtk_curve_new (void); void gtk_curve_reset (GtkCurve *curve); void gtk_curve_set_gamma (GtkCurve *curve, gfloat gamma_); diff --git a/gtk/gtkcustompaperunixdialog.h b/gtk/gtkcustompaperunixdialog.h index 0ff3af165..f1c5aa735 100644 --- a/gtk/gtkcustompaperunixdialog.h +++ b/gtk/gtkcustompaperunixdialog.h @@ -57,7 +57,7 @@ struct _GtkCustomPaperUnixDialogClass void (*_gtk_reserved7) (void); }; -GType gtk_custom_paper_unix_dialog_get_type (void) G_GNUC_CONST; +GType gtk_custom_paper_unix_dialog_get_type (void); GtkWidget * _gtk_custom_paper_unix_dialog_new (GtkWindow *parent, const gchar *title); GtkUnit _gtk_print_get_default_user_units (void); diff --git a/gtk/gtkdialog.c b/gtk/gtkdialog.c index c1826f6a7..548463b9e 100644 --- a/gtk/gtkdialog.c +++ b/gtk/gtkdialog.c @@ -1369,6 +1369,17 @@ typedef struct { gchar *response_id; } ActionWidgetInfo; +static void +action_widget_info_free (gpointer data, + gpointer user_data) +{ + ActionWidgetInfo *item = data; + + g_free (item->widget_name); + g_free (item->response_id); + g_free (item); +} + typedef struct { GtkDialog *dialog; GtkBuilder *builder; @@ -1516,11 +1527,10 @@ gtk_dialog_buildable_custom_finished (GtkBuildable *buildable, if (ad->response_id == GTK_RESPONSE_HELP) gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (dialog->action_area), GTK_WIDGET (object), TRUE); - - g_free (item->widget_name); - g_free (item->response_id); - g_free (item); } + + /* also the items of unknown objects, which were skipped above */ + g_slist_foreach (parser_data->items, action_widget_info_free, NULL); g_slist_free (parser_data->items); g_slice_free (ActionWidgetsSubParserData, parser_data); } diff --git a/gtk/gtkdialog.h b/gtk/gtkdialog.h index 389c52473..74c43f8db 100644 --- a/gtk/gtkdialog.h +++ b/gtk/gtkdialog.h @@ -124,7 +124,7 @@ struct _GtkDialogClass }; -GType gtk_dialog_get_type (void) G_GNUC_CONST; +GType gtk_dialog_get_type (void); GtkWidget* gtk_dialog_new (void); GtkWidget* gtk_dialog_new_with_buttons (const gchar *title, diff --git a/gtk/gtkdnd-quartz.c b/gtk/gtkdnd-quartz.c index 9dcba4a01..2f1e19370 100644 --- a/gtk/gtkdnd-quartz.c +++ b/gtk/gtkdnd-quartz.c @@ -148,11 +148,15 @@ struct _GtkDragFindData { guint target_info; GtkSelectionData selection_data; + gboolean filenames = [type isEqualToString:NSFilenamesPboardType]; selection_data.selection = GDK_NONE; selection_data.data = NULL; selection_data.length = -1; - selection_data.target = gdk_quartz_pasteboard_type_to_atom_libgtk_only (type); + selection_data.type = GDK_NONE; + selection_data.format = 0; + selection_data.target = filenames ? gdk_atom_intern_static_string ("text/uri-list") + : gdk_quartz_pasteboard_type_to_atom_libgtk_only (type); selection_data.display = gdk_display_get_default (); if (gtk_target_list_find (info->target_list, @@ -166,7 +170,12 @@ struct _GtkDragFindData time); if (selection_data.length >= 0) - _gtk_quartz_set_selection_data_for_pasteboard (sender, &selection_data); + { + if (filenames) + _gtk_quartz_set_filenames_for_pasteboard (sender, &selection_data); + else + _gtk_quartz_set_selection_data_for_pasteboard (sender, &selection_data); + } g_free (selection_data.data); } @@ -436,7 +445,9 @@ get_toplevel_nswindow (GtkWidget *widget) { GtkWidget *toplevel = gtk_widget_get_toplevel (widget); - if (gtk_widget_is_toplevel (toplevel) && toplevel->window) + /* a GtkOffscreenWindow has no NSView, and no drag and drop */ + if (gtk_widget_is_toplevel (toplevel) && toplevel->window && + gdk_window_get_window_type (toplevel->window) != GDK_WINDOW_OFFSCREEN) return [gdk_quartz_window_get_nsview (toplevel->window) window]; else return NULL; @@ -1084,6 +1095,12 @@ gtk_drag_begin_idle (gpointer arg) owner = [[GtkDragSourceOwner alloc] initWithInfo:info]; types = _gtk_quartz_target_list_to_pasteboard_types (info->target_list); + /* beside the URL, the names of all files, for the Finder, where the + * widget gives local files only (the file chooser says so); the set + * is a mutable one, made for us */ + if ([types containsObject:NSURLPboardType] && + g_object_get_data (G_OBJECT (info->widget), "gtk-drag-local-files")) + [(NSMutableSet *) types addObject:NSFilenamesPboardType]; [pasteboard declareTypes:[types allObjects] owner:owner]; @@ -1323,7 +1340,9 @@ gtk_drag_source_event_cb (GtkWidget *widget, break; } - if (gtk_drag_check_threshold (widget, site->x, site->y, + /* the target list can have been set to NULL: nothing to drag */ + if (site->target_list && + gtk_drag_check_threshold (widget, site->x, site->y, event->motion.x, event->motion.y)) { site->state = 0; @@ -1914,7 +1933,12 @@ gtk_drag_source_info_destroy (GtkDragSourceInfo *info) * info->context after it has been destroyed. */ pasteboard = [NSPasteboard pasteboardWithName: NSDragPboard]; - [pasteboard declareTypes: nil owner: nil]; + /* clearContents is there from 10.6 on; declareTypes with nil no longer + * builds with newer SDKs */ + if ([pasteboard respondsToSelector: @selector(clearContents)]) + [pasteboard performSelector: @selector(clearContents)]; + else + [pasteboard declareTypes: [NSArray array] owner: nil]; [pool release]; diff --git a/gtk/gtkdnd.c b/gtk/gtkdnd.c index ba8333d9d..27868c703 100644 --- a/gtk/gtkdnd.c +++ b/gtk/gtkdnd.c @@ -1274,7 +1274,7 @@ gtk_drag_dest_set (GtkWidget *widget, g_return_if_fail (GTK_IS_WIDGET (widget)); - site = g_new (GtkDragDestSite, 1); + site = g_new0 (GtkDragDestSite, 1); site->flags = flags; site->have_drag = FALSE; @@ -1314,7 +1314,7 @@ gtk_drag_dest_set_proxy (GtkWidget *widget, g_return_if_fail (GTK_IS_WIDGET (widget)); g_return_if_fail (!proxy_window || GDK_IS_WINDOW (proxy_window)); - site = g_new (GtkDragDestSite, 1); + site = g_new0 (GtkDragDestSite, 1); site->flags = 0; site->have_drag = FALSE; @@ -1980,7 +1980,7 @@ gtk_drag_get_dest_info (GdkDragContext *context, info = g_object_get_qdata (G_OBJECT (context), info_quark); if (!info && create) { - info = g_new (GtkDragDestInfo, 1); + info = g_new0 (GtkDragDestInfo, 1); info->widget = NULL; info->context = context; info->proxy_source = NULL; @@ -2962,7 +2962,7 @@ gtk_drag_get_icon (GtkDragSourceInfo *info, */ save_icon_window = info->icon_window; save_hot_x = info->hot_x; - save_hot_y = info->hot_x; + save_hot_y = info->hot_y; save_destroy_icon = info->destroy_icon; info->icon_window = NULL; @@ -3752,7 +3752,9 @@ gtk_drag_source_event_cb (GtkWidget *widget, break; } - if (gtk_drag_check_threshold (widget, site->x, site->y, + /* the target list can have been set to NULL: nothing to drag */ + if (site->target_list && + gtk_drag_check_threshold (widget, site->x, site->y, event->motion.x, event->motion.y)) { site->state = 0; @@ -3967,6 +3969,10 @@ gtk_drag_source_info_destroy (GtkDragSourceInfo *info) if (info->update_idle) g_source_remove (info->update_idle); + /* left over when the drag ends before the update idle ran */ + if (info->last_event) + gdk_event_free (info->last_event); + g_free (info); } diff --git a/gtk/gtkdrawingarea.h b/gtk/gtkdrawingarea.h index e667c65df..6c5b2da9a 100644 --- a/gtk/gtkdrawingarea.h +++ b/gtk/gtkdrawingarea.h @@ -67,7 +67,7 @@ struct _GtkDrawingAreaClass }; -GType gtk_drawing_area_get_type (void) G_GNUC_CONST; +GType gtk_drawing_area_get_type (void); GtkWidget* gtk_drawing_area_new (void); #ifndef GTK_DISABLE_DEPRECATED diff --git a/gtk/gtkeditable.h b/gtk/gtkeditable.h index 1f5ed3f8e..e1ff68b1b 100644 --- a/gtk/gtkeditable.h +++ b/gtk/gtkeditable.h @@ -84,7 +84,7 @@ struct _GtkEditableClass gint (* get_position) (GtkEditable *editable); }; -GType gtk_editable_get_type (void) G_GNUC_CONST; +GType gtk_editable_get_type (void); void gtk_editable_select_region (GtkEditable *editable, gint start_pos, gint end_pos); diff --git a/gtk/gtkemojichooser.c b/gtk/gtkemojichooser.c new file mode 100644 index 000000000..556b45bdb --- /dev/null +++ b/gtk/gtkemojichooser.c @@ -0,0 +1,692 @@ +/* GTK - The GIMP Toolkit + * gtkemojichooser.c: the emoji chooser of entries and text views + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +/* The emoji chooser of GTK+ 3.22, for every GtkEntry and GtkTextView + * (Ctrl+. or Ctrl+;, and "Insert Emoji" in their menus): a search + * field, one grid of all emoji, drawn as text and only where it is + * exposed, buttons for the groups, and the recently used ones first. + * + * The data is GTK+ 3's (from emojibase and the Unicode CLDR): one file + * per language in $datadir/gtk-2.0/emoji, mapped only when the chooser + * is first opened. The recently used emoji are kept in + * $XDG_CONFIG_HOME/gtk-2.0/emoji-recent. */ + +#include "config.h" + +#include + +#include "gtkemojichooser.h" +#include "gtkentry.h" +#include "gtkwindow.h" +#include "gtkvbox.h" +#include "gtkhbox.h" +#include "gtkframe.h" +#include "gtkscrolledwindow.h" +#include "gtkdrawingarea.h" +#include "gtkbutton.h" +#include "gtklabel.h" +#include "gtkmain.h" +#include "gtkbindings.h" +#include "gtkintl.h" +#include "gtkprivate.h" +#include "gdk/gdkkeysyms.h" +#include "gtkalias.h" + +#define COLUMNS 8 +#define VISIBLE_ROWS 7 +#define MAX_RECENT 24 + +/* the groups of emojibase; 2 (skin tones and hair) is left out */ +static const struct { guint group; const gchar *icon; const gchar *name; } groups[] = { + { G_MAXUINT, "\xf0\x9f\x95\x93", N_("Recent") }, /* 🕓 */ + { 0, "\xf0\x9f\x98\x80", N_("Smileys & Emotion") }, /* 😀 */ + { 1, "\xf0\x9f\x91\x8b", N_("People & Body") }, /* 👋 */ + { 3, "\xf0\x9f\x8c\xb7", N_("Animals & Nature") }, /* 🌷 */ + { 4, "\xf0\x9f\x8d\x9c", N_("Food & Drink") }, /* 🍜 */ + { 5, "\xf0\x9f\x9a\x97", N_("Travel & Places") }, /* 🚗 */ + { 6, "\xe2\x9a\xbd", N_("Activities") }, /* ⚽ */ + { 7, "\xf0\x9f\x92\xa1", N_("Objects") }, /* 💡 */ + { 8, "\xe2\x9d\xa4", N_("Symbols") }, /* ❤ */ + { 9, "\xf0\x9f\x8f\xb4", N_("Flags") }, /* 🏴 */ +}; + +typedef struct +{ + gchar *text; /* the emoji, UTF-8 */ + const gchar *name; /* in the data */ + gchar *search; /* name and keywords, casefolded */ + guint group; +} Emoji; + +static GVariant *data; +static Emoji *emoji; +static guint n_emoji; +static gboolean loaded; + +typedef struct +{ + GtkWidget *window; + GtkWidget *entry; + GtkWidget *scrolled; + GtkWidget *grid; + GtkWidget *for_widget; + GtkEmojiChooserCallback callback; + gpointer callback_data; + + GArray *shown; /* indices into emoji[], -1 - n for recent n */ + GArray *recent; /* indices into emoji[] */ + gint selected; + gint cell; +} Chooser; + +static gboolean +load_file (const gchar *lang) +{ + gchar *name = g_strconcat (lang, ".data", NULL); + gchar *path = g_build_filename (GTK_DATADIR, "gtk-2.0", "emoji", name, NULL); + GMappedFile *file = g_mapped_file_new (path, FALSE, NULL); + + g_free (name); + g_free (path); + if (!file) + return FALSE; + + data = g_variant_new_from_data (G_VARIANT_TYPE ("a(ausasu)"), + g_mapped_file_get_contents (file), + g_mapped_file_get_length (file), + FALSE, + (GDestroyNotify) g_mapped_file_unref, file); + g_variant_ref_sink (data); + return TRUE; +} + +static void +load_emoji (void) +{ + const gchar * const *langs; + GVariantIter iter; + GVariant *item; + guint i; + + if (loaded) + return; + loaded = TRUE; + + /* "de_AT.UTF-8", "de_AT", "de", ...: the first there is a file of */ + for (langs = g_get_language_names (); *langs; langs++) + { + if (strchr (*langs, '.') || strchr (*langs, '@') || strcmp (*langs, "C") == 0) + continue; + if (load_file (*langs)) + break; + } + if (!data && !load_file ("en")) + return; + + emoji = g_new0 (Emoji, g_variant_n_children (data)); + g_variant_iter_init (&iter, data); + for (i = 0; (item = g_variant_iter_next_value (&iter)); g_variant_unref (item)) + { + GVariantIter *codes, *keywords; + const gchar *name, *keyword; + GString *text, *search; + guint32 code, group; + + g_variant_get (item, "(au&sasu)", &codes, &name, &keywords, &group); + if (group == 2) + { + g_variant_iter_free (codes); + g_variant_iter_free (keywords); + continue; + } + + text = g_string_new (NULL); + while (g_variant_iter_next (codes, "u", &code)) + if (code != 0) /* where a skin tone could go */ + g_string_append_unichar (text, code); + search = g_string_new (name); + while (g_variant_iter_next (keywords, "&s", &keyword)) + { + g_string_append_c (search, '\n'); + g_string_append (search, keyword); + } + g_variant_iter_free (codes); + g_variant_iter_free (keywords); + + emoji[i].text = g_string_free (text, FALSE); + emoji[i].name = name; + emoji[i].search = g_utf8_casefold (search->str, -1); + emoji[i].group = group; + g_string_free (search, TRUE); + i++; + } + n_emoji = i; +} + +gboolean +_gtk_emoji_chooser_available (void) +{ + load_emoji (); + return n_emoji > 0; +} + +/* the recently used ones, a line each */ +static gchar * +recent_path (void) +{ + return g_build_filename (g_get_user_config_dir (), "gtk-2.0", "emoji-recent", NULL); +} + +static void +load_recent (Chooser *chooser) +{ + gchar *path = recent_path (), *contents; + gchar **lines; + guint i, j; + + if (g_file_get_contents (path, &contents, NULL, NULL)) + { + lines = g_strsplit (contents, "\n", MAX_RECENT + 1); + for (i = 0; lines[i] && chooser->recent->len < MAX_RECENT; i++) + for (j = 0; j < n_emoji; j++) + if (lines[i][0] && strcmp (lines[i], emoji[j].text) == 0) + { + gint k = j; + g_array_append_val (chooser->recent, k); + break; + } + g_strfreev (lines); + g_free (contents); + } + g_free (path); +} + +static void +save_recent (Chooser *chooser) +{ + gchar *path = recent_path (), *dir = g_path_get_dirname (path); + GString *s = g_string_new (NULL); + guint i; + + for (i = 0; i < chooser->recent->len; i++) + { + g_string_append (s, emoji[g_array_index (chooser->recent, gint, i)].text); + g_string_append_c (s, '\n'); + } + g_mkdir_with_parents (dir, 0700); + g_file_set_contents (path, s->str, s->len, NULL); + g_string_free (s, TRUE); + g_free (dir); + g_free (path); +} + +static void +add_recent (Chooser *chooser, + gint index) +{ + guint i; + + for (i = 0; i < chooser->recent->len; i++) + if (g_array_index (chooser->recent, gint, i) == index) + { + g_array_remove_index (chooser->recent, i); + break; + } + g_array_prepend_val (chooser->recent, index); + if (chooser->recent->len > MAX_RECENT) + g_array_set_size (chooser->recent, MAX_RECENT); + save_recent (chooser); +} + +/* what the grid shows: the search results, or the recent ones and all */ +static void +update_shown (Chooser *chooser) +{ + const gchar *text = gtk_entry_get_text (GTK_ENTRY (chooser->entry)); + gchar *key = text[0] ? g_utf8_casefold (text, -1) : NULL; + gint i, rows; + + g_array_set_size (chooser->shown, 0); + if (key == NULL) + for (i = 0; i < (gint) chooser->recent->len; i++) + { + gint k = -1 - i; + g_array_append_val (chooser->shown, k); + } + for (i = 0; i < (gint) n_emoji; i++) + if (key == NULL || strstr (emoji[i].search, key)) + g_array_append_val (chooser->shown, i); + g_free (key); + + chooser->selected = chooser->shown->len > 0 ? 0 : -1; + rows = MAX (1, (chooser->shown->len + COLUMNS - 1) / COLUMNS); + gtk_widget_set_size_request (chooser->grid, COLUMNS * chooser->cell, rows * chooser->cell); + gtk_adjustment_set_value (gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (chooser->scrolled)), 0); + gtk_widget_queue_draw (chooser->grid); +} + +static Emoji * +shown_emoji (Chooser *chooser, + gint n) +{ + gint k; + + if (n < 0 || n >= (gint) chooser->shown->len) + return NULL; + k = g_array_index (chooser->shown, gint, n); + if (k < 0) + k = g_array_index (chooser->recent, gint, -1 - k); + return &emoji[k]; +} + +static void +close_chooser (Chooser *chooser) +{ + gtk_widget_destroy (chooser->window); +} + +static void +choose (Chooser *chooser, + gint n) +{ + Emoji *e = shown_emoji (chooser, n); + GtkEmojiChooserCallback callback = chooser->callback; + gpointer callback_data = chooser->callback_data; + GtkWidget *for_widget = chooser->for_widget; + gchar *text; + + if (e == NULL) + return; + text = g_strdup (e->text); + add_recent (chooser, e - emoji); + g_object_ref (for_widget); + close_chooser (chooser); + callback (text, callback_data); + g_object_unref (for_widget); + g_free (text); +} + +static void +scroll_to_selected (Chooser *chooser) +{ + GtkAdjustment *adj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (chooser->scrolled)); + gdouble top = (chooser->selected / COLUMNS) * chooser->cell; + + if (top < adj->value) + gtk_adjustment_set_value (adj, top); + else if (top + chooser->cell > adj->value + adj->page_size) + gtk_adjustment_set_value (adj, top + chooser->cell - adj->page_size); +} + +static void +cell_rect (Chooser *chooser, + gint n, + GdkRectangle *rect) +{ + rect->x = (n % COLUMNS) * chooser->cell; + rect->y = (n / COLUMNS) * chooser->cell; + rect->width = rect->height = chooser->cell; +} + +static void +select_cell (Chooser *chooser, + gint n) +{ + GdkRectangle rect; + + if (n == chooser->selected || n < 0 || n >= (gint) chooser->shown->len) + return; + if (chooser->selected >= 0 && chooser->grid->window) + { + cell_rect (chooser, chooser->selected, &rect); + gdk_window_invalidate_rect (chooser->grid->window, &rect, FALSE); + } + chooser->selected = n; + if (chooser->grid->window) + { + cell_rect (chooser, n, &rect); + gdk_window_invalidate_rect (chooser->grid->window, &rect, FALSE); + gtk_widget_set_tooltip_text (chooser->grid, shown_emoji (chooser, n)->name); + } +} + +static gboolean +grid_expose (GtkWidget *widget, + GdkEventExpose *event, + Chooser *chooser) +{ + PangoLayout *layout = gtk_widget_create_pango_layout (widget, NULL); + PangoFontDescription *font = pango_font_description_copy (widget->style->font_desc); + gint first, last, n; + cairo_t *cr = gdk_cairo_create (widget->window); + + /* the emoji somewhat larger than the text */ + pango_font_description_set_size (font, pango_font_description_get_size (font) * 3 / 2); + pango_layout_set_font_description (layout, font); + pango_font_description_free (font); + + gdk_cairo_region (cr, event->region); + cairo_clip (cr); + + /* only the rows of the exposed area */ + first = (event->area.y / chooser->cell) * COLUMNS; + last = ((event->area.y + event->area.height) / chooser->cell + 1) * COLUMNS; + for (n = first; n < last && n < (gint) chooser->shown->len; n++) + { + GdkRectangle rect; + PangoRectangle ink; + + cell_rect (chooser, n, &rect); + if (n == chooser->selected) + gtk_paint_flat_box (widget->style, widget->window, GTK_STATE_SELECTED, GTK_SHADOW_NONE, + &event->area, widget, "cell_even", rect.x, rect.y, rect.width, rect.height); + + pango_layout_set_text (layout, shown_emoji (chooser, n)->text, -1); + pango_layout_get_pixel_extents (layout, NULL, &ink); + gdk_cairo_set_source_color (cr, &widget->style->text[n == chooser->selected ? GTK_STATE_SELECTED : GTK_STATE_NORMAL]); + cairo_move_to (cr, rect.x + (rect.width - ink.width) / 2, rect.y + (rect.height - ink.height) / 2); + pango_cairo_show_layout (cr, layout); + } + + cairo_destroy (cr); + g_object_unref (layout); + return TRUE; +} + +static gint +cell_at (Chooser *chooser, + gdouble x, + gdouble y) +{ + gint col = (gint) x / chooser->cell, n = ((gint) y / chooser->cell) * COLUMNS + col; + + if (x < 0 || y < 0 || col >= COLUMNS || n >= (gint) chooser->shown->len) + return -1; + return n; +} + +static gboolean +grid_motion (GtkWidget *widget, + GdkEventMotion *event, + Chooser *chooser) +{ + select_cell (chooser, cell_at (chooser, event->x, event->y)); + return TRUE; +} + +static gboolean +grid_release (GtkWidget *widget, + GdkEventButton *event, + Chooser *chooser) +{ + gint n = cell_at (chooser, event->x, event->y); + + if (event->button == 1 && n >= 0) + choose (chooser, n); + return TRUE; +} + +static gboolean +entry_key_press (GtkWidget *widget, + GdkEventKey *event, + Chooser *chooser) +{ + gint n = chooser->selected; + + switch (event->keyval) + { + case GDK_Escape: + close_chooser (chooser); + return TRUE; + case GDK_Return: + case GDK_KP_Enter: + case GDK_ISO_Enter: + choose (chooser, chooser->selected); + return TRUE; + case GDK_Left: + case GDK_KP_Left: + n--; + break; + case GDK_Right: + case GDK_KP_Right: + n++; + break; + case GDK_Up: + case GDK_KP_Up: + n -= COLUMNS; + break; + case GDK_Down: + case GDK_KP_Down: + n += COLUMNS; + break; + case GDK_Page_Up: + n -= COLUMNS * VISIBLE_ROWS; + break; + case GDK_Page_Down: + n += COLUMNS * VISIBLE_ROWS; + break; + default: + return FALSE; + } + + n = CLAMP (n, 0, (gint) chooser->shown->len - 1); + select_cell (chooser, n); + scroll_to_selected (chooser); + return TRUE; +} + +static void +group_clicked (GtkButton *button, + Chooser *chooser) +{ + guint group = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (button), "group")); + guint i; + + if (gtk_entry_get_text (GTK_ENTRY (chooser->entry))[0]) + gtk_entry_set_text (GTK_ENTRY (chooser->entry), ""); + for (i = 0; i < chooser->shown->len; i++) + if ((group == G_MAXUINT && g_array_index (chooser->shown, gint, i) < 0) || + (group != G_MAXUINT && g_array_index (chooser->shown, gint, i) >= 0 && + emoji[g_array_index (chooser->shown, gint, i)].group == group)) + { + GtkAdjustment *adj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (chooser->scrolled)); + + select_cell (chooser, i); + gtk_adjustment_set_value (adj, MIN ((i / COLUMNS) * chooser->cell, adj->upper - adj->page_size)); + break; + } + gtk_widget_grab_focus (chooser->entry); +} + +/* a click outside closes it, as with menus */ +static gboolean +window_button_press (GtkWidget *widget, + GdkEventButton *event, + Chooser *chooser) +{ + gint x, y; + + gdk_window_get_origin (widget->window, &x, &y); + if (event->x_root < x || event->y_root < y || + event->x_root >= x + widget->allocation.width || + event->y_root >= y + widget->allocation.height) + { + close_chooser (chooser); + return TRUE; + } + return FALSE; +} + +static gboolean +window_grab_broken (GtkWidget *widget, + GdkEvent *event, + Chooser *chooser) +{ + close_chooser (chooser); + return TRUE; +} + +static void +window_destroyed (GtkWidget *widget, + Chooser *chooser) +{ + GdkDisplay *display = gtk_widget_get_display (widget); + + gdk_display_pointer_ungrab (display, GDK_CURRENT_TIME); + gdk_display_keyboard_ungrab (display, GDK_CURRENT_TIME); + gtk_grab_remove (widget); + g_signal_handlers_disconnect_by_func (chooser->for_widget, close_chooser, chooser); + g_array_free (chooser->shown, TRUE); + g_array_free (chooser->recent, TRUE); + g_free (chooser); +} + +static void +take_grabs (GtkWidget *window) +{ + gdk_pointer_grab (window->window, TRUE, + GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | + GDK_POINTER_MOTION_MASK | GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK, + NULL, NULL, GDK_CURRENT_TIME); + gdk_keyboard_grab (window->window, TRUE, GDK_CURRENT_TIME); + gtk_grab_add (window); +} + +/** + * _gtk_emoji_chooser_popup: + * @for_widget: the entry or text view + * @rect: where the cursor is, in the coordinates of @for_widget's window + * @callback: called with the emoji chosen + * @data: for @callback + * + * Shows the emoji chooser below @rect. + */ +void +_gtk_emoji_chooser_popup (GtkWidget *for_widget, + const GdkRectangle *rect, + GtkEmojiChooserCallback callback, + gpointer callback_data) +{ + Chooser *chooser; + GtkWidget *frame, *vbox, *hbox; + GtkRequisition req; + GdkScreen *screen; + GdkRectangle monitor; + PangoContext *context; + PangoFontMetrics *metrics; + gint x, y, font_px; + guint i; + + if (!_gtk_emoji_chooser_available () || !gtk_widget_get_realized (for_widget)) + return; + + chooser = g_new0 (Chooser, 1); + chooser->for_widget = for_widget; + chooser->callback = callback; + chooser->callback_data = callback_data; + chooser->shown = g_array_new (FALSE, FALSE, sizeof (gint)); + chooser->recent = g_array_new (FALSE, FALSE, sizeof (gint)); + load_recent (chooser); + + chooser->window = gtk_window_new (GTK_WINDOW_POPUP); + screen = gtk_widget_get_screen (for_widget); + gtk_window_set_screen (GTK_WINDOW (chooser->window), screen); + gtk_window_set_type_hint (GTK_WINDOW (chooser->window), GDK_WINDOW_TYPE_HINT_POPUP_MENU); + if (GTK_IS_WINDOW (gtk_widget_get_toplevel (for_widget))) + gtk_window_set_transient_for (GTK_WINDOW (chooser->window), + GTK_WINDOW (gtk_widget_get_toplevel (for_widget))); + + frame = gtk_frame_new (NULL); + gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_OUT); + gtk_container_add (GTK_CONTAINER (chooser->window), frame); + vbox = gtk_vbox_new (FALSE, 4); + gtk_container_set_border_width (GTK_CONTAINER (vbox), 4); + gtk_container_add (GTK_CONTAINER (frame), vbox); + + chooser->entry = gtk_entry_new (); + gtk_entry_set_placeholder_text (GTK_ENTRY (chooser->entry), _("Search")); + gtk_entry_set_input_hints (GTK_ENTRY (chooser->entry), GTK_INPUT_HINT_NO_EMOJI); + gtk_box_pack_start (GTK_BOX (vbox), chooser->entry, FALSE, FALSE, 0); + + /* a cell: twice the height of the text */ + context = gtk_widget_get_pango_context (for_widget); + metrics = pango_context_get_metrics (context, for_widget->style->font_desc, NULL); + font_px = PANGO_PIXELS (pango_font_metrics_get_ascent (metrics) + pango_font_metrics_get_descent (metrics)); + pango_font_metrics_unref (metrics); + chooser->cell = MAX (16, font_px * 2); + + chooser->scrolled = gtk_scrolled_window_new (NULL, NULL); + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (chooser->scrolled), + GTK_POLICY_NEVER, GTK_POLICY_ALWAYS); + chooser->grid = gtk_drawing_area_new (); + gtk_widget_add_events (chooser->grid, GDK_POINTER_MOTION_MASK | GDK_BUTTON_PRESS_MASK | + GDK_BUTTON_RELEASE_MASK); + gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (chooser->scrolled), chooser->grid); + gtk_widget_set_size_request (chooser->scrolled, -1, VISIBLE_ROWS * chooser->cell); + gtk_box_pack_start (GTK_BOX (vbox), chooser->scrolled, TRUE, TRUE, 0); + + hbox = gtk_hbox_new (TRUE, 0); + for (i = 0; i < G_N_ELEMENTS (groups); i++) + { + GtkWidget *button = gtk_button_new_with_label (groups[i].icon); + + gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE); + gtk_button_set_focus_on_click (GTK_BUTTON (button), FALSE); + gtk_widget_set_tooltip_text (button, _(groups[i].name)); + g_object_set_data (G_OBJECT (button), "group", GUINT_TO_POINTER (groups[i].group)); + g_signal_connect (button, "clicked", G_CALLBACK (group_clicked), chooser); + gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0); + } + gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0); + + update_shown (chooser); + + g_signal_connect (chooser->grid, "expose-event", G_CALLBACK (grid_expose), chooser); + g_signal_connect (chooser->grid, "motion-notify-event", G_CALLBACK (grid_motion), chooser); + g_signal_connect (chooser->grid, "button-release-event", G_CALLBACK (grid_release), chooser); + g_signal_connect_swapped (chooser->entry, "changed", G_CALLBACK (update_shown), chooser); + g_signal_connect (chooser->entry, "key-press-event", G_CALLBACK (entry_key_press), chooser); + g_signal_connect (chooser->window, "button-press-event", G_CALLBACK (window_button_press), chooser); + g_signal_connect (chooser->window, "grab-broken-event", G_CALLBACK (window_grab_broken), chooser); + g_signal_connect (chooser->window, "destroy", G_CALLBACK (window_destroyed), chooser); + g_signal_connect_swapped (for_widget, "unmap", G_CALLBACK (close_chooser), chooser); + gtk_widget_add_events (chooser->window, GDK_BUTTON_PRESS_MASK); + + /* below the cursor, on the monitor */ + gtk_widget_show_all (vbox); + gtk_widget_show (frame); + gtk_widget_size_request (chooser->window, &req); + gdk_window_get_origin (for_widget->window, &x, &y); + x += rect->x; + y += rect->y + rect->height; + gdk_screen_get_monitor_geometry (screen, + gdk_screen_get_monitor_at_point (screen, x, y), + &monitor); + if (y + req.height > monitor.y + monitor.height) + y = MAX (monitor.y, y - rect->height - req.height); + x = CLAMP (x, monitor.x, MAX (monitor.x, monitor.x + monitor.width - req.width)); + gtk_window_move (GTK_WINDOW (chooser->window), x, y); + + gtk_widget_show (chooser->window); + gtk_widget_grab_focus (chooser->entry); + take_grabs (chooser->window); +} + +#define __GTK_EMOJI_CHOOSER_C__ +#include "gtkaliasdef.c" diff --git a/gtk/gtkemojichooser.h b/gtk/gtkemojichooser.h new file mode 100644 index 000000000..eee842710 --- /dev/null +++ b/gtk/gtkemojichooser.h @@ -0,0 +1,38 @@ +/* GTK - The GIMP Toolkit + * gtkemojichooser.h: the emoji chooser of entries and text views + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef __GTK_EMOJI_CHOOSER_H__ +#define __GTK_EMOJI_CHOOSER_H__ + +#include + +G_BEGIN_DECLS + +typedef void (*GtkEmojiChooserCallback) (const gchar *text, + gpointer data); + +gboolean _gtk_emoji_chooser_available (void); +void _gtk_emoji_chooser_popup (GtkWidget *for_widget, + const GdkRectangle *rect, + GtkEmojiChooserCallback callback, + gpointer data); + +G_END_DECLS + +#endif /* __GTK_EMOJI_CHOOSER_H__ */ diff --git a/gtk/gtkentry.c b/gtk/gtkentry.c index 2a021df58..eea4b4d9a 100644 --- a/gtk/gtkentry.c +++ b/gtk/gtkentry.c @@ -66,6 +66,7 @@ #include "gtktooltip.h" #include "gtkiconfactory.h" #include "gtkicontheme.h" +#include "gtkemojichooser.h" #include "gtkalias.h" #define GTK_ENTRY_COMPLETION_KEY "gtk-entry-completion-key" @@ -140,6 +141,8 @@ struct _GtkEntryPrivate gint start_y; gchar *im_module; + + gchar *placeholder_text; }; typedef struct _GtkEntryPasswordHint GtkEntryPasswordHint; @@ -173,6 +176,7 @@ enum { ICON_PRESS, ICON_RELEASE, PREEDIT_CHANGED, + INSERT_EMOJI, LAST_SIGNAL }; @@ -219,7 +223,10 @@ enum { PROP_TOOLTIP_MARKUP_PRIMARY, PROP_TOOLTIP_MARKUP_SECONDARY, PROP_IM_MODULE, - PROP_EDITING_CANCELED + PROP_EDITING_CANCELED, + PROP_PLACEHOLDER_TEXT, + PROP_INPUT_PURPOSE, + PROP_INPUT_HINTS }; static guint signals[LAST_SIGNAL] = { 0 }; @@ -385,6 +392,8 @@ static void gtk_entry_copy_clipboard (GtkEntry *entry); static void gtk_entry_paste_clipboard (GtkEntry *entry); static void gtk_entry_toggle_overwrite (GtkEntry *entry); static void gtk_entry_select_all (GtkEntry *entry); +static void gtk_entry_insert_emoji (GtkEntry *entry); +static gboolean gtk_entry_emoji_allowed (GtkEntry *entry); static void gtk_entry_real_activate (GtkEntry *entry); static gboolean gtk_entry_popup_menu (GtkWidget *widget); @@ -1059,7 +1068,7 @@ gtk_entry_class_init (GtkEntryClass *class) g_param_spec_boolean ("primary-icon-activatable", P_("Primary icon activatable"), P_("Whether the primary icon is activatable"), - FALSE, + TRUE, GTK_PARAM_READWRITE)); /** @@ -1080,7 +1089,7 @@ gtk_entry_class_init (GtkEntryClass *class) g_param_spec_boolean ("secondary-icon-activatable", P_("Secondary icon activatable"), P_("Whether the secondary icon is activatable"), - FALSE, + TRUE, GTK_PARAM_READWRITE)); @@ -1220,6 +1229,58 @@ gtk_entry_class_init (GtkEntryClass *class) NULL, GTK_PARAM_READWRITE)); + /** + * GtkEntry:placeholder-text: + * + * The text that will be displayed in the #GtkEntry when it is empty + * and unfocused, as in GTK+ 3.2. + * + * Since: 2.24 + */ + g_object_class_install_property (gobject_class, + PROP_PLACEHOLDER_TEXT, + g_param_spec_string ("placeholder-text", + P_("Placeholder text"), + P_("Show text in the entry when it's empty and unfocused"), + NULL, + GTK_PARAM_READWRITE)); + + /** + * GtkEntry:input-purpose: + * + * The purpose of this text field, as in GTK+ 3.6. It can be used by + * on-screen keyboards and other input methods to adjust their + * behaviour. Setting the visibility to %FALSE makes a free-form + * entry %GTK_INPUT_PURPOSE_PASSWORD. + * + * Since: 2.24 + */ + g_object_class_install_property (gobject_class, + PROP_INPUT_PURPOSE, + g_param_spec_enum ("input-purpose", + P_("Purpose"), + P_("Purpose of the text field"), + GTK_TYPE_INPUT_PURPOSE, + GTK_INPUT_PURPOSE_FREE_FORM, + GTK_PARAM_READWRITE)); + + /** + * GtkEntry:input-hints: + * + * Additional hints (beyond #GtkEntry:input-purpose) that allow + * input methods to fine-tune their behaviour, as in GTK+ 3.6. + * + * Since: 2.24 + */ + g_object_class_install_property (gobject_class, + PROP_INPUT_HINTS, + g_param_spec_flags ("input-hints", + P_("hints"), + P_("Hints for the text field behaviour"), + GTK_TYPE_INPUT_HINTS, + GTK_INPUT_HINT_NONE, + GTK_PARAM_READWRITE)); + /** * GtkEntry:icon-prelight: * @@ -1721,6 +1782,36 @@ gtk_entry_class_init (GtkEntryClass *class) gtk_binding_entry_add_signal (binding_set, GDK_Insert, GDK_SHIFT_MASK, "paste-clipboard", 0); + gtk_binding_entry_add_signal (binding_set, GDK_KP_Delete, GDK_SHIFT_MASK, + "cut-clipboard", 0); + gtk_binding_entry_add_signal (binding_set, GDK_KP_Insert, GDK_CONTROL_MASK, + "copy-clipboard", 0); + gtk_binding_entry_add_signal (binding_set, GDK_KP_Insert, GDK_SHIFT_MASK, + "paste-clipboard", 0); + + /** + * GtkEntry::insert-emoji: + * @entry: the object which received the signal + * + * A keybinding signal which opens the emoji chooser, as in GTK+ 3.22. + * The default bindings are Ctrl-. and Ctrl-; + * + * Since: 2.24 + */ + signals[INSERT_EMOJI] = + g_signal_new_class_handler (I_("insert-emoji"), + G_OBJECT_CLASS_TYPE (gobject_class), + G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, + G_CALLBACK (gtk_entry_insert_emoji), + NULL, NULL, + _gtk_marshal_VOID__VOID, + G_TYPE_NONE, 0); + + gtk_binding_entry_add_signal (binding_set, GDK_period, GDK_CONTROL_MASK, + "insert-emoji", 0); + gtk_binding_entry_add_signal (binding_set, GDK_semicolon, GDK_CONTROL_MASK, + "insert-emoji", 0); + /* Overwrite */ gtk_binding_entry_add_signal (binding_set, GDK_Insert, 0, "toggle-overwrite", 0); @@ -1992,6 +2083,18 @@ gtk_entry_set_property (GObject *object, gtk_im_multicontext_set_context_id (GTK_IM_MULTICONTEXT (entry->im_context), priv->im_module); break; + case PROP_PLACEHOLDER_TEXT: + gtk_entry_set_placeholder_text (entry, g_value_get_string (value)); + break; + + case PROP_INPUT_PURPOSE: + gtk_entry_set_input_purpose (entry, g_value_get_enum (value)); + break; + + case PROP_INPUT_HINTS: + gtk_entry_set_input_hints (entry, g_value_get_flags (value)); + break; + case PROP_EDITING_CANCELED: entry->editing_canceled = g_value_get_boolean (value); break; @@ -2095,6 +2198,18 @@ gtk_entry_get_property (GObject *object, g_value_set_string (value, priv->im_module); break; + case PROP_PLACEHOLDER_TEXT: + g_value_set_string (value, priv->placeholder_text); + break; + + case PROP_INPUT_PURPOSE: + g_value_set_enum (value, gtk_entry_get_input_purpose (entry)); + break; + + case PROP_INPUT_HINTS: + g_value_set_flags (value, gtk_entry_get_input_hints (entry)); + break; + case PROP_CAPS_LOCK_WARNING: g_value_set_boolean (value, priv->caps_lock_warning); break; @@ -2218,12 +2333,20 @@ gtk_entry_get_property (GObject *object, } } +typedef struct +{ + gunichar wanted; /* the invisible-char style property */ + PangoFontMap *font_map; /* not a reference: only compared */ + gunichar found; +} InvisibleCharFound; + +static gunichar find_invisible_char_in_font (GtkWidget *widget, + gunichar *invisible_chars, + gint n_chars); + static gunichar find_invisible_char (GtkWidget *widget) { - PangoLayout *layout; - PangoAttrList *attr_list; - gint i; gunichar invisible_chars [] = { 0, 0x25cf, /* BLACK CIRCLE */ @@ -2232,11 +2355,57 @@ find_invisible_char (GtkWidget *widget) 0x273a /* SIXTEEN POINTED ASTERISK */ }; + static GQuark quark_found; + InvisibleCharFound *found = NULL; + PangoFontMap *font_map; + gunichar result; + if (widget->style) gtk_widget_style_get (widget, "invisible-char", &invisible_chars[0], NULL); + /* Which of the characters the font has depends on the style, which + * many entries share, and the font map; finding out takes laying + * them out, at the start of each entry and at every new style */ + font_map = pango_context_get_font_map (gtk_widget_get_pango_context (widget)); + if (widget->style) + { + if (!quark_found) + quark_found = g_quark_from_static_string ("gtk-entry-invisible-char-found"); + found = g_object_get_qdata (G_OBJECT (widget->style), quark_found); + if (found && + found->wanted == invisible_chars[0] && + found->font_map == font_map) + return found->found; + } + + result = find_invisible_char_in_font (widget, invisible_chars, G_N_ELEMENTS (invisible_chars)); + + if (widget->style) + { + if (!found) + { + found = g_new (InvisibleCharFound, 1); + g_object_set_qdata_full (G_OBJECT (widget->style), quark_found, found, g_free); + } + found->wanted = invisible_chars[0]; + found->font_map = font_map; + found->found = result; + } + + return result; +} + +static gunichar +find_invisible_char_in_font (GtkWidget *widget, + gunichar *invisible_chars, + gint n_chars) +{ + PangoLayout *layout; + PangoAttrList *attr_list; + gint i; + layout = gtk_widget_create_pango_layout (widget, NULL); attr_list = pango_attr_list_new (); @@ -2245,7 +2414,7 @@ find_invisible_char (GtkWidget *widget) pango_layout_set_attributes (layout, attr_list); pango_attr_list_unref (attr_list); - for (i = (invisible_chars[0] != 0 ? 0 : 1); i < G_N_ELEMENTS (invisible_chars); i++) + for (i = (invisible_chars[0] != 0 ? 0 : 1); i < n_chars; i++) { gchar text[7] = { 0, }; gint len, count; @@ -2503,6 +2672,7 @@ gtk_entry_finalize (GObject *object) g_source_remove (entry->recompute_idle); g_free (priv->im_module); + g_free (priv->placeholder_text); G_OBJECT_CLASS (gtk_entry_parent_class)->finalize (object); } @@ -2540,7 +2710,7 @@ gtk_entry_get_display_text (GtkEntry *entry, text = gtk_entry_buffer_get_text (get_buffer (entry)); length = gtk_entry_buffer_get_length (get_buffer (entry)); - if (end_pos < 0) + if (end_pos < 0 || end_pos > length) end_pos = length; if (start_pos > length) start_pos = length; @@ -4130,6 +4300,8 @@ gtk_entry_focus_in (GtkWidget *widget, GdkKeymap *keymap; gtk_widget_queue_draw (widget); + if (GTK_ENTRY_GET_PRIVATE (entry)->placeholder_text) + gtk_entry_reset_layout (entry); keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget)); @@ -4160,6 +4332,8 @@ gtk_entry_focus_out (GtkWidget *widget, GdkKeymap *keymap; gtk_widget_queue_draw (widget); + if (GTK_ENTRY_GET_PRIVATE (entry)->placeholder_text) + gtk_entry_reset_layout (entry); keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget)); @@ -5380,6 +5554,18 @@ gtk_entry_recompute (GtkEntry *entry) } } +/* As in GTK+ 3: the placeholder stands where there is no text and no focus */ +static gboolean +show_placeholder_text (GtkEntry *entry) +{ + GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry); + + return (priv->placeholder_text != NULL && + !gtk_widget_has_focus (GTK_WIDGET (entry)) && + gtk_entry_buffer_get_bytes (get_buffer (entry)) == 0 && + gtk_entry_get_display_mode (entry) != DISPLAY_BLANK); +} + static PangoLayout * gtk_entry_create_layout (GtkEntry *entry, gboolean include_preedit) @@ -5397,6 +5583,33 @@ gtk_entry_create_layout (GtkEntry *entry, pango_layout_set_single_paragraph_mode (layout, TRUE); + if (show_placeholder_text (entry)) + { + GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry); + GdkColor *color = &widget->style->text[GTK_STATE_INSENSITIVE]; + PangoAttribute *attr; + gint area_width; + + /* in the color of insensitive text, cut off with an ellipsis */ + pango_layout_set_text (layout, priv->placeholder_text, -1); + attr = pango_attr_foreground_new (color->red, color->green, color->blue); + attr->start_index = 0; + attr->end_index = G_MAXINT; + pango_attr_list_insert (tmp_attrs, attr); + pango_layout_set_attributes (layout, tmp_attrs); + pango_attr_list_unref (tmp_attrs); + gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, NULL); + if (area_width > 1) + { + GtkBorder inner_border; + + _gtk_entry_effective_inner_border (entry, &inner_border); + pango_layout_set_width (layout, PANGO_SCALE * MAX (1, area_width - inner_border.left - inner_border.right)); + pango_layout_set_ellipsize (layout, PANGO_ELLIPSIZE_END); + } + return layout; + } + display = gtk_entry_get_display_text (entry, 0, -1); n_bytes = strlen (display); @@ -6431,9 +6644,8 @@ gtk_entry_update_primary_selection (GtkEntry *entry) if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end)) { - if (!gtk_clipboard_set_with_owner (clipboard, targets, n_targets, - primary_get_cb, primary_clear_cb, G_OBJECT (entry))) - primary_clear_cb (clipboard, entry); + gtk_clipboard_set_with_owner (clipboard, targets, n_targets, + primary_get_cb, primary_clear_cb, G_OBJECT (entry)); } else { @@ -6445,9 +6657,13 @@ gtk_entry_update_primary_selection (GtkEntry *entry) gtk_target_list_unref (list); } +/* With @hide_window FALSE (another icon is set right away), the icon + * window stays: hiding it would break the grab of a button press on + * the icon, and the release (::icon-release) would be lost. */ static void gtk_entry_clear (GtkEntry *entry, - GtkEntryIconPosition icon_pos) + GtkEntryIconPosition icon_pos, + gboolean hide_window) { GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry); EntryIconInfo *icon_info = priv->icons[icon_pos]; @@ -6460,7 +6676,7 @@ gtk_entry_clear (GtkEntry *entry, /* Explicitly check, as the pointer may become invalidated * during destruction. */ - if (GDK_IS_WINDOW (icon_info->window)) + if (hide_window && GDK_IS_WINDOW (icon_info->window)) gdk_window_hide (icon_info->window); if (icon_info->pixbuf) @@ -6734,6 +6950,7 @@ gtk_entry_set_buffer (GtkEntry *entry, { GtkEntryPrivate *priv; GObject *obj; + gboolean had_buffer = FALSE; g_return_if_fail (GTK_IS_ENTRY (entry)); priv = GTK_ENTRY_GET_PRIVATE (entry); @@ -6746,6 +6963,7 @@ gtk_entry_set_buffer (GtkEntry *entry, if (priv->buffer) { + had_buffer = TRUE; buffer_disconnect_signals (entry); g_object_unref (priv->buffer); @@ -6778,8 +6996,11 @@ gtk_entry_set_buffer (GtkEntry *entry, g_object_notify (obj, "invisible-char-set"); g_object_thaw_notify (obj); - gtk_editable_set_position (GTK_EDITABLE (entry), 0); - gtk_entry_recompute (entry); + if (had_buffer) + { + gtk_editable_set_position (GTK_EDITABLE (entry), 0); + gtk_entry_recompute (entry); + } } /** @@ -6941,8 +7162,16 @@ gtk_entry_set_visibility (GtkEntry *entry, if (entry->visible != visible) { + GtkInputPurpose purpose = gtk_entry_get_input_purpose (entry); + entry->visible = visible; + /* input methods and on-screen keyboards learn of it */ + if (!visible && purpose == GTK_INPUT_PURPOSE_FREE_FORM) + gtk_entry_set_input_purpose (entry, GTK_INPUT_PURPOSE_PASSWORD); + else if (visible && purpose == GTK_INPUT_PURPOSE_PASSWORD) + gtk_entry_set_input_purpose (entry, GTK_INPUT_PURPOSE_FREE_FORM); + g_object_notify (G_OBJECT (entry), "visibility"); gtk_entry_recompute (entry); } @@ -7652,7 +7881,7 @@ gtk_entry_set_icon_from_pixbuf (GtkEntry *entry, if (pixbuf) g_object_ref (pixbuf); - gtk_entry_clear (entry, icon_pos); + gtk_entry_clear (entry, icon_pos, pixbuf == NULL); if (pixbuf) { @@ -7719,7 +7948,7 @@ gtk_entry_set_icon_from_stock (GtkEntry *entry, /* need to dup before clearing */ new_id = g_strdup (stock_id); - gtk_entry_clear (entry, icon_pos); + gtk_entry_clear (entry, icon_pos, new_id == NULL); if (new_id != NULL) { @@ -7789,7 +8018,7 @@ gtk_entry_set_icon_from_icon_name (GtkEntry *entry, /* need to dup before clearing */ new_name = g_strdup (icon_name); - gtk_entry_clear (entry, icon_pos); + gtk_entry_clear (entry, icon_pos, new_name == NULL); if (new_name != NULL) { @@ -7856,7 +8085,7 @@ gtk_entry_set_icon_from_gicon (GtkEntry *entry, if (icon) g_object_ref (icon); - gtk_entry_clear (entry, icon_pos); + gtk_entry_clear (entry, icon_pos, icon == NULL); if (icon) { @@ -7950,7 +8179,7 @@ gtk_entry_get_icon_activatable (GtkEntry *entry, priv = GTK_ENTRY_GET_PRIVATE (entry); icon_info = priv->icons[icon_pos]; - return (icon_info != NULL && !icon_info->nonactivatable); + return (!icon_info || !icon_info->nonactivatable); } /** @@ -8552,6 +8781,9 @@ gtk_entry_set_icon_tooltip_markup (GtkEntry *entry, icon_info->tooltip = g_strdup (tooltip); ensure_has_tooltip (entry); + + g_object_notify (G_OBJECT (entry), + icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-tooltip-markup" : "secondary-icon-tooltip-markup"); } static gboolean @@ -8754,11 +8986,21 @@ popup_targets_received (GtkClipboard *clipboard, gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem); menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_SELECT_ALL, NULL); + gtk_widget_set_sensitive (menuitem, gtk_entry_get_text_length (entry) > 0); g_signal_connect_swapped (menuitem, "activate", G_CALLBACK (gtk_entry_select_all), entry); gtk_widget_show (menuitem); gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem); + if (gtk_entry_emoji_allowed (entry)) + { + menuitem = gtk_menu_item_new_with_mnemonic (_("Insert _Emoji")); + g_signal_connect_swapped (menuitem, "activate", + G_CALLBACK (gtk_entry_insert_emoji), entry); + gtk_widget_show (menuitem); + gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem); + } + g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)), "gtk-show-input-method-menu", &show_input_method_menu, "gtk-show-unicode-menu", &show_unicode_menu, @@ -10166,5 +10408,199 @@ keymap_state_changed (GdkKeymap *keymap, remove_capslock_feedback (entry); } +/* The emoji chooser, as in GTK+ 3.22: where the text is editable and + * shown, and the program did not say no */ +static gboolean +gtk_entry_emoji_allowed (GtkEntry *entry) +{ + GtkInputPurpose purpose = gtk_entry_get_input_purpose (entry); + + return (entry->editable && + gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL && + !(gtk_entry_get_input_hints (entry) & GTK_INPUT_HINT_NO_EMOJI) && + purpose != GTK_INPUT_PURPOSE_DIGITS && + purpose != GTK_INPUT_PURPOSE_NUMBER && + purpose != GTK_INPUT_PURPOSE_PHONE && + purpose != GTK_INPUT_PURPOSE_PIN && + _gtk_emoji_chooser_available ()); +} + +static void +gtk_entry_emoji_chosen (const gchar *text, + gpointer data) +{ + GtkEntry *entry = data; + gint pos; + + if (!entry->editable) + return; + gtk_editable_delete_selection (GTK_EDITABLE (entry)); + pos = gtk_editable_get_position (GTK_EDITABLE (entry)); + gtk_editable_insert_text (GTK_EDITABLE (entry), text, -1, &pos); + gtk_editable_set_position (GTK_EDITABLE (entry), pos); +} + +static void +gtk_entry_insert_emoji (GtkEntry *entry) +{ + GdkRectangle rect; + gint strong_x, area_x, area_y, area_height; + GtkBorder inner_border; + + if (!gtk_entry_emoji_allowed (entry) || !gtk_widget_get_realized (GTK_WIDGET (entry))) + return; + + gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL); + _gtk_entry_effective_inner_border (entry, &inner_border); + gdk_window_get_position (entry->text_area, &area_x, &area_y); + area_height = gdk_window_get_height (entry->text_area); + + rect.x = area_x + inner_border.left + strong_x - entry->scroll_offset; + rect.y = area_y; + rect.width = 1; + rect.height = area_height; + + _gtk_emoji_chooser_popup (GTK_WIDGET (entry), &rect, gtk_entry_emoji_chosen, entry); +} + +/** + * gtk_entry_set_placeholder_text: + * @entry: a #GtkEntry + * @text: a string to be displayed when @entry is empty and unfocused, or %NULL + * + * Sets text to be displayed in @entry when it is empty and unfocused. + * This can be used to give a visual hint of the expected contents of + * the #GtkEntry, as in GTK+ 3.2. + * + * Since: 2.24 + **/ +void +gtk_entry_set_placeholder_text (GtkEntry *entry, + const gchar *text) +{ + GtkEntryPrivate *priv; + + g_return_if_fail (GTK_IS_ENTRY (entry)); + + priv = GTK_ENTRY_GET_PRIVATE (entry); + if (g_strcmp0 (priv->placeholder_text, text) == 0) + return; + + g_free (priv->placeholder_text); + priv->placeholder_text = g_strdup (text); + + gtk_entry_reset_layout (entry); + gtk_widget_queue_draw (GTK_WIDGET (entry)); + + g_object_notify (G_OBJECT (entry), "placeholder-text"); +} + +/** + * gtk_entry_get_placeholder_text: + * @entry: a #GtkEntry + * + * Retrieves the text that will be displayed when @entry is empty and unfocused + * + * Returns: a pointer to the placeholder text as a string. This string points + * to internally allocated storage in the widget and must not be freed, + * modified or stored. + * + * Since: 2.24 + **/ +const gchar * +gtk_entry_get_placeholder_text (GtkEntry *entry) +{ + g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL); + + return GTK_ENTRY_GET_PRIVATE (entry)->placeholder_text; +} + +/** + * gtk_entry_set_input_purpose: + * @entry: a #GtkEntry + * @purpose: the purpose + * + * Sets the #GtkEntry:input-purpose property which + * can be used by on-screen keyboards and other input + * methods to adjust their behaviour. + * + * Since: 2.24 + */ +void +gtk_entry_set_input_purpose (GtkEntry *entry, + GtkInputPurpose purpose) +{ + g_return_if_fail (GTK_IS_ENTRY (entry)); + + if (gtk_entry_get_input_purpose (entry) != purpose) + { + g_object_set (G_OBJECT (entry->im_context), "input-purpose", purpose, NULL); + g_object_notify (G_OBJECT (entry), "input-purpose"); + } +} + +/** + * gtk_entry_get_input_purpose: + * @entry: a #GtkEntry + * + * Gets the value of the #GtkEntry:input-purpose property. + * + * Since: 2.24 + */ +GtkInputPurpose +gtk_entry_get_input_purpose (GtkEntry *entry) +{ + GtkInputPurpose purpose; + + g_return_val_if_fail (GTK_IS_ENTRY (entry), GTK_INPUT_PURPOSE_FREE_FORM); + + g_object_get (G_OBJECT (entry->im_context), "input-purpose", &purpose, NULL); + + return purpose; +} + +/** + * gtk_entry_set_input_hints: + * @entry: a #GtkEntry + * @hints: the hints + * + * Sets the #GtkEntry:input-hints property, which + * allows input methods to fine-tune their behaviour. + * + * Since: 2.24 + */ +void +gtk_entry_set_input_hints (GtkEntry *entry, + GtkInputHints hints) +{ + g_return_if_fail (GTK_IS_ENTRY (entry)); + + if (gtk_entry_get_input_hints (entry) != hints) + { + g_object_set (G_OBJECT (entry->im_context), "input-hints", hints, NULL); + g_object_notify (G_OBJECT (entry), "input-hints"); + } +} + +/** + * gtk_entry_get_input_hints: + * @entry: a #GtkEntry + * + * Gets the value of the #GtkEntry:input-hints property. + * + * Since: 2.24 + */ +GtkInputHints +gtk_entry_get_input_hints (GtkEntry *entry) +{ + GtkInputHints hints; + + g_return_val_if_fail (GTK_IS_ENTRY (entry), GTK_INPUT_HINT_NONE); + + g_object_get (G_OBJECT (entry->im_context), "input-hints", &hints, NULL); + + return hints; +} + #define __GTK_ENTRY_C__ #include "gtkaliasdef.c" diff --git a/gtk/gtkentry.h b/gtk/gtkentry.h index 0fc2483c8..17471e45a 100644 --- a/gtk/gtkentry.h +++ b/gtk/gtkentry.h @@ -163,7 +163,7 @@ struct _GtkEntryClass void (*_gtk_reserved2) (void); }; -GType gtk_entry_get_type (void) G_GNUC_CONST; +GType gtk_entry_get_type (void); GtkWidget* gtk_entry_new (void); GtkWidget* gtk_entry_new_with_buffer (GtkEntryBuffer *buffer); @@ -310,6 +310,17 @@ gboolean gtk_entry_im_context_filter_keypress (GtkEntry * GdkEventKey *event); void gtk_entry_reset_im_context (GtkEntry *entry); +/* as in GTK+ 3.2 and 3.6 */ +void gtk_entry_set_placeholder_text (GtkEntry *entry, + const gchar *text); +const gchar * gtk_entry_get_placeholder_text (GtkEntry *entry); +void gtk_entry_set_input_purpose (GtkEntry *entry, + GtkInputPurpose purpose); +GtkInputPurpose gtk_entry_get_input_purpose (GtkEntry *entry); +void gtk_entry_set_input_hints (GtkEntry *entry, + GtkInputHints hints); +GtkInputHints gtk_entry_get_input_hints (GtkEntry *entry); + /* Deprecated compatibility functions */ diff --git a/gtk/gtkentrybuffer.c b/gtk/gtkentrybuffer.c index fc6216dfb..40c32c9c4 100644 --- a/gtk/gtkentrybuffer.c +++ b/gtk/gtkentrybuffer.c @@ -659,6 +659,9 @@ gtk_entry_buffer_insert_text (GtkEntryBuffer *buffer, n_chars -= (length + n_chars) - pv->max_length; } + if (n_chars == 0) + return 0; + klass = GTK_ENTRY_BUFFER_GET_CLASS (buffer); g_return_val_if_fail (klass->insert_text != NULL, 0); diff --git a/gtk/gtkentrybuffer.h b/gtk/gtkentrybuffer.h index 5f78b8018..c28c706f7 100644 --- a/gtk/gtkentrybuffer.h +++ b/gtk/gtkentrybuffer.h @@ -90,7 +90,7 @@ struct _GtkEntryBufferClass void (*_gtk_reserved5) (void); }; -GType gtk_entry_buffer_get_type (void) G_GNUC_CONST; +GType gtk_entry_buffer_get_type (void); GtkEntryBuffer* gtk_entry_buffer_new (const gchar *initial_chars, gint n_initial_chars); diff --git a/gtk/gtkentrycompletion.c b/gtk/gtkentrycompletion.c index aee364505..8d13e2683 100644 --- a/gtk/gtkentrycompletion.c +++ b/gtk/gtkentrycompletion.c @@ -1175,6 +1175,7 @@ gtk_entry_completion_complete (GtkEntryCompletion *completion) gchar *tmp; g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion)); + g_return_if_fail (GTK_IS_ENTRY (completion->priv->entry)); if (!completion->priv->filter_model) return; @@ -1416,7 +1417,9 @@ _gtk_entry_completion_resize_popup (GtkEntryCompletion *completion) - if (y > monitor.height / 2) + if (height == 0) + items = 0; + else if (y > monitor.height / 2) items = MIN (matches, (((monitor.y + y) - (actions * action_height)) / height) - 1); else items = MIN (matches, (((monitor.height - y) - (actions * action_height)) / height) - 1); diff --git a/gtk/gtkentrycompletion.h b/gtk/gtkentrycompletion.h index 7a99f787c..efd3fd985 100644 --- a/gtk/gtkentrycompletion.h +++ b/gtk/gtkentrycompletion.h @@ -77,7 +77,7 @@ struct _GtkEntryCompletionClass }; /* core */ -GType gtk_entry_completion_get_type (void) G_GNUC_CONST; +GType gtk_entry_completion_get_type (void); GtkEntryCompletion *gtk_entry_completion_new (void); GtkWidget *gtk_entry_completion_get_entry (GtkEntryCompletion *completion); diff --git a/gtk/gtkenums.h b/gtk/gtkenums.h index 29241362b..cf743ec90 100644 --- a/gtk/gtkenums.h +++ b/gtk/gtkenums.h @@ -579,6 +579,79 @@ typedef enum GTK_DRAG_RESULT_ERROR } GtkDragResult; +/** + * GtkInputPurpose: + * @GTK_INPUT_PURPOSE_FREE_FORM: Allow any character + * @GTK_INPUT_PURPOSE_ALPHA: Allow only alphabetic characters + * @GTK_INPUT_PURPOSE_DIGITS: Allow only digits + * @GTK_INPUT_PURPOSE_NUMBER: Edited field expects numbers + * @GTK_INPUT_PURPOSE_PHONE: Edited field expects phone number + * @GTK_INPUT_PURPOSE_URL: Edited field expects URL + * @GTK_INPUT_PURPOSE_EMAIL: Edited field expects email address + * @GTK_INPUT_PURPOSE_NAME: Edited field expects the name of a person + * @GTK_INPUT_PURPOSE_PASSWORD: Like @GTK_INPUT_PURPOSE_FREE_FORM, but characters are hidden + * @GTK_INPUT_PURPOSE_PIN: Like @GTK_INPUT_PURPOSE_DIGITS, but characters are hidden + * @GTK_INPUT_PURPOSE_TERMINAL: Allow any character, in addition to control codes + * + * Describes primary purpose of the input widget. This information is + * useful for on-screen keyboards and similar input methods to decide + * which keys should be presented to the user. As in GTK+ 3.6. + * + * Since: 2.24 + */ +typedef enum +{ + GTK_INPUT_PURPOSE_FREE_FORM, + GTK_INPUT_PURPOSE_ALPHA, + GTK_INPUT_PURPOSE_DIGITS, + GTK_INPUT_PURPOSE_NUMBER, + GTK_INPUT_PURPOSE_PHONE, + GTK_INPUT_PURPOSE_URL, + GTK_INPUT_PURPOSE_EMAIL, + GTK_INPUT_PURPOSE_NAME, + GTK_INPUT_PURPOSE_PASSWORD, + GTK_INPUT_PURPOSE_PIN, + GTK_INPUT_PURPOSE_TERMINAL +} GtkInputPurpose; + +/** + * GtkInputHints: + * @GTK_INPUT_HINT_NONE: No special behaviour suggested + * @GTK_INPUT_HINT_SPELLCHECK: Suggest checking for typos + * @GTK_INPUT_HINT_NO_SPELLCHECK: Suggest not checking for typos + * @GTK_INPUT_HINT_WORD_COMPLETION: Suggest word completion + * @GTK_INPUT_HINT_LOWERCASE: Suggest to convert all text to lowercase + * @GTK_INPUT_HINT_UPPERCASE_CHARS: Suggest to capitalize all text + * @GTK_INPUT_HINT_UPPERCASE_WORDS: Suggest to capitalize the first + * character of each word + * @GTK_INPUT_HINT_UPPERCASE_SENTENCES: Suggest to capitalize the + * first word of each sentence + * @GTK_INPUT_HINT_INHIBIT_OSK: Suggest to not show an onscreen keyboard + * @GTK_INPUT_HINT_VERTICAL_WRITING: The text is vertical + * @GTK_INPUT_HINT_EMOJI: Suggest offering Emoji support + * @GTK_INPUT_HINT_NO_EMOJI: Suggest not offering Emoji support + * + * Describes hints that might be taken into account by input methods + * or applications, as in GTK+ 3.6 to 3.22. + * + * Since: 2.24 + */ +typedef enum +{ + GTK_INPUT_HINT_NONE = 0, + GTK_INPUT_HINT_SPELLCHECK = 1 << 0, + GTK_INPUT_HINT_NO_SPELLCHECK = 1 << 1, + GTK_INPUT_HINT_WORD_COMPLETION = 1 << 2, + GTK_INPUT_HINT_LOWERCASE = 1 << 3, + GTK_INPUT_HINT_UPPERCASE_CHARS = 1 << 4, + GTK_INPUT_HINT_UPPERCASE_WORDS = 1 << 5, + GTK_INPUT_HINT_UPPERCASE_SENTENCES = 1 << 6, + GTK_INPUT_HINT_INHIBIT_OSK = 1 << 7, + GTK_INPUT_HINT_VERTICAL_WRITING = 1 << 8, + GTK_INPUT_HINT_EMOJI = 1 << 9, + GTK_INPUT_HINT_NO_EMOJI = 1 << 10 +} GtkInputHints; + G_END_DECLS #endif /* __GTK_ENUMS_H__ */ diff --git a/gtk/gtkeventbox.h b/gtk/gtkeventbox.h index 15675cb37..46c220d3f 100644 --- a/gtk/gtkeventbox.h +++ b/gtk/gtkeventbox.h @@ -57,7 +57,7 @@ struct _GtkEventBoxClass GtkBinClass parent_class; }; -GType gtk_event_box_get_type (void) G_GNUC_CONST; +GType gtk_event_box_get_type (void); GtkWidget* gtk_event_box_new (void); gboolean gtk_event_box_get_visible_window (GtkEventBox *event_box); void gtk_event_box_set_visible_window (GtkEventBox *event_box, diff --git a/gtk/gtkexpander.c b/gtk/gtkexpander.c index 0284cf3af..02af40f34 100644 --- a/gtk/gtkexpander.c +++ b/gtk/gtkexpander.c @@ -958,7 +958,8 @@ gtk_expander_button_release (GtkWidget *widget, if (event->button == 1 && expander->priv->button_down) { - gtk_widget_activate (widget); + if (expander->priv->prelight) + gtk_widget_activate (widget); expander->priv->button_down = FALSE; return TRUE; } diff --git a/gtk/gtkexpander.h b/gtk/gtkexpander.h index 0cfa0e12a..257c0d6f6 100644 --- a/gtk/gtkexpander.h +++ b/gtk/gtkexpander.h @@ -60,7 +60,7 @@ struct _GtkExpanderClass void (* activate) (GtkExpander *expander); }; -GType gtk_expander_get_type (void) G_GNUC_CONST; +GType gtk_expander_get_type (void); GtkWidget *gtk_expander_new (const gchar *label); GtkWidget *gtk_expander_new_with_mnemonic (const gchar *label); diff --git a/gtk/gtkfilechooser.c b/gtk/gtkfilechooser.c index e91887be5..a8e0fbf5c 100644 --- a/gtk/gtkfilechooser.c +++ b/gtk/gtkfilechooser.c @@ -639,7 +639,8 @@ gtk_file_chooser_get_type (void) (GClassInitFunc) gtk_file_chooser_class_init, 0, NULL, 0); - g_type_interface_add_prerequisite (file_chooser_type, GTK_TYPE_WIDGET); + /* G_TYPE_OBJECT, as in GTK+ 3: GtkFileChooserNative is no widget */ + g_type_interface_add_prerequisite (file_chooser_type, G_TYPE_OBJECT); } return file_chooser_type; diff --git a/gtk/gtkfilechooser.h b/gtk/gtkfilechooser.h index aa27be435..74cb9d3f1 100644 --- a/gtk/gtkfilechooser.h +++ b/gtk/gtkfilechooser.h @@ -85,7 +85,7 @@ typedef enum GTK_FILE_CHOOSER_CONFIRMATION_SELECT_AGAIN } GtkFileChooserConfirmation; -GType gtk_file_chooser_get_type (void) G_GNUC_CONST; +GType gtk_file_chooser_get_type (void); /* GError enumeration for GtkFileChooser */ /** diff --git a/gtk/gtkfilechooserbutton.c b/gtk/gtkfilechooserbutton.c index 4bc93b5de..91ea6eb93 100644 --- a/gtk/gtkfilechooserbutton.c +++ b/gtk/gtkfilechooserbutton.c @@ -625,10 +625,9 @@ unselect_current_file (GtkFileChooserButton *button) { g_object_unref (priv->selection_while_inactive); priv->selection_while_inactive = NULL; + priv->is_changing_selection = TRUE; } - priv->is_changing_selection = TRUE; - update_label_and_image (button); update_combo_box (button); } @@ -1163,7 +1162,7 @@ dnd_select_folder_get_info_cb (GCancellable *cancellable, data->selected = (((data->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER && is_folder) || (data->action == GTK_FILE_CHOOSER_ACTION_OPEN && !is_folder)) && - gtk_file_chooser_select_file (GTK_FILE_CHOOSER (data->button->priv->dialog), + gtk_file_chooser_select_file (GTK_FILE_CHOOSER (data->button), data->file, NULL)); } else @@ -2347,6 +2346,8 @@ name_cell_data_func (GtkCellLayout *layout, if (type == ROW_TYPE_CURRENT_FOLDER) g_object_set (cell, "ellipsize", PANGO_ELLIPSIZE_END, NULL); + else if (type == ROW_TYPE_BOOKMARK || type == ROW_TYPE_SHORTCUT) + g_object_set (cell, "ellipsize", PANGO_ELLIPSIZE_MIDDLE, NULL); else g_object_set (cell, "ellipsize", PANGO_ELLIPSIZE_NONE, NULL); } @@ -2564,7 +2565,12 @@ update_label_and_image (GtkFileChooserButton *button) } } - if (g_file_is_native (file)) + /* a remote file that is not a bookmark is asked for its name too, + * instead of showing "(None)" as if nothing was chosen */ + if (!g_file_is_native (file)) + label_text = _gtk_file_system_get_bookmark_label (button->priv->fs, file); + + if (g_file_is_native (file) || label_text == NULL) { priv->update_button_cancellable = _gtk_file_system_get_info (priv->fs, file, @@ -2576,7 +2582,6 @@ update_label_and_image (GtkFileChooserButton *button) { GdkPixbuf *pixbuf; - label_text = _gtk_file_system_get_bookmark_label (button->priv->fs, file); pixbuf = gtk_icon_theme_load_icon (get_icon_theme (GTK_WIDGET (priv->image)), "text-x-generic", priv->icon_size, 0, NULL); @@ -2737,11 +2742,12 @@ static void combo_box_changed_cb (GtkComboBox *combo_box, gpointer user_data) { + GtkFileChooserButton *button = GTK_FILE_CHOOSER_BUTTON (user_data); GtkTreeIter iter; + gboolean file_was_set = FALSE; if (gtk_combo_box_get_active_iter (combo_box, &iter)) { - GtkFileChooserButton *button = GTK_FILE_CHOOSER_BUTTON (user_data); GtkFileChooserButtonPrivate *priv = button->priv; gchar type; gpointer data; @@ -2761,7 +2767,10 @@ combo_box_changed_cb (GtkComboBox *combo_box, case ROW_TYPE_BOOKMARK: case ROW_TYPE_CURRENT_FOLDER: if (data) - gtk_file_chooser_button_select_file (GTK_FILE_CHOOSER (button), data, NULL); + { + gtk_file_chooser_button_select_file (GTK_FILE_CHOOSER (button), data, NULL); + file_was_set = TRUE; + } break; case ROW_TYPE_VOLUME: { @@ -2771,6 +2780,7 @@ combo_box_changed_cb (GtkComboBox *combo_box, if (base_file) { gtk_file_chooser_button_select_file (GTK_FILE_CHOOSER (button), base_file, NULL); + file_was_set = TRUE; g_object_unref (base_file); } } @@ -2782,6 +2792,10 @@ combo_box_changed_cb (GtkComboBox *combo_box, break; } } + + /* the user chose a file or folder in the menu of the button */ + if (file_was_set) + g_signal_emit (button, file_chooser_button_signals[FILE_SET], 0); } /* Calback for the "notify::popup-shown" signal on the combo box. diff --git a/gtk/gtkfilechooserbutton.h b/gtk/gtkfilechooserbutton.h index fdacc4b6e..5de7d9546 100644 --- a/gtk/gtkfilechooserbutton.h +++ b/gtk/gtkfilechooserbutton.h @@ -66,7 +66,7 @@ struct _GtkFileChooserButtonClass }; -GType gtk_file_chooser_button_get_type (void) G_GNUC_CONST; +GType gtk_file_chooser_button_get_type (void); GtkWidget * gtk_file_chooser_button_new (const gchar *title, GtkFileChooserAction action); diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c index 6b5239d85..6b945eb4f 100644 --- a/gtk/gtkfilechooserdefault.c +++ b/gtk/gtkfilechooserdefault.c @@ -39,9 +39,11 @@ #include "gtkfilechooserentry.h" #include "gtkfilechoosersettings.h" #include "gtkfilechooserutils.h" +#include "gtkfileoperation.h" #include "gtkfilechooser.h" #include "gtkfilesystem.h" #include "gtkfilesystemmodel.h" +#include "gtkfilethumbnail.h" #include "gtkframe.h" #include "gtkhbox.h" #include "gtkhpaned.h" @@ -56,12 +58,14 @@ #include "gtkmountoperation.h" #include "gtkpathbar.h" #include "gtkprivate.h" +#include "gtktimeprivate.h" #include "gtkradiobutton.h" #include "gtkrecentfilter.h" #include "gtkrecentmanager.h" #include "gtkscrolledwindow.h" #include "gtkseparatormenuitem.h" #include "gtksizegroup.h" +#include "gtkspinbutton.h" #include "gtkstock.h" #include "gtktable.h" #include "gtktoolbar.h" @@ -88,6 +92,10 @@ #endif #ifdef G_OS_WIN32 #include +#include +#include +#include +#include "win32/gdkwin32.h" #endif /* Profiling stuff */ @@ -168,6 +176,11 @@ enum { SHOW_HIDDEN, SEARCH_SHORTCUT, RECENT_SHORTCUT, + BACK_FOLDER, + FORWARD_FOLDER, + UNDO, + REDO, + CONNECT_TO_SERVER, LAST_SIGNAL }; @@ -183,6 +196,7 @@ enum { SHORTCUTS_COL_REMOVABLE, SHORTCUTS_COL_PIXBUF_VISIBLE, SHORTCUTS_COL_CANCELLABLE, + SHORTCUTS_COL_EJECT, SHORTCUTS_COL_NUM_COLUMNS }; @@ -191,17 +205,19 @@ typedef enum { SHORTCUT_TYPE_VOLUME, SHORTCUT_TYPE_SEPARATOR, SHORTCUT_TYPE_SEARCH, - SHORTCUT_TYPE_RECENT + SHORTCUT_TYPE_RECENT, + SHORTCUT_TYPE_CONNECT } ShortcutType; #define MODEL_ATTRIBUTES "standard::name,standard::type,standard::display-name," \ "standard::is-hidden,standard::is-backup,standard::size," \ "standard::fast-content-type,time::modified" enum { - /* the first 3 must be these due to settings caching sort column */ + /* the first 4 must be these due to settings caching sort column */ MODEL_COL_NAME, MODEL_COL_SIZE, MODEL_COL_MTIME, + MODEL_COL_TYPE, MODEL_COL_FILE, MODEL_COL_NAME_COLLATED, MODEL_COL_IS_FOLDER, @@ -220,6 +236,7 @@ enum { G_TYPE_STRING, /* MODEL_COL_NAME */ \ G_TYPE_INT64, /* MODEL_COL_SIZE */ \ G_TYPE_INT64, /* MODEL_COL_MTIME */ \ + G_TYPE_STRING, /* MODEL_COL_TYPE */ \ G_TYPE_FILE, /* MODEL_COL_FILE */ \ G_TYPE_STRING, /* MODEL_COL_NAME_COLLATED */ \ G_TYPE_BOOLEAN, /* MODEL_COL_IS_FOLDER */ \ @@ -230,6 +247,75 @@ enum { G_TYPE_STRING, /* MODEL_COL_MTIME_TEXT */ \ PANGO_TYPE_ELLIPSIZE_MODE /* MODEL_COL_ELLIPSIZE */ +/* The kinds of files in the Type column, as Nautilus and GTK+ 3 have + * them: by the generic icon of the shared MIME info; where GLib has none + * (Windows and the Mac), by the MIME type ("x/" for all of x), by the + * UTIs of the Mac a type conforms to, and on Windows by the extension + * when the registry does not know it. The more special ones first. */ +static const struct +{ + const gchar *icon_name; + const gchar *mime_types; + const gchar *utis; + const gchar *extensions; + const gchar *display_name; +} file_type_categories[] = { + { "x-office-address-book", "text/vcard text/x-vcard text/directory", + "public.vcard", "vcf", N_("Contacts") }, + { "x-office-calendar", "text/calendar", + "public.calendar-event com.apple.ical.ics", "ics", N_("Calendar") }, + { "text-html", "text/html application/xhtml+xml", + "public.html", "htm html xhtml", N_("Markup") }, + { "x-office-document", + "application/pdf application/msword application/rtf text/rtf " + "application/vnd.oasis.opendocument.text " + "application/vnd.openxmlformats-officedocument.wordprocessingml.document", + "com.adobe.pdf public.rtf com.microsoft.word.doc " + "org.openxmlformats.wordprocessingml.document org.oasis-open.opendocument.text", + "pdf doc docx odt rtf", N_("Document") }, + { "x-office-spreadsheet", + "text/csv application/vnd.ms-excel application/vnd.oasis.opendocument.spreadsheet " + "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", + "public.comma-separated-values-text com.microsoft.excel.xls " + "org.openxmlformats.spreadsheetml.sheet org.oasis-open.opendocument.spreadsheet", + "csv xls xlsx ods", N_("Spreadsheet") }, + { "x-office-presentation", + "application/vnd.ms-powerpoint application/vnd.oasis.opendocument.presentation " + "application/vnd.openxmlformats-officedocument.presentationml.presentation", + "com.microsoft.powerpoint.ppt org.openxmlformats.presentationml.presentation " + "org.oasis-open.opendocument.presentation com.apple.keynote.key", + "ppt pptx odp", N_("Presentation") }, + { "text-x-script", + "application/x-shellscript text/x-python text/x-perl application/javascript " + "text/javascript application/x-bat", + "public.script", "sh py pl js bat cmd ps1 vbs", N_("Program") }, + { "application-x-executable", + "application/x-msdownload application/x-ms-dos-executable application/x-executable " + "application/x-msi", + "public.executable com.apple.application", "exe com msi scr", N_("Program") }, + { "package-x-generic", + "application/zip application/x-zip-compressed application/x-7z-compressed " + "application/x-rar-compressed application/vnd.rar application/gzip application/x-gzip " + "application/x-tar application/x-gtar application/x-bzip2 application/x-xz " + "application/x-compressed application/x-compress application/vnd.ms-cab-compressed " + "application/java-archive application/zstd", + "public.archive", "zip 7z rar gz tgz bz2 xz tar cab lzh lha zst jar", N_("Archive") }, + { "font-x-generic", + "font/ application/x-font-ttf application/x-font-otf application/font-woff " + "application/vnd.ms-fontobject", + "public.font", "ttf otf ttc fon woff woff2 pfb", N_("Font") }, + { "image-x-generic", "image/", "public.image", + "png jpg jpeg gif bmp tif tiff ico webp svg xcf psd pcx tga xpm heic avif", N_("Image") }, + { "audio-x-generic", "audio/", "public.audio", + "mp3 ogg oga opus flac wav wma m4a aac mid midi aif aiff ape", N_("Audio") }, + { "video-x-generic", "video/", "public.movie", + "avi mp4 m4v mkv webm mov wmv mpg mpeg flv ogv 3gp", N_("Video") }, + { "text-x-generic", "text/", "public.text", + "txt log ini cfg conf md nfo c h cc cpp hpp java css xml json yml yaml diff patch po tex", + N_("Text") }, + { "text-x-generic-template", NULL, NULL, NULL, N_("Text") }, +}; + /* Identifiers for target types */ enum { GTK_TREE_MODEL_ROW, @@ -244,6 +330,7 @@ typedef enum { SHORTCUTS_HOME, SHORTCUTS_DESKTOP, SHORTCUTS_VOLUMES, + SHORTCUTS_CONNECT, SHORTCUTS_SHORTCUTS, SHORTCUTS_BOOKMARKS_SEPARATOR, SHORTCUTS_BOOKMARKS, @@ -256,6 +343,7 @@ typedef enum { #define FALLBACK_ICON_VIEW_ICON_SIZE 48 #define ICON_VIEW_ITEM_WIDTH 128 +#define COMPACT_VIEW_ITEM_WIDTH 200 #define ICON_VIEW_SCALE_MAX_VISIBLE_OVERSCAN 128 #define PREVIEW_HBOX_SPACING 12 @@ -335,6 +423,21 @@ static void location_popup_handler (GtkFileChooserDefault *impl, static void location_popup_on_paste_handler (GtkFileChooserDefault *impl); static void location_toggle_popup_handler (GtkFileChooserDefault *impl); static void up_folder_handler (GtkFileChooserDefault *impl); +static void back_folder_handler (GtkFileChooserDefault *impl); +static gboolean history_button_press_cb (GtkWidget *widget, + GdkEventButton *event, + GtkFileChooserDefault *impl); +static void history_buttons_create (GtkFileChooserDefault *impl, + GtkWidget *box); +static void forward_folder_handler (GtkFileChooserDefault *impl); +static void undo_handler (GtkFileChooserDefault *impl); +static void connect_to_server_handler (GtkFileChooserDefault *impl); +static GdkPixbuf *render_connect_icon (GtkFileChooserDefault *impl); +static void shortcuts_append_connect (GtkFileChooserDefault *impl); +#ifdef GDK_WINDOWING_QUARTZ +static gboolean connect_waited (gpointer data); +#endif +static void redo_handler (GtkFileChooserDefault *impl); static void down_folder_handler (GtkFileChooserDefault *impl); static void home_folder_handler (GtkFileChooserDefault *impl); static void desktop_folder_handler (GtkFileChooserDefault *impl); @@ -349,6 +452,7 @@ static void set_sort_column (GtkFileChooserDefault *impl); static void set_current_filter (GtkFileChooserDefault *impl, GtkFileFilter *filter); static void check_preview_change (GtkFileChooserDefault *impl); +static void preview_panel_sync (GtkFileChooserDefault *impl); static void filter_combo_changed (GtkComboBox *combo_box, GtkFileChooserDefault *impl); @@ -471,6 +575,7 @@ static void current_selection_selected_foreach (GtkFileChooserDefault GtkTreeSelectionForeachFunc func, gpointer data); static guint current_selection_count_selected_rows (GtkFileChooserDefault *impl); +static GFile * get_selected_file (GtkFileChooserDefault *impl); static void current_selection_select_iter (GtkFileChooserDefault *impl, GtkTreeIter *iter); static void copy_old_selection_to_current_view (GtkFileChooserDefault *impl, @@ -663,8 +768,81 @@ _gtk_file_chooser_default_class_init (GtkFileChooserDefaultClass *class) _gtk_marshal_VOID__VOID, G_TYPE_NONE, 0); + signals[BACK_FOLDER] = + g_signal_new_class_handler (I_("back-folder"), + G_OBJECT_CLASS_TYPE (class), + G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION, + G_CALLBACK (back_folder_handler), + NULL, NULL, + _gtk_marshal_VOID__VOID, + G_TYPE_NONE, 0); + + signals[FORWARD_FOLDER] = + g_signal_new_class_handler (I_("forward-folder"), + G_OBJECT_CLASS_TYPE (class), + G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION, + G_CALLBACK (forward_folder_handler), + NULL, NULL, + _gtk_marshal_VOID__VOID, + G_TYPE_NONE, 0); + + signals[UNDO] = + g_signal_new_class_handler (I_("undo"), + G_OBJECT_CLASS_TYPE (class), + G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION, + G_CALLBACK (undo_handler), + NULL, NULL, + _gtk_marshal_VOID__VOID, + G_TYPE_NONE, 0); + + signals[REDO] = + g_signal_new_class_handler (I_("redo"), + G_OBJECT_CLASS_TYPE (class), + G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION, + G_CALLBACK (redo_handler), + NULL, NULL, + _gtk_marshal_VOID__VOID, + G_TYPE_NONE, 0); + + signals[CONNECT_TO_SERVER] = + g_signal_new_class_handler (I_("connect-to-server"), + G_OBJECT_CLASS_TYPE (class), + G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION, + G_CALLBACK (connect_to_server_handler), + NULL, NULL, + _gtk_marshal_VOID__VOID, + G_TYPE_NONE, 0); + binding_set = gtk_binding_set_by_class (class); +#ifdef GDK_WINDOWING_QUARTZ + /* as in the Finder */ + gtk_binding_entry_add_signal (binding_set, GDK_KEY_k, GDK_MOD2_MASK, "connect-to-server", 0); +#endif + + /* Undo and Redo of what was done to files */ +#ifdef GDK_WINDOWING_QUARTZ + gtk_binding_entry_add_signal (binding_set, GDK_KEY_z, GDK_MOD2_MASK, "undo", 0); + gtk_binding_entry_add_signal (binding_set, GDK_KEY_z, GDK_MOD2_MASK | GDK_SHIFT_MASK, "redo", 0); +#else + gtk_binding_entry_add_signal (binding_set, GDK_KEY_z, GDK_CONTROL_MASK, "undo", 0); + gtk_binding_entry_add_signal (binding_set, GDK_KEY_z, GDK_CONTROL_MASK | GDK_SHIFT_MASK, "redo", 0); + gtk_binding_entry_add_signal (binding_set, GDK_KEY_y, GDK_CONTROL_MASK, "redo", 0); +#endif + + /* Back and Forward as in file managers and browsers; the keys of + * keyboards that have them; Command+[ and ] as in the Finder */ + gtk_binding_entry_add_signal (binding_set, GDK_KEY_Left, GDK_MOD1_MASK, "back-folder", 0); + gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Left, GDK_MOD1_MASK, "back-folder", 0); + gtk_binding_entry_add_signal (binding_set, GDK_KEY_Back, 0, "back-folder", 0); + gtk_binding_entry_add_signal (binding_set, GDK_KEY_Right, GDK_MOD1_MASK, "forward-folder", 0); + gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Right, GDK_MOD1_MASK, "forward-folder", 0); + gtk_binding_entry_add_signal (binding_set, GDK_KEY_Forward, 0, "forward-folder", 0); +#ifdef GDK_WINDOWING_QUARTZ + gtk_binding_entry_add_signal (binding_set, GDK_KEY_bracketleft, GDK_MOD2_MASK, "back-folder", 0); + gtk_binding_entry_add_signal (binding_set, GDK_KEY_bracketright, GDK_MOD2_MASK, "forward-folder", 0); +#endif + gtk_binding_entry_add_signal (binding_set, GDK_KEY_l, GDK_CONTROL_MASK, "location-toggle-popup", @@ -786,6 +964,9 @@ _gtk_file_chooser_default_init (GtkFileChooserDefault *impl) impl->select_multiple = FALSE; impl->show_hidden = FALSE; impl->show_size_column = TRUE; + impl->show_type_column = TRUE; + impl->show_thumbnails = TRUE; + impl->thumbnail_max_size = 64; impl->list_view_icon_size = FALLBACK_LIST_VIEW_ICON_SIZE; impl->icon_view_icon_size = FALLBACK_ICON_VIEW_ICON_SIZE; impl->load_state = LOAD_EMPTY; @@ -889,6 +1070,16 @@ gtk_file_chooser_default_finalize (GObject *object) icon_view_scale_remove_timeout (impl); + if (impl->drag_press_row) + gtk_tree_row_reference_free (impl->drag_press_row); + + /* requests hold a reference: none are left */ + if (impl->thumbnail_requests) + { + g_hash_table_destroy (impl->thumbnail_requests); + impl->thumbnail_requests = NULL; + } + unset_file_system_backend (impl); if (impl->shortcuts_pane_filter_model) @@ -930,6 +1121,14 @@ gtk_file_chooser_default_finalize (GObject *object) g_free (impl->preview_display_name); g_free (impl->edited_new_text); + if (impl->rename_file) + g_object_unref (impl->rename_file); + if (impl->tooltip_file) + g_object_unref (impl->tooltip_file); + if (impl->type_texts) + g_hash_table_destroy (impl->type_texts); + g_clear_object (&impl->place_space_file); + g_free (impl->place_space_text); G_OBJECT_CLASS (_gtk_file_chooser_default_parent_class)->finalize (object); } @@ -948,8 +1147,9 @@ error_message_with_parent (GtkWindow *parent, GTK_BUTTONS_OK, "%s", msg); - gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), - "%s", detail); + if (detail) + gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), + "%s", detail); if (parent && gtk_window_has_group (parent)) gtk_window_group_add_window (gtk_window_get_group (parent), @@ -1053,15 +1253,14 @@ error_creating_folder_dialog (GtkFileChooserDefault *impl, * the same name is already there. */ static void -error_creating_folder_over_existing_file_dialog (GtkFileChooserDefault *impl, - GFile *file, - GError *error) +error_creating_folder_over_existing_file_dialog (GtkFileChooserDefault *impl) { - error_dialog (impl, - _("The folder could not be created, as a file with the same " - "name already exists. Try using a different name for the " - "folder, or rename the file first."), - file, error); + /* there is no GError here: the file was found */ + error_message (impl, + _("The folder could not be created, as a file with the same " + "name already exists. Try using a different name for the " + "folder, or rename the file first."), + NULL); } static void @@ -1079,6 +1278,14 @@ error_with_file_under_nonfolder (GtkFileChooserDefault *impl, parent_file, error); } +static void +error_filename_too_long_dialog (GtkFileChooserDefault *impl) +{ + error_message (impl, + _("Cannot create file as the filename is too long"), + _("Try using a shorter name.")); +} + /* Shows an error about not being able to select a folder because a file with * the same name is already there. */ @@ -1086,10 +1293,11 @@ static void error_selecting_folder_over_existing_file_dialog (GtkFileChooserDefault *impl, GFile *file) { - error_dialog (impl, - _("You may only select folders. The item that you selected is not a folder; " - "try using a different item."), - file, NULL); + /* error_dialog() shows nothing without a GError, so use error_message() */ + error_message (impl, + _("You may only select folders. The item that you selected is not a folder; " + "try using a different item."), + NULL); } /* Shows an error dialog about not being able to create a filename */ @@ -1176,10 +1384,269 @@ update_preview_widget_visibility (GtkFileChooserDefault *impl) else gtk_widget_hide (impl->preview_box); + preview_panel_sync (impl); + if (!gtk_widget_get_mapped (GTK_WIDGET (impl))) emit_default_size_changed (impl); } +/* The preview of GTK+ itself, beside the files, for programs that have + * none: the picture, the name, the type, size and date of the file under + * the cursor. It is made when turned on and destroyed when turned off; + * it follows the cursor after a short pause, so going through a folder + * with the arrow keys reads nothing. Pictures come from thumbnails, + * made in the background where there are none yet (gtkfilethumbnail.c). */ + +#define MEGABYTES(n) ((goffset) (n) * 1024 * 1024) + +#define PREVIEW_PANEL_WIDTH 220 +#define PREVIEW_PANEL_IMAGE 200 +#define PREVIEW_PANEL_DELAY 120 /* milliseconds */ + +static gchar *file_list_format_size (goffset size); +static char *my_g_format_time_for_display (gint64 secs); + +/* Not beside a preview of the program, even while that one is not + * active: many turn theirs off and on for each file */ +static gboolean +preview_panel_wanted (GtkFileChooserDefault *impl) +{ + return impl->show_preview_panel && impl->preview_widget == NULL; +} + +static void +preview_panel_stop (GtkFileChooserDefault *impl) +{ + if (impl->preview_panel_update_id) + { + g_source_remove (impl->preview_panel_update_id); + impl->preview_panel_update_id = 0; + } + if (impl->preview_panel_cancellable) + { + g_cancellable_cancel (impl->preview_panel_cancellable); + g_clear_object (&impl->preview_panel_cancellable); + } +} + +/* Shows the thumbnail at @path, never made bigger; FALSE if it cannot + * be read. *@small tells whether it is smaller than the panel, and a + * bigger one could be made. */ +static gboolean +preview_panel_set_picture (GtkFileChooserDefault *impl, + const gchar *path, + gboolean *small) +{ + GdkPixbuf *pixbuf; + gint width, height; + + if (!gdk_pixbuf_get_file_info (path, &width, &height)) + return FALSE; + + *small = width < PREVIEW_PANEL_IMAGE && height < PREVIEW_PANEL_IMAGE; + if (width <= PREVIEW_PANEL_IMAGE && height <= PREVIEW_PANEL_IMAGE) + pixbuf = gdk_pixbuf_new_from_file (path, NULL); + else + pixbuf = gdk_pixbuf_new_from_file_at_size (path, PREVIEW_PANEL_IMAGE, + PREVIEW_PANEL_IMAGE, NULL); + if (pixbuf == NULL) + return FALSE; + + /* as big as the picture itself already */ + if (*small) + { + const gchar *original = gdk_pixbuf_get_option (pixbuf, "tEXt::Thumb::Image::Width"); + + if (original && g_ascii_strtoll (original, NULL, 10) <= width) + *small = FALSE; + } + + gtk_image_set_from_pixbuf (GTK_IMAGE (impl->preview_panel_image), pixbuf); + g_object_unref (pixbuf); + + return TRUE; +} + +static void +preview_panel_thumbnail_done (GFile *file, + const gchar *thumbnail, + gpointer data) +{ + GtkFileChooserDefault *impl = data; + gboolean small; + + if (thumbnail && impl->preview_panel && + impl->preview_file && g_file_equal (impl->preview_file, file)) + preview_panel_set_picture (impl, thumbnail, &small); +} + +static void +preview_panel_update (GtkFileChooserDefault *impl) +{ + GFileInfo *info = NULL; + GtkTreeIter iter; + GString *text; + const gchar *type, *thumbnail; + gboolean small = TRUE; + + preview_panel_stop (impl); + + if (impl->preview_file && GTK_IS_FILE_SYSTEM_MODEL (impl->current_model) && + _gtk_file_system_model_get_iter_for_file (GTK_FILE_SYSTEM_MODEL (impl->current_model), + &iter, impl->preview_file)) + info = _gtk_file_system_model_get_info (GTK_FILE_SYSTEM_MODEL (impl->current_model), &iter); + + if (info == NULL) + { + gtk_image_clear (GTK_IMAGE (impl->preview_panel_image)); + gtk_label_set_text (GTK_LABEL (impl->preview_panel_name), ""); + gtk_label_set_text (GTK_LABEL (impl->preview_panel_info), ""); + return; + } + + gtk_label_set_text (GTK_LABEL (impl->preview_panel_name), g_file_info_get_display_name (info)); + + text = g_string_new (NULL); + type = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE); + if (type) + { + gchar *description = g_content_type_get_description (type); + + /* Where the system knows no name for the type, GIO makes one of + * the type itself (".jpg filetype" on Windows without that file + * type registered, "image/x-foo" elsewhere); an image gdk-pixbuf + * can read has the name of its format instead */ + if (description == NULL || strstr (description, type) != NULL) + { + gchar *path = g_file_get_path (impl->preview_file); + GdkPixbufFormat *format = path ? gdk_pixbuf_get_file_info (path, NULL, NULL) : NULL; + + if (format != NULL) + { + g_free (description); + description = gdk_pixbuf_format_get_description (format); + } + g_free (path); + } + if (description) + g_string_append (text, description); + g_free (description); + } + if (!_gtk_file_info_consider_as_directory (info) && + g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_SIZE)) + { + gchar *size = file_list_format_size (g_file_info_get_size (info)); + + g_string_append_printf (text, "\n%s", size); + g_free (size); + } + if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_TIME_MODIFIED)) + { + gchar *date = my_g_format_time_for_display (g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_TIME_MODIFIED)); + + g_string_append_printf (text, "\n%s", date); + g_free (date); + } + gtk_label_set_text (GTK_LABEL (impl->preview_panel_info), text->str); + g_string_free (text, TRUE); + + /* The thumbnail there is, else the icon; a large thumbnail is made + * when the one there is smaller than the panel */ + thumbnail = impl->show_thumbnails ? + g_file_info_get_attribute_byte_string (info, G_FILE_ATTRIBUTE_THUMBNAIL_PATH) : NULL; + if (!thumbnail || !preview_panel_set_picture (impl, thumbnail, &small)) + { + GdkPixbuf *pixbuf = _gtk_file_info_render_icon (info, impl->preview_panel, 128); + + gtk_image_set_from_pixbuf (GTK_IMAGE (impl->preview_panel_image), pixbuf); + if (pixbuf) + g_object_unref (pixbuf); + } + + if (small && impl->show_thumbnails && + _gtk_file_thumbnail_wanted (impl->preview_file, info, MEGABYTES (impl->thumbnail_max_size))) + { + impl->preview_panel_cancellable = g_cancellable_new (); + _gtk_file_thumbnail_request (impl->preview_file, info, 256, + MEGABYTES (impl->thumbnail_max_size_remote), + impl->preview_panel_cancellable, + preview_panel_thumbnail_done, + g_object_ref (impl), g_object_unref); + } +} + +static gboolean +preview_panel_update_cb (gpointer data) +{ + GtkFileChooserDefault *impl = data; + + impl->preview_panel_update_id = 0; + preview_panel_update (impl); + + return FALSE; +} + +static void +preview_panel_queue_update (GtkFileChooserDefault *impl) +{ + if (impl->preview_panel == NULL) + return; + + if (impl->preview_panel_update_id) + g_source_remove (impl->preview_panel_update_id); + impl->preview_panel_update_id = gdk_threads_add_timeout (PREVIEW_PANEL_DELAY, + preview_panel_update_cb, impl); +} + +/* Makes or destroys the panel as it is wanted */ +static void +preview_panel_sync (GtkFileChooserDefault *impl) +{ + GtkWidget *box; + + if (!preview_panel_wanted (impl)) + { + if (impl->preview_panel) + { + preview_panel_stop (impl); + gtk_widget_destroy (impl->preview_panel); + impl->preview_panel = NULL; + impl->preview_panel_image = NULL; + impl->preview_panel_name = NULL; + impl->preview_panel_info = NULL; + } + return; + } + + if (impl->preview_panel == NULL && impl->preview_box) + { + impl->preview_panel = gtk_vbox_new (FALSE, 6); + gtk_widget_set_size_request (impl->preview_panel, PREVIEW_PANEL_WIDTH, -1); + + impl->preview_panel_image = gtk_image_new (); + gtk_widget_set_size_request (impl->preview_panel_image, -1, PREVIEW_PANEL_IMAGE); + gtk_box_pack_start (GTK_BOX (impl->preview_panel), impl->preview_panel_image, FALSE, FALSE, 0); + + impl->preview_panel_name = gtk_label_new (NULL); + gtk_label_set_line_wrap (GTK_LABEL (impl->preview_panel_name), TRUE); + gtk_label_set_line_wrap_mode (GTK_LABEL (impl->preview_panel_name), PANGO_WRAP_WORD_CHAR); + gtk_label_set_selectable (GTK_LABEL (impl->preview_panel_name), TRUE); + gtk_misc_set_alignment (GTK_MISC (impl->preview_panel_name), 0.0, 0.0); + gtk_widget_set_size_request (impl->preview_panel_name, PREVIEW_PANEL_WIDTH, -1); + gtk_box_pack_start (GTK_BOX (impl->preview_panel), impl->preview_panel_name, FALSE, FALSE, 0); + + impl->preview_panel_info = gtk_label_new (NULL); + gtk_misc_set_alignment (GTK_MISC (impl->preview_panel_info), 0.0, 0.0); + gtk_box_pack_start (GTK_BOX (impl->preview_panel), impl->preview_panel_info, FALSE, FALSE, 0); + + box = gtk_widget_get_parent (impl->preview_box); + gtk_box_pack_start (GTK_BOX (box), impl->preview_panel, FALSE, FALSE, 0); + gtk_widget_show_all (impl->preview_panel); + } + + preview_panel_queue_update (impl); +} + static void set_preview_widget (GtkFileChooserDefault *impl, GtkWidget *preview_widget) @@ -1372,6 +1839,10 @@ shortcuts_reload_icons (GtkFileChooserDefault *impl) { pixbuf = render_recent_icon (impl); } + else if (shortcut_type == SHORTCUT_TYPE_CONNECT) + { + pixbuf = render_connect_icon (impl); + } gtk_list_store_set (impl->shortcuts_model, &iter, SHORTCUTS_COL_PIXBUF, pixbuf, @@ -1657,6 +2128,11 @@ _gtk_file_chooser_label_for_file (GFile *file) /* Inserts a path in the shortcuts tree, making a copy of it; alternatively, * inserts a volume. A position of -1 indicates the end of the tree. */ +static gboolean volume_can (GtkFileSystemVolume *fs_volume, + gboolean eject); +static GtkFileSystemVolume *shortcuts_get_selected_volume (GtkFileChooserDefault *impl); +static void shortcuts_eject_icon_update (GtkFileChooserDefault *impl); + static void shortcuts_insert_file (GtkFileChooserDefault *impl, int pos, @@ -1764,6 +2240,8 @@ shortcuts_insert_file (GtkFileChooserDefault *impl, SHORTCUTS_COL_TYPE, shortcut_type, SHORTCUTS_COL_REMOVABLE, removable, SHORTCUTS_COL_CANCELLABLE, NULL, + SHORTCUTS_COL_EJECT, shortcut_type == SHORTCUT_TYPE_VOLUME && + (volume_can (volume, TRUE) || volume_can (volume, FALSE)), -1); if (impl->shortcuts_pane_filter_model) @@ -2002,6 +2480,11 @@ shortcuts_get_index (GtkFileChooserDefault *impl, n += impl->num_volumes; + if (where == SHORTCUTS_CONNECT) + goto out; + + n += impl->has_connect ? 1 : 0; + if (where == SHORTCUTS_SHORTCUTS) goto out; @@ -2328,7 +2811,8 @@ shortcuts_model_create (GtkFileChooserDefault *impl) G_TYPE_INT, /* ShortcutType */ G_TYPE_BOOLEAN, /* removable */ G_TYPE_BOOLEAN, /* pixbuf cell visibility */ - G_TYPE_POINTER); /* GCancellable */ + G_TYPE_POINTER, /* GCancellable */ + G_TYPE_BOOLEAN); /* eject button */ shortcuts_append_search (impl); @@ -2344,6 +2828,7 @@ shortcuts_model_create (GtkFileChooserDefault *impl) shortcuts_append_home (impl); shortcuts_append_desktop (impl); shortcuts_add_volumes (impl); + shortcuts_append_connect (impl); } impl->shortcuts_pane_filter_model = shortcuts_pane_model_filter_new (impl, @@ -2491,6 +2976,9 @@ create_folder_cb (GObject *source, g_clear_object (&impl->create_folder_cancellable); + if (created) + _gtk_file_operation_add_new_folder (data->file); + if (!created) error_creating_folder_dialog (impl, data->file, error); else if (data->respond) @@ -2538,6 +3026,723 @@ create_folder (GtkFileChooserDefault *impl, create_folder_cb, data); } +/* Renaming a file: F2 or "Rename..." edits its name in place, like a new + * folder's; then GIO renames it in the background. The list follows + * from the folder monitor; the renamed file is selected when it shows. */ + +static void +rename_select_clear (GtkFileChooserDefault *impl) +{ + if (impl->rename_select_handler) + g_signal_handler_disconnect (impl->rename_select_model, impl->rename_select_handler); + impl->rename_select_handler = 0; + g_clear_object (&impl->rename_select_model); + g_clear_object (&impl->rename_select); +} + +/* Selects the renamed file if it is in the list */ +static gboolean +rename_select_now (GtkFileChooserDefault *impl) +{ + GtkFileSystemModel *model = impl->browse_files_model; + GtkTreeIter iter; + GtkTreePath *path; + + if (model == NULL || impl->current_model != GTK_TREE_MODEL (model) || + !_gtk_file_system_model_get_iter_for_file (model, &iter, impl->rename_select) || + !_gtk_file_system_model_iter_is_visible (model, &iter)) + return FALSE; + + current_selection_unselect_all (impl); + current_selection_select_iter (impl, &iter); + path = gtk_tree_model_get_path (GTK_TREE_MODEL (model), &iter); + current_view_set_cursor (impl, path); + gtk_tree_path_free (path); + + return TRUE; +} + +static void +rename_row_inserted_cb (GtkTreeModel *model, + GtkTreePath *path, + GtkTreeIter *iter, + GtkFileChooserDefault *impl) +{ + GFile *file = _gtk_file_system_model_get_file (GTK_FILE_SYSTEM_MODEL (model), iter); + + if (file && g_file_equal (file, impl->rename_select)) + { + rename_select_now (impl); + rename_select_clear (impl); + } +} + +typedef struct +{ + GtkFileChooserDefault *impl; + GFile *file; +} RenameData; + +static void +rename_done (GObject *source, + GAsyncResult *result, + gpointer user_data) +{ + RenameData *data = user_data; + GtkFileChooserDefault *impl = data->impl; + GError *error = NULL; + GFile *renamed; + + renamed = g_file_set_display_name_finish (G_FILE (source), result, &error); + + GDK_THREADS_ENTER (); + + if (renamed) + _gtk_file_operation_add_rename (data->file, renamed); + + if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) + g_error_free (error); + else if (renamed == NULL) + error_dialog (impl, _("The file could not be renamed"), data->file, error); + else if (impl->browse_files_model && impl->current_folder && + g_file_has_parent (renamed, impl->current_folder)) + { + /* still in its folder */ + rename_select_clear (impl); + impl->rename_select = g_object_ref (renamed); + if (rename_select_now (impl)) + rename_select_clear (impl); + else + { + /* the monitor may be slower, or there is none */ + impl->rename_select_model = g_object_ref (impl->browse_files_model); + impl->rename_select_handler = + g_signal_connect (impl->rename_select_model, "row-inserted", + G_CALLBACK (rename_row_inserted_cb), impl); + _gtk_file_system_model_add_and_query_file (impl->browse_files_model, + renamed, MODEL_ATTRIBUTES); + } + } + + GDK_THREADS_LEAVE (); + + if (renamed) + g_object_unref (renamed); + g_object_unref (data->file); + g_object_unref (data->impl); + g_slice_free (RenameData, data); +} + +static void +rename_finish_editing (GtkFileChooserDefault *impl) +{ + GFile *file = impl->rename_file; + gchar *name = impl->edited_new_text; + gchar *old_name = NULL; + GtkTreeIter iter; + + impl->rename_file = NULL; + impl->edited_new_text = NULL; + + if (impl->list_name_renderer) + g_object_set (impl->list_name_renderer, "editable", FALSE, NULL); + gtk_widget_set_sensitive (impl->browse_new_folder_button, TRUE); + + if (impl->browse_files_model && + _gtk_file_system_model_get_iter_for_file (impl->browse_files_model, &iter, file)) + gtk_tree_model_get (GTK_TREE_MODEL (impl->browse_files_model), &iter, + MODEL_COL_NAME, &old_name, -1); + + if (name && *name && g_strcmp0 (name, old_name) != 0 && + strchr (name, '/') == NULL && strchr (name, G_DIR_SEPARATOR) == NULL) + { + RenameData *data = g_slice_new (RenameData); + + data->impl = g_object_ref (impl); + data->file = g_object_ref (file); + + if (impl->rename_cancellable == NULL) + impl->rename_cancellable = g_cancellable_new (); + g_file_set_display_name_async (file, name, G_PRIORITY_DEFAULT, + impl->rename_cancellable, rename_done, data); + } + + g_free (old_name); + g_free (name); + g_object_unref (file); +} + +/* Moving the selected files to the trash, one after the other in the + * background, with progress for many (gtkfileoperation.c); the folder + * monitor takes them off the list. The files go even if the dialog + * closes meanwhile, as the user asked for that. */ + +static void file_operation_done (GtkFileOperation *operation, + gboolean cancelled, + gboolean moved, + gpointer data); + +static void +trash_selected_foreach (GtkTreeModel *model, + GtkTreePath *path, + GtkTreeIter *iter, + gpointer user_data) +{ + GList **files = user_data; + GFile *file; + + gtk_tree_model_get (model, iter, MODEL_COL_FILE, &file, -1); + if (file) + *files = g_list_prepend (*files, file); +} + +static void +trash_selected_files (GtkFileChooserDefault *impl) +{ + GList *files = NULL; + GtkWidget *toplevel; + GtkFileOperation *operation; + + if (impl->operation_mode != OPERATION_MODE_BROWSE || + impl->rename_file || impl->edited_idle) + return; + + current_selection_selected_foreach (impl, trash_selected_foreach, &files); + if (files == NULL) + return; + + files = g_list_reverse (files); + toplevel = gtk_widget_get_toplevel (GTK_WIDGET (impl)); + operation = _gtk_file_operation_start (GTK_FILE_OPERATION_TRASH, files, NULL, + impl->file_operations_box, + GTK_IS_WINDOW (toplevel) ? GTK_WINDOW (toplevel) : NULL, + file_operation_done, impl); + if (operation) + impl->file_operations = g_slist_prepend (impl->file_operations, operation); + g_list_free_full (files, g_object_unref); +} + +/* Starts editing the name of the one selected file */ +static void +rename_selected_file (GtkFileChooserDefault *impl) +{ + GtkTreeIter iter; + GtkTreePath *path; + GFile *file; + + if (impl->operation_mode != OPERATION_MODE_BROWSE || + impl->rename_file || impl->edited_idle || impl->start_editing_icon_view_idle || + impl->browse_files_model == NULL || + impl->current_model != GTK_TREE_MODEL (impl->browse_files_model) || + current_selection_count_selected_rows (impl) != 1) + return; + + file = get_selected_file (impl); + if (file == NULL || + !_gtk_file_system_model_get_iter_for_file (impl->browse_files_model, &iter, file)) + { + if (file) + g_object_unref (file); + return; + } + + impl->rename_file = file; + gtk_widget_set_sensitive (impl->browse_new_folder_button, FALSE); + path = gtk_tree_model_get_path (GTK_TREE_MODEL (impl->browse_files_model), &iter); + + if (impl->view_mode == VIEW_MODE_LIST) + { + g_object_set (impl->list_name_renderer, "editable", TRUE, NULL); + gtk_tree_view_set_cursor (GTK_TREE_VIEW (impl->browse_files_tree_view), + path, impl->list_name_column, TRUE); + gtk_tree_path_free (path); + } + else + add_idle_to_edit_icon_view (impl, path); +} + +/* Cut, Copy and Paste of files, as in file managers. Cut and Copy put + * the selected files on the clipboard in the forms file managers take: + * x-special/gnome-copied-files ("copy" or "cut" and the URIs: Nautilus, + * Caja, Thunar, PCManFM), text/uri-list with the cut mark of KDE + * (Dolphin), and the locations as text for any other program. Paste + * copies or moves what is on the clipboard into the current folder, + * with progress, Cancel and questions (gtkfileoperation.c); after a cut + * the clipboard is emptied, as the files are no longer where it says. + * Cut files are shown dimmed until they are pasted or something else + * goes on the clipboard. The clipboard is only ever asked without + * waiting, so a program that owns it but does not answer blocks + * nothing. */ +enum +{ + COPIED_FILES_GNOME, + COPIED_FILES_KDE_CUT, + COPIED_FILES_URIS, + COPIED_FILES_TEXT +}; + +typedef struct +{ + GtkFileChooserDefault *impl; /* weak, for a cut */ + gboolean cut; + gchar **uris; + gchar *locations; /* one per line */ +} CopiedFiles; + +static void +cut_files_changed (GtkFileChooserDefault *impl) +{ + GtkFileSystemModel *models[3]; + gint i; + + models[0] = impl->browse_files_model; + models[1] = impl->search_model; + models[2] = impl->recent_model; + for (i = 0; i < 3; i++) + if (models[i]) + { + _gtk_file_system_model_clear_cache (models[i], MODEL_COL_LIST_PIXBUF); + _gtk_file_system_model_clear_cache (models[i], MODEL_COL_ICON_PIXBUF); + } +} + +static void +copied_files_free (CopiedFiles *files) +{ + if (files->impl) + { + if (files->impl->cut_files == files) + { + files->impl->cut_files = NULL; + cut_files_changed (files->impl); + } + g_object_remove_weak_pointer (G_OBJECT (files->impl), (gpointer *) &files->impl); + } + g_strfreev (files->uris); + g_free (files->locations); + g_slice_free (CopiedFiles, files); +} + +/* Whether @file is cut and waits on the clipboard to be pasted */ +static gboolean +file_is_cut (GtkFileChooserDefault *impl, + GFile *file) +{ + CopiedFiles *cut_files = impl->cut_files; + gchar *uri; + gboolean cut = FALSE; + gint i; + + if (cut_files == NULL || file == NULL) + return FALSE; + + uri = g_file_get_uri (file); + for (i = 0; cut_files->uris[i]; i++) + if (strcmp (cut_files->uris[i], uri) == 0) + { + cut = TRUE; + break; + } + g_free (uri); + + return cut; +} + +static void +copied_files_get_cb (GtkClipboard *clipboard, + GtkSelectionData *selection_data, + guint info, + gpointer data) +{ + CopiedFiles *files = data; + + switch (info) + { + case COPIED_FILES_GNOME: + { + gchar *list = g_strjoinv ("\n", files->uris); + gchar *text = g_strconcat (files->cut ? "cut\n" : "copy\n", list, NULL); + + gtk_selection_data_set (selection_data, + gtk_selection_data_get_target (selection_data), + 8, (const guchar *) text, strlen (text)); + g_free (text); + g_free (list); + } + break; + + case COPIED_FILES_KDE_CUT: + gtk_selection_data_set (selection_data, + gtk_selection_data_get_target (selection_data), + 8, (const guchar *) (files->cut ? "1" : "0"), 1); + break; + + case COPIED_FILES_URIS: + gtk_selection_data_set_uris (selection_data, files->uris); + break; + + default: + gtk_selection_data_set_text (selection_data, files->locations, -1); + break; + } +} + +static void +copied_files_clear_cb (GtkClipboard *clipboard, + gpointer data) +{ + copied_files_free (data); +} + +static void +copy_files_foreach_cb (GtkTreeModel *model, + GtkTreePath *path, + GtkTreeIter *iter, + gpointer data) +{ + GPtrArray *uris = ((gpointer *) data)[0]; + GString *locations = ((gpointer *) data)[1]; + GFile *file; + gchar *location; + + gtk_tree_model_get (model, iter, MODEL_COL_FILE, &file, -1); + if (file == NULL) + return; + + g_ptr_array_add (uris, g_file_get_uri (file)); + + location = g_file_get_path (file); + if (location == NULL) + location = g_file_get_uri (file); + if (locations->len != 0) + g_string_append_c (locations, '\n'); + g_string_append (locations, location); + g_free (location); + + g_object_unref (file); +} + +static void +put_files_on_clipboard (GtkFileChooserDefault *impl, + gboolean cut) +{ + GPtrArray *uris = g_ptr_array_new (); + GString *locations = g_string_new (NULL); + gpointer data[2]; + CopiedFiles *files; + GtkTargetList *list; + GtkTargetEntry *targets; + gint n_targets; + GtkClipboard *clipboard; + + data[0] = uris; + data[1] = locations; + current_selection_selected_foreach (impl, copy_files_foreach_cb, data); + + if (uris->len == 0) + { + g_ptr_array_free (uris, TRUE); + g_string_free (locations, TRUE); + return; + } + + g_ptr_array_add (uris, NULL); + files = g_slice_new0 (CopiedFiles); + files->cut = cut; + files->uris = (gchar **) g_ptr_array_free (uris, FALSE); + files->locations = g_string_free (locations, FALSE); + + list = gtk_target_list_new (NULL, 0); + gtk_target_list_add (list, gdk_atom_intern_static_string (GTK_FILE_CLIPBOARD_GNOME), + 0, COPIED_FILES_GNOME); + if (cut) + gtk_target_list_add (list, gdk_atom_intern_static_string (GTK_FILE_CLIPBOARD_KDE_CUT), + 0, COPIED_FILES_KDE_CUT); + gtk_target_list_add_uri_targets (list, COPIED_FILES_URIS); + gtk_target_list_add_text_targets (list, COPIED_FILES_TEXT); + targets = gtk_target_table_new_from_list (list, &n_targets); + gtk_target_list_unref (list); + + clipboard = gtk_widget_get_clipboard (GTK_WIDGET (impl), GDK_SELECTION_CLIPBOARD); + if (gtk_clipboard_set_with_data (clipboard, targets, n_targets, + copied_files_get_cb, copied_files_clear_cb, files)) + { + if (cut) + { + /* what was cut before is no longer (its clear callback ran) */ + files->impl = impl; + g_object_add_weak_pointer (G_OBJECT (impl), (gpointer *) &files->impl); + impl->cut_files = files; + cut_files_changed (impl); + } + else + /* a copy stays there for others when the program ends */ + gtk_clipboard_set_can_store (clipboard, NULL, 0); + } + else + copied_files_free (files); + + gtk_target_table_free (targets, n_targets); +} + +static void +copy_files (GtkFileChooserDefault *impl) +{ + put_files_on_clipboard (impl, FALSE); +} + +static void +cut_files (GtkFileChooserDefault *impl) +{ + put_files_on_clipboard (impl, TRUE); +} + +/* Pasting: what is on the clipboard, asked without waiting */ +typedef struct +{ + GtkFileChooserDefault *impl; /* weak */ + GFile *destination; + GList *files; +} PasteData; + +static void +paste_data_free (PasteData *paste) +{ + if (paste->impl) + g_object_remove_weak_pointer (G_OBJECT (paste->impl), (gpointer *) &paste->impl); + g_object_unref (paste->destination); + g_list_foreach (paste->files, (GFunc) g_object_unref, NULL); + g_list_free (paste->files); + g_slice_free (PasteData, paste); +} + +/* The folder shown, when an operation took it away (Undo of a new + * folder or of a move into it): the nearest folder above that is there + * is shown instead, as file managers do; on Windows that also lets go of + * it, as a folder that is open cannot be gone there */ +static void +leave_folder_if_gone (GtkFileChooserDefault *impl) +{ + GFile *folder, *parent; + + if (impl->current_folder == NULL || + !g_file_is_native (impl->current_folder) || + g_file_query_exists (impl->current_folder, NULL)) + return; + + folder = g_object_ref (impl->current_folder); + while ((parent = g_file_get_parent (folder)) != NULL) + { + g_object_unref (folder); + folder = parent; + if (g_file_query_exists (folder, NULL)) + break; + } + change_folder_and_display_error (impl, folder, FALSE); + g_object_unref (folder); +} + +static void +file_operation_done (GtkFileOperation *operation, + gboolean cancelled, + gboolean moved, + gpointer data) +{ + GtkFileChooserDefault *impl = data; + + impl->file_operations = g_slist_remove (impl->file_operations, operation); + leave_folder_if_gone (impl); +} + +static void +paste_cut_done (GtkFileOperation *operation, + gboolean cancelled, + gboolean moved, + gpointer data) +{ + GtkFileChooserDefault *impl = data; + + file_operation_done (operation, cancelled, moved, data); + + /* the files are no longer where the clipboard says: it is emptied, + * if it still holds them */ + if (moved) + { + GtkClipboard *clipboard = gtk_widget_get_clipboard (GTK_WIDGET (impl), + GDK_SELECTION_CLIPBOARD); + + if (impl->cut_files) + gtk_clipboard_clear (clipboard); + else + gtk_clipboard_set_text (clipboard, "", 0); + } +} + +static void +paste_start (PasteData *paste, + gboolean cut) +{ + GtkFileChooserDefault *impl = paste->impl; + GtkFileOperation *operation; + GtkWidget *toplevel; + + if (impl == NULL || paste->files == NULL) + return; + + toplevel = gtk_widget_get_toplevel (GTK_WIDGET (impl)); + operation = _gtk_file_operation_start (cut ? GTK_FILE_OPERATION_MOVE : GTK_FILE_OPERATION_COPY, + paste->files, paste->destination, + impl->file_operations_box, + GTK_IS_WINDOW (toplevel) ? GTK_WINDOW (toplevel) : NULL, + cut ? paste_cut_done : file_operation_done, impl); + if (operation) + impl->file_operations = g_slist_prepend (impl->file_operations, operation); +} + +static void +paste_add_uris (PasteData *paste, + gchar **uris, + gint first) +{ + gint i; + + for (i = first; uris && uris[i]; i++) + if (*uris[i] != '\0') + paste->files = g_list_append (paste->files, g_file_new_for_uri (uris[i])); +} + +static void +paste_kde_cut_received (GtkClipboard *clipboard, + GtkSelectionData *selection_data, + gpointer data) +{ + PasteData *paste = data; + gboolean cut = FALSE; + + if (selection_data && gtk_selection_data_get_length (selection_data) > 0) + cut = gtk_selection_data_get_data (selection_data)[0] == '1'; + + paste_start (paste, cut); + paste_data_free (paste); +} + +static void +paste_uris_received (GtkClipboard *clipboard, + gchar **uris, + gpointer data) +{ + PasteData *paste = data; + + paste_add_uris (paste, uris, 0); + if (paste->impl == NULL || paste->files == NULL) + { + paste_data_free (paste); + return; + } + + /* cut in Dolphin? */ + gtk_clipboard_request_contents (clipboard, + gdk_atom_intern_static_string (GTK_FILE_CLIPBOARD_KDE_CUT), + paste_kde_cut_received, paste); +} + +static void +paste_gnome_received (GtkClipboard *clipboard, + GtkSelectionData *selection_data, + gpointer data) +{ + PasteData *paste = data; + gint length = selection_data ? gtk_selection_data_get_length (selection_data) : -1; + + if (paste->impl == NULL) + { + paste_data_free (paste); + return; + } + + if (length > 0) + { + gchar *text = g_strndup ((const gchar *) gtk_selection_data_get_data (selection_data), length); + gchar **lines = g_strsplit (text, "\n", -1); + gboolean cut = lines[0] && g_str_equal (g_strstrip (lines[0]), "cut"); + gint i; + + for (i = 1; lines[i]; i++) + g_strstrip (lines[i]); + paste_add_uris (paste, lines, 1); + g_strfreev (lines); + g_free (text); + + paste_start (paste, cut); + paste_data_free (paste); + return; + } + + gtk_clipboard_request_uris (clipboard, paste_uris_received, paste); +} + +static void +paste_files_into (GtkFileChooserDefault *impl, + GFile *destination) +{ + PasteData *paste; + + paste = g_slice_new0 (PasteData); + paste->impl = impl; + g_object_add_weak_pointer (G_OBJECT (impl), (gpointer *) &paste->impl); + paste->destination = g_object_ref (destination); + + gtk_clipboard_request_contents (gtk_widget_get_clipboard (GTK_WIDGET (impl), + GDK_SELECTION_CLIPBOARD), + gdk_atom_intern_static_string (GTK_FILE_CLIPBOARD_GNOME), + paste_gnome_received, paste); +} + +static void +paste_files (GtkFileChooserDefault *impl) +{ + if (impl->operation_mode != OPERATION_MODE_BROWSE || impl->current_folder == NULL) + return; + + paste_files_into (impl, impl->current_folder); +} + +/* "Paste Into Folder": into the one folder that is selected */ +static void +paste_into_folder (GtkFileChooserDefault *impl) +{ + GFile *folder = get_selected_file (impl); + + if (folder == NULL) + return; + if (impl->operation_mode == OPERATION_MODE_BROWSE) + paste_files_into (impl, folder); + g_object_unref (folder); +} + +/* Paste in the menu is sensitive when the clipboard has files, which is + * asked when the menu is built, without waiting */ +static void +paste_targets_received (GtkClipboard *clipboard, + GdkAtom *atoms, + gint n_atoms, + gpointer data) +{ + GtkWidget *item = data; + gboolean files = FALSE; + gint i; + + for (i = 0; atoms && i < n_atoms; i++) + if (atoms[i] == gdk_atom_intern_static_string (GTK_FILE_CLIPBOARD_GNOME)) + files = TRUE; + if (!files && atoms) + files = gtk_targets_include_uri (atoms, n_atoms); + + if (gtk_widget_get_parent (item)) + gtk_widget_set_sensitive (item, files); + g_object_unref (item); +} + /* Idle handler for creating a new folder after editing its name cell, or for * canceling the editing. */ @@ -2549,6 +3754,13 @@ edited_idle_cb (GtkFileChooserDefault *impl) g_source_destroy (impl->edited_idle); impl->edited_idle = NULL; + if (impl->rename_file) + { + rename_finish_editing (impl); + GDK_THREADS_LEAVE (); + return FALSE; + } + _gtk_file_system_model_remove_editable (impl->browse_files_model); g_object_set (impl->list_name_renderer, "editable", FALSE, NULL); @@ -3112,6 +4324,15 @@ shortcuts_check_popup_sensitivity (GtkFileChooserDefault *impl) gtk_widget_set_sensitive (impl->browse_shortcuts_popup_menu_remove_item, removable); gtk_widget_set_sensitive (impl->browse_shortcuts_popup_menu_rename_item, removable); + + { + GtkFileSystemVolume *volume = shortcuts_get_selected_volume (impl); + + gtk_widget_set_visible (impl->browse_shortcuts_popup_menu_unmount_item, + volume_can (volume, FALSE)); + gtk_widget_set_visible (impl->browse_shortcuts_popup_menu_eject_item, + volume_can (volume, TRUE)); + } } /* GtkWidget::drag-begin handler for the shortcuts list. */ @@ -3167,6 +4388,92 @@ shortcuts_drag_data_delete_cb (GtkWidget *widget, g_signal_stop_emission_by_name (widget, "drag-data-delete"); } +/* dropping files: further below */ +static gboolean dnd_offers_uris (GdkDragContext *context); +static gint dnd_choose_for (GtkFileChooserDefault *impl, + GtkWidget *widget, + GdkDragContext *context, + GFile *folder); +static void dnd_hover (GtkFileChooserDefault *impl, + GFile *folder); +static void dnd_set (GtkFileChooserDefault *impl, + GdkDragContext *context, + GFile *folder, + gint action, + guint time_); +static void dnd_leave (GtkFileChooserDefault *impl); +static void dnd_set_state (GtkFileChooserDefault *impl, + GFile *folder, + gint action); +static void dnd_data_received (GtkFileChooserDefault *impl, + GtkWidget *widget, + GdkDragContext *context, + GtkSelectionData *selection_data, + guint time_); + +/* The folder of the place at @x, @y, for dropping files into it: a + * place that is not a bookmark anywhere on its row, a bookmark in the + * middle of its row (above and below, new bookmarks are put) */ +static GFile * +shortcuts_folder_at (GtkFileChooserDefault *impl, + gint x, + gint y, + GtkTreePath **path_out) +{ + GtkTreeView *tree_view = GTK_TREE_VIEW (impl->browse_shortcuts_tree_view); + GtkTreeModel *model = gtk_tree_view_get_model (tree_view); + GtkTreePath *path, *child_path; + GtkTreeViewColumn *column; + GtkTreeIter iter, child_iter; + GdkRectangle cell; + gpointer col_data; + ShortcutType shortcut_type; + GFile *folder = NULL; + gint cell_y, row, bookmarks_index; + + *path_out = NULL; + /* the coordinates of a drop include the column header */ + gtk_tree_view_convert_widget_to_bin_window_coords (tree_view, x, y, &x, &y); + if (!gtk_tree_view_get_path_at_pos (tree_view, x, y, &path, &column, NULL, &cell_y)) + return NULL; + + gtk_tree_view_get_background_area (tree_view, path, column, &cell); + if (!gtk_tree_model_get_iter (model, &iter, path)) + { + gtk_tree_path_free (path); + return NULL; + } + + gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &child_iter, &iter); + child_path = gtk_tree_model_get_path (GTK_TREE_MODEL (impl->shortcuts_model), &child_iter); + row = *gtk_tree_path_get_indices (child_path); + gtk_tree_path_free (child_path); + + bookmarks_index = shortcuts_get_index (impl, SHORTCUTS_BOOKMARKS); + if (row >= bookmarks_index && row < bookmarks_index + impl->num_bookmarks && + (cell_y < cell.height / 4 || cell_y >= cell.height - cell.height / 4)) + { + gtk_tree_path_free (path); + return NULL; + } + + gtk_tree_model_get (model, &iter, + SHORTCUTS_COL_DATA, &col_data, + SHORTCUTS_COL_TYPE, &shortcut_type, + -1); + if (shortcut_type == SHORTCUT_TYPE_FILE && col_data) + folder = g_object_ref (col_data); + else if (shortcut_type == SHORTCUT_TYPE_VOLUME && col_data && + _gtk_file_system_volume_is_mounted (col_data)) + folder = _gtk_file_system_volume_get_root (col_data); + + if (folder) + *path_out = path; + else + gtk_tree_path_free (path); + return folder; +} + /* GtkWidget::drag-leave handler for the shortcuts list. We unhighlight the * drop position. */ @@ -3186,6 +4493,7 @@ shortcuts_drag_leave_cb (GtkWidget *widget, gtk_tree_view_set_drag_dest_row (GTK_TREE_VIEW (impl->browse_shortcuts_tree_view), NULL, GTK_TREE_VIEW_DROP_BEFORE); + dnd_leave (impl); g_signal_stop_emission_by_name (widget, "drag-leave"); } @@ -3268,6 +4576,25 @@ shortcuts_drag_motion_cb (GtkWidget *widget, GtkTreeViewDropPosition pos; GdkDragAction action; + /* files onto a place go into it; the place opens when the drag stays */ + if (gtk_drag_get_source_widget (context) != widget && dnd_offers_uris (context)) + { + GFile *folder = shortcuts_folder_at (impl, x, y, &path); + + if (folder) + { + gtk_tree_view_set_drag_dest_row (GTK_TREE_VIEW (widget), path, GTK_TREE_VIEW_DROP_INTO_OR_BEFORE); + dnd_hover (impl, folder); + dnd_set (impl, context, folder, dnd_choose_for (impl, widget, context, folder), time_); + gtk_tree_path_free (path); + g_object_unref (folder); + g_signal_stop_emission_by_name (widget, "drag-motion"); + return TRUE; + } + } + dnd_hover (impl, NULL); + dnd_set (impl, context, NULL, 0, time_); + #if 0 if (gtk_drag_get_source_widget (context) == widget) { @@ -3319,11 +4646,33 @@ shortcuts_drag_drop_cb (GtkWidget *widget, guint time_, GtkFileChooserDefault *impl) { + GdkAtom target; + #if 0 shortcuts_cancel_drag_outside_idle (impl); #endif g_signal_stop_emission_by_name (widget, "drag-drop"); + + /* files into a place, or new bookmarks: where it was dropped */ + { + GtkTreePath *path = NULL; + GFile *folder = NULL; + + if (gtk_drag_get_source_widget (context) != widget && dnd_offers_uris (context)) + folder = shortcuts_folder_at (impl, x, y, &path); + dnd_set_state (impl, folder, folder ? dnd_choose_for (impl, widget, context, folder) : 0); + if (path) + gtk_tree_path_free (path); + if (folder) + g_object_unref (folder); + } + + target = gtk_drag_dest_find_target (widget, context, NULL); + if (target == GDK_NONE) + gtk_drag_finish (context, FALSE, FALSE, time_); + else + gtk_drag_get_data (widget, context, target, time_); return TRUE; } @@ -3348,6 +4697,15 @@ shortcuts_drop_uris (GtkFileChooserDefault *impl, uri = uris[i]; file = g_file_new_for_uri (uri); + /* bookmarks are of folders: a file dropped there would be one + * nothing can be done with (as GTK+ 3 has it) */ + if (g_file_is_native (file) && + g_file_query_file_type (file, G_FILE_QUERY_INFO_NONE, NULL) != G_FILE_TYPE_DIRECTORY) + { + g_object_unref (file); + continue; + } + if (shortcuts_add_bookmark_from_file (impl, file, position)) position++; @@ -3372,7 +4730,7 @@ shortcuts_reorder (GtkFileChooserDefault *impl, int bookmarks_index; GFile *file; GError *error; - gchar *name; + gchar *name = NULL; GtkTreeModel *model; /* Get the selected path */ @@ -3428,6 +4786,7 @@ shortcuts_reorder (GtkFileChooserDefault *impl, out: g_object_unref (file); + g_free (name); } /* Callback used when we get the drag data for the bookmarks list. We add the @@ -3451,6 +4810,15 @@ shortcuts_drag_data_received_cb (GtkWidget *widget, int bookmarks_index; impl = GTK_FILE_CHOOSER_DEFAULT (data); + target = gtk_selection_data_get_target (selection_data); + + /* files into a place */ + if (impl->dnd_folder && gtk_targets_include_uri (&target, 1)) + { + g_signal_stop_emission_by_name (widget, "drag-data-received"); + dnd_data_received (impl, widget, context, selection_data, time_); + return; + } /* Compute position */ @@ -3466,16 +4834,415 @@ shortcuts_drag_data_received_cb (GtkWidget *widget, g_assert (position >= bookmarks_index); position -= bookmarks_index; - target = gtk_selection_data_get_target (selection_data); - if (gtk_targets_include_uri (&target, 1)) shortcuts_drop_uris (impl, selection_data, position); else if (target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW")) shortcuts_reorder (impl, selection_data, position); + gtk_drag_finish (context, TRUE, FALSE, time_); g_signal_stop_emission_by_name (widget, "drag-data-received"); } +/* Unmounting and ejecting, as in file managers: drives, their volumes + * and mounts (also those of servers) have an eject button on their place + * and Unmount and Eject in its menu. The file chooser leaves a folder + * that goes with them for the home folder. */ + +typedef struct +{ + GtkFileChooserDefault *impl; + GObject *volume; + GFile *root; + gboolean eject; +} EjectData; + +static GMount * +volume_get_mount (GObject *volume) +{ + if (G_IS_MOUNT (volume)) + return G_MOUNT (g_object_ref (volume)); + if (G_IS_VOLUME (volume)) + return g_volume_get_mount (G_VOLUME (volume)); + return NULL; +} + +/* Whether the place of @volume can be ejected (@eject) or unmounted */ +static gboolean +volume_can (GtkFileSystemVolume *fs_volume, + gboolean eject) +{ + GObject *volume = _gtk_file_system_volume_get_object (fs_volume); + GMount *mount; + gboolean can = FALSE; + + if (volume == NULL) + return FALSE; + + if (G_IS_DRIVE (volume)) + return eject && g_drive_can_eject (G_DRIVE (volume)); + + if (eject && G_IS_VOLUME (volume) && g_volume_can_eject (G_VOLUME (volume))) + return TRUE; + + mount = volume_get_mount (volume); + if (mount) + { + can = eject ? g_mount_can_eject (mount) : g_mount_can_unmount (mount); + g_object_unref (mount); + } + return can; +} + +static void +eject_done (GObject *source, + GAsyncResult *result, + gpointer user_data) +{ + EjectData *data = user_data; + GtkFileChooserDefault *impl = data->impl; + GError *error = NULL; + gboolean done; + + if (G_IS_DRIVE (source)) + done = g_drive_eject_with_operation_finish (G_DRIVE (source), result, &error); + else if (G_IS_VOLUME (source)) + done = g_volume_eject_with_operation_finish (G_VOLUME (source), result, &error); + else if (data->eject) + done = g_mount_eject_with_operation_finish (G_MOUNT (source), result, &error); + else + done = g_mount_unmount_with_operation_finish (G_MOUNT (source), result, &error); + + GDK_THREADS_ENTER (); + + if (!done) + { + /* the user said no to it in a dialog of GIO or of the system */ + if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_FAILED_HANDLED) && + !g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) + { + gchar *name = _gtk_file_system_volume_get_display_name ((GtkFileSystemVolume *) data->volume); + gchar *msg = g_strdup_printf (data->eject ? _("“%s” could not be ejected") + : _("“%s” could not be unmounted"), + name); + + error_message (impl, msg, error->message); + g_free (msg); + g_free (name); + } + g_error_free (error); + } + else if (data->root && impl->current_folder && + (g_file_equal (impl->current_folder, data->root) || + g_file_has_prefix (impl->current_folder, data->root))) + { + /* what was shown is gone */ + GFile *home = g_file_new_for_path (g_get_home_dir ()); + + change_folder_and_display_error (impl, home, FALSE); + g_object_unref (home); + } + + GDK_THREADS_LEAVE (); + + g_object_unref (data->impl); + g_object_unref (data->volume); + if (data->root) + g_object_unref (data->root); + g_slice_free (EjectData, data); +} + +static void +shortcuts_eject (GtkFileChooserDefault *impl, + GtkFileSystemVolume *fs_volume, + gboolean eject) +{ + GObject *volume = _gtk_file_system_volume_get_object (fs_volume); + GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (impl)); + GMountOperation *operation; + EjectData *data; + GMount *mount; + + if (!volume_can (fs_volume, eject)) + return; + + operation = gtk_mount_operation_new (GTK_IS_WINDOW (toplevel) ? GTK_WINDOW (toplevel) : NULL); + data = g_slice_new0 (EjectData); + data->impl = g_object_ref (impl); + data->volume = g_object_ref (volume); + data->eject = eject; + if (_gtk_file_system_volume_is_mounted (fs_volume)) + data->root = _gtk_file_system_volume_get_root (fs_volume); + + mount = volume_get_mount (volume); + if (G_IS_DRIVE (volume)) + g_drive_eject_with_operation (G_DRIVE (volume), G_MOUNT_UNMOUNT_NONE, operation, + NULL, eject_done, data); + else if (eject && G_IS_VOLUME (volume) && g_volume_can_eject (G_VOLUME (volume))) + g_volume_eject_with_operation (G_VOLUME (volume), G_MOUNT_UNMOUNT_NONE, operation, + NULL, eject_done, data); + else if (eject) + g_mount_eject_with_operation (mount, G_MOUNT_UNMOUNT_NONE, operation, + NULL, eject_done, data); + else + g_mount_unmount_with_operation (mount, G_MOUNT_UNMOUNT_NONE, operation, + NULL, eject_done, data); + + if (mount) + g_object_unref (mount); + g_object_unref (operation); +} + +/* The picture of the eject button: "media-eject" of the icon theme, or + * one drawn here for themes without it (Windows, plain GTK+) */ +static void +shortcuts_eject_icon_update (GtkFileChooserDefault *impl) +{ + GtkIconTheme *theme; + GdkPixbuf *pixbuf = NULL; + gint size; + + if (impl->shortcuts_eject_renderer == NULL) + return; + + if (!gtk_icon_size_lookup_for_settings (gtk_widget_get_settings (GTK_WIDGET (impl)), + GTK_ICON_SIZE_MENU, &size, NULL)) + size = 16; + + theme = gtk_icon_theme_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (impl))); + if (gtk_icon_theme_has_icon (theme, "media-eject")) + pixbuf = gtk_icon_theme_load_icon (theme, "media-eject", size, 0, NULL); + + if (pixbuf == NULL) + { + GtkStyle *style = gtk_widget_get_style (GTK_WIDGET (impl)); + cairo_surface_t *surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, size, size); + cairo_t *cr = cairo_create (surface); + gdouble u = size / 16.0; + + /* a triangle over a bar, in the color of text */ + gdk_cairo_set_source_color (cr, &style->text[GTK_STATE_NORMAL]); + cairo_move_to (cr, 8 * u, 2.5 * u); + cairo_line_to (cr, 14 * u, 9 * u); + cairo_line_to (cr, 2 * u, 9 * u); + cairo_close_path (cr); + cairo_rectangle (cr, 2 * u, 11 * u, 12 * u, 2.5 * u); + cairo_fill (cr); + cairo_destroy (cr); + + /* premultiplied ARGB to the RGBA of a pixbuf */ + { + guchar *src, *dst; + gint x, y, src_stride, dst_stride; + + cairo_surface_flush (surface); + pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, size, size); + src = cairo_image_surface_get_data (surface); + src_stride = cairo_image_surface_get_stride (surface); + dst = gdk_pixbuf_get_pixels (pixbuf); + dst_stride = gdk_pixbuf_get_rowstride (pixbuf); + for (y = 0; y < size; y++) + for (x = 0; x < size; x++) + { + guint32 argb = *(guint32 *) (src + y * src_stride + 4 * x); + guint a = argb >> 24; + guchar *d = dst + y * dst_stride + 4 * x; + + d[0] = a ? (((argb >> 16) & 0xff) * 255 + a / 2) / a : 0; + d[1] = a ? (((argb >> 8) & 0xff) * 255 + a / 2) / a : 0; + d[2] = a ? ((argb & 0xff) * 255 + a / 2) / a : 0; + d[3] = a; + } + } + cairo_surface_destroy (surface); + } + + g_object_set (impl->shortcuts_eject_renderer, "pixbuf", pixbuf, NULL); + if (pixbuf) + g_object_unref (pixbuf); +} + +/* The volume of the selected place, if it is one */ +static GtkFileSystemVolume * +shortcuts_get_selected_volume (GtkFileChooserDefault *impl) +{ + GtkTreeIter iter; + gpointer col_data; + ShortcutType shortcut_type; + + if (!shortcuts_get_selected (impl, &iter)) + return NULL; + + gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter, + SHORTCUTS_COL_DATA, &col_data, + SHORTCUTS_COL_TYPE, &shortcut_type, + -1); + return shortcut_type == SHORTCUT_TYPE_VOLUME ? col_data : NULL; +} + +static void +unmount_shortcut_cb (GtkMenuItem *item, + GtkFileChooserDefault *impl) +{ + GtkFileSystemVolume *volume = shortcuts_get_selected_volume (impl); + + if (volume) + shortcuts_eject (impl, volume, FALSE); +} + +static void +eject_shortcut_cb (GtkMenuItem *item, + GtkFileChooserDefault *impl) +{ + GtkFileSystemVolume *volume = shortcuts_get_selected_volume (impl); + + if (volume) + shortcuts_eject (impl, volume, TRUE); +} + +/* A click on the eject button of a place: TRUE when it was there */ +static gboolean +shortcuts_eject_button_press (GtkFileChooserDefault *impl, + GdkEventButton *event) +{ + GtkTreeView *tree_view = GTK_TREE_VIEW (impl->browse_shortcuts_tree_view); + GtkTreeModel *model = gtk_tree_view_get_model (tree_view); + GtkTreeViewColumn *column; + GtkTreePath *path; + GtkTreeIter iter; + gpointer col_data; + ShortcutType shortcut_type; + gboolean eject_visible; + gint cell_x, start, width; + + if (event->type != GDK_BUTTON_PRESS || event->button != 1 || + event->window != gtk_tree_view_get_bin_window (tree_view) || + impl->shortcuts_eject_renderer == NULL || + !gtk_tree_view_get_path_at_pos (tree_view, event->x, event->y, &path, &column, &cell_x, NULL)) + return FALSE; + + if (!gtk_tree_model_get_iter (model, &iter, path)) + { + gtk_tree_path_free (path); + return FALSE; + } + gtk_tree_path_free (path); + + gtk_tree_model_get (model, &iter, + SHORTCUTS_COL_DATA, &col_data, + SHORTCUTS_COL_TYPE, &shortcut_type, + SHORTCUTS_COL_EJECT, &eject_visible, + -1); + if (shortcut_type != SHORTCUT_TYPE_VOLUME || !eject_visible) + return FALSE; + + /* where the button is drawn on this row */ + gtk_tree_view_column_cell_set_cell_data (column, model, &iter, FALSE, FALSE); + if (!gtk_tree_view_column_cell_get_position (column, impl->shortcuts_eject_renderer, &start, &width) || + cell_x < start || cell_x >= start + width) + return FALSE; + + shortcuts_eject (impl, col_data, + volume_can (col_data, TRUE) ? TRUE : FALSE); + return TRUE; +} + +/* The free space of places, in their tooltips: asked for when the tooltip + * wants it, without waiting; the tooltip comes again with it */ + +#define PLACE_SPACE_SECONDS 5 + +static void +place_space_received (GObject *source, + GAsyncResult *result, + gpointer user_data) +{ + GtkFileChooserDefault *impl = user_data; + GFileInfo *info; + GError *error = NULL; + + info = g_file_query_filesystem_info_finish (G_FILE (source), result, &error); + + GDK_THREADS_ENTER (); + + if (impl->place_space_file && g_file_equal (G_FILE (source), impl->place_space_file)) + { + g_free (impl->place_space_text); + impl->place_space_text = NULL; + if (info && + g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_FILESYSTEM_FREE) && + g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_FILESYSTEM_SIZE) && + g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_FILESYSTEM_SIZE) > 0) + { + gchar *free_text = g_format_size (g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_FILESYSTEM_FREE)); + gchar *size_text = g_format_size (g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_FILESYSTEM_SIZE)); + + /* Translators: "12.3 GB free of 100.0 GB" */ + impl->place_space_text = g_strdup_printf (_("%s free of %s"), free_text, size_text); + g_free (free_text); + g_free (size_text); + } + else + impl->place_space_text = g_strdup (""); + impl->place_space_time = g_get_monotonic_time (); + if (impl->browse_shortcuts_tree_view) + gtk_widget_trigger_tooltip_query (impl->browse_shortcuts_tree_view); + } + + GDK_THREADS_LEAVE (); + + if (info) + g_object_unref (info); + g_clear_error (&error); + g_object_unref (impl); +} + +/* The free space on the file system of @root, as text, or NULL when it + * is not known yet */ +static const gchar * +place_space (GtkFileChooserDefault *impl, + GFile *root) +{ + if (impl->place_space_file && g_file_equal (root, impl->place_space_file) && + impl->place_space_text && + g_get_monotonic_time () - impl->place_space_time < PLACE_SPACE_SECONDS * G_USEC_PER_SEC) + return impl->place_space_text; + + if (impl->place_space_file && g_file_equal (root, impl->place_space_file) && + impl->place_space_text == NULL) + return NULL; /* asked already */ + + g_clear_object (&impl->place_space_file); + g_free (impl->place_space_text); + impl->place_space_text = NULL; + impl->place_space_file = g_object_ref (root); + g_file_query_filesystem_info_async (root, + G_FILE_ATTRIBUTE_FILESYSTEM_FREE "," + G_FILE_ATTRIBUTE_FILESYSTEM_SIZE, + G_PRIORITY_DEFAULT, NULL, + place_space_received, g_object_ref (impl)); + return NULL; +} + +/* The tooltip of a place: where it is, and the space that is free */ +static void +place_tooltip (GtkFileChooserDefault *impl, + GtkTooltip *tooltip, + const gchar *where, + GFile *root) +{ + const gchar *space = root ? place_space (impl, root) : NULL; + + if (space && *space) + { + gchar *text = g_strconcat (where, "\n", space, NULL); + + gtk_tooltip_set_text (tooltip, text); + g_free (text); + } + else + gtk_tooltip_set_text (tooltip, where); +} + /* Callback used to display a tooltip in the shortcuts tree */ static gboolean shortcuts_query_tooltip_cb (GtkWidget *widget, @@ -3506,7 +5273,24 @@ shortcuts_query_tooltip_cb (GtkWidget *widget, if (shortcut_type == SHORTCUT_TYPE_SEPARATOR) return FALSE; else if (shortcut_type == SHORTCUT_TYPE_VOLUME) - return FALSE; + { + GtkFileSystemVolume *volume = col_data; + gchar *name; + GFile *root; + + if (!_gtk_file_system_volume_is_mounted (volume)) + return FALSE; + + /* where it is mounted, and the space that is free */ + root = _gtk_file_system_volume_get_root (volume); + if (root == NULL) + return FALSE; + name = g_file_get_parse_name (root); + place_tooltip (impl, tooltip, name, root); + g_free (name); + g_object_unref (root); + return TRUE; + } else if (shortcut_type == SHORTCUT_TYPE_FILE) { GFile *file; @@ -3515,7 +5299,8 @@ shortcuts_query_tooltip_cb (GtkWidget *widget, file = G_FILE (col_data); parse_name = g_file_get_parse_name (file); - gtk_tooltip_set_text (tooltip, parse_name); + /* asking a server for its space could ask for a password */ + place_tooltip (impl, tooltip, parse_name, g_file_is_native (file) ? file : NULL); g_free (parse_name); @@ -3613,6 +5398,8 @@ shortcuts_popup_menu_detach_cb (GtkWidget *attach_widget, impl->browse_shortcuts_popup_menu = NULL; impl->browse_shortcuts_popup_menu_remove_item = NULL; impl->browse_shortcuts_popup_menu_rename_item = NULL; + impl->browse_shortcuts_popup_menu_unmount_item = NULL; + impl->browse_shortcuts_popup_menu_eject_item = NULL; } static void @@ -3683,6 +5470,18 @@ shortcuts_build_popup_menu (GtkFileChooserDefault *impl) gtk_widget_show (item); gtk_menu_shell_append (GTK_MENU_SHELL (impl->browse_shortcuts_popup_menu), item); + item = gtk_menu_item_new_with_mnemonic (_("_Unmount")); + impl->browse_shortcuts_popup_menu_unmount_item = item; + g_signal_connect (item, "activate", + G_CALLBACK (unmount_shortcut_cb), impl); + gtk_menu_shell_append (GTK_MENU_SHELL (impl->browse_shortcuts_popup_menu), item); + + item = gtk_menu_item_new_with_mnemonic (_("_Eject")); + impl->browse_shortcuts_popup_menu_eject_item = item; + g_signal_connect (item, "activate", + G_CALLBACK (eject_shortcut_cb), impl); + gtk_menu_shell_append (GTK_MENU_SHELL (impl->browse_shortcuts_popup_menu), item); + item = gtk_separator_menu_item_new (); gtk_widget_show (item); gtk_menu_shell_append (GTK_MENU_SHELL (impl->browse_shortcuts_popup_menu), item); @@ -3745,6 +5544,9 @@ shortcuts_button_press_event_cb (GtkWidget *widget, if (in_press) return FALSE; + if (shortcuts_eject_button_press (impl, event)) + return TRUE; + if (!_gtk_button_event_triggers_context_menu (event)) return FALSE; @@ -3840,6 +5642,8 @@ shortcuts_list_create (GtkFileChooserDefault *impl) g_signal_connect (impl->browse_shortcuts_tree_view, "popup-menu", G_CALLBACK (shortcuts_popup_menu_cb), impl); + g_signal_connect (impl->browse_shortcuts_tree_view, "button-press-event", + G_CALLBACK (history_button_press_cb), impl); g_signal_connect (impl->browse_shortcuts_tree_view, "button-press-event", G_CALLBACK (shortcuts_button_press_event_cb), impl); /* Accessible object name for the file chooser's shortcuts pane */ @@ -3854,10 +5658,10 @@ shortcuts_list_create (GtkFileChooserDefault *impl) GDK_ACTION_MOVE); gtk_drag_dest_set (impl->browse_shortcuts_tree_view, - GTK_DEST_DEFAULT_ALL, + GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_HIGHLIGHT, tree_model_row_targets, G_N_ELEMENTS (tree_model_row_targets), - GDK_ACTION_COPY | GDK_ACTION_MOVE); + GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK | GDK_ACTION_ASK); gtk_drag_dest_add_uri_targets (impl->browse_shortcuts_tree_view); selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_shortcuts_tree_view)); @@ -3923,6 +5727,18 @@ shortcuts_list_create (GtkFileChooserDefault *impl) "text", SHORTCUTS_COL_NAME, NULL); + /* the eject button of drives and mounts */ + renderer = gtk_cell_renderer_pixbuf_new (); + g_object_set (renderer, "xpad", 3, NULL); + gtk_tree_view_column_pack_end (column, renderer, FALSE); + gtk_tree_view_column_set_attributes (column, renderer, + "visible", SHORTCUTS_COL_EJECT, + NULL); + impl->shortcuts_eject_renderer = renderer; + shortcuts_eject_icon_update (impl); + g_signal_connect_swapped (impl->browse_shortcuts_tree_view, "style-set", + G_CALLBACK (shortcuts_eject_icon_update), impl); + gtk_tree_view_set_row_separator_func (GTK_TREE_VIEW (impl->browse_shortcuts_tree_view), shortcuts_row_separator_func, NULL, NULL); @@ -4035,6 +5851,51 @@ browse_files_key_press_event_cb (GtkWidget *widget, return TRUE; } + if (event->keyval == GDK_KEY_F2 && + !(event->state & gtk_accelerator_get_default_mod_mask ())) + { + rename_selected_file (impl); + return TRUE; + } + + /* Ctrl+X, Ctrl+C and Ctrl+V, on the Mac with Command */ +#ifdef GDK_WINDOWING_QUARTZ + if ((event->state & (gtk_accelerator_get_default_mod_mask () | GDK_MOD2_MASK)) == GDK_MOD2_MASK) +#else + if ((event->state & gtk_accelerator_get_default_mod_mask ()) == GDK_CONTROL_MASK) +#endif + switch (event->keyval) + { + case GDK_KEY_c: + case GDK_KEY_C: + copy_files (impl); + return TRUE; + case GDK_KEY_x: + case GDK_KEY_X: + if (impl->operation_mode == OPERATION_MODE_BROWSE) + cut_files (impl); + return TRUE; + case GDK_KEY_v: + case GDK_KEY_V: + paste_files (impl); + return TRUE; + default: + break; + } + + if ((((event->keyval == GDK_KEY_Delete || event->keyval == GDK_KEY_KP_Delete) && + !(event->state & gtk_accelerator_get_default_mod_mask ())) +#ifdef GDK_WINDOWING_QUARTZ + /* Command+Backspace, as in the Finder */ + || (event->keyval == GDK_KEY_BackSpace && + (event->state & (gtk_accelerator_get_default_mod_mask () | GDK_MOD2_MASK)) == GDK_MOD2_MASK) +#endif + ) && impl->operation_mode == OPERATION_MODE_BROWSE) + { + trash_selected_files (impl); + return TRUE; + } + if ((event->keyval == GDK_KEY_Return || event->keyval == GDK_KEY_ISO_Enter || event->keyval == GDK_KEY_KP_Enter @@ -4079,8 +5940,39 @@ popup_menu_detach_cb (GtkWidget *attach_widget, impl->browse_files_popup_menu = NULL; impl->browse_files_popup_menu_add_shortcut_item = NULL; + impl->browse_files_popup_menu_cut_item = NULL; + impl->browse_files_popup_menu_copy_item = NULL; + impl->browse_files_popup_menu_paste_item = NULL; + impl->browse_files_popup_menu_paste_into_item = NULL; impl->browse_files_popup_menu_copy_location_item = NULL; + impl->browse_files_popup_menu_undo_item = NULL; + impl->browse_files_popup_menu_redo_item = NULL; + impl->browse_files_popup_menu_rename_item = NULL; + impl->browse_files_popup_menu_trash_item = NULL; + impl->browse_files_popup_menu_visit_item = NULL; impl->browse_files_popup_menu_hidden_files_item = NULL; + impl->browse_files_popup_menu_thumbnails_item = NULL; + impl->browse_files_popup_menu_preview_item = NULL; + impl->browse_files_popup_menu_size_column_item = NULL; + impl->browse_files_popup_menu_type_column_item = NULL; + impl->browse_files_popup_menu_sort_by_name_item = NULL; + impl->browse_files_popup_menu_sort_by_size_item = NULL; + impl->browse_files_popup_menu_sort_by_mtime_item = NULL; + impl->browse_files_popup_menu_sort_by_type_item = NULL; +} + +/* "Visit File": a file found by searching, or a recent one, in its folder */ +static void +visit_file_cb (GtkMenuItem *item, + GtkFileChooserDefault *impl) +{ + GFile *file = get_selected_file (impl); + + if (file) + { + gtk_file_chooser_select_file (GTK_FILE_CHOOSER (impl), file, NULL); + g_object_unref (file); + } } /* Callback used when the "Add to Bookmarks" menu item is activated */ @@ -4149,6 +6041,239 @@ show_hidden_toggled_cb (GtkCheckMenuItem *item, NULL); } +static void thumbnails_reload (GtkFileChooserDefault *impl); + +/* Callback used when the "Show Thumbnails" menu item is toggled */ +static void +show_thumbnails_toggled_cb (GtkCheckMenuItem *item, + GtkFileChooserDefault *impl) +{ + impl->show_thumbnails = gtk_check_menu_item_get_active (item); + thumbnails_reload (impl); + preview_panel_queue_update (impl); +} + +/* Callback used when the "Show Preview" menu item is toggled */ +static void +show_preview_panel_toggled_cb (GtkCheckMenuItem *item, + GtkFileChooserDefault *impl) +{ + impl->show_preview_panel = gtk_check_menu_item_get_active (item); + preview_panel_sync (impl); +} + +/* The preferences of the file chooser, which all GTK+ 2 programs share: + * thumbnails, up to which size of the files, also on network shares, the + * preview, hidden files, and where to start. Changes take effect at + * once and are saved for the other programs. */ + +static void settings_save (GtkFileChooserDefault *impl); + +static void +preferences_thumbnails_toggled_cb (GtkToggleButton *button, + GtkFileChooserDefault *impl) +{ + GtkWidget *sizes = g_object_get_data (G_OBJECT (button), "gtk-sizes"); + + impl->show_thumbnails = gtk_toggle_button_get_active (button); + gtk_widget_set_sensitive (sizes, impl->show_thumbnails); + thumbnails_reload (impl); + preview_panel_queue_update (impl); + settings_save (impl); +} + +static gboolean +preferences_apply_cb (gpointer data) +{ + GtkFileChooserDefault *impl = data; + + impl->preferences_apply_id = 0; + thumbnails_reload (impl); + settings_save (impl); + + return FALSE; +} + +/* Applied when the value rests, not at each step of a held arrow */ +static void +preferences_size_changed_cb (GtkSpinButton *spin, + GtkFileChooserDefault *impl) +{ + gint megabytes = gtk_spin_button_get_value_as_int (spin); + + if (g_object_get_data (G_OBJECT (spin), "gtk-remote")) + impl->thumbnail_max_size_remote = megabytes; + else + impl->thumbnail_max_size = megabytes; + if (impl->preferences_apply_id) + g_source_remove (impl->preferences_apply_id); + impl->preferences_apply_id = gdk_threads_add_timeout (400, preferences_apply_cb, impl); +} + +static void +preferences_preview_toggled_cb (GtkToggleButton *button, + GtkFileChooserDefault *impl) +{ + impl->show_preview_panel = gtk_toggle_button_get_active (button); + preview_panel_sync (impl); + settings_save (impl); +} + +static void +preferences_hidden_toggled_cb (GtkToggleButton *button, + GtkFileChooserDefault *impl) +{ + gtk_file_chooser_set_show_hidden (GTK_FILE_CHOOSER (impl), + gtk_toggle_button_get_active (button)); + settings_save (impl); +} + +static void +preferences_start_toggled_cb (GtkToggleButton *button, + GtkFileChooserDefault *impl) +{ + if (!gtk_toggle_button_get_active (button)) + return; + impl->startup_mode = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (button), "gtk-mode")); + settings_save (impl); +} + +/* A heading in bold and what belongs to it below, indented */ +static GtkWidget * +preferences_section (GtkWidget *box, + const gchar *title) +{ + GtkWidget *label, *alignment, *content; + gchar *markup = g_markup_printf_escaped ("%s", title); + + label = gtk_label_new (NULL); + gtk_label_set_markup (GTK_LABEL (label), markup); + g_free (markup); + gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); + gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0); + + alignment = gtk_alignment_new (0.0, 0.0, 1.0, 1.0); + gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 0, 0, 12, 0); + content = gtk_vbox_new (FALSE, 6); + gtk_container_add (GTK_CONTAINER (alignment), content); + gtk_box_pack_start (GTK_BOX (box), alignment, FALSE, FALSE, 0); + + return content; +} + +static GtkWidget * +preferences_size_row (GtkFileChooserDefault *impl, + GtkSizeGroup *group, + const gchar *text, + gint megabytes, + gboolean remote) +{ + GtkWidget *row = gtk_hbox_new (FALSE, 6); + GtkWidget *label = gtk_label_new_with_mnemonic (text); + GtkWidget *spin = gtk_spin_button_new_with_range (0, 4096, 1); + + gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); + gtk_size_group_add_widget (group, label); + gtk_label_set_mnemonic_widget (GTK_LABEL (label), spin); + gtk_spin_button_set_value (GTK_SPIN_BUTTON (spin), megabytes); + if (remote) + { + g_object_set_data (G_OBJECT (spin), I_("gtk-remote"), GINT_TO_POINTER (TRUE)); + gtk_widget_set_tooltip_text (spin, _("Reading pictures over the network can be slow; 0 makes no thumbnails there")); + } + g_signal_connect (spin, "value-changed", G_CALLBACK (preferences_size_changed_cb), impl); + + gtk_box_pack_start (GTK_BOX (row), label, FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX (row), spin, FALSE, FALSE, 0); + /* Translators: the unit of the file sizes above, megabytes */ + gtk_box_pack_start (GTK_BOX (row), gtk_label_new (_("MB")), FALSE, FALSE, 0); + + return row; +} + +static void +preferences_cb (GtkMenuItem *item, + GtkFileChooserDefault *impl) +{ + GtkWidget *dialog, *box, *section, *button, *sizes, *radio; + GtkWindow *toplevel; + GtkSizeGroup *group; + + if (impl->preferences_dialog) + { + gtk_window_present (GTK_WINDOW (impl->preferences_dialog)); + return; + } + + toplevel = get_toplevel (GTK_WIDGET (impl)); + dialog = gtk_dialog_new_with_buttons (_("File Chooser Preferences"), + toplevel, + GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT | + GTK_DIALOG_NO_SEPARATOR, + GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE, + NULL); + impl->preferences_dialog = dialog; + g_signal_connect (dialog, "destroy", G_CALLBACK (gtk_widget_destroyed), &impl->preferences_dialog); + g_signal_connect (dialog, "response", G_CALLBACK (gtk_widget_destroy), NULL); + gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE); + + box = gtk_vbox_new (FALSE, 6); + gtk_container_set_border_width (GTK_CONTAINER (box), 12); + gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))), box, TRUE, TRUE, 0); + + /* Thumbnails */ + section = preferences_section (box, _("Thumbnails")); + button = gtk_check_button_new_with_mnemonic (_("Show _thumbnails of pictures")); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), impl->show_thumbnails); + gtk_box_pack_start (GTK_BOX (section), button, FALSE, FALSE, 0); + + group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL); + sizes = gtk_vbox_new (FALSE, 6); + gtk_box_pack_start (GTK_BOX (sizes), + preferences_size_row (impl, group, _("Of _local files up to"), + impl->thumbnail_max_size, FALSE), + FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX (sizes), + preferences_size_row (impl, group, _("Of files on _network shares up to"), + impl->thumbnail_max_size_remote, TRUE), + FALSE, FALSE, 0); + g_object_unref (group); + gtk_widget_set_sensitive (sizes, impl->show_thumbnails); + gtk_box_pack_start (GTK_BOX (section), sizes, FALSE, FALSE, 0); + g_object_set_data (G_OBJECT (button), I_("gtk-sizes"), sizes); + g_signal_connect (button, "toggled", G_CALLBACK (preferences_thumbnails_toggled_cb), impl); + + /* The list */ + section = preferences_section (box, _("Files")); + button = gtk_check_button_new_with_mnemonic (_("Show the _preview beside the files")); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), impl->show_preview_panel); + /* not beside the preview of the program */ + gtk_widget_set_sensitive (button, impl->preview_widget == NULL); + g_signal_connect (button, "toggled", G_CALLBACK (preferences_preview_toggled_cb), impl); + gtk_box_pack_start (GTK_BOX (section), button, FALSE, FALSE, 0); + + button = gtk_check_button_new_with_mnemonic (_("Show _hidden files")); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), impl->show_hidden); + g_signal_connect (button, "toggled", G_CALLBACK (preferences_hidden_toggled_cb), impl); + gtk_box_pack_start (GTK_BOX (section), button, FALSE, FALSE, 0); + + /* Where to start, unless the program says */ + section = preferences_section (box, _("Start With")); + radio = gtk_radio_button_new_with_mnemonic (NULL, _("_Recently used files")); + g_object_set_data (G_OBJECT (radio), I_("gtk-mode"), GINT_TO_POINTER (STARTUP_MODE_RECENT)); + gtk_box_pack_start (GTK_BOX (section), radio, FALSE, FALSE, 0); + button = gtk_radio_button_new_with_mnemonic_from_widget (GTK_RADIO_BUTTON (radio), + _("The _folder the program runs in")); + g_object_set_data (G_OBJECT (button), I_("gtk-mode"), GINT_TO_POINTER (STARTUP_MODE_CWD)); + gtk_box_pack_start (GTK_BOX (section), button, FALSE, FALSE, 0); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (impl->startup_mode == STARTUP_MODE_CWD ? button : radio), + TRUE); + g_signal_connect (radio, "toggled", G_CALLBACK (preferences_start_toggled_cb), impl); + g_signal_connect (button, "toggled", G_CALLBACK (preferences_start_toggled_cb), impl); + + gtk_widget_show_all (dialog); +} + /* Callback used when the "Show Size Column" menu item is toggled */ static void show_size_column_toggled_cb (GtkCheckMenuItem *item, @@ -4160,85 +6285,46 @@ show_size_column_toggled_cb (GtkCheckMenuItem *item, impl->show_size_column); } -/* Callback used when "Sort by Name" menu item is toggled */ +/* Callback used when the "Show Type Column" menu item is toggled */ static void -sort_by_name_toggled_cb (GtkCheckMenuItem *item, - GtkFileChooserDefault *impl) +show_type_column_toggled_cb (GtkCheckMenuItem *item, + GtkFileChooserDefault *impl) { - GtkCheckMenuItem *size_item = GTK_CHECK_MENU_ITEM (impl->browse_files_popup_menu_sort_by_size_item), - *mtime_item = GTK_CHECK_MENU_ITEM (impl->browse_files_popup_menu_sort_by_mtime_item); + impl->show_type_column = gtk_check_menu_item_get_active (item); - // This could be avoided if we used GtkAction's - if (!gtk_check_menu_item_get_active (item) && - !gtk_check_menu_item_get_active (size_item) && - !gtk_check_menu_item_get_active (mtime_item)) - { - gtk_check_menu_item_set_active (item, TRUE); - return; - } - - if (gtk_check_menu_item_get_active (item)) - { - gtk_check_menu_item_set_active (size_item, FALSE); - gtk_check_menu_item_set_active (mtime_item, FALSE); - - impl->sort_column = MODEL_COL_NAME; - set_sort_column (impl); - } + gtk_tree_view_column_set_visible (impl->list_type_column, + impl->show_type_column); } -/* Callback used when "Sort by Size" menu item is toggled */ +/* The "Sort by" items of the icon view are radio items: the one toggled on + * sorts by its column, the others go off; the last one stays on. */ static void -sort_by_size_toggled_cb (GtkCheckMenuItem *item, - GtkFileChooserDefault *impl) +sort_by_toggled_cb (GtkCheckMenuItem *item, + GtkFileChooserDefault *impl) { - GtkCheckMenuItem *name_item = GTK_CHECK_MENU_ITEM (impl->browse_files_popup_menu_sort_by_name_item), - *mtime_item = GTK_CHECK_MENU_ITEM (impl->browse_files_popup_menu_sort_by_mtime_item); + GtkWidget *items[4]; + gint i; - // This could be avoided if we used GtkAction's - if (!gtk_check_menu_item_get_active (item) && - !gtk_check_menu_item_get_active (name_item) && - !gtk_check_menu_item_get_active (mtime_item)) + items[0] = impl->browse_files_popup_menu_sort_by_name_item; + items[1] = impl->browse_files_popup_menu_sort_by_size_item; + items[2] = impl->browse_files_popup_menu_sort_by_mtime_item; + items[3] = impl->browse_files_popup_menu_sort_by_type_item; + + if (!gtk_check_menu_item_get_active (item)) { + for (i = 0; i < G_N_ELEMENTS (items); i++) + if (gtk_check_menu_item_get_active (GTK_CHECK_MENU_ITEM (items[i]))) + return; gtk_check_menu_item_set_active (item, TRUE); return; } - if (gtk_check_menu_item_get_active (item)) - { - gtk_check_menu_item_set_active (name_item, FALSE); - gtk_check_menu_item_set_active (mtime_item, FALSE); + for (i = 0; i < G_N_ELEMENTS (items); i++) + if (items[i] != GTK_WIDGET (item)) + gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (items[i]), FALSE); - impl->sort_column = MODEL_COL_SIZE; - set_sort_column (impl); - } -} - -/* Callback used when "Sort by Modification Date" menu item is toggled */ -static void -sort_by_mtime_toggled_cb (GtkCheckMenuItem *item, - GtkFileChooserDefault *impl) -{ - GtkCheckMenuItem *name_item = GTK_CHECK_MENU_ITEM (impl->browse_files_popup_menu_sort_by_name_item), - *size_item = GTK_CHECK_MENU_ITEM (impl->browse_files_popup_menu_sort_by_size_item); - - // This could be avoided if we used GtkAction's - if (!gtk_check_menu_item_get_active (item) && - !gtk_check_menu_item_get_active (name_item) && - !gtk_check_menu_item_get_active (size_item)) - { - gtk_check_menu_item_set_active (item, TRUE); - return; - } - - if (gtk_check_menu_item_get_active (item)) - { - gtk_check_menu_item_set_active (name_item, FALSE); - gtk_check_menu_item_set_active (size_item, FALSE); - - impl->sort_column = MODEL_COL_MTIME; - set_sort_column (impl); - } + impl->sort_column = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (item), "gtk-sort-column")); + set_sort_column (impl); } /* Callback used when "Ascending" menu item is toggled */ @@ -4387,6 +6473,1048 @@ out: g_object_unref (cancellable); } +/* What a drop on the list always did: the files are selected, a folder + * alone is opened. Takes @uris. */ +static void +dnd_select_uris (GtkFileChooserDefault *impl, + gchar **uris) +{ + struct FileListDragData *data; + + if (uris == NULL || uris[0] == NULL) + { + g_strfreev (uris); + return; + } + + data = g_new0 (struct FileListDragData, 1); + data->impl = g_object_ref (impl); + data->uris = uris; + data->file = g_file_new_for_uri (uris[0]); + + if (impl->file_list_drag_data_received_cancellable) + g_cancellable_cancel (impl->file_list_drag_data_received_cancellable); + + impl->file_list_drag_data_received_cancellable = + _gtk_file_system_get_info (impl->file_system, data->file, + "standard::type", + file_list_drag_data_received_get_info_cb, + data); +} + +/* Drag and drop of files, as in file managers. A drop on a folder (a + * row of the list, a place, a button of the path bar) copies or moves + * the files into it: within the file chooser a move on the same file + * system and a copy to another one, from other programs what they + * suggest; Ctrl copies, Shift moves, both make links (Option, Command + * and both on the Mac), and a source that asks gets a menu. A drop on + * the list itself selects the files, as the file chooser always did; + * with the keys they go into its folder. A drag that stays on a folder + * for a second opens it, and the list scrolls at its edges. Programs + * that give a file only once they know where it goes (XdndDirectSave: + * Firefox, Chromium, archive managers) write it into the folder. + * Copies and moves have progress and can be undone + * (gtkfileoperation.c). */ + +#define DND_HOVER_TIMEOUT 1000 +/* what the files of the list can be dragged for: links are no + * symbolic links on Windows */ +#ifdef G_OS_WIN32 +#define DRAG_SOURCE_ACTIONS (GDK_ACTION_COPY | GDK_ACTION_MOVE) +#else +#define DRAG_SOURCE_ACTIONS (GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK) +#endif +#define DND_SCROLL_EDGE 24 +#define XDS_TARGET "XdndDirectSave0" +#define XDS_TEXT_TARGET "text/plain" +#define XDS_DATA_TARGET "application/octet-stream" + +typedef enum +{ + DROP_NONE, + DROP_SELECT, + DROP_COPY, + DROP_MOVE, + DROP_LINK, + DROP_ASK +} DropAction; + +static void +dnd_highlight_button (GtkFileChooserDefault *impl, + GtkWidget *button) +{ + if (impl->dnd_highlighted == button) + return; + if (impl->dnd_highlighted) + { + gtk_drag_unhighlight (impl->dnd_highlighted); + g_object_remove_weak_pointer (G_OBJECT (impl->dnd_highlighted), + (gpointer *) &impl->dnd_highlighted); + } + impl->dnd_highlighted = button; + if (button) + { + gtk_drag_highlight (button); + g_object_add_weak_pointer (G_OBJECT (button), (gpointer *) &impl->dnd_highlighted); + } +} + +static gboolean dnd_hover_timeout (gpointer data); +static gboolean dnd_scroll_timeout (gpointer data); + +/* A folder to open when the drag stays on it; NULL for none */ +static void +dnd_hover (GtkFileChooserDefault *impl, + GFile *folder) +{ + if (folder && impl->dnd_hover_folder && g_file_equal (folder, impl->dnd_hover_folder)) + return; + + if (impl->dnd_hover_id) + { + g_source_remove (impl->dnd_hover_id); + impl->dnd_hover_id = 0; + } + g_clear_object (&impl->dnd_hover_folder); + + if (folder && !(impl->current_folder && g_file_equal (folder, impl->current_folder) && + impl->operation_mode == OPERATION_MODE_BROWSE)) + { + impl->dnd_hover_folder = g_object_ref (folder); + impl->dnd_hover_id = gdk_threads_add_timeout (DND_HOVER_TIMEOUT, dnd_hover_timeout, impl); + } +} + +static gboolean +dnd_hover_timeout (gpointer data) +{ + GtkFileChooserDefault *impl = data; + GFile *folder = impl->dnd_hover_folder; + + impl->dnd_hover_id = 0; + impl->dnd_hover_folder = NULL; + if (folder) + { + change_folder_and_display_error (impl, folder, FALSE); + g_object_unref (folder); + } + return FALSE; +} + +/* Scrolls the list while the drag is at its upper or lower edge */ +static void +dnd_autoscroll (GtkFileChooserDefault *impl, + GtkWidget *view, + gint y) +{ + gint step = 0; + + if (view) + { + gint height = view->allocation.height; + + if (GTK_IS_TREE_VIEW (view) && gtk_tree_view_get_headers_visible (GTK_TREE_VIEW (view))) + y -= TREE_VIEW_HEADER_HEIGHT (GTK_TREE_VIEW (view)); + if (y < DND_SCROLL_EDGE) + step = -1; + else if (y > height - DND_SCROLL_EDGE) + step = 1; + } + + impl->dnd_scroll_step = step; + impl->dnd_scroll_view = view; + if (step == 0 && impl->dnd_scroll_id) + { + g_source_remove (impl->dnd_scroll_id); + impl->dnd_scroll_id = 0; + } + else if (step != 0 && impl->dnd_scroll_id == 0) + impl->dnd_scroll_id = gdk_threads_add_timeout (50, dnd_scroll_timeout, impl); +} + +static gboolean +dnd_scroll_timeout (gpointer data) +{ + GtkFileChooserDefault *impl = data; + GtkAdjustment *adjustment; + gdouble value; + + if (impl->dnd_scroll_step == 0 || impl->browse_files_scrolled_window == NULL) + { + impl->dnd_scroll_id = 0; + return FALSE; + } + + adjustment = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (impl->browse_files_scrolled_window)); + value = gtk_adjustment_get_value (adjustment) + + impl->dnd_scroll_step * MAX (gtk_adjustment_get_step_increment (adjustment), 8.0) / 2; + gtk_adjustment_set_value (adjustment, + CLAMP (value, gtk_adjustment_get_lower (adjustment), + gtk_adjustment_get_upper (adjustment) - + gtk_adjustment_get_page_size (adjustment))); + return TRUE; +} + +/* The end of a drag over the file chooser: what shows it goes */ +static void +dnd_leave (GtkFileChooserDefault *impl) +{ + dnd_highlight_button (impl, NULL); + dnd_hover (impl, NULL); + dnd_autoscroll (impl, NULL, 0); + if (impl->browse_files_tree_view) + gtk_tree_view_set_drag_dest_row (GTK_TREE_VIEW (impl->browse_files_tree_view), + NULL, GTK_TREE_VIEW_DROP_BEFORE); + if (impl->browse_files_icon_view) + gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (impl->browse_files_icon_view), + NULL, GTK_ICON_VIEW_NO_DROP); +} + +/* The state of a drag, once it is over */ +static void +dnd_reset (GtkFileChooserDefault *impl) +{ + dnd_leave (impl); + g_clear_object (&impl->dnd_folder); + impl->dnd_action = DROP_NONE; + if (impl->dnd_filesystems) + { + g_hash_table_destroy (impl->dnd_filesystems); + impl->dnd_filesystems = NULL; + } +} + +static gboolean +dnd_own_drag (GtkFileChooserDefault *impl, + GdkDragContext *context) +{ + GtkWidget *source = gtk_drag_get_source_widget (context); + + return source != NULL && + (source == impl->browse_files_tree_view || source == impl->browse_files_icon_view); +} + +/* Whether the files of our own drag and @folder are on one file + * system, where a move is a rename; asked once per folder and drag, and + * only for local folders, which answer at once */ +static gboolean +dnd_same_filesystem (GtkFileChooserDefault *impl, + GFile *folder) +{ + GFile *files[2]; + const gchar *ids[2]; + gint i; + + if (impl->drag_uris == NULL || impl->drag_uris[0] == NULL) + return FALSE; + + if (impl->dnd_filesystems == NULL) + impl->dnd_filesystems = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); + + files[0] = g_file_new_for_uri (impl->drag_uris[0]); + files[1] = g_object_ref (folder); + for (i = 0; i < 2; i++) + { + gchar *uri = g_file_get_uri (files[i]); + gpointer id; + + if (!g_hash_table_lookup_extended (impl->dnd_filesystems, uri, NULL, &id)) + { + GFileInfo *info = NULL; + + if (g_file_is_native (files[i])) + info = g_file_query_info (files[i], G_FILE_ATTRIBUTE_ID_FILESYSTEM, + G_FILE_QUERY_INFO_NONE, NULL, NULL); + id = g_strdup (info ? g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_ID_FILESYSTEM) : NULL); + if (info) + g_object_unref (info); + g_hash_table_insert (impl->dnd_filesystems, g_strdup (uri), id); + } + ids[i] = id; + g_free (uri); + g_object_unref (files[i]); + } + + return ids[0] != NULL && g_strcmp0 (ids[0], ids[1]) == 0; +} + +/* Whether @folder is one of the files of our own drag (or in one) */ +static gboolean +dnd_folder_is_dragged (GtkFileChooserDefault *impl, + GFile *folder) +{ + gint i; + + for (i = 0; impl->drag_uris && impl->drag_uris[i]; i++) + { + GFile *file = g_file_new_for_uri (impl->drag_uris[i]); + gboolean inside = g_file_equal (file, folder) || g_file_has_prefix (folder, file); + + g_object_unref (file); + if (inside) + return TRUE; + } + return FALSE; +} + +/* What a drop on @folder does: @on_folder is FALSE for the list itself */ +static DropAction +dnd_choose (GtkFileChooserDefault *impl, + GtkWidget *widget, + GdkDragContext *context, + GFile *folder, + gboolean on_folder) +{ + GdkDragAction actions = gdk_drag_context_get_actions (context); + GdkDragAction suggested = gdk_drag_context_get_suggested_action (context); + GdkModifierType mods = 0; + gboolean own = dnd_own_drag (impl, context); +#ifdef GDK_WINDOWING_QUARTZ + const GdkModifierType copy_mask = GDK_MOD1_MASK, move_mask = GDK_MOD2_MASK; +#else + const GdkModifierType copy_mask = GDK_CONTROL_MASK, move_mask = GDK_SHIFT_MASK; +#endif +#ifdef G_OS_WIN32 + const gboolean can_link = FALSE; +#else + const gboolean can_link = TRUE; +#endif + + if (folder == NULL) + return DROP_NONE; + + /* the keys as they are now: other programs do not tell */ + gdk_window_get_pointer (gtk_widget_get_root_window (widget), NULL, NULL, &mods); + + if (own) + { + GFile *parent; + gboolean same_folder; + + if (dnd_folder_is_dragged (impl, folder)) + return DROP_NONE; + parent = impl->drag_uris && impl->drag_uris[0] ? g_file_new_for_uri (impl->drag_uris[0]) : NULL; + if (parent) + { + GFile *p = g_file_get_parent (parent); + + g_object_unref (parent); + parent = p; + } + same_folder = parent && g_file_equal (parent, folder); + if (parent) + g_object_unref (parent); + /* a move into the folder it is in does nothing; a copy is a copy */ + if (same_folder && !(mods & copy_mask)) + return DROP_NONE; + } + + if ((mods & copy_mask) && (mods & move_mask)) + return can_link ? DROP_LINK : DROP_COPY; + if (mods & copy_mask) + return DROP_COPY; + if (mods & move_mask) + return own || (actions & GDK_ACTION_MOVE) ? DROP_MOVE : DROP_COPY; + + if (suggested == GDK_ACTION_ASK) + return DROP_ASK; + + if (own) + return dnd_same_filesystem (impl, folder) ? DROP_MOVE : DROP_COPY; + + if (!on_folder) + return DROP_SELECT; + + if (suggested == GDK_ACTION_MOVE) + return DROP_MOVE; + if (suggested == GDK_ACTION_LINK && can_link) + return DROP_LINK; + return DROP_COPY; +} + +static GdkDragAction +dnd_drag_action (GdkDragContext *context, + DropAction action) +{ + GdkDragAction actions = gdk_drag_context_get_actions (context); + + switch (action) + { + case DROP_MOVE: + return GDK_ACTION_MOVE; + case DROP_LINK: + return GDK_ACTION_LINK; + case DROP_ASK: + return GDK_ACTION_ASK; + case DROP_NONE: + return 0; + default: + /* selecting takes nothing away, nor does copying */ + if (actions & GDK_ACTION_COPY) + return GDK_ACTION_COPY; + return gdk_drag_context_get_suggested_action (context); + } +} + +static gboolean +dnd_offers_text (GdkDragContext *context) +{ + GList *l; + + for (l = gdk_drag_context_list_targets (context); l; l = l->next) + if (gtk_targets_include_text ((GdkAtom *) &l->data, 1)) + return TRUE; + return FALSE; +} + +static gboolean +dnd_offers_uris (GdkDragContext *context) +{ + GList *l; + + for (l = gdk_drag_context_list_targets (context); l; l = l->next) + if (gtk_targets_include_uri ((GdkAtom *) &l->data, 1)) + return TRUE; + return FALSE; +} + +static gboolean +dnd_offers (GtkWidget *widget, + GdkDragContext *context, + const gchar *target) +{ + GdkAtom atom = gdk_atom_intern (target, FALSE); + GList *l; + + for (l = gdk_drag_context_list_targets (context); l; l = l->next) + if (GDK_POINTER_TO_ATOM (l->data) == atom) + return TRUE; + return FALSE; +} + +/* Files of some kind: a list of them, or one the source saves itself */ +static GdkAtom +dnd_files_target (GtkWidget *widget, + GdkDragContext *context) +{ + GList *l; + + for (l = gdk_drag_context_list_targets (context); l; l = l->next) + if (gtk_targets_include_uri ((GdkAtom *) &l->data, 1)) + return GDK_POINTER_TO_ATOM (l->data); + if (dnd_offers (widget, context, XDS_TARGET)) + return gdk_atom_intern_static_string (XDS_TARGET); + return GDK_NONE; +} + +/* Copies, moves or links @files into @folder */ +static void +dnd_start (GtkFileChooserDefault *impl, + DropAction action, + GList *files, + GFile *folder) +{ + GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (impl)); + GtkFileOperation *operation; + + if (files == NULL || folder == NULL) + return; + + operation = _gtk_file_operation_start (action == DROP_MOVE ? GTK_FILE_OPERATION_MOVE + : action == DROP_LINK ? GTK_FILE_OPERATION_LINK + : GTK_FILE_OPERATION_COPY, + files, folder, impl->file_operations_box, + GTK_IS_WINDOW (toplevel) ? GTK_WINDOW (toplevel) : NULL, + file_operation_done, impl); + if (operation) + impl->file_operations = g_slist_prepend (impl->file_operations, operation); +} + +static GList * +dnd_files_from_uris (gchar **uris) +{ + GList *files = NULL; + gint i; + + for (i = 0; uris && uris[i]; i++) + if (*uris[i] != '\0') + files = g_list_prepend (files, g_file_new_for_uri (uris[i])); + return g_list_reverse (files); +} + +/* The menu for a source that asks */ +typedef struct +{ + GtkFileChooserDefault *impl; + gchar **uris; + GFile *folder; +} DndAsk; + +static void +dnd_ask_free (DndAsk *ask) +{ + g_object_unref (ask->impl); + g_strfreev (ask->uris); + g_object_unref (ask->folder); + g_slice_free (DndAsk, ask); +} + +static void +dnd_ask_activate (GtkMenuItem *item, + DndAsk *ask) +{ + DropAction action = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (item), "gtk-drop-action")); + + if (action == DROP_SELECT) + { + dnd_select_uris (ask->impl, ask->uris); + ask->uris = NULL; + } + else + { + GList *files = dnd_files_from_uris (ask->uris); + + dnd_start (ask->impl, action, files, ask->folder); + g_list_free_full (files, g_object_unref); + } +} + +static void +dnd_ask (GtkFileChooserDefault *impl, + gchar **uris, + GFile *folder, + gboolean can_select, + guint32 time_) +{ + static const struct + { + DropAction action; + const gchar *label; + } items[] = { + { DROP_MOVE, N_("_Move Here") }, + { DROP_COPY, N_("_Copy Here") }, +#ifndef G_OS_WIN32 + { DROP_LINK, N_("_Link Here") }, +#endif + { DROP_SELECT, N_("_Select") } + }; + GtkWidget *menu, *item; + DndAsk *ask; + gint i; + + ask = g_slice_new0 (DndAsk); + ask->impl = g_object_ref (impl); + ask->uris = uris; + ask->folder = g_object_ref (folder); + + menu = gtk_menu_new (); + gtk_menu_set_screen (GTK_MENU (menu), gtk_widget_get_screen (GTK_WIDGET (impl))); + for (i = 0; i < G_N_ELEMENTS (items); i++) + { + if (items[i].action == DROP_SELECT) + { + if (!can_select) + continue; + item = gtk_separator_menu_item_new (); + gtk_widget_show (item); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); + } + item = gtk_menu_item_new_with_mnemonic (_(items[i].label)); + g_object_set_data (G_OBJECT (item), I_("gtk-drop-action"), GINT_TO_POINTER (items[i].action)); + g_signal_connect (item, "activate", G_CALLBACK (dnd_ask_activate), ask); + gtk_widget_show (item); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); + } + + item = gtk_separator_menu_item_new (); + gtk_widget_show (item); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); + item = gtk_image_menu_item_new_from_stock (GTK_STOCK_CANCEL, NULL); + gtk_widget_show (item); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); + + /* the menu goes when it is closed; its answer comes before that */ + g_object_set_data_full (G_OBJECT (menu), I_("gtk-drop-ask"), ask, (GDestroyNotify) dnd_ask_free); + g_signal_connect (menu, "deactivate", G_CALLBACK (gtk_widget_destroy), NULL); + g_object_ref_sink (menu); + gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL, 0, time_); + g_object_unref (menu); +} + +/* Directly saved files (XdndDirectSave): the source names the file, we + * say where it goes, the source writes it there (or hands it over) */ +static gboolean +dnd_xds_start (GtkFileChooserDefault *impl, + GtkWidget *widget, + GdkDragContext *context, + GFile *folder, + guint32 time_) +{ + GdkAtom property = gdk_atom_intern_static_string (XDS_TARGET); + GdkAtom text = gdk_atom_intern_static_string (XDS_TEXT_TARGET); + GdkWindow *source = gdk_drag_context_get_source_window (context); + GdkAtom type; + gint format, length; + guchar *data = NULL; + gchar *name, *basename, *filename, *uri; + + if (source == NULL || folder == NULL || + !gdk_property_get (source, property, text, 0, 4096, FALSE, + &type, &format, &length, &data) || + data == NULL || length <= 0 || format != 8) + { + g_free (data); + return FALSE; + } + + name = g_strndup ((const gchar *) data, length); + g_free (data); + /* a name, nothing that goes elsewhere */ + basename = g_path_get_basename (name); + g_free (name); + if (strcmp (basename, ".") == 0 || strcmp (basename, "..") == 0 || + strcmp (basename, G_DIR_SEPARATOR_S) == 0 || strchr (basename, '/') != NULL) + { + g_free (basename); + return FALSE; + } + + filename = g_utf8_validate (basename, -1, NULL) + ? g_filename_from_utf8 (basename, -1, NULL, NULL, NULL) : NULL; + if (filename == NULL) + filename = g_strdup (basename); + g_free (basename); + + g_clear_object (&impl->dnd_xds_file); + impl->dnd_xds_file = _gtk_file_operation_free_name (folder, filename); + g_free (filename); + if (impl->dnd_xds_file == NULL) + return FALSE; + + uri = g_file_get_uri (impl->dnd_xds_file); + gdk_property_change (source, property, text, 8, GDK_PROP_MODE_REPLACE, + (const guchar *) uri, strlen (uri)); + g_free (uri); + + gtk_drag_get_data (widget, context, property, time_); + return TRUE; +} + +/* The file the source saved: shown and selected */ +static void +dnd_xds_done (GtkFileChooserDefault *impl) +{ + GFile *parent = g_file_get_parent (impl->dnd_xds_file); + + if (parent && impl->current_folder && g_file_equal (parent, impl->current_folder) && + impl->browse_files_model) + { + rename_select_clear (impl); + impl->rename_select = g_object_ref (impl->dnd_xds_file); + if (rename_select_now (impl)) + rename_select_clear (impl); + else + { + impl->rename_select_model = g_object_ref (impl->browse_files_model); + impl->rename_select_handler = + g_signal_connect (impl->rename_select_model, "row-inserted", + G_CALLBACK (rename_row_inserted_cb), impl); + _gtk_file_system_model_add_and_query_file (impl->browse_files_model, + impl->dnd_xds_file, MODEL_ATTRIBUTES); + } + } + if (parent) + g_object_unref (parent); + g_clear_object (&impl->dnd_xds_file); +} + +/* After a drop: the data for it. Used by the list and the path bar. */ +static void +dnd_data_received (GtkFileChooserDefault *impl, + GtkWidget *widget, + GdkDragContext *context, + GtkSelectionData *selection_data, + guint time_) +{ + GdkAtom target = gtk_selection_data_get_target (selection_data); + const guchar *data = gtk_selection_data_get_data (selection_data); + gint length = gtk_selection_data_get_length (selection_data); + GFile *folder = impl->dnd_folder; + DropAction action = impl->dnd_action; + gboolean success = FALSE; + + if (target == gdk_atom_intern_static_string (XDS_TARGET)) + { + if (impl->dnd_xds_file && length == 1 && data[0] == 'S') + { + dnd_xds_done (impl); + success = TRUE; + } + else if (impl->dnd_xds_file && length == 1 && data[0] == 'F' && + dnd_offers (widget, context, XDS_DATA_TARGET)) + { + /* the source can not write there: it hands over the data */ + gtk_drag_get_data (widget, context, gdk_atom_intern_static_string (XDS_DATA_TARGET), time_); + return; + } + else if (impl->dnd_xds_file) + { + error_message (impl, _("The file could not be saved"), + _("The program it came from could not write it there.")); + g_clear_object (&impl->dnd_xds_file); + } + goto out; + } + + if (target == gdk_atom_intern_static_string (XDS_DATA_TARGET)) + { + GError *error = NULL; + + if (impl->dnd_xds_file && length >= 0 && + g_file_replace_contents (impl->dnd_xds_file, (const gchar *) data, length, + NULL, FALSE, G_FILE_CREATE_NONE, NULL, NULL, &error)) + { + dnd_xds_done (impl); + success = TRUE; + } + else if (impl->dnd_xds_file) + { + error_message (impl, _("The file could not be saved"), + error ? error->message : ""); + g_clear_error (&error); + g_clear_object (&impl->dnd_xds_file); + } + goto out; + } + + /* a list of files */ + { + gchar **uris = gtk_selection_data_get_uris (selection_data); + gboolean local = FALSE; + gint i; + + if (uris == NULL) + { + /* a path or a URI as text, from a program that has nothing else */ + gchar *text = (gchar *) gtk_selection_data_get_text (selection_data); + + if (text) + { + g_strstrip (text); + if (g_path_is_absolute (text) && strchr (text, '\n') == NULL) + { + GFile *file = g_file_new_for_path (text); + + uris = g_new0 (gchar *, 2); + uris[0] = g_file_get_uri (file); + g_object_unref (file); + } + else if (g_uri_parse_scheme (text) && strchr (text, '\n') == NULL) + { + uris = g_new0 (gchar *, 2); + uris[0] = g_strdup (text); + } + g_free (text); + } + } + + if (uris == NULL || uris[0] == NULL || folder == NULL || action == DROP_NONE) + { + g_strfreev (uris); + goto out; + } + + for (i = 0; uris[i]; i++) + { + GFile *file = g_file_new_for_uri (uris[i]); + + local = local || g_file_is_native (file); + g_object_unref (file); + } + + /* a picture of a web page and the like: the source saves it, if it + * can, as GIO might not get it from the web */ + if (!local && dnd_offers (widget, context, XDS_TARGET) && + dnd_xds_start (impl, widget, context, folder, time_)) + { + g_strfreev (uris); + return; + } + + switch (action) + { + case DROP_SELECT: + dnd_select_uris (impl, uris); + break; + case DROP_ASK: + dnd_ask (impl, uris, folder, widget != impl->browse_path_bar, time_); + break; + default: + { + GList *files = dnd_files_from_uris (uris); + + dnd_start (impl, action, files, folder); + g_list_free_full (files, g_object_unref); + g_strfreev (uris); + } + break; + } + success = TRUE; + } + + out: + /* nothing is deleted by the source: what was moved, we moved */ + gtk_drag_finish (context, success, FALSE, time_); + dnd_reset (impl); +} + +/* After a drop: asks for the files, as a list or saved by the source */ +static gboolean +dnd_drop (GtkFileChooserDefault *impl, + GtkWidget *widget, + GdkDragContext *context, + guint time_) +{ + GdkAtom target; + + dnd_leave (impl); + + if (impl->dnd_folder == NULL || impl->dnd_action == DROP_NONE) + { + gtk_drag_finish (context, FALSE, FALSE, time_); + dnd_reset (impl); + return TRUE; + } + + target = dnd_files_target (widget, context); + if (target == gdk_atom_intern_static_string (XDS_TARGET)) + { + if (!dnd_xds_start (impl, widget, context, impl->dnd_folder, time_)) + { + gtk_drag_finish (context, FALSE, FALSE, time_); + dnd_reset (impl); + } + return TRUE; + } + if (target == GDK_NONE && dnd_offers_text (context)) + target = gdk_atom_intern_static_string ("UTF8_STRING"); + if (target == GDK_NONE || !dnd_offers (widget, context, gdk_atom_name (target))) + target = gtk_drag_dest_find_target (widget, context, NULL); + if (target == GDK_NONE) + { + gtk_drag_finish (context, FALSE, FALSE, time_); + dnd_reset (impl); + return TRUE; + } + + gtk_drag_get_data (widget, context, target, time_); + return TRUE; +} + +/* What a drop on the folder of a place or of the path bar does */ +static gint +dnd_choose_for (GtkFileChooserDefault *impl, + GtkWidget *widget, + GdkDragContext *context, + GFile *folder) +{ + return dnd_choose (impl, widget, context, folder, TRUE); +} + +/* Sets what a drop now does */ +static void +dnd_set_state (GtkFileChooserDefault *impl, + GFile *folder, + gint action) +{ + if (folder != impl->dnd_folder) + { + if (folder) + g_object_ref (folder); + if (impl->dnd_folder) + g_object_unref (impl->dnd_folder); + impl->dnd_folder = folder; + } + impl->dnd_action = folder ? action : DROP_NONE; +} + +/* The same, and tells the source */ +static void +dnd_set (GtkFileChooserDefault *impl, + GdkDragContext *context, + GFile *folder, + gint action, + guint time_) +{ + dnd_set_state (impl, folder, action); + gdk_drag_status (context, dnd_drag_action (context, impl->dnd_action), time_); +} + +/* The folder of the row at @x, @y of the list, if that is one */ +static GFile * +file_list_folder_at (GtkFileChooserDefault *impl, + GtkWidget *view, + gint x, + gint y, + GtkTreePath **path) +{ + GtkTreeModel *model = impl->current_model; + GtkTreeIter iter; + GFile *file = NULL; + gboolean is_folder = FALSE; + + *path = NULL; + if (model == NULL) + return NULL; + + if (GTK_IS_TREE_VIEW (view)) + gtk_tree_view_get_dest_row_at_pos (GTK_TREE_VIEW (view), x, y, path, NULL); + else + gtk_icon_view_get_dest_item_at_pos (GTK_ICON_VIEW (view), x, y, path, NULL); + + if (*path == NULL || !gtk_tree_model_get_iter (model, &iter, *path)) + { + if (*path) + gtk_tree_path_free (*path); + *path = NULL; + return NULL; + } + + gtk_tree_model_get (model, &iter, + MODEL_COL_FILE, &file, + MODEL_COL_IS_FOLDER, &is_folder, + -1); + if (file && is_folder) + return file; + + if (file) + g_object_unref (file); + gtk_tree_path_free (*path); + *path = NULL; + return NULL; +} + +/* Where a drop on the list at @x, @y goes and what it does: the + * folder under it, or the one of the list; FALSE for nothing. @path is + * the row of the folder. */ +static DropAction +file_list_drop_at (GtkFileChooserDefault *impl, + GtkWidget *widget, + GdkDragContext *context, + gint x, + gint y, + GFile **folder_out, + GtkTreePath **path) +{ + GFile *folder; + gboolean on_folder; + DropAction action; + + folder = file_list_folder_at (impl, widget, x, y, path); + on_folder = folder != NULL; + if (!on_folder && impl->current_folder && impl->operation_mode == OPERATION_MODE_BROWSE) + folder = g_object_ref (impl->current_folder); + + action = dnd_choose (impl, widget, context, folder, on_folder); + /* in Recently Used and Search, the list itself only selects */ + if (!on_folder && impl->operation_mode != OPERATION_MODE_BROWSE) + action = DROP_SELECT; + if (!on_folder && action == DROP_SELECT && impl->current_folder) + { + if (folder == NULL) + folder = g_object_ref (impl->current_folder); + } + + *folder_out = folder; + return action; +} + +static gboolean +file_list_drag_motion_cb (GtkWidget *widget, + GdkDragContext *context, + gint x, + gint y, + guint time_, + GtkFileChooserDefault *impl) +{ + GtkTreePath *path; + GFile *folder; + gboolean on_folder; + DropAction action; + + g_signal_stop_emission_by_name (widget, "drag-motion"); + + if (dnd_files_target (widget, context) == GDK_NONE && !dnd_offers_text (context)) + { + gdk_drag_status (context, 0, time_); + return FALSE; + } + + dnd_autoscroll (impl, widget, y); + + action = file_list_drop_at (impl, widget, context, x, y, &folder, &path); + on_folder = path != NULL; + + if (on_folder && action != DROP_NONE) + { + if (GTK_IS_TREE_VIEW (widget)) + gtk_tree_view_set_drag_dest_row (GTK_TREE_VIEW (widget), path, GTK_TREE_VIEW_DROP_INTO_OR_AFTER); + else + gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget), path, GTK_ICON_VIEW_DROP_INTO); + } + else if (GTK_IS_TREE_VIEW (widget)) + gtk_tree_view_set_drag_dest_row (GTK_TREE_VIEW (widget), NULL, GTK_TREE_VIEW_DROP_BEFORE); + else + gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget), NULL, GTK_ICON_VIEW_NO_DROP); + + /* a drag that stays on a folder opens it */ + dnd_hover (impl, on_folder && dnd_files_target (widget, context) != GDK_NONE ? folder : NULL); + + dnd_set (impl, context, folder, action, time_); + + if (path) + gtk_tree_path_free (path); + if (folder) + g_object_unref (folder); + return TRUE; +} + +static void +file_list_drag_leave_cb (GtkWidget *widget, + GdkDragContext *context, + guint time_, + GtkFileChooserDefault *impl) +{ + g_signal_stop_emission_by_name (widget, "drag-leave"); + /* comes before a drop as well, which still wants the folder */ + dnd_leave (impl); +} + +static gboolean +file_list_drag_drop_cb (GtkWidget *widget, + GdkDragContext *context, + gint x, + gint y, + guint time_, + GtkFileChooserDefault *impl) +{ + GtkTreePath *path; + GFile *folder; + DropAction action; + + g_signal_stop_emission_by_name (widget, "drag-drop"); + + /* where it was dropped: files from Explorer come with no motion */ + action = file_list_drop_at (impl, widget, context, x, y, &folder, &path); + dnd_set_state (impl, folder, action); + if (path) + gtk_tree_path_free (path); + if (folder) + g_object_unref (folder); + + return dnd_drop (impl, widget, context, time_); +} + static void file_list_drag_data_received_cb (GtkWidget *widget, GdkDragContext *context, @@ -4397,72 +7525,90 @@ file_list_drag_data_received_cb (GtkWidget *widget, guint time_, gpointer data) { - GtkFileChooserDefault *impl; - gchar **uris; - char *uri; - GFile *file; - - impl = GTK_FILE_CHOOSER_DEFAULT (data); - - /* Allow only drags from other widgets; see bug #533891. */ - if (gtk_drag_get_source_widget (context) == widget) - { - g_signal_stop_emission_by_name (widget, "drag-data-received"); - return; - } - - /* Parse the text/uri-list string, navigate to the first one */ - uris = gtk_selection_data_get_uris (selection_data); - if (uris && uris[0]) - { - struct FileListDragData *data; - - uri = uris[0]; - file = g_file_new_for_uri (uri); - - data = g_new0 (struct FileListDragData, 1); - data->impl = g_object_ref (impl); - data->uris = uris; - data->file = file; - - if (impl->file_list_drag_data_received_cancellable) - g_cancellable_cancel (impl->file_list_drag_data_received_cancellable); - - impl->file_list_drag_data_received_cancellable = - _gtk_file_system_get_info (impl->file_system, file, - "standard::type", - file_list_drag_data_received_get_info_cb, - data); - } - g_signal_stop_emission_by_name (widget, "drag-data-received"); + dnd_data_received (GTK_FILE_CHOOSER_DEFAULT (data), widget, context, selection_data, time_); } -/* Don't do anything with the drag_drop signal */ +/* The folders of the path bar take drops as well */ static gboolean -file_list_drag_drop_cb (GtkWidget *widget, - GdkDragContext *context, - gint x, - gint y, - guint time_, - GtkFileChooserDefault *impl) +path_bar_drag_motion_cb (GtkWidget *widget, + GdkDragContext *context, + gint x, + gint y, + guint time_, + GtkFileChooserDefault *impl) { - g_signal_stop_emission_by_name (widget, "drag-drop"); + GtkWidget *button; + GFile *folder; + DropAction action; + + if (dnd_files_target (widget, context) == GDK_NONE) + { + gdk_drag_status (context, 0, time_); + return FALSE; + } + + folder = _gtk_path_bar_get_file_at (GTK_PATH_BAR (widget), x, y, &button); + action = dnd_choose (impl, widget, context, folder, TRUE); + dnd_highlight_button (impl, action != DROP_NONE ? button : NULL); + dnd_hover (impl, folder); + dnd_set (impl, context, folder, action, time_); return TRUE; } -/* Disable the normal tree drag motion handler, it makes it look like you're - dropping the dragged item onto a tree item */ -static gboolean -file_list_drag_motion_cb (GtkWidget *widget, - GdkDragContext *context, - gint x, - gint y, - guint time_, - GtkFileChooserDefault *impl) +static void +path_bar_drag_leave_cb (GtkWidget *widget, + GdkDragContext *context, + guint time_, + GtkFileChooserDefault *impl) { - g_signal_stop_emission_by_name (widget, "drag-motion"); - return TRUE; + dnd_leave (impl); +} + +static gboolean +path_bar_drag_drop_cb (GtkWidget *widget, + GdkDragContext *context, + gint x, + gint y, + guint time_, + GtkFileChooserDefault *impl) +{ + GtkWidget *button; + GFile *folder = _gtk_path_bar_get_file_at (GTK_PATH_BAR (widget), x, y, &button); + + dnd_set_state (impl, folder, dnd_choose (impl, widget, context, folder, TRUE)); + return dnd_drop (impl, widget, context, time_); +} + +static void +path_bar_drag_data_received_cb (GtkWidget *widget, + GdkDragContext *context, + gint x, + gint y, + GtkSelectionData *selection_data, + guint info, + guint time_, + GtkFileChooserDefault *impl) +{ + dnd_data_received (impl, widget, context, selection_data, time_); +} + +/* The targets of drops of files: lists of files, files saved by the + * source (and their data), paths as text */ +static void +dnd_dest_set (GtkWidget *widget) +{ + GtkTargetList *list = gtk_target_list_new (NULL, 0); + + gtk_target_list_add_uri_targets (list, 0); + gtk_target_list_add (list, gdk_atom_intern_static_string (XDS_TARGET), 0, 0); + gtk_target_list_add_text_targets (list, 0); + /* only asked for after a source of XdndDirectSave says so */ + gtk_target_list_add (list, gdk_atom_intern_static_string (XDS_DATA_TARGET), 0, 0); + gtk_drag_dest_set (widget, 0, NULL, 0, + GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK | GDK_ACTION_ASK); + gtk_drag_dest_set_target_list (widget, list); + gtk_target_list_unref (list); } /* Constructs the popup menu for the file list if needed */ @@ -4479,6 +7625,14 @@ file_list_build_popup_menu (GtkFileChooserDefault *impl) impl->browse_files_current_view, popup_menu_detach_cb); + item = gtk_image_menu_item_new_with_mnemonic (_("_Visit File")); + impl->browse_files_popup_menu_visit_item = item; + gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), + gtk_image_new_from_stock (GTK_STOCK_DIRECTORY, GTK_ICON_SIZE_MENU)); + g_signal_connect (item, "activate", + G_CALLBACK (visit_file_cb), impl); + gtk_menu_shell_append (GTK_MENU_SHELL (impl->browse_files_popup_menu), item); + item = gtk_image_menu_item_new_with_mnemonic (_("_Add to Bookmarks")); impl->browse_files_popup_menu_add_shortcut_item = item; gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), @@ -4488,6 +7642,53 @@ file_list_build_popup_menu (GtkFileChooserDefault *impl) gtk_widget_show (item); gtk_menu_shell_append (GTK_MENU_SHELL (impl->browse_files_popup_menu), item); + item = gtk_menu_item_new_with_mnemonic (_("_Rename\342\200\246")); + impl->browse_files_popup_menu_rename_item = item; + g_signal_connect_swapped (item, "activate", + G_CALLBACK (rename_selected_file), impl); + gtk_widget_show (item); + gtk_menu_shell_append (GTK_MENU_SHELL (impl->browse_files_popup_menu), item); + + item = gtk_image_menu_item_new_with_mnemonic (_("Move to _Trash")); + impl->browse_files_popup_menu_trash_item = item; + gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), + gtk_image_new_from_icon_name ("user-trash", GTK_ICON_SIZE_MENU)); + g_signal_connect_swapped (item, "activate", + G_CALLBACK (trash_selected_files), impl); + gtk_widget_show (item); + gtk_menu_shell_append (GTK_MENU_SHELL (impl->browse_files_popup_menu), item); + + item = gtk_separator_menu_item_new (); + gtk_widget_show (item); + gtk_menu_shell_append (GTK_MENU_SHELL (impl->browse_files_popup_menu), item); + + item = gtk_image_menu_item_new_from_stock (GTK_STOCK_CUT, NULL); + impl->browse_files_popup_menu_cut_item = item; + g_signal_connect_swapped (item, "activate", + G_CALLBACK (cut_files), impl); + gtk_widget_show (item); + gtk_menu_shell_append (GTK_MENU_SHELL (impl->browse_files_popup_menu), item); + + item = gtk_image_menu_item_new_from_stock (GTK_STOCK_COPY, NULL); + impl->browse_files_popup_menu_copy_item = item; + g_signal_connect_swapped (item, "activate", + G_CALLBACK (copy_files), impl); + gtk_widget_show (item); + gtk_menu_shell_append (GTK_MENU_SHELL (impl->browse_files_popup_menu), item); + + item = gtk_image_menu_item_new_from_stock (GTK_STOCK_PASTE, NULL); + impl->browse_files_popup_menu_paste_item = item; + g_signal_connect_swapped (item, "activate", + G_CALLBACK (paste_files), impl); + gtk_widget_show (item); + gtk_menu_shell_append (GTK_MENU_SHELL (impl->browse_files_popup_menu), item); + + item = gtk_menu_item_new_with_mnemonic (_("Paste _Into Folder")); + impl->browse_files_popup_menu_paste_into_item = item; + g_signal_connect_swapped (item, "activate", + G_CALLBACK (paste_into_folder), impl); + gtk_menu_shell_append (GTK_MENU_SHELL (impl->browse_files_popup_menu), item); + item = gtk_image_menu_item_new_with_mnemonic (_("_Copy Location")); impl->browse_files_popup_menu_copy_location_item = item; gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), @@ -4501,6 +7702,26 @@ file_list_build_popup_menu (GtkFileChooserDefault *impl) gtk_widget_show (item); gtk_menu_shell_append (GTK_MENU_SHELL (impl->browse_files_popup_menu), item); + item = gtk_image_menu_item_new_with_mnemonic (_("_Undo")); + impl->browse_files_popup_menu_undo_item = item; + gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), + gtk_image_new_from_stock (GTK_STOCK_UNDO, GTK_ICON_SIZE_MENU)); + g_signal_connect_swapped (item, "activate", G_CALLBACK (undo_handler), impl); + gtk_widget_show (item); + gtk_menu_shell_append (GTK_MENU_SHELL (impl->browse_files_popup_menu), item); + + item = gtk_image_menu_item_new_with_mnemonic (_("_Redo")); + impl->browse_files_popup_menu_redo_item = item; + gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), + gtk_image_new_from_stock (GTK_STOCK_REDO, GTK_ICON_SIZE_MENU)); + g_signal_connect_swapped (item, "activate", G_CALLBACK (redo_handler), impl); + gtk_widget_show (item); + gtk_menu_shell_append (GTK_MENU_SHELL (impl->browse_files_popup_menu), item); + + item = gtk_separator_menu_item_new (); + gtk_widget_show (item); + gtk_menu_shell_append (GTK_MENU_SHELL (impl->browse_files_popup_menu), item); + item = gtk_check_menu_item_new_with_mnemonic (_("Show _Hidden Files")); impl->browse_files_popup_menu_hidden_files_item = item; g_signal_connect (item, "toggled", @@ -4508,6 +7729,25 @@ file_list_build_popup_menu (GtkFileChooserDefault *impl) gtk_widget_show (item); gtk_menu_shell_append (GTK_MENU_SHELL (impl->browse_files_popup_menu), item); + item = gtk_check_menu_item_new_with_mnemonic (_("Show _Thumbnails")); + impl->browse_files_popup_menu_thumbnails_item = item; + g_signal_connect (item, "toggled", + G_CALLBACK (show_thumbnails_toggled_cb), impl); + gtk_widget_show (item); + gtk_menu_shell_append (GTK_MENU_SHELL (impl->browse_files_popup_menu), item); + + item = gtk_check_menu_item_new_with_mnemonic (_("Show _Preview")); + impl->browse_files_popup_menu_preview_item = item; + g_signal_connect (item, "toggled", + G_CALLBACK (show_preview_panel_toggled_cb), impl); + gtk_widget_show (item); + gtk_menu_shell_append (GTK_MENU_SHELL (impl->browse_files_popup_menu), item); + + item = gtk_image_menu_item_new_from_stock (GTK_STOCK_PREFERENCES, NULL); + g_signal_connect (item, "activate", G_CALLBACK (preferences_cb), impl); + gtk_widget_show (item); + gtk_menu_shell_append (GTK_MENU_SHELL (impl->browse_files_popup_menu), item); + if (impl->view_mode == VIEW_MODE_LIST) { item = gtk_check_menu_item_new_with_mnemonic (_("Show _Size Column")); @@ -4516,6 +7756,13 @@ file_list_build_popup_menu (GtkFileChooserDefault *impl) G_CALLBACK (show_size_column_toggled_cb), impl); gtk_widget_show (item); gtk_menu_shell_append (GTK_MENU_SHELL (impl->browse_files_popup_menu), item); + + item = gtk_check_menu_item_new_with_mnemonic (_("Show T_ype Column")); + impl->browse_files_popup_menu_type_column_item = item; + g_signal_connect (item, "toggled", + G_CALLBACK (show_type_column_toggled_cb), impl); + gtk_widget_show (item); + gtk_menu_shell_append (GTK_MENU_SHELL (impl->browse_files_popup_menu), item); } else if (impl->view_mode == VIEW_MODE_ICON) { @@ -4528,24 +7775,36 @@ file_list_build_popup_menu (GtkFileChooserDefault *impl) subitem = gtk_check_menu_item_new_with_mnemonic (_("Sort by _Name")); impl->browse_files_popup_menu_sort_by_name_item = subitem; gtk_check_menu_item_set_draw_as_radio (GTK_CHECK_MENU_ITEM (subitem), TRUE); + g_object_set_data (G_OBJECT (subitem), I_("gtk-sort-column"), GINT_TO_POINTER (MODEL_COL_NAME)); g_signal_connect (subitem, "toggled", - G_CALLBACK (sort_by_name_toggled_cb), impl); + G_CALLBACK (sort_by_toggled_cb), impl); gtk_widget_show (subitem); gtk_menu_shell_append (GTK_MENU_SHELL (menu), subitem); subitem = gtk_check_menu_item_new_with_mnemonic (_("Sort by _Size")); impl->browse_files_popup_menu_sort_by_size_item = subitem; gtk_check_menu_item_set_draw_as_radio (GTK_CHECK_MENU_ITEM (subitem), TRUE); + g_object_set_data (G_OBJECT (subitem), I_("gtk-sort-column"), GINT_TO_POINTER (MODEL_COL_SIZE)); g_signal_connect (subitem, "toggled", - G_CALLBACK (sort_by_size_toggled_cb), impl); + G_CALLBACK (sort_by_toggled_cb), impl); gtk_widget_show (subitem); gtk_menu_shell_append (GTK_MENU_SHELL (menu), subitem); subitem = gtk_check_menu_item_new_with_mnemonic (_("Sort by Modification _Date")); impl->browse_files_popup_menu_sort_by_mtime_item = subitem; gtk_check_menu_item_set_draw_as_radio (GTK_CHECK_MENU_ITEM (subitem), TRUE); + g_object_set_data (G_OBJECT (subitem), I_("gtk-sort-column"), GINT_TO_POINTER (MODEL_COL_MTIME)); g_signal_connect (subitem, "toggled", - G_CALLBACK (sort_by_mtime_toggled_cb), impl); + G_CALLBACK (sort_by_toggled_cb), impl); + gtk_widget_show (subitem); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), subitem); + + subitem = gtk_check_menu_item_new_with_mnemonic (_("Sort by _Type")); + impl->browse_files_popup_menu_sort_by_type_item = subitem; + gtk_check_menu_item_set_draw_as_radio (GTK_CHECK_MENU_ITEM (subitem), TRUE); + g_object_set_data (G_OBJECT (subitem), I_("gtk-sort-column"), GINT_TO_POINTER (MODEL_COL_TYPE)); + g_signal_connect (subitem, "toggled", + G_CALLBACK (sort_by_toggled_cb), impl); gtk_widget_show (subitem); gtk_menu_shell_append (GTK_MENU_SHELL (menu), subitem); @@ -4582,16 +7841,31 @@ file_list_build_popup_menu (GtkFileChooserDefault *impl) static void file_list_update_popup_menu (GtkFileChooserDefault *impl) { + /* counted once: the icon view walks all its items for it */ + gint selected; + file_list_build_popup_menu (impl); + selected = current_selection_count_selected_rows (impl); + /* FIXME - handle OPERATION_MODE_SEARCH and OPERATION_MODE_RECENT */ /* The sensitivity of the Add to Bookmarks item is set in * bookmarks_check_add_sensitivity() */ + gtk_widget_set_visible (impl->browse_files_popup_menu_visit_item, + impl->operation_mode != OPERATION_MODE_BROWSE); + gtk_widget_set_sensitive (impl->browse_files_popup_menu_visit_item, + selected == 1); + gtk_widget_set_sensitive (impl->browse_files_popup_menu_rename_item, + impl->operation_mode == OPERATION_MODE_BROWSE && + selected == 1); + gtk_widget_set_sensitive (impl->browse_files_popup_menu_trash_item, + impl->operation_mode == OPERATION_MODE_BROWSE && + selected > 0); gtk_widget_set_sensitive (impl->browse_files_popup_menu_copy_location_item, - current_selection_count_selected_rows (impl) > 0); + selected > 0); /* 'Show Hidden Files' */ g_signal_handlers_block_by_func (impl->browse_files_popup_menu_hidden_files_item, @@ -4601,6 +7875,76 @@ file_list_update_popup_menu (GtkFileChooserDefault *impl) g_signal_handlers_unblock_by_func (impl->browse_files_popup_menu_hidden_files_item, G_CALLBACK (show_hidden_toggled_cb), impl); + /* 'Show Thumbnails' */ + g_signal_handlers_block_by_func (impl->browse_files_popup_menu_thumbnails_item, + G_CALLBACK (show_thumbnails_toggled_cb), impl); + gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (impl->browse_files_popup_menu_thumbnails_item), + impl->show_thumbnails); + g_signal_handlers_unblock_by_func (impl->browse_files_popup_menu_thumbnails_item, + G_CALLBACK (show_thumbnails_toggled_cb), impl); + + /* 'Cut', 'Copy', 'Paste': cut and paste only in the folders themselves */ + gtk_widget_set_sensitive (impl->browse_files_popup_menu_copy_item, + gtk_widget_get_sensitive (impl->browse_files_popup_menu_copy_location_item)); + gtk_widget_set_sensitive (impl->browse_files_popup_menu_cut_item, + impl->operation_mode == OPERATION_MODE_BROWSE && + gtk_widget_get_sensitive (impl->browse_files_popup_menu_copy_location_item)); + gtk_widget_set_visible (impl->browse_files_popup_menu_paste_item, + impl->operation_mode == OPERATION_MODE_BROWSE); + gtk_widget_set_sensitive (impl->browse_files_popup_menu_paste_item, FALSE); + if (impl->operation_mode == OPERATION_MODE_BROWSE) + gtk_clipboard_request_targets (gtk_widget_get_clipboard (GTK_WIDGET (impl), + GDK_SELECTION_CLIPBOARD), + paste_targets_received, + g_object_ref (impl->browse_files_popup_menu_paste_item)); + + /* 'Paste Into Folder', on one folder */ + { + gboolean one_folder = FALSE; + + if (impl->operation_mode == OPERATION_MODE_BROWSE && selected == 1) + { + GFile *file = get_selected_file (impl); + GtkTreeIter iter; + + if (file && impl->browse_files_model && + _gtk_file_system_model_get_iter_for_file (impl->browse_files_model, &iter, file)) + gtk_tree_model_get (GTK_TREE_MODEL (impl->browse_files_model), &iter, + MODEL_COL_IS_FOLDER, &one_folder, -1); + if (file) + g_object_unref (file); + } + gtk_widget_set_visible (impl->browse_files_popup_menu_paste_into_item, one_folder); + gtk_widget_set_sensitive (impl->browse_files_popup_menu_paste_into_item, FALSE); + if (one_folder) + gtk_clipboard_request_targets (gtk_widget_get_clipboard (GTK_WIDGET (impl), + GDK_SELECTION_CLIPBOARD), + paste_targets_received, + g_object_ref (impl->browse_files_popup_menu_paste_into_item)); + } + + /* 'Undo ...', 'Redo ...' */ + { + gboolean possible; + + gtk_menu_item_set_label (GTK_MENU_ITEM (impl->browse_files_popup_menu_undo_item), + _gtk_file_operation_undo_label (FALSE, &possible)); + gtk_widget_set_sensitive (impl->browse_files_popup_menu_undo_item, possible); + gtk_menu_item_set_label (GTK_MENU_ITEM (impl->browse_files_popup_menu_redo_item), + _gtk_file_operation_undo_label (TRUE, &possible)); + gtk_widget_set_sensitive (impl->browse_files_popup_menu_redo_item, possible); + } + + /* 'Show Preview', not beside the preview of the program */ + gtk_widget_set_visible (impl->browse_files_popup_menu_preview_item, + impl->preview_widget == NULL); + g_signal_handlers_block_by_func (impl->browse_files_popup_menu_preview_item, + G_CALLBACK (show_preview_panel_toggled_cb), impl); + gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (impl->browse_files_popup_menu_preview_item), + impl->show_preview_panel); + g_signal_handlers_unblock_by_func (impl->browse_files_popup_menu_preview_item, + G_CALLBACK (show_preview_panel_toggled_cb), impl); + if (impl->view_mode == VIEW_MODE_LIST) { /* 'Show Size Column' */ @@ -4610,6 +7954,14 @@ file_list_update_popup_menu (GtkFileChooserDefault *impl) impl->show_size_column); g_signal_handlers_unblock_by_func (impl->browse_files_popup_menu_size_column_item, G_CALLBACK (show_size_column_toggled_cb), impl); + + /* 'Show Type Column' */ + g_signal_handlers_block_by_func (impl->browse_files_popup_menu_type_column_item, + G_CALLBACK (show_type_column_toggled_cb), impl); + gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (impl->browse_files_popup_menu_type_column_item), + impl->show_type_column); + g_signal_handlers_unblock_by_func (impl->browse_files_popup_menu_type_column_item, + G_CALLBACK (show_type_column_toggled_cb), impl); } else if (impl->view_mode == VIEW_MODE_ICON) { @@ -4619,26 +7971,23 @@ file_list_update_popup_menu (GtkFileChooserDefault *impl) if (impl->current_model == GTK_TREE_MODEL (impl->recent_model)) gtk_tree_sortable_get_sort_column_id (GTK_TREE_SORTABLE (impl->current_model), &column, &order); - g_signal_handlers_block_by_func (impl->browse_files_popup_menu_sort_by_name_item, - G_CALLBACK (sort_by_name_toggled_cb), impl); - gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (impl->browse_files_popup_menu_sort_by_name_item), - column == MODEL_COL_NAME); - g_signal_handlers_unblock_by_func (impl->browse_files_popup_menu_sort_by_name_item, - G_CALLBACK (sort_by_name_toggled_cb), impl); + { + GtkWidget *items[4]; + gint i; - g_signal_handlers_block_by_func (impl->browse_files_popup_menu_sort_by_size_item, - G_CALLBACK (sort_by_size_toggled_cb), impl); - gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (impl->browse_files_popup_menu_sort_by_size_item), - column == MODEL_COL_SIZE); - g_signal_handlers_unblock_by_func (impl->browse_files_popup_menu_sort_by_size_item, - G_CALLBACK (sort_by_size_toggled_cb), impl); - - g_signal_handlers_block_by_func (impl->browse_files_popup_menu_sort_by_mtime_item, - G_CALLBACK (sort_by_mtime_toggled_cb), impl); - gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (impl->browse_files_popup_menu_sort_by_mtime_item), - column == MODEL_COL_MTIME); - g_signal_handlers_unblock_by_func (impl->browse_files_popup_menu_sort_by_mtime_item, - G_CALLBACK (sort_by_mtime_toggled_cb), impl); + items[0] = impl->browse_files_popup_menu_sort_by_name_item; + items[1] = impl->browse_files_popup_menu_sort_by_size_item; + items[2] = impl->browse_files_popup_menu_sort_by_mtime_item; + items[3] = impl->browse_files_popup_menu_sort_by_type_item; + for (i = 0; i < G_N_ELEMENTS (items); i++) + { + g_signal_handlers_block_by_func (items[i], G_CALLBACK (sort_by_toggled_cb), impl); + gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (items[i]), + column == GPOINTER_TO_INT (g_object_get_data (G_OBJECT (items[i]), + "gtk-sort-column"))); + g_signal_handlers_unblock_by_func (items[i], G_CALLBACK (sort_by_toggled_cb), impl); + } + } g_signal_handlers_block_by_func (impl->browse_files_popup_menu_sort_ascending_item, G_CALLBACK (sort_ascending_toggled_cb), impl); @@ -4767,6 +8116,229 @@ list_button_press_event_cb (GtkWidget *widget, return TRUE; } +/* Dragging several files, as in file managers: a press on one of the + * selected files keeps them all selected, so that they all go; a click + * without a drag then selects just that one. The views themselves + * would drop the others on the press already. */ + +static gboolean +file_list_button_press_drag_cb (GtkWidget *widget, + GdkEventButton *event, + GtkFileChooserDefault *impl) +{ + GtkTreePath *path = NULL; + GList *selected, *l; + gpointer selection; + + /* Command, which selects on the Mac, is not among the default ones */ + if (event->type != GDK_BUTTON_PRESS || event->button != 1 || + (event->state & (gtk_accelerator_get_default_mod_mask () | + GTK_MODIFY_SELECTION_MOD_MASK | GTK_EXTEND_SELECTION_MOD_MASK))) + return FALSE; + + /* A press on a file that is not selected drags that file, as in file + * managers; the list view would start a rubber band there, which + * still starts below the files. It is selected before the view sees + * the press. */ + if (GTK_IS_TREE_VIEW (widget) && impl->select_multiple && + event->window == gtk_tree_view_get_bin_window (GTK_TREE_VIEW (widget)) && + gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (widget), event->x, event->y, &path, NULL, NULL, NULL)) + { + GtkTreeSelection *tree_selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (widget)); + + if (!gtk_tree_selection_path_is_selected (tree_selection, path)) + { + gtk_tree_selection_unselect_all (tree_selection); + gtk_tree_selection_select_path (tree_selection, path); + } + gtk_tree_path_free (path); + path = NULL; + } + + if (current_selection_count_selected_rows (impl) < 2) + return FALSE; + + if (GTK_IS_TREE_VIEW (widget)) + { + GtkTreeView *tree_view = GTK_TREE_VIEW (widget); + + selection = gtk_tree_view_get_selection (tree_view); + if (event->window != gtk_tree_view_get_bin_window (tree_view) || + !gtk_tree_view_get_path_at_pos (tree_view, event->x, event->y, &path, NULL, NULL, NULL) || + !gtk_tree_selection_path_is_selected (selection, path)) + goto out; + selected = gtk_tree_selection_get_selected_rows (selection, NULL); + } + else + { + GtkIconView *icon_view = GTK_ICON_VIEW (widget); + + selection = icon_view; + if (event->window == widget->window || + !(path = gtk_icon_view_get_path_at_pos (icon_view, event->x, event->y)) || + !gtk_icon_view_path_is_selected (icon_view, path)) + goto out; + selected = gtk_icon_view_get_selected_items (icon_view); + } + + /* the view does its part, the press for a drag, the cursor, focus; + * then the selection is as it was, and nobody hears of the change */ + g_signal_handlers_block_by_func (selection, list_selection_changed, impl); + GTK_WIDGET_GET_CLASS (widget)->button_press_event (widget, event); + for (l = selected; l; l = l->next) + { + if (GTK_IS_TREE_VIEW (widget)) + gtk_tree_selection_select_path (selection, l->data); + else + gtk_icon_view_select_path (selection, l->data); + } + g_signal_handlers_unblock_by_func (selection, list_selection_changed, impl); + g_list_free_full (selected, (GDestroyNotify) gtk_tree_path_free); + check_preview_change (impl); + + /* rows may come meanwhile, while the folder loads */ + if (impl->drag_press_row) + gtk_tree_row_reference_free (impl->drag_press_row); + impl->drag_press_row = gtk_tree_row_reference_new (impl->current_model, path); + gtk_tree_path_free (path); + + return TRUE; + + out: + if (path) + gtk_tree_path_free (path); + return FALSE; +} + +static gboolean +file_list_button_release_drag_cb (GtkWidget *widget, + GdkEventButton *event, + GtkFileChooserDefault *impl) +{ + GtkTreePath *path; + + if (impl->drag_press_row == NULL || event->button != 1) + return FALSE; + + path = gtk_tree_row_reference_get_model (impl->drag_press_row) == impl->current_model ? + gtk_tree_row_reference_get_path (impl->drag_press_row) : NULL; + gtk_tree_row_reference_free (impl->drag_press_row); + impl->drag_press_row = NULL; + if (path == NULL) + return FALSE; + + current_selection_unselect_all (impl); + if (GTK_IS_TREE_VIEW (widget)) + gtk_tree_selection_select_path (gtk_tree_view_get_selection (GTK_TREE_VIEW (widget)), path); + else + gtk_icon_view_select_path (GTK_ICON_VIEW (widget), path); + gtk_tree_path_free (path); + + return FALSE; +} + +static void drag_uris_foreach (GtkTreeModel *model, GtkTreePath *path, + GtkTreeIter *iter, gpointer data); + +static void +file_list_drag_begin_cb (GtkWidget *widget, + GdkDragContext *context, + GtkFileChooserDefault *impl) +{ + GPtrArray *uris; + + /* what is dragged is kept: the drag can go into another folder, where + * nothing of it is selected */ + uris = g_ptr_array_new (); + current_selection_selected_foreach (impl, drag_uris_foreach, uris); + g_ptr_array_add (uris, NULL); + g_strfreev (impl->drag_uris); + impl->drag_uris = (gchar **) g_ptr_array_free (uris, FALSE); + + if (impl->drag_press_row) + { + gtk_tree_row_reference_free (impl->drag_press_row); + impl->drag_press_row = NULL; + impl->drag_several = TRUE; + gtk_drag_set_icon_stock (context, GTK_STOCK_DND_MULTIPLE, -2, -2); + } +} + +static void +file_list_drag_end_cb (GtkWidget *widget, + GdkDragContext *context, + GtkFileChooserDefault *impl) +{ + impl->drag_several = FALSE; + g_strfreev (impl->drag_uris); + impl->drag_uris = NULL; +} + +static void +drag_uris_foreach (GtkTreeModel *model, + GtkTreePath *path, + GtkTreeIter *iter, + gpointer data) +{ + GPtrArray *uris = data; + GFile *file; + + gtk_tree_model_get (model, iter, MODEL_COL_FILE, &file, -1); + if (file) + { + g_ptr_array_add (uris, g_file_get_uri (file)); + g_object_unref (file); + } +} + +/* after the view, which gives the one file under the pointer */ +static void +file_list_drag_data_get_cb (GtkWidget *widget, + GdkDragContext *context, + GtkSelectionData *selection_data, + guint info, + guint time_, + GtkFileChooserDefault *impl) +{ + GPtrArray *uris; + + if (impl->drag_uris && impl->drag_uris[0]) + { + gtk_selection_data_set_uris (selection_data, impl->drag_uris); + return; + } + + if (!impl->drag_several) + return; + + uris = g_ptr_array_new_with_free_func (g_free); + current_selection_selected_foreach (impl, drag_uris_foreach, uris); + g_ptr_array_add (uris, NULL); + gtk_selection_data_set_uris (selection_data, (gchar **) uris->pdata); + g_ptr_array_free (uris, TRUE); +} + +static void +file_list_drag_source_connect (GtkFileChooserDefault *impl, + GtkWidget *view) +{ + g_signal_connect (view, "button-press-event", + G_CALLBACK (file_list_button_press_drag_cb), impl); + g_signal_connect (view, "button-release-event", + G_CALLBACK (file_list_button_release_drag_cb), impl); + g_signal_connect_after (view, "drag-begin", + G_CALLBACK (file_list_drag_begin_cb), impl); + g_signal_connect (view, "drag-end", + G_CALLBACK (file_list_drag_end_cb), impl); + g_signal_connect_after (view, "drag-data-get", + G_CALLBACK (file_list_drag_data_get_cb), impl); +#ifdef GDK_WINDOWING_QUARTZ + /* files on the Mac are local ones: the Finder is given the names of + * all of them then (gtkdnd-quartz.c) */ + g_object_set_data (G_OBJECT (view), I_("gtk-drag-local-files"), GINT_TO_POINTER (TRUE)); +#endif +} + /* Sets the sort column IDs for the file list; needs to be done whenever we * change the model on the treeview. */ @@ -4778,9 +8350,104 @@ file_list_set_sort_column_ids (GtkFileChooserDefault *impl) gtk_tree_view_column_set_sort_column_id (impl->list_name_column, MODEL_COL_NAME); gtk_tree_view_column_set_sort_column_id (impl->list_mtime_column, MODEL_COL_MTIME); gtk_tree_view_column_set_sort_column_id (impl->list_size_column, MODEL_COL_SIZE); + gtk_tree_view_column_set_sort_column_id (impl->list_type_column, MODEL_COL_TYPE); } } +static PangoLayout *name_renderer_create_layout (GtkCellRenderer *cell, + GtkWidget *widget, + gint width); +static gint get_icon_view_item_width (GtkFileChooserDefault *impl); + +/* Whether the name of @file is cut short at @width; the answer for the + * last name is kept, as tooltips ask at every motion while shown */ +static gboolean +file_name_ellipsized (GtkFileChooserDefault *impl, + GtkWidget *view, + GFile *file, + const gchar *name, + gint width) +{ + PangoLayout *layout; + + if (impl->tooltip_file && g_file_equal (impl->tooltip_file, file) && + impl->tooltip_width == width) + return impl->tooltip_ellipsized; + + if (GTK_IS_ICON_VIEW (view)) + { + g_object_set (impl->list_name_renderer, "text", name, NULL); + layout = name_renderer_create_layout (GTK_CELL_RENDERER (impl->list_name_renderer), view, width); + } + else + { + layout = gtk_widget_create_pango_layout (view, name); + pango_layout_set_width (layout, MAX (width, 1) * PANGO_SCALE); + pango_layout_set_ellipsize (layout, PANGO_ELLIPSIZE_END); + } + + if (impl->tooltip_file) + g_object_unref (impl->tooltip_file); + impl->tooltip_file = g_object_ref (file); + impl->tooltip_width = width; + impl->tooltip_ellipsized = pango_layout_is_ellipsized (layout); + g_object_unref (layout); + + return impl->tooltip_ellipsized; +} + +/* Tooltips: in search and recent results, where the file is; elsewhere + * the name, if it is cut short */ +static gboolean +file_icon_view_query_tooltip_cb (GtkWidget *widget, + gint x, + gint y, + gboolean keyboard_tip, + GtkTooltip *tooltip, + gpointer user_data) +{ + GtkFileChooserDefault *impl = user_data; + GtkTreeModel *model; + GtkTreePath *path; + GtkTreeIter iter; + GFile *file; + gchar *name, *text = NULL; + + if (!gtk_icon_view_get_tooltip_context (GTK_ICON_VIEW (widget), &x, &y, keyboard_tip, + &model, &path, &iter)) + return FALSE; + + gtk_tree_model_get (model, &iter, MODEL_COL_FILE, &file, MODEL_COL_NAME, &name, -1); + + if (file && name) + { + gint width = get_icon_view_item_width (impl); + + /* in the compact view the name has what the icon leaves */ + if (impl->compact_view) + gtk_cell_renderer_get_fixed_size (GTK_CELL_RENDERER (impl->list_name_renderer), &width, NULL); + + if (impl->operation_mode != OPERATION_MODE_BROWSE) + text = g_file_get_parse_name (file); + else if (file_name_ellipsized (impl, widget, file, name, width)) + text = g_strdup (name); + } + + if (text) + { + gtk_tooltip_set_text (tooltip, text); + gtk_icon_view_set_tooltip_item (GTK_ICON_VIEW (widget), tooltip, path); + } + + g_free (text); + g_free (name); + if (file) + g_object_unref (file); + gtk_tree_path_free (path); + + return text != NULL; +} + static gboolean file_list_query_tooltip_cb (GtkWidget *widget, gint x, @@ -4794,11 +8461,7 @@ file_list_query_tooltip_cb (GtkWidget *widget, GtkTreePath *path; GtkTreeIter iter; GFile *file; - char *parse_name; - - if (impl->operation_mode == OPERATION_MODE_BROWSE) - return FALSE; - + gchar *name, *text = NULL; if (!gtk_tree_view_get_tooltip_context (GTK_TREE_VIEW (impl->browse_files_tree_view), &x, &y, @@ -4808,25 +8471,45 @@ file_list_query_tooltip_cb (GtkWidget *widget, gtk_tree_model_get (model, &iter, MODEL_COL_FILE, &file, + MODEL_COL_NAME, &name, -1); - if (file == NULL) + if (file && name) { - gtk_tree_path_free (path); - return FALSE; + if (impl->operation_mode != OPERATION_MODE_BROWSE) + text = g_file_get_parse_name (file); + else + { + gint start, width, xpad; + + if (gtk_tree_view_column_cell_get_position (impl->list_name_column, + GTK_CELL_RENDERER (impl->list_name_renderer), + &start, &width)) + { + gtk_cell_renderer_get_padding (GTK_CELL_RENDERER (impl->list_name_renderer), &xpad, NULL); + /* the column may be narrower than its cells want */ + width = MIN (width, gtk_tree_view_column_get_width (impl->list_name_column) - start); + if (file_name_ellipsized (impl, widget, file, name, width - 2 * xpad)) + text = g_strdup (name); + } + } } - parse_name = g_file_get_parse_name (file); - gtk_tooltip_set_text (tooltip, parse_name); - gtk_tree_view_set_tooltip_row (GTK_TREE_VIEW (impl->browse_files_tree_view), - tooltip, - path); + if (text) + { + gtk_tooltip_set_text (tooltip, text); + gtk_tree_view_set_tooltip_row (GTK_TREE_VIEW (impl->browse_files_tree_view), + tooltip, + path); + } - g_free (parse_name); - g_object_unref (file); + g_free (text); + g_free (name); + if (file) + g_object_unref (file); gtk_tree_path_free (path); - return TRUE; + return text != NULL; } static void @@ -4867,6 +8550,9 @@ get_icon_view_item_width (GtkFileChooserDefault *impl) gint xpad = 0; gint item_width; + if (impl->compact_view) + return COMPACT_VIEW_ITEM_WIDTH; + icon_size = impl->icon_view_icon_size; if (icon_size <= 0) icon_size = FALLBACK_ICON_VIEW_ICON_SIZE; @@ -4887,6 +8573,9 @@ get_icon_view_item_width (GtkFileChooserDefault *impl) return MAX (ICON_VIEW_ITEM_WIDTH, item_width); } +static void name_renderer_set_compact (GtkCellRenderer *cell, + gboolean compact); + static void update_icon_view_cell_layout (GtkFileChooserDefault *impl) { @@ -4902,6 +8591,39 @@ update_icon_view_cell_layout (GtkFileChooserDefault *impl) gtk_icon_view_set_item_width (GTK_ICON_VIEW (impl->browse_files_icon_view), item_width); + /* The compact view: the small icon of the list beside one line of name */ + gtk_icon_view_set_orientation (GTK_ICON_VIEW (impl->browse_files_icon_view), + impl->compact_view ? GTK_ORIENTATION_HORIZONTAL + : GTK_ORIENTATION_VERTICAL); + if (impl->list_name_renderer) + name_renderer_set_compact (GTK_CELL_RENDERER (impl->list_name_renderer), impl->compact_view); + if (impl->list_icon_renderer) + gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (impl->browse_files_icon_view), + impl->list_icon_renderer, + "pixbuf", impl->compact_view ? MODEL_COL_LIST_PIXBUF + : MODEL_COL_ICON_PIXBUF, + NULL); + if (impl->compact_view) + { + gint small = impl->list_view_icon_size > 0 ? impl->list_view_icon_size : FALLBACK_LIST_VIEW_ICON_SIZE; + + gtk_icon_view_set_spacing (GTK_ICON_VIEW (impl->browse_files_icon_view), 4); + gtk_icon_view_set_row_spacing (GTK_ICON_VIEW (impl->browse_files_icon_view), 0); + if (impl->list_icon_renderer) + { + gtk_cell_renderer_get_padding (impl->list_icon_renderer, &xpad, &ypad); + gtk_cell_renderer_set_fixed_size (impl->list_icon_renderer, + small + 2 * xpad, small + 2 * ypad); + if (impl->list_name_renderer) + gtk_cell_renderer_set_fixed_size (GTK_CELL_RENDERER (impl->list_name_renderer), + item_width - small - 2 * xpad - 4, -1); + } + return; + } + + gtk_icon_view_set_spacing (GTK_ICON_VIEW (impl->browse_files_icon_view), 0); + gtk_icon_view_set_row_spacing (GTK_ICON_VIEW (impl->browse_files_icon_view), 6); + icon_size = impl->icon_view_icon_size; if (icon_size <= 0) icon_size = FALLBACK_ICON_VIEW_ICON_SIZE; @@ -4931,11 +8653,7 @@ static char *my_g_format_time_for_display (gint64 secs); static gchar * file_list_format_size (goffset size) { -#if GLIB_CHECK_VERSION(2,30,0) return g_format_size (size); -#else - return g_format_size_for_display (size); -#endif } /* Widest pixel width of @texts rendered with @widget's font. */ @@ -5020,7 +8738,7 @@ file_list_update_fixed_sizing (GtkFileChooserDefault *impl) /* Date column: today, yesterday, every weekday and one date per month, * formatted exactly like the column does. */ texts = g_ptr_array_new_with_free_func (g_free); - now = g_date_time_new_now_local (); + now = _gtk_date_time_new_now_local (); now_secs = g_date_time_to_unix (now); for (i = 0; i < 7; i++) g_ptr_array_add (texts, my_g_format_time_for_display (now_secs - i * 24 * 3600)); @@ -5040,6 +8758,18 @@ file_list_update_fixed_sizing (GtkFileChooserDefault *impl) file_list_set_fixed_column_width (tree_view, impl->list_mtime_column, texts); g_ptr_array_free (texts, TRUE); + /* Type column: the kinds of files; descriptions and MIME types are + * longer and get the width of a long kind, the rest is ellipsized */ + texts = g_ptr_array_new_with_free_func (g_free); + for (i = 0; i < G_N_ELEMENTS (file_type_categories); i++) + g_ptr_array_add (texts, g_strdup (_(file_type_categories[i].display_name))); + g_ptr_array_add (texts, g_strdup (_("Folder"))); + g_ptr_array_add (texts, g_strdup (_("Unknown"))); + if (impl->type_format != TYPE_FORMAT_CATEGORY) + g_ptr_array_add (texts, g_strdup ("application/vnd.oasis.opendocument")); + file_list_set_fixed_column_width (tree_view, impl->list_type_column, texts); + g_ptr_array_free (texts, TRUE); + gtk_tree_view_column_set_sizing (impl->list_name_column, GTK_TREE_VIEW_COLUMN_FIXED); if (gtk_tree_view_column_get_fixed_width (impl->list_name_column) <= 0) gtk_tree_view_column_set_fixed_width (impl->list_name_column, 200); @@ -5075,11 +8805,9 @@ create_browse_files_tree_view (GtkFileChooserDefault *impl) gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (impl->browse_files_tree_view), TRUE); - gtk_drag_dest_set (impl->browse_files_tree_view, - GTK_DEST_DEFAULT_ALL, - NULL, 0, - GDK_ACTION_COPY | GDK_ACTION_MOVE); - gtk_drag_dest_add_uri_targets (impl->browse_files_tree_view); + dnd_dest_set (impl->browse_files_tree_view); + g_signal_connect (impl->browse_files_tree_view, "drag-leave", + G_CALLBACK (file_list_drag_leave_cb), impl); g_signal_connect (impl->browse_files_tree_view, "row-activated", G_CALLBACK (list_row_activated), impl); @@ -5087,6 +8815,8 @@ create_browse_files_tree_view (GtkFileChooserDefault *impl) G_CALLBACK (browse_files_key_press_event_cb), impl); g_signal_connect (impl->browse_files_tree_view, "popup-menu", G_CALLBACK (list_popup_menu_cb), impl); + g_signal_connect (impl->browse_files_tree_view, "button-press-event", + G_CALLBACK (history_button_press_cb), impl); g_signal_connect (impl->browse_files_tree_view, "button-press-event", G_CALLBACK (list_button_press_event_cb), impl); @@ -5108,8 +8838,9 @@ create_browse_files_tree_view (GtkFileChooserDefault *impl) gtk_tree_view_enable_model_drag_source (GTK_TREE_VIEW (impl->browse_files_tree_view), GDK_BUTTON1_MASK, NULL, 0, - GDK_ACTION_COPY | GDK_ACTION_MOVE); + DRAG_SOURCE_ACTIONS); gtk_drag_source_add_uri_targets (impl->browse_files_tree_view); + file_list_drag_source_connect (impl, impl->browse_files_tree_view); g_signal_connect (selection, "changed", G_CALLBACK (list_selection_changed), impl); @@ -5157,6 +8888,19 @@ create_browse_files_tree_view (GtkFileChooserDefault *impl) gtk_tree_view_append_column (GTK_TREE_VIEW (impl->browse_files_tree_view), column); impl->list_size_column = column; + /* Type column */ + + column = gtk_tree_view_column_new (); + gtk_tree_view_column_set_resizable (column, TRUE); + gtk_tree_view_column_set_title (column, _("Type")); + + renderer = gtk_cell_renderer_text_new (); + g_object_set (renderer, "ellipsize", PANGO_ELLIPSIZE_END, NULL); + gtk_tree_view_column_pack_start (column, renderer, TRUE); + gtk_tree_view_append_column (GTK_TREE_VIEW (impl->browse_files_tree_view), column); + gtk_tree_view_column_set_visible (column, impl->show_type_column); + impl->list_type_column = column; + /* Modification time column */ column = gtk_tree_view_column_new (); @@ -5193,6 +8937,7 @@ typedef struct GtkCellRendererText parent; GtkStyle *metrics_style; /* style line_height was computed for, not a reference */ gint line_height; + gint lines; /* NAME_RENDERER_LINES, or 1 in the compact view */ } NameRenderer; typedef GtkCellRendererTextClass NameRendererClass; @@ -5207,12 +8952,14 @@ name_renderer_create_layout (GtkCellRenderer *cell, { PangoLayout *layout; + gint lines = ((NameRenderer *) cell)->lines; + layout = gtk_widget_create_pango_layout (widget, GTK_CELL_RENDERER_TEXT (cell)->text); pango_layout_set_width (layout, MAX (width, 1) * PANGO_SCALE); pango_layout_set_wrap (layout, PANGO_WRAP_WORD_CHAR); - pango_layout_set_alignment (layout, PANGO_ALIGN_CENTER); + pango_layout_set_alignment (layout, lines > 1 ? PANGO_ALIGN_CENTER : PANGO_ALIGN_LEFT); pango_layout_set_ellipsize (layout, PANGO_ELLIPSIZE_END); - pango_layout_set_height (layout, -NAME_RENDERER_LINES); + pango_layout_set_height (layout, -lines); return layout; } @@ -5251,7 +8998,7 @@ name_renderer_get_size (GtkCellRenderer *cell, } if (height) - *height = 2 * cell->ypad + NAME_RENDERER_LINES * renderer->line_height; + *height = 2 * cell->ypad + renderer->lines * renderer->line_height; if (x_offset) *x_offset = 0; if (y_offset) @@ -5282,12 +9029,24 @@ name_renderer_render (GtkCellRenderer *cell, else state = gtk_widget_get_state (widget) == GTK_STATE_INSENSITIVE ? GTK_STATE_INSENSITIVE : GTK_STATE_NORMAL; - /* As wide as the item, like the wrap width a text renderer gets here. */ + /* As wide as the item, like the wrap width a text renderer gets here; + * a single line stands in the middle of its height */ layout = name_renderer_create_layout (cell, widget, cell_area->width); - gtk_paint_layout (widget->style, window, state, TRUE, expose_area, widget, - "cellrenderertext", - cell_area->x, cell_area->y + cell->ypad, - layout); + { + gint y = cell_area->y + cell->ypad; + + if (((NameRenderer *) cell)->lines == 1) + { + PangoRectangle logical; + + pango_layout_get_pixel_extents (layout, NULL, &logical); + y = cell_area->y + MAX (0, (cell_area->height - logical.height) / 2); + } + gtk_paint_layout (widget->style, window, state, TRUE, expose_area, widget, + "cellrenderertext", + cell_area->x, y, + layout); + } g_object_unref (layout); } @@ -5303,6 +9062,14 @@ name_renderer_class_init (NameRendererClass *class) static void name_renderer_init (NameRenderer *renderer) { + renderer->lines = NAME_RENDERER_LINES; +} + +static void +name_renderer_set_compact (GtkCellRenderer *cell, + gboolean compact) +{ + ((NameRenderer *) cell)->lines = compact ? 1 : NAME_RENDERER_LINES; } static GtkWidget * @@ -5325,17 +9092,17 @@ create_browse_files_icon_view (GtkFileChooserDefault *impl) G_CALLBACK (icons_queue_update), impl); g_signal_connect (impl->browse_files_icon_view, "popup-menu", G_CALLBACK (list_popup_menu_cb), impl); + g_signal_connect (impl->browse_files_icon_view, "button-press-event", + G_CALLBACK (history_button_press_cb), impl); g_signal_connect (impl->browse_files_icon_view, "button-press-event", G_CALLBACK (list_button_press_event_cb), impl); gtk_widget_add_events (impl->browse_files_icon_view, GDK_SCROLL_MASK); g_signal_connect (impl->browse_files_icon_view, "scroll-event", G_CALLBACK (browse_files_icon_view_scroll_event_cb), impl); - gtk_drag_dest_set (impl->browse_files_icon_view, - GTK_DEST_DEFAULT_ALL, - NULL, 0, - GDK_ACTION_COPY | GDK_ACTION_MOVE); - gtk_drag_dest_add_uri_targets (impl->browse_files_icon_view); + dnd_dest_set (impl->browse_files_icon_view); + g_signal_connect (impl->browse_files_icon_view, "drag-leave", + G_CALLBACK (file_list_drag_leave_cb), impl); g_signal_connect (impl->browse_files_icon_view, "drag-data-received", G_CALLBACK (file_list_drag_data_received_cb), impl); g_signal_connect (impl->browse_files_icon_view, "drag-drop", @@ -5345,8 +9112,9 @@ create_browse_files_icon_view (GtkFileChooserDefault *impl) gtk_icon_view_enable_model_drag_source (GTK_ICON_VIEW (impl->browse_files_icon_view), GDK_BUTTON1_MASK, NULL, 0, - GDK_ACTION_COPY | GDK_ACTION_MOVE); + DRAG_SOURCE_ACTIONS); gtk_drag_source_add_uri_targets (impl->browse_files_icon_view); + file_list_drag_source_connect (impl, impl->browse_files_icon_view); impl->list_icon_renderer = gtk_cell_renderer_pixbuf_new (); g_object_set (G_OBJECT (impl->list_icon_renderer), @@ -5364,6 +9132,10 @@ create_browse_files_icon_view (GtkFileChooserDefault *impl) impl->list_name_renderer = g_object_new (name_renderer_get_type (), NULL); update_icon_view_cell_layout (impl); + gtk_widget_set_has_tooltip (impl->browse_files_icon_view, TRUE); + g_signal_connect (impl->browse_files_icon_view, "query-tooltip", + G_CALLBACK (file_icon_view_query_tooltip_cb), impl); + g_signal_connect (impl->list_name_renderer, "edited", G_CALLBACK (renderer_edited_cb), impl); g_signal_connect (impl->list_name_renderer, "editing-started", @@ -5426,6 +9198,11 @@ file_pane_create (GtkFileChooserDefault *impl, gtk_box_pack_start (GTK_BOX (hbox), widget, TRUE, TRUE, 0); gtk_size_group_add_widget (size_group, widget); + /* Copying and moving files: a row for each, while it runs */ + impl->file_operations_box = gtk_vbox_new (FALSE, 6); + gtk_box_pack_start (GTK_BOX (vbox), impl->file_operations_box, FALSE, FALSE, 0); + gtk_widget_show (impl->file_operations_box); + /* Preview */ impl->preview_box = gtk_vbox_new (FALSE, 12); @@ -5446,6 +9223,53 @@ file_pane_create (GtkFileChooserDefault *impl, return vbox; } +static void check_save_entry (GtkFileChooserDefault *impl, + GFile **file_ret, + gboolean *is_well_formed_ret, + gboolean *is_empty_ret, + gboolean *is_file_part_empty_ret, + gboolean *is_folder); + +/* Enter in the location entry where nothing takes it as the default: + * a file chooser in a window of the program's own, not in a dialog. + * A folder is opened, a file chosen ("file-activated"), as Ardour's + * YTK does. */ +static void +location_entry_activate_cb (GtkEntry *entry, + GtkFileChooserDefault *impl) +{ + GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (impl)); + GFile *file; + gboolean is_well_formed, is_empty, is_file_part_empty, is_folder; + + if (GTK_IS_WINDOW (toplevel) && GTK_WINDOW (toplevel)->default_widget != NULL) + return; + if (impl->location_mode != LOCATION_MODE_FILENAME_ENTRY && + impl->action != GTK_FILE_CHOOSER_ACTION_SAVE && + impl->action != GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER) + return; + + check_save_entry (impl, &file, &is_well_formed, &is_empty, &is_file_part_empty, &is_folder); + if (!is_well_formed || is_empty || file == NULL) + { + if (file) + g_object_unref (file); + return; + } + + if (is_folder) + change_folder_and_display_error (impl, file, TRUE); + else if (impl->action != GTK_FILE_CHOOSER_ACTION_OPEN || + !g_file_is_native (file) || g_file_query_exists (file, NULL)) + { + /* to open, only what is there (a local file is quick to look at) */ + if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN) + gtk_file_chooser_select_file (GTK_FILE_CHOOSER (impl), file, NULL); + g_signal_emit_by_name (impl, "file-activated"); + } + g_object_unref (file); +} + static void location_entry_create (GtkFileChooserDefault *impl) { @@ -5456,6 +9280,9 @@ location_entry_create (GtkFileChooserDefault *impl) _gtk_file_chooser_entry_set_action (GTK_FILE_CHOOSER_ENTRY (impl->location_entry), impl->action); gtk_entry_set_width_chars (GTK_ENTRY (impl->location_entry), 45); gtk_entry_set_activates_default (GTK_ENTRY (impl->location_entry), TRUE); + g_signal_handlers_disconnect_by_func (impl->location_entry, location_entry_activate_cb, impl); + g_signal_connect (impl->location_entry, "activate", + G_CALLBACK (location_entry_activate_cb), impl); } /* Creates the widgets specific to Save mode */ @@ -5575,6 +9402,7 @@ location_switch_to_filename_entry (GtkFileChooserDefault *impl) /* Configure the entry */ _gtk_file_chooser_entry_set_base_folder (GTK_FILE_CHOOSER_ENTRY (impl->location_entry), impl->current_folder); + _gtk_file_chooser_entry_set_local_only (GTK_FILE_CHOOSER_ENTRY (impl->location_entry), impl->local_only); /* Done */ @@ -5582,6 +9410,46 @@ location_switch_to_filename_entry (GtkFileChooserDefault *impl) gtk_widget_grab_focus (impl->location_entry); } +/* In Open and Select Folder mode the location entry shows the path of the + * current folder when it is turned on, as in file managers, so that it can + * be copied or edited; it is selected while the entry has the focus, so + * that typing a name replaces it. The completion does not pop up with all + * the files of the folder for it. */ +static void +location_entry_set_folder_text (GtkFileChooserDefault *impl) +{ + gchar *text; + gsize len; + + if (impl->location_entry == NULL || impl->current_folder == NULL || + impl->operation_mode != OPERATION_MODE_BROWSE || + !(impl->action == GTK_FILE_CHOOSER_ACTION_OPEN || + impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)) + return; + + text = g_file_get_parse_name (impl->current_folder); + len = strlen (text); + if (len == 0 || (text[len - 1] != G_DIR_SEPARATOR && text[len - 1] != '/')) + { + gchar *folder_text = g_strconcat (text, + g_file_is_native (impl->current_folder) ? G_DIR_SEPARATOR_S : "/", + NULL); + + g_free (text); + text = folder_text; + } + + _gtk_file_chooser_entry_set_folder_text (GTK_FILE_CHOOSER_ENTRY (impl->location_entry), text); + + /* not taking the PRIMARY selection of a dialog that is not in use */ + if (gtk_widget_has_focus (impl->location_entry)) + gtk_editable_select_region (GTK_EDITABLE (impl->location_entry), 0, -1); + else + gtk_editable_set_position (GTK_EDITABLE (impl->location_entry), -1); + + g_free (text); +} + /* Sets a new location mode. set_buttons determines whether the toggle button * for the mode will also be changed. */ @@ -5626,6 +9494,7 @@ location_mode_set (GtkFileChooserDefault *impl, case LOCATION_MODE_FILENAME_ENTRY: button_active = TRUE; location_switch_to_filename_entry (impl); + location_entry_set_folder_text (impl); break; default: @@ -5690,7 +9559,7 @@ view_mode_set (GtkFileChooserDefault *impl, ViewMode view_mode) impl->view_mode = view_mode; gtk_combo_box_set_active (GTK_COMBO_BOX (impl->view_mode_combo_box), - view_mode); + view_mode == VIEW_MODE_ICON && impl->compact_view ? 2 : view_mode); /* Creating the target view */ if (view_mode == VIEW_MODE_ICON) @@ -5733,7 +9602,8 @@ view_mode_set (GtkFileChooserDefault *impl, ViewMode view_mode) impl->list_name_column = NULL; impl->list_mtime_column = NULL; impl->list_size_column = NULL; - gtk_widget_show (impl->icon_view_scale_hbox); + impl->list_type_column = NULL; + gtk_widget_set_visible (impl->icon_view_scale_hbox, !impl->compact_view); } else if (view_mode == VIEW_MODE_LIST) { @@ -5759,14 +9629,56 @@ view_mode_set (GtkFileChooserDefault *impl, ViewMode view_mode) browse_files_center_selected_row (impl); } -/* Callback used when view mode combo box active item is changed */ +static void thumbnail_requests_cancel_all (GtkFileChooserDefault *impl); +static void browse_files_center_selected_row (GtkFileChooserDefault *impl); + +/* The icon view, compact or not: the same view, other sizes */ +static void +compact_view_set (GtkFileChooserDefault *impl, + gboolean compact) +{ + if (impl->compact_view == (compact != FALSE)) + return; + + impl->compact_view = compact != FALSE; + if (impl->view_mode != VIEW_MODE_ICON || impl->browse_files_icon_view == NULL) + return; + + /* the setting may say so, on the next showing of the dialog */ + g_signal_handlers_block_by_func (impl->view_mode_combo_box, + view_mode_combo_box_changed_cb, impl); + gtk_combo_box_set_active (GTK_COMBO_BOX (impl->view_mode_combo_box), compact ? 2 : 1); + g_signal_handlers_unblock_by_func (impl->view_mode_combo_box, + view_mode_combo_box_changed_cb, impl); + + thumbnail_requests_cancel_all (impl); + update_icon_view_cell_layout (impl); + gtk_widget_set_visible (impl->icon_view_scale_hbox, !compact); + gtk_widget_queue_resize (impl->browse_files_icon_view); + browse_files_center_selected_row (impl); +} + +/* Callback used when view mode combo box active item is changed: list, + * icons, compact */ static void view_mode_combo_box_changed_cb (GtkComboBox *combo, GtkFileChooserDefault *impl) { - ViewMode target = gtk_combo_box_get_active (combo); + gint target = gtk_combo_box_get_active (combo); - view_mode_set (impl, target); + if (target < 0) + return; + + if (target == 2) + { + compact_view_set (impl, TRUE); + view_mode_set (impl, VIEW_MODE_ICON); + } + else + { + compact_view_set (impl, FALSE); + view_mode_set (impl, target); + } } static void @@ -6112,7 +10024,7 @@ browse_files_icon_view_scroll_event_cb (GtkWidget *widget, GdkEventScroll *event, GtkFileChooserDefault *impl) { - if (impl->view_mode != VIEW_MODE_ICON) + if (impl->view_mode != VIEW_MODE_ICON || impl->compact_view) return FALSE; if ((event->state & GDK_CONTROL_MASK) == 0) @@ -6202,6 +10114,8 @@ view_mode_combo_box_create (GtkFileChooserDefault *impl) _("List View")); /* VIEW_MODE_LIST */ gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT(impl->view_mode_combo_box), _("Icon View")); /* VIEW_MODE_ICON */ + gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT(impl->view_mode_combo_box), + _("Compact View")); /* VIEW_MODE_ICON, compact */ gtk_combo_box_set_active (GTK_COMBO_BOX(impl->view_mode_combo_box), VIEW_MODE_LIST); @@ -6382,6 +10296,9 @@ path_bar_widgets_create (GtkFileChooserDefault *impl) impl->browse_path_bar_size_group = gtk_size_group_new (GTK_SIZE_GROUP_VERTICAL); gtk_size_group_set_ignore_hidden (impl->browse_path_bar_size_group, FALSE); + /* Back and Forward */ + history_buttons_create (impl, impl->browse_path_bar_hbox); + /* View mode combo box */ view_mode_combo_box_create (impl); gtk_box_pack_start (GTK_BOX (impl->browse_path_bar_hbox), impl->view_mode_combo_box, FALSE, FALSE, 0); @@ -6395,6 +10312,11 @@ path_bar_widgets_create (GtkFileChooserDefault *impl) impl->browse_path_bar = g_object_new (GTK_TYPE_PATH_BAR, NULL); _gtk_path_bar_set_file_system (GTK_PATH_BAR (impl->browse_path_bar), impl->file_system); g_signal_connect (impl->browse_path_bar, "path-clicked", G_CALLBACK (path_bar_clicked), impl); + dnd_dest_set (impl->browse_path_bar); + g_signal_connect (impl->browse_path_bar, "drag-motion", G_CALLBACK (path_bar_drag_motion_cb), impl); + g_signal_connect (impl->browse_path_bar, "drag-leave", G_CALLBACK (path_bar_drag_leave_cb), impl); + g_signal_connect (impl->browse_path_bar, "drag-drop", G_CALLBACK (path_bar_drag_drop_cb), impl); + g_signal_connect (impl->browse_path_bar, "drag-data-received", G_CALLBACK (path_bar_drag_data_received_cb), impl); gtk_size_group_add_widget (impl->browse_path_bar_size_group, impl->browse_path_bar); gtk_box_pack_start (GTK_BOX (impl->browse_path_bar_hbox), impl->browse_path_bar, TRUE, TRUE, 0); @@ -6559,6 +10481,10 @@ gtk_file_chooser_default_constructor (GType type, gtk_widget_pop_composite_child (); update_appearance (impl); + /* presses elsewhere in the file chooser come up to here */ + g_signal_connect (impl, "button-press-event", + G_CALLBACK (history_button_press_cb), impl); + profile_end ("end", NULL); return object; @@ -6990,6 +10916,19 @@ update_appearance (GtkFileChooserDefault *impl) emit_default_size_changed (impl); } +static void +set_show_hidden (GtkFileChooserDefault *impl, + gboolean show_hidden) +{ + if (impl->show_hidden != show_hidden) + { + impl->show_hidden = show_hidden; + + if (impl->browse_files_model) + _gtk_file_system_model_set_show_hidden (impl->browse_files_model, show_hidden); + } +} + static void gtk_file_chooser_default_set_property (GObject *object, guint prop_id, @@ -7074,16 +11013,8 @@ gtk_file_chooser_default_set_property (GObject *object, break; case GTK_FILE_CHOOSER_PROP_SHOW_HIDDEN: - { - gboolean show_hidden = g_value_get_boolean (value); - if (show_hidden != impl->show_hidden) - { - impl->show_hidden = show_hidden; - - if (impl->browse_files_model) - _gtk_file_system_model_set_show_hidden (impl->browse_files_model, show_hidden); - } - } + impl->show_hidden_set = TRUE; + set_show_hidden (impl, g_value_get_boolean (value)); break; case GTK_FILE_CHOOSER_PROP_DO_OVERWRITE_CONFIRMATION: @@ -7175,6 +11106,13 @@ cancel_all_operations (GtkFileChooserDefault *impl) pending_select_files_free (impl); + if (impl->rename_cancellable) + { + g_cancellable_cancel (impl->rename_cancellable); + g_clear_object (&impl->rename_cancellable); + } + rename_select_clear (impl); + if (impl->reload_icon_cancellables) { for (l = impl->reload_icon_cancellables; l; l = l->next) @@ -7249,6 +11187,7 @@ cancel_all_operations (GtkFileChooserDefault *impl) search_stop_searching (impl, TRUE); recent_stop_loading (impl); + preview_panel_stop (impl); } /* Removes the settings signal handler. It's safe to call multiple times */ @@ -7274,6 +11213,28 @@ gtk_file_chooser_default_dispose (GObject *object) cancel_all_operations (impl); + /* copies and moves stop with the file chooser; their rows go with it, + * and they no longer call back */ + g_slist_foreach (impl->file_operations, (GFunc) _gtk_file_operation_cancel, NULL); + g_slist_free (impl->file_operations); + impl->file_operations = NULL; + + /* it belongs to the toplevel, not to us, but speaks to us */ + if (impl->preferences_dialog) + gtk_widget_destroy (impl->preferences_dialog); + if (impl->connect_dialog) + gtk_widget_destroy (impl->connect_dialog); + impl->connect_dialog = NULL; +#ifdef GDK_WINDOWING_QUARTZ + if (impl->connect_timeout) + connect_waited (impl); +#endif + if (impl->preferences_apply_id) + { + g_source_remove (impl->preferences_apply_id); + impl->preferences_apply_id = 0; + } + if (impl->extra_widget) { g_object_unref (impl->extra_widget); @@ -7282,6 +11243,35 @@ gtk_file_chooser_default_dispose (GObject *object) remove_settings_signal (impl, gtk_widget_get_screen (GTK_WIDGET (impl))); + /* the views are gone already: only the state of a drag */ + if (impl->dnd_hover_id) + g_source_remove (impl->dnd_hover_id); + impl->dnd_hover_id = 0; + if (impl->dnd_scroll_id) + g_source_remove (impl->dnd_scroll_id); + impl->dnd_scroll_id = 0; + if (impl->dnd_highlighted) + g_object_remove_weak_pointer (G_OBJECT (impl->dnd_highlighted), (gpointer *) &impl->dnd_highlighted); + impl->dnd_highlighted = NULL; + g_clear_object (&impl->dnd_hover_folder); + g_clear_object (&impl->dnd_folder); + if (impl->dnd_filesystems) + g_hash_table_destroy (impl->dnd_filesystems); + impl->dnd_filesystems = NULL; + g_clear_object (&impl->dnd_xds_file); + g_strfreev (impl->drag_uris); + impl->drag_uris = NULL; + + g_list_free_full (impl->history_back, g_object_unref); + impl->history_back = NULL; + g_list_free_full (impl->history_forward, g_object_unref); + impl->history_forward = NULL; + if (impl->history_target) + { + g_object_unref (impl->history_target); + impl->history_target = NULL; + } + G_OBJECT_CLASS (_gtk_file_chooser_default_parent_class)->dispose (object); } @@ -7527,7 +11517,9 @@ settings_load (GtkFileChooserDefault *impl) LocationMode location_mode; ViewMode view_mode; gboolean show_hidden; - gboolean show_size_column; + gboolean show_size_column, show_type_column, show_thumbnails, show_preview_panel; + TypeFormat type_format; + gint thumbnail_max_size, thumbnail_max_size_remote; gint sort_column, icon_view_scale; GtkSortType sort_order; StartupMode startup_mode; @@ -7539,6 +11531,12 @@ settings_load (GtkFileChooserDefault *impl) icon_view_scale = _gtk_file_chooser_settings_get_icon_view_scale (settings); show_hidden = _gtk_file_chooser_settings_get_show_hidden (settings); show_size_column = _gtk_file_chooser_settings_get_show_size_column (settings); + show_type_column = _gtk_file_chooser_settings_get_show_type_column (settings); + type_format = _gtk_file_chooser_settings_get_type_format (settings); + show_thumbnails = _gtk_file_chooser_settings_get_show_thumbnails (settings); + show_preview_panel = _gtk_file_chooser_settings_get_show_preview_panel (settings); + thumbnail_max_size = _gtk_file_chooser_settings_get_thumbnail_max_size (settings, FALSE); + thumbnail_max_size_remote = _gtk_file_chooser_settings_get_thumbnail_max_size (settings, TRUE); sort_column = _gtk_file_chooser_settings_get_sort_column (settings); sort_order = _gtk_file_chooser_settings_get_sort_order (settings); startup_mode = _gtk_file_chooser_settings_get_startup_mode (settings); @@ -7564,13 +11562,43 @@ settings_load (GtkFileChooserDefault *impl) impl); } - view_mode_set (impl, view_mode); + /* compact is the icon view, smaller */ + compact_view_set (impl, view_mode == VIEW_MODE_COMPACT); + view_mode_set (impl, view_mode == VIEW_MODE_COMPACT ? VIEW_MODE_ICON : view_mode); - gtk_file_chooser_set_show_hidden (GTK_FILE_CHOOSER (impl), show_hidden); + /* A show-hidden that was set (by the application) is not overridden + * by the settings */ + if (!impl->show_hidden_set && impl->show_hidden != show_hidden) + { + set_show_hidden (impl, show_hidden); + g_object_notify (G_OBJECT (impl), "show-hidden"); + } impl->show_size_column = show_size_column; + if (impl->show_thumbnails != show_thumbnails || + impl->thumbnail_max_size != thumbnail_max_size || + impl->thumbnail_max_size_remote != thumbnail_max_size_remote) + { + impl->show_thumbnails = show_thumbnails; + impl->thumbnail_max_size = thumbnail_max_size; + impl->thumbnail_max_size_remote = thumbnail_max_size_remote; + thumbnails_reload (impl); + } + impl->show_preview_panel = show_preview_panel; + preview_panel_sync (impl); if (impl->list_size_column) gtk_tree_view_column_set_visible (impl->list_size_column, show_size_column); + impl->show_type_column = show_type_column; + if (impl->list_type_column) + gtk_tree_view_column_set_visible (impl->list_type_column, show_type_column); + if (impl->type_format != type_format) + { + impl->type_format = type_format; + if (impl->type_texts) + g_hash_table_remove_all (impl->type_texts); + if (impl->browse_files_tree_view) + file_list_update_fixed_sizing (impl); + } impl->sort_column = sort_column; impl->sort_order = sort_order; @@ -7609,10 +11637,17 @@ settings_save (GtkFileChooserDefault *impl) /* All the other state */ _gtk_file_chooser_settings_set_location_mode (settings, impl->location_mode); - _gtk_file_chooser_settings_set_view_mode (settings, impl->view_mode); + _gtk_file_chooser_settings_set_view_mode (settings, + impl->view_mode == VIEW_MODE_ICON && impl->compact_view + ? VIEW_MODE_COMPACT : impl->view_mode); _gtk_file_chooser_settings_set_icon_view_scale (settings, impl->icon_view_icon_size); _gtk_file_chooser_settings_set_show_hidden (settings, gtk_file_chooser_get_show_hidden (GTK_FILE_CHOOSER (impl))); _gtk_file_chooser_settings_set_show_size_column (settings, impl->show_size_column); + _gtk_file_chooser_settings_set_show_type_column (settings, impl->show_type_column); + _gtk_file_chooser_settings_set_show_thumbnails (settings, impl->show_thumbnails); + _gtk_file_chooser_settings_set_show_preview_panel (settings, impl->show_preview_panel); + _gtk_file_chooser_settings_set_thumbnail_max_size (settings, FALSE, impl->thumbnail_max_size); + _gtk_file_chooser_settings_set_thumbnail_max_size (settings, TRUE, impl->thumbnail_max_size_remote); _gtk_file_chooser_settings_set_sort_column (settings, impl->sort_column); _gtk_file_chooser_settings_set_sort_order (settings, impl->sort_order); _gtk_file_chooser_settings_set_startup_mode (settings, impl->startup_mode); @@ -7793,6 +11828,28 @@ mtime_sort_func (GtkTreeModel *model, } } +/* Sort callback for the type column: the same kinds together, by name + * within each */ +static gint +type_sort_func (GtkTreeModel *model, + GtkTreeIter *a, + GtkTreeIter *b, + gpointer user_data) +{ + COMPARE_DIRECTORIES; + else + { + gint result; + + result = g_strcmp0 (g_value_get_string (_gtk_file_system_model_get_value (fs_model, a, MODEL_COL_TYPE)), + g_value_get_string (_gtk_file_system_model_get_value (fs_model, b, MODEL_COL_TYPE))); + if (result == 0) + result = g_strcmp0 (g_value_get_string (_gtk_file_system_model_get_value (fs_model, a, MODEL_COL_NAME_COLLATED)), + g_value_get_string (_gtk_file_system_model_get_value (fs_model, b, MODEL_COL_NAME_COLLATED))); + return result; + } +} + /* Callback used when the sort column changes. We cache the sort order for use * in name_sort_func(). */ @@ -7881,7 +11938,13 @@ browse_files_select_first_row (GtkFileChooserDefault *impl) /* If the list is empty, do nothing. */ if (gtk_tree_model_get_iter (tree_model, &dummy_iter, path)) - current_view_set_cursor (impl, path); + { + /* Setting the cursor also selects the row in the tree view; the + * location entry is only filled from selections by the user. */ + impl->auto_selecting_first_row = TRUE; + current_view_set_cursor (impl, path); + impl->auto_selecting_first_row = FALSE; + } gtk_tree_path_free (path); } @@ -8121,6 +12184,7 @@ stop_loading_and_clear_list_model (GtkFileChooserDefault *impl, /* Icon queries keep the model alive; drop them so it is disposed * and stops loading now, and do not hear from it any more. */ icon_queries_cancel_all (impl); + rename_select_clear (impl); g_signal_handlers_disconnect_by_data (impl->browse_files_model, impl); if (impl->current_model == GTK_TREE_MODEL (impl->browse_files_model)) @@ -8172,7 +12236,7 @@ my_g_format_time_for_display (gint64 secs) (GDateMonth) g_date_time_get_month (mtime_dt), g_date_time_get_year (mtime_dt)); - now_dt = g_date_time_new_now_local (); + now_dt = _gtk_date_time_new_now_local (); if (now_dt == NULL) { g_date_time_unref (mtime_dt); @@ -8311,6 +12375,173 @@ icon_query_cancel (IconQuery *query) static void icon_queries_start (GtkFileChooserDefault *impl); +/* Thumbnails of images that have none are made in the background for + * the icon view, once a row on screen has its icon: see gtkfilethumbnail.c. + * The list view only shows those that exist. Rows scrolled far away + * give up their request and ask again when they come back. */ +#define THUMBNAIL_TRIED_ATTRIBUTE "filechooser::thumbnail_tried" + +typedef struct +{ + GtkFileChooserDefault *impl; /* owns a reference */ + GtkFileSystemModel *model; /* owns a reference */ + GFile *file; + GCancellable *cancellable; +} ThumbnailRequest; + +static void +thumbnail_request_free (gpointer data) +{ + ThumbnailRequest *request = data; + GtkFileChooserDefault *impl = request->impl; + + if (impl->thumbnail_requests && + g_hash_table_lookup (impl->thumbnail_requests, request->file) == request) + g_hash_table_remove (impl->thumbnail_requests, request->file); + + g_object_unref (request->cancellable); + g_object_unref (request->file); + g_object_unref (request->model); + g_object_unref (impl); + g_slice_free (ThumbnailRequest, request); +} + +static void +thumbnail_done (GFile *file, + const gchar *thumbnail, + gpointer data) +{ + ThumbnailRequest *request = data; + GtkTreeIter iter; + + if (thumbnail && + _gtk_file_system_model_get_iter_for_file (request->model, &iter, file)) + { + GFileInfo *info = g_file_info_dup (_gtk_file_system_model_get_info (request->model, &iter)); + + g_file_info_set_attribute_byte_string (info, G_FILE_ATTRIBUTE_THUMBNAIL_PATH, thumbnail); + _gtk_file_system_model_update_file (request->model, file, info); + g_object_unref (info); + } +} + +/* Gives up the request for @file; the row may ask again later */ +static void +thumbnail_request_cancel (GtkFileChooserDefault *impl, + ThumbnailRequest *request) +{ + GtkTreeIter iter; + + if (_gtk_file_system_model_get_iter_for_file (request->model, &iter, request->file)) + { + GFileInfo *info = _gtk_file_system_model_get_info (request->model, &iter); + + if (info) + g_file_info_remove_attribute (info, THUMBNAIL_TRIED_ATTRIBUTE); + } + + g_cancellable_cancel (request->cancellable); + g_hash_table_remove (impl->thumbnail_requests, request->file); +} + +static void +thumbnail_requests_cancel_all (GtkFileChooserDefault *impl) +{ + GList *requests, *l; + + if (impl->thumbnail_requests == NULL) + return; + + requests = g_hash_table_get_values (impl->thumbnail_requests); + for (l = requests; l; l = l->next) + thumbnail_request_cancel (impl, l->data); + g_list_free (requests); +} + +static void +thumbnail_maybe_request (GtkFileChooserDefault *impl, + GtkFileSystemModel *model, + GtkTreeIter *iter, + GFileInfo *info) +{ + ThumbnailRequest *request; + GFile *file; + + if (!impl->show_thumbnails || impl->view_mode != VIEW_MODE_ICON || impl->compact_view || + !g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_ICON) || + g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_THUMBNAIL_PATH) || + g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_THUMBNAILING_FAILED) || + g_file_info_has_attribute (info, THUMBNAIL_TRIED_ATTRIBUTE)) + return; + + file = _gtk_file_system_model_get_file (model, iter); + if (!_gtk_file_thumbnail_wanted (file, info, MEGABYTES (impl->thumbnail_max_size))) + return; + + g_file_info_set_attribute_boolean (info, THUMBNAIL_TRIED_ATTRIBUTE, TRUE); + + if (impl->thumbnail_requests == NULL) + impl->thumbnail_requests = g_hash_table_new (g_file_hash, (GEqualFunc) g_file_equal); + /* the row changed meanwhile; the request still runs and updates it */ + else if (g_hash_table_lookup (impl->thumbnail_requests, file)) + return; + + request = g_slice_new (ThumbnailRequest); + request->impl = g_object_ref (impl); + request->model = g_object_ref (model); + request->file = g_object_ref (file); + request->cancellable = g_cancellable_new (); + g_hash_table_insert (impl->thumbnail_requests, request->file, request); + + _gtk_file_thumbnail_request (file, info, impl->icon_view_icon_size, + MEGABYTES (impl->thumbnail_max_size_remote), + request->cancellable, thumbnail_done, + request, thumbnail_request_free); +} + +/* The thumbnail to show at @size, if valid: one of that size, or the + * large one for normal icons; not the x-large ones newer programs make, + * slow to decode; from those the worker makes one of the size. GLib + * 2.76 tells the sizes apart, before only the one path. */ +static const gchar * +thumbnail_for_icon (GFileInfo *queried, + gint size, + GFile *file, + GFileInfo *info) +{ + static const gchar *const dirs[] = { "normal", "large" }; + const gchar *path; + gint i; + + for (i = size > 128 ? 1 : 0; i < 2; i++) + { + gchar *path_attribute = g_strconcat ("thumbnail::path-", dirs[i], NULL); + gchar *valid_attribute = g_strconcat ("thumbnail::is-valid-", dirs[i], NULL); + + path = g_file_info_get_attribute_byte_string (queried, path_attribute); + if (path && g_file_info_has_attribute (queried, valid_attribute) && + !g_file_info_get_attribute_boolean (queried, valid_attribute)) + path = NULL; + g_free (path_attribute); + g_free (valid_attribute); + if (path) + return path; + } + + /* GLib before 2.40 cannot tell whether it is valid: that is checked + * here then, by the text of the PNG, not decoding it */ + path = g_file_info_get_attribute_byte_string (queried, G_FILE_ATTRIBUTE_THUMBNAIL_PATH); + if (path == NULL || + (g_file_info_has_attribute (queried, "thumbnail::is-valid") ? + !g_file_info_get_attribute_boolean (queried, "thumbnail::is-valid") : + !_gtk_file_thumbnail_valid (path, file, info)) || + strstr (path, G_DIR_SEPARATOR_S "x-large" G_DIR_SEPARATOR_S) || + strstr (path, G_DIR_SEPARATOR_S "xx-large" G_DIR_SEPARATOR_S)) + return NULL; + + return path; +} + static void icon_query_done (GObject *object, GAsyncResult *res, @@ -8334,7 +12565,15 @@ icon_query_done (GObject *object, { GFileInfo *info = g_file_info_dup (_gtk_file_system_model_get_info (query->model, &iter)); - copy_attribute (info, queried, G_FILE_ATTRIBUTE_THUMBNAIL_PATH); + /* a thumbnail older than its file is not shown */ + if (impl->show_thumbnails) + { + const gchar *thumbnail = thumbnail_for_icon (queried, impl->icon_view_icon_size, + file, info); + + if (thumbnail) + g_file_info_set_attribute_byte_string (info, G_FILE_ATTRIBUTE_THUMBNAIL_PATH, thumbnail); + } copy_attribute (info, queried, G_FILE_ATTRIBUTE_THUMBNAILING_FAILED); copy_attribute (info, queried, G_FILE_ATTRIBUTE_STANDARD_ICON); @@ -8364,6 +12603,9 @@ icon_queries_start (GtkFileChooserDefault *impl) impl->icon_queries_running = g_list_prepend (impl->icon_queries_running, query); g_file_query_info_async (query->file, G_FILE_ATTRIBUTE_THUMBNAIL_PATH "," + "thumbnail::is-valid," + "thumbnail::path-normal,thumbnail::is-valid-normal," + "thumbnail::path-large,thumbnail::is-valid-large," G_FILE_ATTRIBUTE_THUMBNAILING_FAILED "," G_FILE_ATTRIBUTE_STANDARD_ICON, G_FILE_QUERY_INFO_NONE, @@ -8396,6 +12638,8 @@ icon_queries_cancel_all (GtkFileChooserDefault *impl) /* Running queries free themselves when they complete. */ for (l = impl->icon_queries_running; l; l = l->next) icon_query_cancel (l->data); + + thumbnail_requests_cancel_all (impl); } static gboolean @@ -8459,6 +12703,31 @@ icons_update_cb (gpointer data) } } + /* So may thumbnails */ + if (impl->thumbnail_requests) + { + GList *requests = g_hash_table_get_values (impl->thumbnail_requests), *r; + + for (r = requests; r; r = r->next) + { + ThumbnailRequest *request = r->data; + GtkTreeIter iter; + + row = -1; + if (request->model == model && + _gtk_file_system_model_get_iter_for_file (model, &iter, request->file)) + { + GtkTreePath *path = gtk_tree_model_get_path (impl->current_model, &iter); + + row = gtk_tree_path_get_indices (path)[0]; + gtk_tree_path_free (path); + } + if (row < first - margin || row > last + margin) + thumbnail_request_cancel (impl, request); + } + g_list_free (requests); + } + for (row = first; row <= last; row++) { GtkTreeIter iter; @@ -8469,10 +12738,14 @@ icons_update_cb (gpointer data) break; info = _gtk_file_system_model_get_info (model, &iter); - if (info == NULL || - g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_ICON) || - g_file_info_has_attribute (info, ICON_QUERIED_ATTRIBUTE)) + if (info == NULL) continue; + if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_ICON) || + g_file_info_has_attribute (info, ICON_QUERIED_ATTRIBUTE)) + { + thumbnail_maybe_request (impl, model, &iter, info); + continue; + } g_file_info_set_attribute_boolean (info, ICON_QUERIED_ATTRIBUTE, TRUE); @@ -8505,6 +12778,50 @@ icons_queue_update (GtkWidget *view, return FALSE; } +static gboolean +forget_icon (GtkTreeModel *model, + GtkTreePath *path, + GtkTreeIter *iter, + gpointer data) +{ + GFileInfo *info = _gtk_file_system_model_get_info (GTK_FILE_SYSTEM_MODEL (model), iter); + + if (info) + { + g_file_info_remove_attribute (info, G_FILE_ATTRIBUTE_THUMBNAIL_PATH); + g_file_info_remove_attribute (info, G_FILE_ATTRIBUTE_STANDARD_ICON); + g_file_info_remove_attribute (info, ICON_QUERIED_ATTRIBUTE); + g_file_info_remove_attribute (info, THUMBNAIL_TRIED_ATTRIBUTE); + } + + return FALSE; +} + +/* Thumbnails were turned on or off: the icons are queried again */ +static void +thumbnails_reload (GtkFileChooserDefault *impl) +{ + GtkFileSystemModel *models[3]; + gint i; + + models[0] = impl->browse_files_model; + models[1] = impl->search_model; + models[2] = impl->recent_model; + + icon_queries_cancel_all (impl); + + for (i = 0; i < 3; i++) + if (models[i]) + { + gtk_tree_model_foreach (GTK_TREE_MODEL (models[i]), forget_icon, NULL); + _gtk_file_system_model_clear_cache (models[i], MODEL_COL_LIST_PIXBUF); + _gtk_file_system_model_clear_cache (models[i], MODEL_COL_ICON_PIXBUF); + } + + if (impl->icons_update_id == 0) + impl->icons_update_id = gdk_threads_add_idle (icons_update_cb, impl); +} + static gboolean get_visible_range (GtkTreePath **start, GtkTreePath **end, GtkFileChooserDefault *impl) @@ -8516,6 +12833,202 @@ get_visible_range (GtkTreePath **start, GtkTreePath **end, g_assert_not_reached (); } +/* Hidden files and backups are shown with a dimmed icon, as in file + * managers: half transparent. The dimmed icon is made once and kept in + * the model like any other, so drawing it costs nothing more; the name + * stays as readable as the others. */ +static GdkPixbuf * +file_icon_dim (GtkWidget *widget, + GdkPixbuf *pixbuf) +{ + GdkPixbuf *dimmed; + guchar *pixels; + gint width, height, rowstride, x, y; + + if (pixbuf == NULL) + return NULL; + + dimmed = gdk_pixbuf_add_alpha (pixbuf, FALSE, 0, 0, 0); + g_object_unref (pixbuf); + if (dimmed == NULL) + return NULL; + + pixels = gdk_pixbuf_get_pixels (dimmed); + width = gdk_pixbuf_get_width (dimmed); + height = gdk_pixbuf_get_height (dimmed); + rowstride = gdk_pixbuf_get_rowstride (dimmed); + + for (y = 0; y < height; y++) + { + guchar *p = pixels + y * rowstride + 3; + + for (x = 0; x < width; x++, p += 4) + *p >>= 1; + } + + return dimmed; +} + +static GdkPixbuf * +file_icon_dim_if_hidden (GtkFileChooserDefault *impl, + GFile *file, + GFileInfo *info, + GdkPixbuf *pixbuf) +{ + /* and files that are cut, waiting to be pasted */ + if (file_is_cut (impl, file) || + (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN) && + g_file_info_get_is_hidden (info)) || + (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_IS_BACKUP) && + g_file_info_get_is_backup (info))) + return file_icon_dim (GTK_WIDGET (impl), pixbuf); + + return pixbuf; +} + +/* What the Type column shows for a file, as in GTK+ 3 (and Nautilus): + * by default the kind of file, from the generic icon of its type, so + * that pictures or archives of all formats come together; the strings + * are kept per type, as there are few types in a folder. */ +/* Whether @word is one of the words of @list (separated by spaces), or + * with @prefixes begins with one of them that ends with a slash */ +static gboolean +file_type_word_in (const gchar *list, + const gchar *word, + gboolean prefixes) +{ + gsize length = strlen (word); + + while (list && *list) + { + const gchar *end = strchr (list, ' '); + gsize n = end ? (gsize) (end - list) : strlen (list); + + if (g_ascii_strncasecmp (list, word, n) == 0 && + (n == length || (prefixes && n < length && list[n - 1] == '/'))) + return TRUE; + list = end ? end + 1 : NULL; + } + return FALSE; +} + +#ifndef G_OS_WIN32 +/* Whether the type of the Mac @content_type conforms to one of @utis */ +static gboolean +file_type_conforms (const gchar *content_type, + const gchar *utis) +{ + gchar **list = g_strsplit (utis, " ", -1); + gboolean result = FALSE; + gint i; + + for (i = 0; list[i] && !result; i++) + result = g_content_type_is_a (content_type, list[i]); + g_strfreev (list); + return result; +} +#endif + +/* The kind of files of @content_type, untranslated, or NULL */ +static const gchar * +file_type_category (const gchar *content_type) +{ + const gchar *result = NULL; + gchar *icon_name, *mime_type; + gint i; + + icon_name = g_content_type_get_generic_icon_name (content_type); + for (i = 0; icon_name && !result && i < G_N_ELEMENTS (file_type_categories); i++) + if (strcmp (file_type_categories[i].icon_name, icon_name) == 0) + result = file_type_categories[i].display_name; + g_free (icon_name); + if (result) + return result; + + mime_type = g_content_type_get_mime_type (content_type); + for (i = 0; mime_type && !result && i < G_N_ELEMENTS (file_type_categories); i++) + if (file_type_word_in (file_type_categories[i].mime_types, mime_type, TRUE)) + result = file_type_categories[i].display_name; + g_free (mime_type); + if (result) + return result; + + if (content_type[0] == '.') + { + /* Windows: the extension is the type */ + for (i = 0; !result && i < G_N_ELEMENTS (file_type_categories); i++) + if (file_type_word_in (file_type_categories[i].extensions, content_type + 1, FALSE)) + result = file_type_categories[i].display_name; + } +#ifndef G_OS_WIN32 + else if (strchr (content_type, '/') == NULL) + { + /* the Mac: UTIs */ + for (i = 0; !result && i < G_N_ELEMENTS (file_type_categories); i++) + if (file_type_categories[i].utis && + file_type_conforms (content_type, file_type_categories[i].utis)) + result = file_type_categories[i].display_name; + } +#endif + + return result; +} + +static const gchar * +file_type_text (GtkFileChooserDefault *impl, + GFileInfo *info) +{ + const gchar *content_type; + gchar *text = NULL; + + if (_gtk_file_info_consider_as_directory (info)) + return _("Folder"); + + content_type = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE); + if (content_type == NULL) + content_type = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE); + if (content_type == NULL) + return ""; + + if (impl->type_texts == NULL) + impl->type_texts = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); + else + { + const gchar *known = g_hash_table_lookup (impl->type_texts, content_type); + + if (known) + return known; + } + + switch (impl->type_format) + { + case TYPE_FORMAT_MIME: + text = g_content_type_get_mime_type (content_type); + break; + + case TYPE_FORMAT_DESCRIPTION: + text = g_content_type_get_description (content_type); + break; + + default: + { + const gchar *category = file_type_category (content_type); + + if (category) + text = g_strdup (_(category)); + if (text == NULL) + text = g_content_type_get_description (content_type); + } + break; + } + + if (text == NULL) + text = g_strdup (_("Unknown")); + + g_hash_table_insert (impl->type_texts, g_strdup (content_type), text); + return text; +} + static gboolean file_system_model_set (GtkFileSystemModel *model, GFile *file, @@ -8607,7 +13120,8 @@ file_system_model_set (GtkFileSystemModel *model, icon_size = FALLBACK_LIST_VIEW_ICON_SIZE; } - g_value_take_object (value, _gtk_file_info_render_icon (info, GTK_WIDGET (impl), icon_size)); + g_value_take_object (value, file_icon_dim_if_hidden (impl, file, info, + _gtk_file_info_render_icon (info, GTK_WIDGET (impl), icon_size))); return TRUE; } @@ -8646,26 +13160,12 @@ file_system_model_set (GtkFileSystemModel *model, if (info == NULL) break; -/* GLib 2.62 replaced the old GTimeVal API with GDateTime. */ -#if GLIB_CHECK_VERSION (2, 62, 0) - { - GDateTime *dt; - - dt = g_file_info_get_modification_date_time (info); - if (dt) - { - tv = g_date_time_to_unix (dt); - g_date_time_unref (dt); - } - } -#else - { - GTimeVal timeval; - - g_file_info_get_modification_time (info, &timeval); - tv = timeval.tv_sec; - } -#endif + /* The seconds as GIO keeps them, 64 bits on all systems: not + * the GTimeVal of older GLib, whose glong ends in 2038 on 32-bit + * systems and on Windows, and no GDateTime made for every cell + * drawn. GIO puts st_mtime into a uint64; read as signed, a + * time before 1970 comes back as it was. */ + tv = (gint64) g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_TIME_MODIFIED); if (column == MODEL_COL_MTIME) g_value_set_int64 (value, tv); @@ -8678,6 +13178,9 @@ file_system_model_set (GtkFileSystemModel *model, case MODEL_COL_ELLIPSIZE: g_value_set_enum (value, info ? PANGO_ELLIPSIZE_END : PANGO_ELLIPSIZE_NONE); break; + case MODEL_COL_TYPE: + g_value_set_string (value, info ? file_type_text (impl, info) : _("Folder")); + break; default: g_assert_not_reached (); break; @@ -8712,6 +13215,7 @@ set_list_model (GtkFileChooserDefault *impl, gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (impl->browse_files_model), MODEL_COL_NAME, name_sort_func, impl, NULL); gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (impl->browse_files_model), MODEL_COL_SIZE, size_sort_func, impl, NULL); gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (impl->browse_files_model), MODEL_COL_MTIME, mtime_sort_func, impl, NULL); + gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (impl->browse_files_model), MODEL_COL_TYPE, type_sort_func, impl, NULL); gtk_tree_sortable_set_default_sort_func (GTK_TREE_SORTABLE (impl->browse_files_model), NULL, NULL, NULL); /* Sort from the start: the model sorts files as it adds them, while * resorting rows that are already shown takes extra work. */ @@ -8834,7 +13338,7 @@ update_chooser_entry (GtkFileChooserDefault *impl) else change_entry = TRUE; /* ... unless we are in SELECT_FOLDER mode */ - if (change_entry) + if (change_entry && !impl->auto_selecting_first_row) { gtk_entry_set_text (GTK_ENTRY (impl->location_entry), impl->browse_files_last_selected_name); @@ -8955,12 +13459,267 @@ update_current_folder_mount_enclosing_volume_cb (GCancellable *cancellabl change_folder_and_display_error (impl, data->file, data->clear_entry); out: + g_object_unref (data->impl); g_object_unref (data->file); g_free (data); g_object_unref (cancellable); } +/* Whether the location entry of Open and Select Folder mode is to show the + * new folder: when it is to be cleared, is empty, or holds a folder + * (ending in a separator) or the name of the file that was selected, + * rather than a name the user typed */ +static gboolean +location_entry_follows_folder (GtkFileChooserDefault *impl, + gboolean clear_entry) +{ + const gchar *text; + gsize len; + + if (!(impl->action == GTK_FILE_CHOOSER_ACTION_OPEN || + impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER) || + impl->location_mode != LOCATION_MODE_FILENAME_ENTRY || + impl->operation_mode != OPERATION_MODE_BROWSE) + return FALSE; + + if (clear_entry) + return TRUE; + + text = gtk_entry_get_text (GTK_ENTRY (impl->location_entry)); + len = strlen (text); + + return (len == 0 || + text[len - 1] == G_DIR_SEPARATOR || text[len - 1] == '/' || + (impl->browse_files_last_selected_name && + compare_utf8_filenames (impl->browse_files_last_selected_name, text) == 0)); +} + +/* Back and Forward: the folders shown before, as in file managers */ + +#define HISTORY_LENGTH 50 + +static void +history_update_buttons (GtkFileChooserDefault *impl) +{ + if (impl->history_back_button) + gtk_widget_set_sensitive (impl->history_back_button, impl->history_back != NULL); + if (impl->history_forward_button) + gtk_widget_set_sensitive (impl->history_forward_button, impl->history_forward != NULL); +} + +static GList * +history_push (GList *list, + GFile *file) +{ + GList *last; + + list = g_list_prepend (list, g_object_ref (file)); + if (g_list_length (list) > HISTORY_LENGTH) + { + last = g_list_last (list); + g_object_unref (last->data); + list = g_list_delete_link (list, last); + } + return list; +} + +/* The folder changes from @old to @new: Back gets @old, and Forward is + * cleared, except when the change is Back or Forward itself */ +static void +history_add (GtkFileChooserDefault *impl, + GFile *old, + GFile *new) +{ + gint step = impl->history_step; + gboolean expected = impl->history_target && g_file_equal (impl->history_target, new); + + impl->history_step = 0; + if (impl->history_target) + { + g_object_unref (impl->history_target); + impl->history_target = NULL; + } + + if (g_file_equal (old, new)) + return; + + if (step < 0 && expected && impl->history_back) + { + g_object_unref (impl->history_back->data); + impl->history_back = g_list_delete_link (impl->history_back, impl->history_back); + impl->history_forward = history_push (impl->history_forward, old); + } + else if (step > 0 && expected && impl->history_forward) + { + g_object_unref (impl->history_forward->data); + impl->history_forward = g_list_delete_link (impl->history_forward, impl->history_forward); + impl->history_back = history_push (impl->history_back, old); + } + else + { + impl->history_back = history_push (impl->history_back, old); + g_list_free_full (impl->history_forward, g_object_unref); + impl->history_forward = NULL; + } + + history_update_buttons (impl); +} + +static void +history_go (GtkFileChooserDefault *impl, + gint step) +{ + GList *list = step < 0 ? impl->history_back : impl->history_forward; + + if (list == NULL) + { + gtk_widget_error_bell (GTK_WIDGET (impl)); + return; + } + + if (impl->history_target) + g_object_unref (impl->history_target); + impl->history_target = g_object_ref (list->data); + impl->history_step = step; + + /* a folder that is gone is taken off, so that the next one is there */ + if (!change_folder_and_display_error (impl, list->data, FALSE)) + { + if (step < 0) + { + g_object_unref (impl->history_back->data); + impl->history_back = g_list_delete_link (impl->history_back, impl->history_back); + } + else + { + g_object_unref (impl->history_forward->data); + impl->history_forward = g_list_delete_link (impl->history_forward, impl->history_forward); + } + history_update_buttons (impl); + } +} + +static void +back_folder_handler (GtkFileChooserDefault *impl) +{ + history_go (impl, -1); +} + +static void +forward_folder_handler (GtkFileChooserDefault *impl) +{ + history_go (impl, 1); +} + +/* Undo and Redo: of the last copy, move, trash, rename or new folder in + * any file chooser of the program (gtkfileoperation.c); not while a + * name is typed, as text has no undo here */ +static void +undo_or_redo (GtkFileChooserDefault *impl, + gboolean redo) +{ + GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (impl)); + GtkWidget *focus = GTK_IS_WINDOW (toplevel) ? gtk_window_get_focus (GTK_WINDOW (toplevel)) : NULL; + GtkFileOperation *operation; + GFile *gone; + gboolean possible; + + if (focus && GTK_IS_EDITABLE (focus)) + return; + + /* out of a folder that goes away first, to the one above it */ + _gtk_file_operation_undo_label (redo, &possible); + gone = possible ? _gtk_file_operation_undo_removes (redo, impl->current_folder) : NULL; + if (gone) + { + GFile *parent = g_file_get_parent (gone); + + if (parent) + { + change_folder_and_display_error (impl, parent, FALSE); + g_object_unref (parent); + } + } + + operation = _gtk_file_operation_undo (redo, impl->file_operations_box, + GTK_IS_WINDOW (toplevel) ? GTK_WINDOW (toplevel) : NULL, + file_operation_done, impl); + if (operation) + impl->file_operations = g_slist_prepend (impl->file_operations, operation); + else + gtk_widget_error_bell (GTK_WIDGET (impl)); +} + +static void +undo_handler (GtkFileChooserDefault *impl) +{ + undo_or_redo (impl, FALSE); +} + +static void +redo_handler (GtkFileChooserDefault *impl) +{ + undo_or_redo (impl, TRUE); +} + +/* The back and forward buttons of mice, and the swipes of touchpads, + * which GDK gives as these buttons; for a press anywhere in the file + * chooser (the views pass theirs on, too) */ +static gboolean +history_button_press_cb (GtkWidget *widget, + GdkEventButton *event, + GtkFileChooserDefault *impl) +{ + /* the back and forward buttons of mice: 8 and 9 on X11, 4 and 5 on + * Windows and the Mac, where the wheel does not press buttons */ +#if defined (G_OS_WIN32) || defined (GDK_WINDOWING_QUARTZ) + const guint back = 4, forward = 5; +#else + const guint back = 8, forward = 9; +#endif + + if (event->type != GDK_BUTTON_PRESS || (event->button != back && event->button != forward)) + return FALSE; + + history_go (impl, event->button == back ? -1 : 1); + return TRUE; +} + +static void +history_buttons_create (GtkFileChooserDefault *impl, + GtkWidget *box) +{ + GtkWidget *hbox, *image; + + hbox = gtk_hbox_new (FALSE, 0); + + image = gtk_image_new_from_stock (GTK_STOCK_GO_BACK, GTK_ICON_SIZE_BUTTON); + impl->history_back_button = gtk_button_new (); + gtk_button_set_image (GTK_BUTTON (impl->history_back_button), image); + gtk_widget_set_tooltip_text (impl->history_back_button, _("Back")); + atk_object_set_name (gtk_widget_get_accessible (impl->history_back_button), _("Back")); + gtk_button_set_focus_on_click (GTK_BUTTON (impl->history_back_button), FALSE); + g_signal_connect_swapped (impl->history_back_button, "clicked", + G_CALLBACK (back_folder_handler), impl); + gtk_box_pack_start (GTK_BOX (hbox), impl->history_back_button, FALSE, FALSE, 0); + + image = gtk_image_new_from_stock (GTK_STOCK_GO_FORWARD, GTK_ICON_SIZE_BUTTON); + impl->history_forward_button = gtk_button_new (); + gtk_button_set_image (GTK_BUTTON (impl->history_forward_button), image); + gtk_widget_set_tooltip_text (impl->history_forward_button, _("Forward")); + atk_object_set_name (gtk_widget_get_accessible (impl->history_forward_button), _("Forward")); + gtk_button_set_focus_on_click (GTK_BUTTON (impl->history_forward_button), FALSE); + g_signal_connect_swapped (impl->history_forward_button, "clicked", + G_CALLBACK (forward_folder_handler), impl); + gtk_box_pack_start (GTK_BOX (hbox), impl->history_forward_button, FALSE, FALSE, 0); + + gtk_size_group_add_widget (impl->browse_path_bar_size_group, hbox); + gtk_widget_show_all (hbox); + gtk_box_pack_start (GTK_BOX (box), hbox, FALSE, FALSE, 0); + history_update_buttons (impl); +} + static void update_current_folder_get_info_cb (GCancellable *cancellable, GFileInfo *info, @@ -9074,7 +13833,10 @@ update_current_folder_get_info_cb (GCancellable *cancellable, if (impl->current_folder != data->file) { if (impl->current_folder) - g_object_unref (impl->current_folder); + { + history_add (impl, impl->current_folder, data->file); + g_object_unref (impl->current_folder); + } impl->current_folder = g_object_ref (data->file); } @@ -9099,7 +13861,9 @@ update_current_folder_get_info_cb (GCancellable *cancellable, _gtk_file_chooser_entry_set_base_folder (GTK_FILE_CHOOSER_ENTRY (impl->location_entry), impl->current_folder); - if (data->clear_entry) + if (location_entry_follows_folder (impl, data->clear_entry)) + location_entry_set_folder_text (impl); + else if (data->clear_entry) gtk_entry_set_text (GTK_ENTRY (impl->location_entry), ""); } @@ -9121,6 +13885,7 @@ update_current_folder_get_info_cb (GCancellable *cancellable, g_signal_emit_by_name (impl, "selection-changed", 0); out: + g_object_unref (data->impl); g_object_unref (data->file); g_free (data); @@ -9160,7 +13925,7 @@ gtk_file_chooser_default_update_current_folder (GtkFileChooser *chooser, /* Test validity of path here. */ data = g_new0 (struct UpdateCurrentFolderData, 1); - data->impl = impl; + data->impl = g_object_ref (impl); data->file = g_object_ref (file); data->keep_trail = keep_trail; data->clear_entry = clear_entry; @@ -9243,6 +14008,10 @@ gtk_file_chooser_default_select_file (GtkFileChooser *chooser, files.data = (gpointer) file; files.next = NULL; + /* Prevent the file chooser from loading a different folder when + * it is mapped (again: a dialog that is reused) */ + impl->reload_state = RELOAD_HAS_FOLDER; + result = show_and_select_files (impl, &files); g_object_unref (parent_file); return result; @@ -9524,6 +14293,21 @@ gtk_file_chooser_default_get_files (GtkFileChooser *chooser) if (!is_well_formed) return NULL; + /* The current folder the entry shows in Open mode + * (location_entry_set_folder_text()) is no file the user chose: + * programs get nothing for it, as for the empty entry before */ + if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN && is_file_part_empty && + info.file_from_entry && impl->current_folder && + g_file_equal (info.file_from_entry, impl->current_folder)) + { + g_object_unref (info.file_from_entry); + info.file_from_entry = NULL; + + if (!file_list_seen) + goto file_list; + goto out; + } + if (is_file_part_empty && impl->action == GTK_FILE_CHOOSER_ACTION_SAVE) { g_object_unref (info.file_from_entry); @@ -10383,8 +15167,7 @@ file_exists_get_info_cb (GCancellable *cancellable, /* Oops, the user typed the name of an existing path which is not * a folder */ - error_creating_folder_over_existing_file_dialog (data->impl, data->file, - g_error_copy (error)); + error_creating_folder_over_existing_file_dialog (data->impl); } else { @@ -10412,6 +15195,9 @@ file_exists_get_info_cb (GCancellable *cancellable, { if (is_folder) change_folder_and_display_error (data->impl, data->file, TRUE); + else if (!file_exists && + g_error_matches (error, G_IO_ERROR, G_IO_ERROR_FILENAME_TOO_LONG)) + error_filename_too_long_dialog (data->impl); else needs_parent_check = TRUE; } @@ -10812,7 +15598,7 @@ search_selected_foreach_get_file_cb (GtkTreeModel *model, list = data; gtk_tree_model_get (model, iter, MODEL_COL_FILE, &file, -1); - *list = g_slist_prepend (*list, g_object_ref (file)); + *list = g_slist_prepend (*list, file); /* The file already has a new ref courtesy of gtk_tree_model_get(); this will be unreffed by the caller */ } /* Constructs a list of the selected paths in search mode */ @@ -10987,6 +15773,10 @@ search_setup_model (GtkFileChooserDefault *impl) MODEL_COL_SIZE, size_sort_func, impl, NULL); + gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (impl->search_model), + MODEL_COL_TYPE, + type_sort_func, + impl, NULL); set_sort_column (impl); /* EB: setting the model here will make the hits list update feel @@ -11199,6 +15989,10 @@ recent_setup_model (GtkFileChooserDefault *impl) MODEL_COL_MTIME, mtime_sort_func, impl, NULL); + gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (impl->recent_model), + MODEL_COL_TYPE, + type_sort_func, + impl, NULL); set_sort_column (impl); } @@ -11241,6 +16035,22 @@ get_recent_files_limit (GtkWidget *widget) return limit; } +/* Whether @info was registered as private by other applications only; + * GtkRecentChooser leaves out private items as well */ +static gboolean +recent_item_is_private (GtkRecentInfo *info) +{ + const gchar *app_name; + + if (!gtk_recent_info_get_private_hint (info)) + return FALSE; + + app_name = g_get_application_name (); + + return app_name == NULL || + !gtk_recent_info_has_application (info, app_name); +} + /* Populates the file system model with the GtkRecentInfo* items in the provided list; frees the items */ static void populate_model_with_recent_items (GtkFileChooserDefault *impl, GList *items) @@ -11258,6 +16068,9 @@ populate_model_with_recent_items (GtkFileChooserDefault *impl, GList *items) GtkRecentInfo *info = l->data; GFile *file; + if (recent_item_is_private (info)) + continue; + file = g_file_new_for_uri (gtk_recent_info_get_uri (info)); _gtk_file_system_model_add_and_query_file (impl->recent_model, file, @@ -11414,6 +16227,19 @@ set_current_filter (GtkFileChooserDefault *impl, if (impl->recent_model) _gtk_file_system_model_set_filter (impl->recent_model, filter); + /* Folders are sensitive by the filter when choosing a folder; + * the cached sensitivity is from the old one */ + if (impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER || + impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER) + { + if (impl->browse_files_model) + _gtk_file_system_model_clear_cache (impl->browse_files_model, MODEL_COL_IS_SENSITIVE); + if (impl->search_model) + _gtk_file_system_model_clear_cache (impl->search_model, MODEL_COL_IS_SENSITIVE); + if (impl->recent_model) + _gtk_file_system_model_clear_cache (impl->recent_model, MODEL_COL_IS_SENSITIVE); + } + g_object_notify (G_OBJECT (impl), "filter"); } } @@ -11439,7 +16265,7 @@ check_preview_change (GtkFileChooserDefault *impl) if (impl->view_mode == VIEW_MODE_LIST) gtk_tree_view_get_cursor (GTK_TREE_VIEW (impl->browse_files_tree_view), &cursor_path, NULL); else if (impl->view_mode == VIEW_MODE_ICON) - cursor_path = NULL; + gtk_icon_view_get_cursor (GTK_ICON_VIEW (impl->browse_files_icon_view), &cursor_path, NULL); else g_assert_not_reached (); @@ -11488,6 +16314,7 @@ check_preview_change (GtkFileChooserDefault *impl) if (impl->use_preview_label && impl->preview_label) gtk_label_set_text (GTK_LABEL (impl->preview_label), impl->preview_display_name); + preview_panel_queue_update (impl); g_signal_emit_by_name (impl, "update-preview"); } else @@ -11690,6 +16517,562 @@ out: g_object_unref (cancellable); } +/* Connect to Server, as GTK+ 3 and Nautilus have it ("Other Locations"), + * the Finder (Command+K) and Explorer (\\server\share): a place opens a + * dialog for the address of the server, with the servers used before + * (the list of GTK+ 3 and Nautilus, ~/.config/gtk-3.0/servers, so that + * they share it) and examples of the protocols there are. GVfs mounts + * the server, asking for a password as needed; it then shows up among + * the places with its eject button. On Windows the shell connects to the + * share and asks for the name and password itself; on the Mac the Finder + * connects, and the server is opened once it is there. The place is + * only there where servers can be reached. */ + +#if !defined (G_OS_WIN32) && !defined (GDK_WINDOWING_QUARTZ) +static const struct +{ + const gchar *scheme; + const gchar *example; +} connect_examples[] = { + { "smb", "smb://server/share" }, + { "sftp", "sftp://user@server/folder" }, + { "ftp", "ftp://server" }, + { "dav", "dav://server/folder" }, + { "davs", "davs://server/folder" }, + { "nfs", "nfs://server/path" }, + { "afp", "afp://server/volume" } +}; + +static gboolean +connect_scheme_supported (const gchar *scheme) +{ + const gchar * const *schemes = g_vfs_get_supported_uri_schemes (g_vfs_get_default ()); + gint i; + + for (i = 0; schemes && schemes[i]; i++) + if (g_ascii_strcasecmp (schemes[i], scheme) == 0) + return TRUE; + return FALSE; +} +#endif + +static gboolean +connect_to_server_possible (void) +{ +#if defined (G_OS_WIN32) || defined (GDK_WINDOWING_QUARTZ) + return TRUE; +#else + gint i; + + for (i = 0; i < G_N_ELEMENTS (connect_examples); i++) + if (connect_scheme_supported (connect_examples[i].scheme)) + return TRUE; + return FALSE; +#endif +} + +static gchar * +connect_servers_filename (void) +{ + return g_build_filename (g_get_user_config_dir (), "gtk-3.0", "servers", NULL); +} + +static gint64 +connect_visited (GBookmarkFile *bookmarks, + const gchar *uri) +{ +#if GLIB_CHECK_VERSION (2, 66, 0) + GDateTime *date = g_bookmark_file_get_visited_date_time (bookmarks, uri, NULL); + + return date ? g_date_time_to_unix (date) : 0; +#else + return g_bookmark_file_get_visited (bookmarks, uri, NULL); +#endif +} + +static gint +connect_compare_visited (gconstpointer a, + gconstpointer b, + gpointer bookmarks) +{ + gint64 ta = connect_visited (bookmarks, *(const gchar **) a); + gint64 tb = connect_visited (bookmarks, *(const gchar **) b); + + return ta < tb ? 1 : ta > tb ? -1 : 0; +} + +/* The servers used before, most recent first */ +static gchar ** +connect_servers_load (void) +{ + GBookmarkFile *bookmarks = g_bookmark_file_new (); + gchar *filename = connect_servers_filename (); + gchar **uris = NULL; + gsize n = 0; + + if (g_bookmark_file_load_from_file (bookmarks, filename, NULL)) + { + uris = g_bookmark_file_get_uris (bookmarks, &n); + g_qsort_with_data (uris, n, sizeof (gchar *), connect_compare_visited, bookmarks); + } + + g_bookmark_file_free (bookmarks); + g_free (filename); + return uris; +} + +static void +connect_servers_add (GFile *file) +{ + GBookmarkFile *bookmarks = g_bookmark_file_new (); + gchar *filename = connect_servers_filename (); + gchar *dir = g_path_get_dirname (filename); + gchar *uri = g_file_get_uri (file); + gchar *title = _gtk_file_chooser_label_for_file (file); + + g_bookmark_file_load_from_file (bookmarks, filename, NULL); + g_bookmark_file_set_title (bookmarks, uri, title); +#if GLIB_CHECK_VERSION (2, 66, 0) + { + GDateTime *now = g_date_time_new_now_utc (); + + g_bookmark_file_set_visited_date_time (bookmarks, uri, now); + g_date_time_unref (now); + } +#else + g_bookmark_file_set_visited (bookmarks, uri, -1); +#endif + g_bookmark_file_add_application (bookmarks, uri, NULL, NULL); + g_mkdir_with_parents (dir, 0700); + g_bookmark_file_to_file (bookmarks, filename, NULL); + + g_bookmark_file_free (bookmarks); + g_free (title); + g_free (uri); + g_free (dir); + g_free (filename); +} + +/* What was typed, as a location: a URI, a path (\\server\share on + * Windows), or a server name for the protocol of Windows networks */ +static GFile * +connect_parse_address (const gchar *text) +{ + gchar *scheme; + + while (g_ascii_isspace (*text)) + text++; + if (*text == '\0') + return NULL; + +#ifdef G_OS_WIN32 + if (g_path_is_absolute (text)) + return g_file_new_for_path (text); + scheme = g_uri_parse_scheme (text); + if (scheme && g_ascii_strcasecmp (scheme, "smb") == 0) + { + /* smb://server/share/folder is \\server\share\folder */ + gchar *path = g_strdelimit (g_strconcat ("\\\\", text + strlen ("smb://"), NULL), "/", '\\'); + gchar *unescaped = g_uri_unescape_string (path, NULL); + GFile *file = g_file_new_for_path (unescaped ? unescaped : path); + + g_free (unescaped); + g_free (path); + g_free (scheme); + return file; + } + if (scheme) + { + g_free (scheme); + return g_file_new_for_uri (text); + } + { + gchar *path = g_strdelimit (g_strconcat ("\\\\", text, NULL), "/", '\\'); + GFile *file = g_file_new_for_path (path); + + g_free (path); + return file; + } +#else + if (g_path_is_absolute (text)) + return g_file_new_for_path (text); + scheme = g_uri_parse_scheme (text); + if (scheme) + { + g_free (scheme); + return g_file_new_for_uri (text); + } + else + { + /* "server/share", as people of Windows networks write it */ + gchar *uri = g_strconcat ("smb://", text, NULL); + GFile *file = g_file_new_for_uri (uri); + + g_free (uri); + return file; + } +#endif +} + +static void +connect_show (GtkFileChooserDefault *impl, + GFile *file, + gboolean remember) +{ + if (impl->local_only && !_gtk_file_has_native_path (file)) + { + error_message (impl, _("The server could not be opened"), + _("This program can only open local files, and the server has no local path here.")); + return; + } + + if (change_folder_and_display_error (impl, file, FALSE) && remember) + connect_servers_add (file); +} + +#ifdef GDK_WINDOWING_QUARTZ +/* in gtkquartz.c, where Cocoa is */ +gboolean _gtk_quartz_connect_to_server (const gchar *uri); + +/* The Finder mounts the server into /Volumes: what comes next is opened */ +static void +connect_mount_added (GVolumeMonitor *monitor, + GMount *mount, + GtkFileChooserDefault *impl) +{ + GFile *root = g_mount_get_root (mount); + + g_signal_handlers_disconnect_by_func (monitor, connect_mount_added, impl); + if (impl->connect_timeout) + { + g_source_remove (impl->connect_timeout); + impl->connect_timeout = 0; + } + set_busy_cursor (impl, FALSE); + connect_show (impl, root, FALSE); + g_object_unref (root); + g_object_unref (impl); +} + +static gboolean +connect_waited (gpointer data) +{ + GtkFileChooserDefault *impl = data; + GVolumeMonitor *monitor = g_volume_monitor_get (); + + impl->connect_timeout = 0; + set_busy_cursor (impl, FALSE); + g_signal_handlers_disconnect_by_func (monitor, connect_mount_added, impl); + g_object_unref (monitor); + g_object_unref (impl); + return FALSE; +} +#endif + +#if !defined (G_OS_WIN32) && !defined (GDK_WINDOWING_QUARTZ) +typedef struct +{ + GtkFileChooserDefault *impl; + GFile *file; +} ConnectData; + +static void +connect_mounted (GObject *source, + GAsyncResult *result, + gpointer user_data) +{ + ConnectData *data = user_data; + GError *error = NULL; + gboolean mounted; + + mounted = g_file_mount_enclosing_volume_finish (G_FILE (source), result, &error); + + GDK_THREADS_ENTER (); + + set_busy_cursor (data->impl, FALSE); + if (mounted || + g_error_matches (error, G_IO_ERROR, G_IO_ERROR_ALREADY_MOUNTED) || + (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED) && g_file_is_native (data->file))) + connect_show (data->impl, data->file, !g_file_is_native (data->file)); + else if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_FAILED_HANDLED)) + error_message (data->impl, _("The server could not be connected"), + error ? error->message : ""); + + GDK_THREADS_LEAVE (); + + g_clear_error (&error); + g_object_unref (data->impl); + g_object_unref (data->file); + g_slice_free (ConnectData, data); +} +#endif + +static void +connect_to (GtkFileChooserDefault *impl, + const gchar *address) +{ + GFile *file = connect_parse_address (address); + + if (file == NULL) + return; + +#ifdef G_OS_WIN32 + { + gchar *path = g_file_get_path (file); + + /* \\server\share: the shell connects, asking for the name and the + * password where they are needed */ + if (path && path[0] == '\\' && path[1] == '\\') + { + gchar **parts = g_strsplit (path + 2, "\\", 3); + GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (impl)); + HWND hwnd = NULL; + NETRESOURCEW resource = { 0 }; + gchar *share; + gunichar2 *wshare; + DWORD result; + + share = g_strdup_printf ("\\\\%s\\%s", parts[0] ? parts[0] : "", + parts[0] && parts[1] ? parts[1] : ""); + wshare = g_utf8_to_utf16 (share, -1, NULL, NULL, NULL); + if (gtk_widget_get_realized (toplevel)) + hwnd = GDK_WINDOW_HWND (toplevel->window); + resource.dwType = RESOURCETYPE_DISK; + resource.lpRemoteName = (wchar_t *) wshare; + set_busy_cursor (impl, TRUE); + result = WNetAddConnection3W (hwnd, &resource, NULL, NULL, + CONNECT_INTERACTIVE | CONNECT_TEMPORARY); + set_busy_cursor (impl, FALSE); + g_free (wshare); + g_free (share); + g_strfreev (parts); + + if (result == NO_ERROR || result == ERROR_SESSION_CREDENTIAL_CONFLICT || + result == ERROR_ALREADY_ASSIGNED || result == ERROR_DEVICE_ALREADY_REMEMBERED) + connect_show (impl, file, TRUE); + else if (result != ERROR_CANCELLED) + { + gchar *message = g_win32_error_message (result); + + error_message (impl, _("The server could not be connected"), message); + g_free (message); + } + g_free (path); + g_object_unref (file); + return; + } + g_free (path); + connect_show (impl, file, FALSE); + } +#elif defined (GDK_WINDOWING_QUARTZ) + if (g_file_is_native (file)) + connect_show (impl, file, FALSE); + else + { + gchar *uri = g_file_get_uri (file); + + if (_gtk_quartz_connect_to_server (uri)) + { + GVolumeMonitor *monitor = g_volume_monitor_get (); + + connect_servers_add (file); + g_signal_handlers_disconnect_by_func (monitor, connect_mount_added, impl); + if (impl->connect_timeout) + g_source_remove (impl->connect_timeout); + else + g_object_ref (impl); + g_signal_connect (monitor, "mount-added", G_CALLBACK (connect_mount_added), impl); + impl->connect_timeout = gdk_threads_add_timeout_seconds (120, connect_waited, impl); + set_busy_cursor (impl, TRUE); + g_object_unref (monitor); + } + else + error_message (impl, _("The server could not be connected"), uri); + g_free (uri); + } +#else + { + GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (impl)); + GMountOperation *operation = gtk_mount_operation_new (GTK_IS_WINDOW (toplevel) ? GTK_WINDOW (toplevel) : NULL); + ConnectData *data = g_slice_new (ConnectData); + + data->impl = g_object_ref (impl); + data->file = g_object_ref (file); + set_busy_cursor (impl, TRUE); + g_file_mount_enclosing_volume (file, G_MOUNT_MOUNT_NONE, operation, NULL, + connect_mounted, data); + g_object_unref (operation); + } +#endif + + g_object_unref (file); +} + +static void +connect_entry_changed (GtkEditable *entry, + GtkWidget *dialog) +{ + const gchar *text = gtk_entry_get_text (GTK_ENTRY (entry)); + + while (g_ascii_isspace (*text)) + text++; + gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT, *text != '\0'); +} + +static void +connect_response (GtkDialog *dialog, + gint response, + GtkFileChooserDefault *impl) +{ + GtkWidget *combo = g_object_get_data (G_OBJECT (dialog), "gtk-connect-combo"); + gchar *address = g_strdup (gtk_entry_get_text (GTK_ENTRY (gtk_bin_get_child (GTK_BIN (combo))))); + + gtk_widget_destroy (GTK_WIDGET (dialog)); + impl->connect_dialog = NULL; + if (response == GTK_RESPONSE_ACCEPT) + connect_to (impl, address); + g_free (address); + + /* the place is no folder to stay on */ + shortcuts_find_current_folder (impl); +} + +static void +connect_to_server_handler (GtkFileChooserDefault *impl) +{ + GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (impl)); + GtkWidget *dialog, *vbox, *hbox, *label, *combo, *entry, *help; + GString *examples; + gchar **servers, *markup; + gboolean have_examples; + gint i; + + if (impl->connect_dialog) + { + gtk_window_present (GTK_WINDOW (impl->connect_dialog)); + return; + } + + dialog = gtk_dialog_new_with_buttons (_("Connect to Server"), + GTK_IS_WINDOW (toplevel) ? GTK_WINDOW (toplevel) : NULL, + GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT | + GTK_DIALOG_NO_SEPARATOR, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + _("C_onnect"), GTK_RESPONSE_ACCEPT, + NULL); + gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT, + GTK_RESPONSE_CANCEL, -1); + gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT); + gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT, FALSE); + gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE); + gtk_container_set_border_width (GTK_CONTAINER (dialog), 5); + impl->connect_dialog = dialog; + + vbox = gtk_vbox_new (FALSE, 6); + gtk_container_set_border_width (GTK_CONTAINER (vbox), 5); + gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))), vbox, TRUE, TRUE, 0); + + hbox = gtk_hbox_new (FALSE, 12); + gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0); + label = gtk_label_new_with_mnemonic (_("Server _Address:")); + gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); + + /* the servers used before */ + combo = gtk_combo_box_text_new_with_entry (); + servers = connect_servers_load (); + for (i = 0; servers && servers[i] && i < 10; i++) + { + GFile *file = g_file_new_for_uri (servers[i]); + + if (!g_file_is_native (file)) + gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), servers[i]); + g_object_unref (file); + } + g_strfreev (servers); + entry = gtk_bin_get_child (GTK_BIN (combo)); + gtk_entry_set_activates_default (GTK_ENTRY (entry), TRUE); + gtk_entry_set_width_chars (GTK_ENTRY (entry), 36); + gtk_label_set_mnemonic_widget (GTK_LABEL (label), entry); + g_signal_connect (entry, "changed", G_CALLBACK (connect_entry_changed), dialog); + gtk_box_pack_start (GTK_BOX (hbox), combo, TRUE, TRUE, 0); + g_object_set_data (G_OBJECT (dialog), I_("gtk-connect-combo"), combo); + + /* what can be typed */ + examples = g_string_new (NULL); +#ifdef G_OS_WIN32 + g_string_append (examples, "\\\\server\\share\nsmb://server/share"); +#elif defined (GDK_WINDOWING_QUARTZ) + g_string_append (examples, "smb://server/share\nafp://server/volume\nftp://server\nhttp://server/webdav"); +#else + for (i = 0; i < G_N_ELEMENTS (connect_examples); i++) + if (connect_scheme_supported (connect_examples[i].scheme)) + { + if (examples->len) + g_string_append_c (examples, '\n'); + g_string_append (examples, connect_examples[i].example); + } +#endif + have_examples = examples->len > 0; + { + gchar *escaped = g_markup_escape_text (examples->str, -1); + + /* Translators: above examples of server addresses */ + markup = g_strdup_printf ("%s\n%s", _("For example:"), escaped); + g_free (escaped); + } + g_string_free (examples, TRUE); + help = gtk_label_new (NULL); + gtk_label_set_markup (GTK_LABEL (help), markup); + gtk_misc_set_alignment (GTK_MISC (help), 0.0, 0.0); + gtk_label_set_selectable (GTK_LABEL (help), TRUE); + gtk_box_pack_start (GTK_BOX (vbox), help, FALSE, FALSE, 0); + gtk_widget_set_no_show_all (help, !have_examples); + g_free (markup); + + g_signal_connect (dialog, "response", G_CALLBACK (connect_response), impl); + gtk_widget_show_all (dialog); + gtk_widget_grab_focus (entry); +} + +static GdkPixbuf * +render_connect_icon (GtkFileChooserDefault *impl) +{ + GtkIconTheme *theme = gtk_icon_theme_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (impl))); + GdkPixbuf *pixbuf; + + pixbuf = gtk_icon_theme_load_icon (theme, "network-server", impl->list_view_icon_size, 0, NULL); + if (pixbuf == NULL) + pixbuf = gtk_icon_theme_load_icon (theme, "network-workgroup", impl->list_view_icon_size, 0, NULL); + if (pixbuf == NULL) + pixbuf = gtk_widget_render_icon (GTK_WIDGET (impl), GTK_STOCK_NETWORK, GTK_ICON_SIZE_MENU, NULL); + return pixbuf; +} + +static void +shortcuts_append_connect (GtkFileChooserDefault *impl) +{ + GdkPixbuf *pixbuf; + GtkTreeIter iter; + + impl->has_connect = connect_to_server_possible (); + if (!impl->has_connect) + return; + + pixbuf = render_connect_icon (impl); + gtk_list_store_insert (impl->shortcuts_model, &iter, + shortcuts_get_index (impl, SHORTCUTS_CONNECT)); + gtk_list_store_set (impl->shortcuts_model, &iter, + SHORTCUTS_COL_PIXBUF, pixbuf, + SHORTCUTS_COL_PIXBUF_VISIBLE, TRUE, + SHORTCUTS_COL_NAME, _("Connect to Server…"), + SHORTCUTS_COL_DATA, NULL, + SHORTCUTS_COL_TYPE, SHORTCUT_TYPE_CONNECT, + SHORTCUTS_COL_REMOVABLE, FALSE, + -1); + if (pixbuf) + g_object_unref (pixbuf); +} + static void shortcuts_activate_iter (GtkFileChooserDefault *impl, GtkTreeIter *iter) @@ -11754,6 +17137,10 @@ shortcuts_activate_iter (GtkFileChooserDefault *impl, { operation_mode_set (impl, OPERATION_MODE_RECENT); } + else if (shortcut_type == SHORTCUT_TYPE_CONNECT) + { + connect_to_server_handler (impl); + } } /* Handler for GtkWidget::key-press-event on the shortcuts list */ @@ -11918,13 +17305,15 @@ item_activated (GtkTreeModel *model, if (is_sensitive && is_folder && file) { change_folder_and_display_error (impl, file, FALSE); - return; + goto out; } if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN || impl->action == GTK_FILE_CHOOSER_ACTION_SAVE) g_signal_emit_by_name (impl, "file-activated"); + out: + if (file) g_object_unref (file); } @@ -11987,26 +17376,29 @@ update_cell_renderer_attributes (GtkFileChooserDefault *impl) } g_list_free (list); - /* size */ - column = gtk_tree_view_get_column (GTK_TREE_VIEW (impl->browse_files_tree_view), 1); - list = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (column)); - renderer = list->data; - gtk_tree_view_column_set_attributes (column, renderer, - "text", MODEL_COL_SIZE_TEXT, - NULL); + /* size, type, mtime */ + { + GtkTreeViewColumn *columns[3]; + gint texts[3], i; - gtk_tree_view_column_add_attribute (column, renderer, "sensitive", MODEL_COL_IS_SENSITIVE); - g_list_free (list); + columns[0] = impl->list_size_column; + texts[0] = MODEL_COL_SIZE_TEXT; + columns[1] = impl->list_type_column; + texts[1] = MODEL_COL_TYPE; + columns[2] = impl->list_mtime_column; + texts[2] = MODEL_COL_MTIME_TEXT; - /* mtime */ - column = gtk_tree_view_get_column (GTK_TREE_VIEW (impl->browse_files_tree_view), 2); - list = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (column)); - renderer = list->data; - gtk_tree_view_column_set_attributes (column, renderer, - "text", MODEL_COL_MTIME_TEXT, - NULL); - gtk_tree_view_column_add_attribute (column, renderer, "sensitive", MODEL_COL_IS_SENSITIVE); - g_list_free (list); + for (i = 0; i < G_N_ELEMENTS (columns); i++) + { + list = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (columns[i])); + renderer = list->data; + gtk_tree_view_column_set_attributes (columns[i], renderer, + "text", texts[i], + NULL); + gtk_tree_view_column_add_attribute (columns[i], renderer, "sensitive", MODEL_COL_IS_SENSITIVE); + g_list_free (list); + } + } } GtkWidget * @@ -12260,6 +17652,8 @@ get_selected_tree_iter_from_icon_view (GtkFileChooserDefault *impl, return TRUE; } +/* In the order shown, as in the list view; the list is taken first, + * as @func may run a dialog, meanwhile the folder may change */ static void icon_view_selection_selected_foreach (GtkFileChooserDefault *impl, GtkTreeSelectionForeachFunc func, @@ -12271,6 +17665,7 @@ icon_view_selection_selected_foreach (GtkFileChooserDefault *impl, GtkTreePath *icon_selection_path; icon_selection = gtk_icon_view_get_selected_items (GTK_ICON_VIEW (impl->browse_files_icon_view)); + icon_selection = g_list_reverse (icon_selection); for (elem = icon_selection; elem; elem = elem->next) { icon_selection_path = elem->data; diff --git a/gtk/gtkfilechooserdefault.h b/gtk/gtkfilechooserdefault.h index e6eabefef..c7602d7ed 100644 --- a/gtk/gtkfilechooserdefault.h +++ b/gtk/gtkfilechooserdefault.h @@ -32,7 +32,7 @@ G_BEGIN_DECLS typedef struct _GtkFileChooserDefault GtkFileChooserDefault; -GType _gtk_file_chooser_default_get_type (void) G_GNUC_CONST; +GType _gtk_file_chooser_default_get_type (void); GtkWidget *_gtk_file_chooser_default_new (void); G_END_DECLS diff --git a/gtk/gtkfilechooserdialog.c b/gtk/gtkfilechooserdialog.c index ea00895c9..9cc204d31 100644 --- a/gtk/gtkfilechooserdialog.c +++ b/gtk/gtkfilechooserdialog.c @@ -141,7 +141,8 @@ file_chooser_widget_file_activated (GtkFileChooser *chooser, widget = GTK_WIDGET (l->data); response_id = gtk_dialog_get_response_for_widget (GTK_DIALOG (dialog), widget); - if (is_stock_accept_response_id (response_id)) + if (gtk_widget_is_sensitive (widget) && + is_stock_accept_response_id (response_id)) { gtk_widget_activate (widget); /* Should we gtk_dialog_response (dialog, response_id) instead? */ break; @@ -238,7 +239,8 @@ file_chooser_widget_response_requested (GtkWidget *widget, widget = GTK_WIDGET (l->data); response_id = gtk_dialog_get_response_for_widget (GTK_DIALOG (dialog), widget); - if (is_stock_accept_response_id (response_id)) + if (gtk_widget_is_sensitive (widget) && + is_stock_accept_response_id (response_id)) { gtk_widget_activate (widget); /* Should we gtk_dialog_response (dialog, response_id) instead? */ break; diff --git a/gtk/gtkfilechooserdialog.h b/gtk/gtkfilechooserdialog.h index 78c02d2a4..0d861309d 100644 --- a/gtk/gtkfilechooserdialog.h +++ b/gtk/gtkfilechooserdialog.h @@ -53,7 +53,7 @@ struct _GtkFileChooserDialogClass GtkDialogClass parent_class; }; -GType gtk_file_chooser_dialog_get_type (void) G_GNUC_CONST; +GType gtk_file_chooser_dialog_get_type (void); GtkWidget *gtk_file_chooser_dialog_new (const gchar *title, GtkWindow *parent, GtkFileChooserAction action, diff --git a/gtk/gtkfilechooserembed.h b/gtk/gtkfilechooserembed.h index 65888981e..49061f57f 100644 --- a/gtk/gtkfilechooserembed.h +++ b/gtk/gtkfilechooserembed.h @@ -53,7 +53,7 @@ struct _GtkFileChooserEmbedIface void (*response_requested) (GtkFileChooserEmbed *chooser_embed); }; -GType _gtk_file_chooser_embed_get_type (void) G_GNUC_CONST; +GType _gtk_file_chooser_embed_get_type (void); void _gtk_file_chooser_embed_get_default_size (GtkFileChooserEmbed *chooser_embed, gint *default_width, diff --git a/gtk/gtkfilechooserentry.c b/gtk/gtkfilechooserentry.c index 07872d0d0..daf73fbf5 100644 --- a/gtk/gtkfilechooserentry.c +++ b/gtk/gtkfilechooserentry.c @@ -65,6 +65,8 @@ struct _GtkFileChooserEntry guint complete_on_load : 1; guint eat_tabs : 1; guint local_only : 1; + guint text_from_program : 1; + guint setting_program_text : 1; }; enum @@ -165,6 +167,20 @@ _gtk_file_chooser_entry_class_init (GtkFileChooserEntryClass *class) widget_class->focus_out_event = gtk_file_chooser_entry_focus_out_event; } +static void update_inline_completion (GtkFileChooserEntry *chooser_entry); + +/* The first change after _gtk_file_chooser_entry_set_folder_text() turns + * the inline completion on again */ +static void +user_edit_callback (GtkFileChooserEntry *chooser_entry) +{ + if (chooser_entry->text_from_program && !chooser_entry->setting_program_text) + { + chooser_entry->text_from_program = FALSE; + update_inline_completion (chooser_entry); + } +} + static void _gtk_file_chooser_entry_init (GtkFileChooserEntry *chooser_entry) { @@ -198,6 +214,13 @@ _gtk_file_chooser_entry_init (GtkFileChooserEntry *chooser_entry) g_signal_connect (comp, "match-selected", G_CALLBACK (match_selected_callback), chooser_entry); + /* NB: These need to be connected before the completion is set, so that + * they run before the handlers installed by entrycompletion */ + g_signal_connect (chooser_entry, "insert-text", + G_CALLBACK (user_edit_callback), NULL); + g_signal_connect (chooser_entry, "delete-text", + G_CALLBACK (user_edit_callback), NULL); + gtk_entry_set_completion (GTK_ENTRY (chooser_entry), comp); g_object_unref (comp); /* NB: This needs to happen after the completion is set, so this handler @@ -452,7 +475,7 @@ update_inline_completion (GtkFileChooserEntry *chooser_entry) { GtkEntryCompletion *completion = gtk_entry_get_completion (GTK_ENTRY (chooser_entry)); - if (!chooser_entry->current_folder_loaded) + if (!chooser_entry->current_folder_loaded || chooser_entry->text_from_program) { gtk_entry_completion_set_inline_completion (completion, FALSE); return; @@ -571,7 +594,8 @@ finished_loading_cb (GtkFileSystemModel *model, completion = gtk_entry_get_completion (GTK_ENTRY (chooser_entry)); update_inline_completion (chooser_entry); - if (gtk_widget_has_focus (GTK_WIDGET (chooser_entry))) + if (gtk_widget_has_focus (GTK_WIDGET (chooser_entry)) && + !chooser_entry->text_from_program) { gtk_entry_completion_complete (completion); gtk_entry_completion_insert_prefix (completion); @@ -948,6 +972,32 @@ _gtk_file_chooser_entry_select_filename (GtkFileChooserEntry *chooser_entry) gtk_editable_select_region (GTK_EDITABLE (chooser_entry), 0, (gint) len); } +/* Sets a folder path the user did not type: nothing is completed for it, + * neither inline (which would add the name of the only subfolder there) + * nor in the popup, until the user changes the text. */ +void +_gtk_file_chooser_entry_set_folder_text (GtkFileChooserEntry *chooser_entry, + const gchar *text) +{ + GtkEntryCompletion *completion; + gboolean popup; + + g_return_if_fail (GTK_IS_FILE_CHOOSER_ENTRY (chooser_entry)); + + completion = gtk_entry_get_completion (GTK_ENTRY (chooser_entry)); + chooser_entry->text_from_program = TRUE; + update_inline_completion (chooser_entry); + + popup = gtk_entry_completion_get_popup_completion (completion); + if (popup) + gtk_entry_completion_set_popup_completion (completion, FALSE); + chooser_entry->setting_program_text = TRUE; + gtk_entry_set_text (GTK_ENTRY (chooser_entry), text); + chooser_entry->setting_program_text = FALSE; + if (popup) + gtk_entry_completion_set_popup_completion (completion, TRUE); +} + void _gtk_file_chooser_entry_set_local_only (GtkFileChooserEntry *chooser_entry, gboolean local_only) diff --git a/gtk/gtkfilechooserentry.h b/gtk/gtkfilechooserentry.h index 216b8ae72..1c0568663 100644 --- a/gtk/gtkfilechooserentry.h +++ b/gtk/gtkfilechooserentry.h @@ -32,7 +32,7 @@ G_BEGIN_DECLS typedef struct _GtkFileChooserEntry GtkFileChooserEntry; -GType _gtk_file_chooser_entry_get_type (void) G_GNUC_CONST; +GType _gtk_file_chooser_entry_get_type (void); GtkWidget * _gtk_file_chooser_entry_new (gboolean eat_tab); void _gtk_file_chooser_entry_set_action (GtkFileChooserEntry *chooser_entry, GtkFileChooserAction action); @@ -44,6 +44,8 @@ const gchar * _gtk_file_chooser_entry_get_file_part (GtkFileChooserEnt gboolean _gtk_file_chooser_entry_get_is_folder (GtkFileChooserEntry *chooser_entry, GFile *file); void _gtk_file_chooser_entry_select_filename (GtkFileChooserEntry *chooser_entry); +void _gtk_file_chooser_entry_set_folder_text (GtkFileChooserEntry *chooser_entry, + const gchar *text); void _gtk_file_chooser_entry_set_local_only (GtkFileChooserEntry *chooser_entry, gboolean local_only); gboolean _gtk_file_chooser_entry_get_local_only (GtkFileChooserEntry *chooser_entry); diff --git a/gtk/gtkfilechoosernative.c b/gtk/gtkfilechoosernative.c new file mode 100644 index 000000000..28e1f5169 --- /dev/null +++ b/gtk/gtkfilechoosernative.c @@ -0,0 +1,657 @@ +/* GTK - The GIMP Toolkit + * gtkfilechoosernative.c: Native File selector dialog + * Copyright (C) 2015, Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +/* GtkFileChooserNative as in GTK+ 3.20: the file dialog of Windows (also + * XP and ReactOS) and Mac OS X, the one of the desktop portal where + * GTK_USE_PORTAL=1 or in Flatpak, and a GtkFileChooserDialog + * elsewhere. It keeps its GtkFileChooser state in a hidden + * GtkFileChooserDialog, which is the fallback too. Pale Moon and + * Firefox look for it at run time (widget.allow-gtk-native-file-chooser). */ + +#include "config.h" + +#include + +#include "gtkfilechoosernative.h" +#include "gtkfilechoosernativeprivate.h" +#include "gtknativedialogprivate.h" +#include "gtkfilechooserdialog.h" +#include "gtkfilechooserprivate.h" +#include "gtkfilechooserutils.h" +#include "gtkbutton.h" +#include "gtkstock.h" +#include "gtkintl.h" +#include "gtkprivate.h" +#include "gtkalias.h" + +/** + * SECTION:gtkfilechoosernative + * @Short_description: A native file chooser dialog, suitable for "File/Open" or "File/Save" commands + * @Title: GtkFileChooserNative + * @See_also: #GtkFileChooser, #GtkNativeDialog, #GtkFileChooserDialog + * + * #GtkFileChooserNative is an abstraction of a dialog box suitable + * for use with "File/Open" or "File/Save as" commands. By default, this + * just uses a #GtkFileChooserDialog to implement the actual dialog. + * However, on Windows and Mac OS X, it uses the native file chooser + * dialog of the system, and where GTK_USE_PORTAL=1 is set or in a + * Flatpak sandbox, the file chooser of the desktop portal. + * + * As with GTK+ 3.20, preview widgets and extra widgets are not shown + * by the native dialogs, and a filter with custom rules makes the + * Windows and Mac OS X dialogs fall back to the #GtkFileChooserDialog. + */ + +enum { + MODE_FALLBACK, + MODE_WIN32, + MODE_QUARTZ, + MODE_PORTAL +}; + +enum { + PROP_0, + PROP_ACCEPT_LABEL, + PROP_CANCEL_LABEL, + LAST_ARG +}; + +static GParamSpec *native_props[LAST_ARG] = { NULL, }; + +static void _gtk_file_chooser_native_iface_init (GtkFileChooserIface *iface); + +G_DEFINE_TYPE_WITH_CODE (GtkFileChooserNative, gtk_file_chooser_native, GTK_TYPE_NATIVE_DIALOG, + G_IMPLEMENT_INTERFACE (GTK_TYPE_FILE_CHOOSER, + _gtk_file_chooser_native_iface_init)) + +/** + * gtk_file_chooser_native_get_accept_label: + * @self: a #GtkFileChooserNative + * + * Retrieves the custom label text for the accept button. + * + * Returns: (nullable): The custom label, or %NULL for the default. This string + * is owned by GTK+ and should not be modified or freed + * + * Since: 2.24 + **/ +const char * +gtk_file_chooser_native_get_accept_label (GtkFileChooserNative *self) +{ + g_return_val_if_fail (GTK_IS_FILE_CHOOSER_NATIVE (self), NULL); + + return self->accept_label; +} + +/** + * gtk_file_chooser_native_set_accept_label: + * @self: a #GtkFileChooserNative + * @accept_label: (allow-none): custom label or %NULL for the default + * + * Sets the custom label text for the accept button. + * + * If characters in @label are preceded by an underscore, they are underlined. + * If you need a literal underscore character in a label, use "__" (two + * underscores). The first underlined character represents a keyboard + * accelerator called a mnemonic. + * Pressing Alt and that key activates the button. + * + * Since: 2.24 + **/ +void +gtk_file_chooser_native_set_accept_label (GtkFileChooserNative *self, + const char *accept_label) +{ + g_return_if_fail (GTK_IS_FILE_CHOOSER_NATIVE (self)); + + g_free (self->accept_label); + self->accept_label = g_strdup (accept_label); + + g_object_notify_by_pspec (G_OBJECT (self), native_props[PROP_ACCEPT_LABEL]); +} + +/** + * gtk_file_chooser_native_get_cancel_label: + * @self: a #GtkFileChooserNative + * + * Retrieves the custom label text for the cancel button. + * + * Returns: (nullable): The custom label, or %NULL for the default. This string + * is owned by GTK+ and should not be modified or freed + * + * Since: 2.24 + **/ +const char * +gtk_file_chooser_native_get_cancel_label (GtkFileChooserNative *self) +{ + g_return_val_if_fail (GTK_IS_FILE_CHOOSER_NATIVE (self), NULL); + + return self->cancel_label; +} + +/** + * gtk_file_chooser_native_set_cancel_label: + * @self: a #GtkFileChooserNative + * @cancel_label: (allow-none): custom label or %NULL for the default + * + * Sets the custom label text for the cancel button. + * + * If characters in @label are preceded by an underscore, they are underlined. + * If you need a literal underscore character in a label, use "__" (two + * underscores). The first underlined character represents a keyboard + * accelerator called a mnemonic. + * Pressing Alt and that key activates the button. + * + * Since: 2.24 + **/ +void +gtk_file_chooser_native_set_cancel_label (GtkFileChooserNative *self, + const char *cancel_label) +{ + g_return_if_fail (GTK_IS_FILE_CHOOSER_NATIVE (self)); + + g_free (self->cancel_label); + self->cancel_label = g_strdup (cancel_label); + + g_object_notify_by_pspec (G_OBJECT (self), native_props[PROP_CANCEL_LABEL]); +} + +/* "_Save" -> "Save", "__" -> "_" */ +gchar * +_gtk_file_chooser_native_strip_mnemonic (const gchar *label) +{ + GString *s; + const gchar *p; + + if (label == NULL) + return NULL; + + s = g_string_new (NULL); + for (p = label; *p; p++) + { + if (*p == '_') + { + if (p[1] == '_') + p++; + else + continue; + } + g_string_append_c (s, *p); + } + + return g_string_free (s, FALSE); +} + +static void +gtk_file_chooser_native_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + GtkFileChooserNative *self = GTK_FILE_CHOOSER_NATIVE (object); + + switch (prop_id) + { + case PROP_ACCEPT_LABEL: + gtk_file_chooser_native_set_accept_label (self, g_value_get_string (value)); + break; + + case PROP_CANCEL_LABEL: + gtk_file_chooser_native_set_cancel_label (self, g_value_get_string (value)); + break; + + case GTK_FILE_CHOOSER_PROP_FILE_SYSTEM_BACKEND: + /* construct-only, and the dialog is made already */ + break; + + case GTK_FILE_CHOOSER_PROP_FILTER: + self->current_filter = g_value_get_object (value); + gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (self->dialog), self->current_filter); + g_object_notify (G_OBJECT (self), "filter"); + break; + + default: + g_object_set_property (G_OBJECT (self->dialog), pspec->name, value); + break; + } +} + +static void +gtk_file_chooser_native_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + GtkFileChooserNative *self = GTK_FILE_CHOOSER_NATIVE (object); + + switch (prop_id) + { + case PROP_ACCEPT_LABEL: + g_value_set_string (value, self->accept_label); + break; + + case PROP_CANCEL_LABEL: + g_value_set_string (value, self->cancel_label); + break; + + case GTK_FILE_CHOOSER_PROP_FILTER: + self->current_filter = gtk_file_chooser_get_filter (GTK_FILE_CHOOSER (self->dialog)); + g_value_set_object (value, self->current_filter); + break; + + default: + g_object_get_property (G_OBJECT (self->dialog), pspec->name, value); + break; + } +} + +static void +gtk_file_chooser_native_finalize (GObject *object) +{ + GtkFileChooserNative *self = GTK_FILE_CHOOSER_NATIVE (object); + + g_free (self->current_name); + if (self->current_file) + g_object_unref (self->current_file); + if (self->current_folder) + g_object_unref (self->current_folder); + + g_free (self->accept_label); + g_free (self->cancel_label); + gtk_widget_destroy (self->dialog); + g_object_unref (self->dialog); + + g_slist_foreach (self->custom_files, (GFunc) g_object_unref, NULL); + g_slist_free (self->custom_files); + + G_OBJECT_CLASS (gtk_file_chooser_native_parent_class)->finalize (object); +} + +static gint +override_delete_handler (GtkDialog *dialog, + GdkEventAny *event, + gpointer data) +{ + return TRUE; /* Do not destroy */ +} + +static void +gtk_file_chooser_native_init (GtkFileChooserNative *self) +{ + /* All properties go to a file chooser dialog: it keeps the state, and + * it is there when the native one cannot be used */ + self->dialog = g_object_new (GTK_TYPE_FILE_CHOOSER_DIALOG, NULL); + g_object_ref_sink (self->dialog); + self->cancel_button = gtk_dialog_add_button (GTK_DIALOG (self->dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL); + self->accept_button = gtk_dialog_add_button (GTK_DIALOG (self->dialog), GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT); + + gtk_dialog_set_default_response (GTK_DIALOG (self->dialog), + GTK_RESPONSE_ACCEPT); + gtk_dialog_set_alternative_button_order (GTK_DIALOG (self->dialog), + GTK_RESPONSE_ACCEPT, + GTK_RESPONSE_CANCEL, + -1); + + /* not destroyed on delete events, but hidden in the response handler */ + g_signal_connect (self->dialog, + "delete-event", + G_CALLBACK (override_delete_handler), + NULL); + + /* The delegate of the methods, set without _gtk_file_chooser_set_delegate() + * so that its signals do not come twice */ + g_object_set_qdata (G_OBJECT (self), GTK_FILE_CHOOSER_DELEGATE_QUARK, self->dialog); +} + +/** + * gtk_file_chooser_native_new: + * @title: (allow-none): Title of the native, or %NULL + * @parent: (allow-none): Transient parent of the native, or %NULL + * @action: Open or save mode for the dialog + * @accept_label: (allow-none): text to go in the accept button, or %NULL for the default + * @cancel_label: (allow-none): text to go in the cancel button, or %NULL for the default + * + * Creates a new #GtkFileChooserNative. + * + * Returns: a new #GtkFileChooserNative + * + * Since: 2.24 + **/ +GtkFileChooserNative * +gtk_file_chooser_native_new (const gchar *title, + GtkWindow *parent, + GtkFileChooserAction action, + const gchar *accept_label, + const gchar *cancel_label) +{ + return g_object_new (GTK_TYPE_FILE_CHOOSER_NATIVE, + "title", title, + "action", action, + "transient-for", parent, + "accept-label", accept_label, + "cancel-label", cancel_label, + NULL); +} + +static void +dialog_response_cb (GtkDialog *dialog, + gint response_id, + gpointer data) +{ + GtkFileChooserNative *self = data; + + g_signal_handlers_disconnect_by_func (self->dialog, dialog_response_cb, self); + gtk_widget_hide (self->dialog); + + _gtk_native_dialog_emit_response (GTK_NATIVE_DIALOG (self), response_id); +} + +static void +dialog_update_preview_cb (GtkFileChooser *file_chooser, + gpointer data) +{ + g_signal_emit_by_name (data, "update-preview"); +} + +static void +set_button_label (GtkWidget *button, + const gchar *label, + const gchar *stock_id) +{ + if (label) + { + gtk_button_set_use_stock (GTK_BUTTON (button), FALSE); + gtk_button_set_image (GTK_BUTTON (button), NULL); + gtk_button_set_use_underline (GTK_BUTTON (button), TRUE); + gtk_button_set_label (GTK_BUTTON (button), label); + } + else + { + gtk_button_set_use_stock (GTK_BUTTON (button), TRUE); + gtk_button_set_label (GTK_BUTTON (button), stock_id); + } +} + +static void +show_dialog (GtkFileChooserNative *self) +{ + GtkFileChooserAction action; + + action = gtk_file_chooser_get_action (GTK_FILE_CHOOSER (self->dialog)); + + set_button_label (self->accept_button, self->accept_label, + action == GTK_FILE_CHOOSER_ACTION_SAVE ? GTK_STOCK_SAVE : GTK_STOCK_OPEN); + set_button_label (self->cancel_button, self->cancel_label, GTK_STOCK_CANCEL); + + gtk_window_set_title (GTK_WINDOW (self->dialog), + gtk_native_dialog_get_title (GTK_NATIVE_DIALOG (self))); + + gtk_window_set_transient_for (GTK_WINDOW (self->dialog), + gtk_native_dialog_get_transient_for (GTK_NATIVE_DIALOG (self))); + + gtk_window_set_modal (GTK_WINDOW (self->dialog), + gtk_native_dialog_get_modal (GTK_NATIVE_DIALOG (self))); + + g_signal_connect (self->dialog, + "response", + G_CALLBACK (dialog_response_cb), + self); + + g_signal_connect (self->dialog, + "update-preview", + G_CALLBACK (dialog_update_preview_cb), + self); + + gtk_window_present (GTK_WINDOW (self->dialog)); +} + +void +_gtk_file_chooser_native_show_fallback (GtkFileChooserNative *self) +{ + self->mode = MODE_FALLBACK; + show_dialog (self); +} + +static void +hide_dialog (GtkFileChooserNative *self) +{ + g_signal_handlers_disconnect_by_func (self->dialog, dialog_response_cb, self); + g_signal_handlers_disconnect_by_func (self->dialog, dialog_update_preview_cb, self); + gtk_widget_hide (self->dialog); +} + +static void +set_object (GFile **where, + GFile *file) +{ + if (file) + g_object_ref (file); + if (*where) + g_object_unref (*where); + *where = file; +} + +static gboolean +gtk_file_chooser_native_set_current_folder (GtkFileChooser *chooser, + GFile *file, + GError **error) +{ + GtkFileChooserNative *self = GTK_FILE_CHOOSER_NATIVE (chooser); + gboolean res; + + res = gtk_file_chooser_set_current_folder_file (GTK_FILE_CHOOSER (self->dialog), + file, error); + if (res) + { + set_object (&self->current_folder, file); + set_object (&self->current_file, NULL); + } + + return res; +} + +static gboolean +gtk_file_chooser_native_select_file (GtkFileChooser *chooser, + GFile *file, + GError **error) +{ + GtkFileChooserNative *self = GTK_FILE_CHOOSER_NATIVE (chooser); + gboolean res; + + res = gtk_file_chooser_select_file (GTK_FILE_CHOOSER (self->dialog), + file, error); + if (res) + { + set_object (&self->current_file, file); + set_object (&self->current_folder, NULL); + g_free (self->current_name); + self->current_name = NULL; + } + + return res; +} + +static void +gtk_file_chooser_native_set_current_name (GtkFileChooser *chooser, + const gchar *name) +{ + GtkFileChooserNative *self = GTK_FILE_CHOOSER_NATIVE (chooser); + + gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (self->dialog), name); + + g_free (self->current_name); + self->current_name = g_strdup (name); + + set_object (&self->current_file, NULL); +} + +static GSList * +gtk_file_chooser_native_get_files (GtkFileChooser *chooser) +{ + GtkFileChooserNative *self = GTK_FILE_CHOOSER_NATIVE (chooser); + GSList *l, *copy = NULL; + + switch (self->mode) + { + case MODE_PORTAL: + case MODE_WIN32: + case MODE_QUARTZ: + for (l = self->custom_files; l; l = l->next) + copy = g_slist_prepend (copy, g_object_ref (l->data)); + return g_slist_reverse (copy); + + case MODE_FALLBACK: + default: + return gtk_file_chooser_get_files (GTK_FILE_CHOOSER (self->dialog)); + } +} + +static GFile * +gtk_file_chooser_native_get_current_folder (GtkFileChooser *chooser) +{ + GtkFileChooserNative *self = GTK_FILE_CHOOSER_NATIVE (chooser); + + /* after a native dialog, the folder of what was chosen */ + if (self->mode != MODE_FALLBACK && self->custom_files) + { + GFile *first = self->custom_files->data; + + if (gtk_file_chooser_get_action (chooser) == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER || + gtk_file_chooser_get_action (chooser) == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER) + return g_object_ref (first); + return g_file_get_parent (first); + } + + return gtk_file_chooser_get_current_folder_file (GTK_FILE_CHOOSER (self->dialog)); +} + +static void +gtk_file_chooser_native_show (GtkNativeDialog *native) +{ + GtkFileChooserNative *self = GTK_FILE_CHOOSER_NATIVE (native); + + self->mode = MODE_FALLBACK; + +#ifdef GDK_WINDOWING_WIN32 + if (_gtk_file_chooser_native_win32_show (self)) + self->mode = MODE_WIN32; +#endif + +#ifdef GDK_WINDOWING_QUARTZ + if (_gtk_file_chooser_native_quartz_show (self)) + self->mode = MODE_QUARTZ; +#endif + + if (self->mode == MODE_FALLBACK && + _gtk_file_chooser_native_portal_show (self)) + self->mode = MODE_PORTAL; + + if (self->mode == MODE_FALLBACK) + show_dialog (self); +} + +static void +gtk_file_chooser_native_hide (GtkNativeDialog *native) +{ + GtkFileChooserNative *self = GTK_FILE_CHOOSER_NATIVE (native); + + switch (self->mode) + { + case MODE_FALLBACK: + hide_dialog (self); + break; + case MODE_WIN32: +#ifdef GDK_WINDOWING_WIN32 + _gtk_file_chooser_native_win32_hide (self); +#endif + break; + case MODE_QUARTZ: +#ifdef GDK_WINDOWING_QUARTZ + _gtk_file_chooser_native_quartz_hide (self); +#endif + break; + case MODE_PORTAL: + _gtk_file_chooser_native_portal_hide (self); + break; + } +} + +static void +gtk_file_chooser_native_class_init (GtkFileChooserNativeClass *class) +{ + GObjectClass *gobject_class = G_OBJECT_CLASS (class); + GtkNativeDialogClass *native_dialog_class = GTK_NATIVE_DIALOG_CLASS (class); + + gobject_class->finalize = gtk_file_chooser_native_finalize; + gobject_class->set_property = gtk_file_chooser_native_set_property; + gobject_class->get_property = gtk_file_chooser_native_get_property; + + native_dialog_class->show = gtk_file_chooser_native_show; + native_dialog_class->hide = gtk_file_chooser_native_hide; + + _gtk_file_chooser_install_properties (gobject_class); + + /** + * GtkFileChooserNative:accept-label: + * + * The text used for the label on the accept button in the dialog, or + * %NULL to use the default text. + * + * Since: 2.24 + */ + native_props[PROP_ACCEPT_LABEL] = + g_param_spec_string ("accept-label", + P_("Accept label"), + P_("The label on the accept button"), + NULL, + GTK_PARAM_READWRITE); + + /** + * GtkFileChooserNative:cancel-label: + * + * The text used for the label on the cancel button in the dialog, or + * %NULL to use the default text. + * + * Since: 2.24 + */ + native_props[PROP_CANCEL_LABEL] = + g_param_spec_string ("cancel-label", + P_("Cancel label"), + P_("The label on the cancel button"), + NULL, + GTK_PARAM_READWRITE); + + g_object_class_install_property (gobject_class, PROP_ACCEPT_LABEL, native_props[PROP_ACCEPT_LABEL]); + g_object_class_install_property (gobject_class, PROP_CANCEL_LABEL, native_props[PROP_CANCEL_LABEL]); +} + +static void +_gtk_file_chooser_native_iface_init (GtkFileChooserIface *iface) +{ + _gtk_file_chooser_delegate_iface_init (iface); + iface->select_file = gtk_file_chooser_native_select_file; + iface->set_current_name = gtk_file_chooser_native_set_current_name; + iface->set_current_folder = gtk_file_chooser_native_set_current_folder; + iface->get_current_folder = gtk_file_chooser_native_get_current_folder; + iface->get_files = gtk_file_chooser_native_get_files; +} + +#define __GTK_FILE_CHOOSER_NATIVE_C__ +#include "gtkaliasdef.c" diff --git a/gtk/gtkfilechoosernative.h b/gtk/gtkfilechoosernative.h new file mode 100644 index 000000000..fb8f852ca --- /dev/null +++ b/gtk/gtkfilechoosernative.h @@ -0,0 +1,68 @@ +/* GTK - The GIMP Toolkit + * gtkfilechoosernative.h: Native File selector dialog + * Copyright (C) 2015, Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef __GTK_FILE_CHOOSER_NATIVE_H__ +#define __GTK_FILE_CHOOSER_NATIVE_H__ + +#if defined(GTK_DISABLE_SINGLE_INCLUDES) && !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION) +#error "Only can be included directly." +#endif + +#include +#include + +G_BEGIN_DECLS + +#define GTK_TYPE_FILE_CHOOSER_NATIVE (gtk_file_chooser_native_get_type ()) +#define GTK_FILE_CHOOSER_NATIVE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_FILE_CHOOSER_NATIVE, GtkFileChooserNative)) +#define GTK_FILE_CHOOSER_NATIVE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_FILE_CHOOSER_NATIVE, GtkFileChooserNativeClass)) +#define GTK_IS_FILE_CHOOSER_NATIVE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_FILE_CHOOSER_NATIVE)) +#define GTK_IS_FILE_CHOOSER_NATIVE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_FILE_CHOOSER_NATIVE)) +#define GTK_FILE_CHOOSER_NATIVE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_FILE_CHOOSER_NATIVE, GtkFileChooserNativeClass)) + +/* The file dialog of the system - Windows, Mac OS X, or the desktop + * portal where GTK_USE_PORTAL=1 or in Flatpak - with the GtkFileChooser + * interface and the API of GTK+ 3.20; elsewhere a GtkFileChooserDialog */ +typedef struct _GtkFileChooserNative GtkFileChooserNative; +typedef struct _GtkFileChooserNativeClass GtkFileChooserNativeClass; + +struct _GtkFileChooserNativeClass +{ + GtkNativeDialogClass parent_class; +}; + +GType gtk_file_chooser_native_get_type (void); + +GtkFileChooserNative *gtk_file_chooser_native_new (const gchar *title, + GtkWindow *parent, + GtkFileChooserAction action, + const gchar *accept_label, + const gchar *cancel_label); + +const char * gtk_file_chooser_native_get_accept_label (GtkFileChooserNative *self); +void gtk_file_chooser_native_set_accept_label (GtkFileChooserNative *self, + const char *accept_label); +const char * gtk_file_chooser_native_get_cancel_label (GtkFileChooserNative *self); +void gtk_file_chooser_native_set_cancel_label (GtkFileChooserNative *self, + const char *cancel_label); + +G_END_DECLS + +#endif /* __GTK_FILE_CHOOSER_NATIVE_H__ */ diff --git a/gtk/gtkfilechoosernativeportal.c b/gtk/gtkfilechoosernativeportal.c new file mode 100644 index 000000000..bf13d85a8 --- /dev/null +++ b/gtk/gtkfilechoosernativeportal.c @@ -0,0 +1,585 @@ +/* GTK - The GIMP Toolkit + * gtkfilechoosernativeportal.c: Portal File selector dialog + * Copyright (C) 2015, Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +/* The file chooser of the desktop portal (org.freedesktop.portal.FileChooser, + * from xdg-desktop-portal): the dialog of the desktop (KDE, GNOME, ...), + * and the way out of a Flatpak sandbox. Used where GTK_USE_PORTAL=1 is + * set or in Flatpak, as GTK+ 3 does; on X11 only, with the window of the + * program as "x11:XID". */ + +#include "config.h" + +#include + +#include "gtkfilechoosernativeprivate.h" +#include "gtknativedialogprivate.h" +#include "gtkfilechooser.h" +#include "gtkfilefilter.h" +#include "gtkinvisible.h" +#include "gtkmain.h" +#include "gtkdialog.h" +#include "gtkprivate.h" +#include "gtkalias.h" + +#ifdef GDK_WINDOWING_X11 +#include "x11/gdkx.h" +#endif + +typedef struct { + GtkFileChooserNative *self; + + GtkWidget *grab_widget; + + GDBusConnection *connection; + char *portal_handle; + guint portal_response_signal_id; + gboolean modal; + + gboolean hidden; + gboolean call_pending; /* the callback of the call frees the data */ + + const char *method_name; +} FilechooserPortalData; + +/* as GTK+ 3: the portal in a Flatpak sandbox, or where asked for */ +static gboolean +should_use_portal (void) +{ + static const char *use_portal = NULL; + + if (G_UNLIKELY (use_portal == NULL)) + { + if (g_file_test ("/.flatpak-info", G_FILE_TEST_EXISTS)) + use_portal = "1"; + else + { + use_portal = g_getenv ("GTK_USE_PORTAL"); + if (!use_portal) + use_portal = ""; + } + } + + return use_portal[0] == '1'; +} + +static guint +get_portal_interface_version (GDBusConnection *connection, + const char *interface_name) +{ + GError *error = NULL; + GVariant *ret; + guint version = 0; + + ret = g_dbus_connection_call_sync (connection, + "org.freedesktop.portal.Desktop", + "/org/freedesktop/portal/desktop", + "org.freedesktop.DBus.Properties", + "Get", + g_variant_new ("(ss)", interface_name, "version"), + G_VARIANT_TYPE ("(v)"), + G_DBUS_CALL_FLAGS_NONE, + 5000, + NULL, + &error); + if (ret == NULL) + { + g_error_free (error); + return 0; + } + else + { + GVariant *v; + + g_variant_get (ret, "(v)", &v); + if (g_variant_is_of_type (v, G_VARIANT_TYPE_UINT32)) + version = g_variant_get_uint32 (v); + g_variant_unref (v); + g_variant_unref (ret); + } + + return version; +} + +/* where the portal answers a request with @token */ +static char * +get_portal_request_path (GDBusConnection *connection, + char **token) +{ + static int counter = 0; + char *sender, *path; + int i; + + *token = g_strdup_printf ("gtk%d", counter++); + + sender = g_strdup (g_dbus_connection_get_unique_name (connection) + 1); + for (i = 0; sender[i]; i++) + if (sender[i] == '.') + sender[i] = '_'; + + path = g_strconcat ("/org/freedesktop/portal/desktop/request/", sender, "/", *token, NULL); + g_free (sender); + + return path; +} + +static void +filechooser_portal_data_clear (FilechooserPortalData *data) +{ + if (data->portal_response_signal_id != 0) + { + g_dbus_connection_signal_unsubscribe (data->connection, + data->portal_response_signal_id); + data->portal_response_signal_id = 0; + } + + if (data->connection) + { + g_object_unref (data->connection); + data->connection = NULL; + } + + if (data->grab_widget) + { + gtk_grab_remove (data->grab_widget); + gtk_widget_destroy (data->grab_widget); + data->grab_widget = NULL; + } + + if (data->self) + { + g_object_unref (data->self); + data->self = NULL; + } + + g_free (data->portal_handle); + data->portal_handle = NULL; +} + +static void +filechooser_portal_data_free (FilechooserPortalData *data) +{ + if (data != NULL) + { + filechooser_portal_data_clear (data); + g_free (data); + } +} + +static void +response_cb (GDBusConnection *connection, + const char *sender_name, + const char *object_path, + const char *interface_name, + const char *signal_name, + GVariant *parameters, + gpointer user_data) +{ + GtkFileChooserNative *self = user_data; + FilechooserPortalData *data = self->mode_data; + guint32 portal_response; + int gtk_response; + const char **uris = NULL; + int i; + GVariant *response_data; + GVariant *current_filter; + + g_variant_get (parameters, "(u@a{sv})", &portal_response, &response_data); + if (!g_variant_lookup (response_data, "uris", "^a&s", &uris)) + uris = NULL; + + current_filter = g_variant_lookup_value (response_data, "current_filter", G_VARIANT_TYPE ("(sa(us))")); + if (current_filter) + { + GtkFileFilter *filter = gtk_file_filter_new_from_gvariant (current_filter); + const char *current_filter_name = gtk_file_filter_get_name (filter); + GtkFileFilter *filter_to_select = filter; + GSList *filters, *l; + + /* Filters are compared by pointer: the one of the list with the + * same name is the one chosen */ + filters = gtk_file_chooser_list_filters (GTK_FILE_CHOOSER (self)); + for (l = filters; l; l = l->next) + { + GtkFileFilter *f = l->data; + + if (g_strcmp0 (gtk_file_filter_get_name (f), current_filter_name) == 0) + { + filter_to_select = f; + break; + } + } + g_slist_free (filters); + + g_object_ref_sink (filter); + gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (self), filter_to_select); + g_object_unref (filter); + g_variant_unref (current_filter); + } + + g_slist_foreach (self->custom_files, (GFunc) g_object_unref, NULL); + g_slist_free (self->custom_files); + self->custom_files = NULL; + for (i = 0; uris && uris[i]; i++) + self->custom_files = g_slist_prepend (self->custom_files, g_file_new_for_uri (uris[i])); + self->custom_files = g_slist_reverse (self->custom_files); + + g_free (uris); + g_variant_unref (response_data); + + switch (portal_response) + { + case 0: + gtk_response = GTK_RESPONSE_ACCEPT; + break; + case 1: + gtk_response = GTK_RESPONSE_CANCEL; + break; + case 2: + default: + gtk_response = GTK_RESPONSE_DELETE_EVENT; + break; + } + + /* the native dialog lives until the response is out; the data held + * a reference too */ + g_object_ref (self); + + filechooser_portal_data_free (data); + self->mode_data = NULL; + + _gtk_native_dialog_emit_response (GTK_NATIVE_DIALOG (self), gtk_response); + + g_object_unref (self); +} + +static void +send_close (FilechooserPortalData *data) +{ + GDBusMessage *message; + GError *error = NULL; + + message = g_dbus_message_new_method_call ("org.freedesktop.portal.Desktop", + data->portal_handle, + "org.freedesktop.portal.Request", + "Close"); + + if (!g_dbus_connection_send_message (data->connection, + message, + G_DBUS_SEND_MESSAGE_FLAGS_NONE, + NULL, &error)) + { + g_warning ("unable to send FileChooser Close message: %s", error->message); + g_error_free (error); + } + + g_object_unref (message); +} + +static void +open_file_msg_cb (GObject *source_object, + GAsyncResult *res, + gpointer user_data) +{ + FilechooserPortalData *data = user_data; + GtkFileChooserNative *self = data->self; + GDBusMessage *reply; + GError *error = NULL; + char *handle = NULL; + + data->call_pending = FALSE; + reply = g_dbus_connection_send_message_with_reply_finish (G_DBUS_CONNECTION (source_object), res, &error); + + if (reply && g_dbus_message_to_gerror (reply, &error)) + { + g_object_unref (reply); + reply = NULL; + } + + if (reply == NULL) + { + if (!data->hidden) + { + /* no portal after all: the user still gets a dialog */ + g_object_ref (self); + filechooser_portal_data_free (data); + self->mode_data = NULL; + _gtk_file_chooser_native_show_fallback (self); + g_object_unref (self); + } + else + g_free (data); + if (error) + g_error_free (error); + return; + } + + g_variant_get_child (g_dbus_message_get_body (reply), 0, "o", &handle); + + if (data->hidden) + { + /* hidden before the handle came: closed now; the data was + * cleared then */ + g_free (data); + } + else if (strcmp (handle, data->portal_handle) != 0) + { + /* an older portal that does not know handle_token */ + g_free (data->portal_handle); + data->portal_handle = handle; + handle = NULL; + g_dbus_connection_signal_unsubscribe (data->connection, + data->portal_response_signal_id); + + data->portal_response_signal_id = + g_dbus_connection_signal_subscribe (data->connection, + "org.freedesktop.portal.Desktop", + "org.freedesktop.portal.Request", + "Response", + data->portal_handle, + NULL, + G_DBUS_SIGNAL_FLAGS_NO_MATCH_RULE, + response_cb, + self, NULL); + } + + g_object_unref (reply); + g_free (handle); +} + +static GVariant * +get_filters (GtkFileChooser *self) +{ + GSList *list, *l; + GVariantBuilder builder; + + g_variant_builder_init (&builder, G_VARIANT_TYPE ("a(sa(us))")); + list = gtk_file_chooser_list_filters (self); + for (l = list; l; l = l->next) + { + GtkFileFilter *filter = l->data; + + g_variant_builder_add (&builder, "@(sa(us))", gtk_file_filter_to_gvariant (filter)); + } + g_slist_free (list); + + return g_variant_builder_end (&builder); +} + +static void +show_portal_file_chooser (GtkFileChooserNative *self, + const char *parent_window_str) +{ + FilechooserPortalData *data = self->mode_data; + GDBusMessage *message; + GVariantBuilder opt_builder; + gboolean multiple; + gboolean directory; + const char *title; + char *token; + GtkFileFilter *current_filter; + + message = g_dbus_message_new_method_call ("org.freedesktop.portal.Desktop", + "/org/freedesktop/portal/desktop", + "org.freedesktop.portal.FileChooser", + data->method_name); + + data->portal_handle = get_portal_request_path (data->connection, &token); + data->portal_response_signal_id = + g_dbus_connection_signal_subscribe (data->connection, + "org.freedesktop.portal.Desktop", + "org.freedesktop.portal.Request", + "Response", + data->portal_handle, + NULL, + G_DBUS_SIGNAL_FLAGS_NO_MATCH_RULE, + response_cb, + self, NULL); + + multiple = gtk_file_chooser_get_select_multiple (GTK_FILE_CHOOSER (self)); + directory = gtk_file_chooser_get_action (GTK_FILE_CHOOSER (self)) == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER; + g_variant_builder_init (&opt_builder, G_VARIANT_TYPE_VARDICT); + + g_variant_builder_add (&opt_builder, "{sv}", "handle_token", + g_variant_new_string (token)); + g_free (token); + + g_variant_builder_add (&opt_builder, "{sv}", "multiple", + g_variant_new_boolean (multiple)); + g_variant_builder_add (&opt_builder, "{sv}", "directory", + g_variant_new_boolean (directory)); + if (self->accept_label) + g_variant_builder_add (&opt_builder, "{sv}", "accept_label", + g_variant_new_string (self->accept_label)); + if (self->cancel_label) + g_variant_builder_add (&opt_builder, "{sv}", "cancel_label", + g_variant_new_string (self->cancel_label)); + g_variant_builder_add (&opt_builder, "{sv}", "modal", + g_variant_new_boolean (data->modal)); + g_variant_builder_add (&opt_builder, "{sv}", "filters", get_filters (GTK_FILE_CHOOSER (self))); + current_filter = gtk_file_chooser_get_filter (GTK_FILE_CHOOSER (self->dialog)); + if (current_filter) + g_variant_builder_add (&opt_builder, "{sv}", "current_filter", + gtk_file_filter_to_gvariant (current_filter)); + if (self->current_name) + g_variant_builder_add (&opt_builder, "{sv}", "current_name", + g_variant_new_string (self->current_name)); + if (self->current_folder) + { + char *path = g_file_get_path (self->current_folder); + + if (path) + g_variant_builder_add (&opt_builder, "{sv}", "current_folder", + g_variant_new_bytestring (path)); + g_free (path); + } + if (self->current_file) + { + char *path = g_file_get_path (self->current_file); + + if (path) + g_variant_builder_add (&opt_builder, "{sv}", "current_file", + g_variant_new_bytestring (path)); + g_free (path); + } + + title = gtk_native_dialog_get_title (GTK_NATIVE_DIALOG (self)); + + g_dbus_message_set_body (message, + g_variant_new ("(ss@a{sv})", + parent_window_str ? parent_window_str : "", + title ? title : "", + g_variant_builder_end (&opt_builder))); + + data->call_pending = TRUE; + g_dbus_connection_send_message_with_reply (data->connection, + message, + G_DBUS_SEND_MESSAGE_FLAGS_NONE, + G_MAXINT, + NULL, + NULL, + open_file_msg_cb, + data); + + g_object_unref (message); +} + +gboolean +_gtk_file_chooser_native_portal_show (GtkFileChooserNative *self) +{ + FilechooserPortalData *data; + GtkWindow *transient_for; + GDBusConnection *connection; + GtkFileChooserAction action; + const char *method_name; + char *handle_str = NULL; + + if (!should_use_portal ()) + return FALSE; + + /* The session bus is kept once used: the bus connection is shared and + * goes away with the last reference, and with it a Close not sent yet */ + { + static GDBusConnection *session_bus; + + if (session_bus == NULL) + session_bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL); + if (session_bus == NULL || g_dbus_connection_is_closed (session_bus)) + return FALSE; + connection = g_object_ref (session_bus); + } + + action = gtk_file_chooser_get_action (GTK_FILE_CHOOSER (self)); + + if (action == GTK_FILE_CHOOSER_ACTION_OPEN) + method_name = "OpenFile"; + else if (action == GTK_FILE_CHOOSER_ACTION_SAVE) + method_name = "SaveFile"; + else if (action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER) + { + if (get_portal_interface_version (connection, "org.freedesktop.portal.FileChooser") < 3) + { + g_object_unref (connection); + return FALSE; + } + method_name = "OpenFile"; + } + else + { + /* CREATE_FOLDER: the portal has nothing for it */ + g_object_unref (connection); + return FALSE; + } + + data = g_new0 (FilechooserPortalData, 1); + data->self = g_object_ref (self); + data->connection = connection; + data->method_name = method_name; + data->modal = gtk_native_dialog_get_modal (GTK_NATIVE_DIALOG (self)); + + self->mode_data = data; + + transient_for = gtk_native_dialog_get_transient_for (GTK_NATIVE_DIALOG (self)); +#ifdef GDK_WINDOWING_X11 + if (transient_for != NULL && gtk_widget_get_realized (GTK_WIDGET (transient_for)) && + GDK_IS_WINDOW (gtk_widget_get_window (GTK_WIDGET (transient_for)))) + handle_str = g_strdup_printf ("x11:%lx", + (gulong) GDK_WINDOW_XID (gtk_widget_get_window (GTK_WIDGET (transient_for)))); +#endif + + /* modal: the windows of the program take no input meanwhile */ + if (data->modal) + { + GdkScreen *screen = transient_for ? gtk_widget_get_screen (GTK_WIDGET (transient_for)) + : gdk_screen_get_default (); + + data->grab_widget = gtk_invisible_new_for_screen (screen); + gtk_grab_add (data->grab_widget); + } + + show_portal_file_chooser (self, handle_str); + g_free (handle_str); + + return TRUE; +} + +void +_gtk_file_chooser_native_portal_hide (GtkFileChooserNative *self) +{ + FilechooserPortalData *data = self->mode_data; + + /* set while the dialog is visible */ + g_return_if_fail (data != NULL); + + data->hidden = TRUE; + + if (data->portal_handle) + send_close (data); + + /* The call may still be on its way: then its callback frees the + * data, which is cleared here */ + if (data->call_pending) + filechooser_portal_data_clear (data); + else + filechooser_portal_data_free (data); + self->mode_data = NULL; +} + +#define __GTK_FILE_CHOOSER_NATIVE_PORTAL_C__ +#include "gtkaliasdef.c" diff --git a/gtk/gtkfilechoosernativeprivate.h b/gtk/gtkfilechoosernativeprivate.h new file mode 100644 index 000000000..ca5e083a8 --- /dev/null +++ b/gtk/gtkfilechoosernativeprivate.h @@ -0,0 +1,68 @@ +/* GTK - The GIMP Toolkit + * gtkfilechoosernativeprivate.h: Native File selector dialog + * Copyright (C) 2015, Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef __GTK_FILE_CHOOSER_NATIVE_PRIVATE_H__ +#define __GTK_FILE_CHOOSER_NATIVE_PRIVATE_H__ + +#include + +G_BEGIN_DECLS + +struct _GtkFileChooserNative +{ + GtkNativeDialog parent_instance; + + char *accept_label; + char *cancel_label; + + int mode; + GSList *custom_files; + + GFile *current_folder; + GFile *current_file; + char *current_name; + GtkFileFilter *current_filter; + + /* Fallback mode, and where the GtkFileChooser state is kept */ + GtkWidget *dialog; + GtkWidget *accept_button; + GtkWidget *cancel_button; + + gpointer mode_data; +}; + +gboolean _gtk_file_chooser_native_win32_show (GtkFileChooserNative *self); +void _gtk_file_chooser_native_win32_hide (GtkFileChooserNative *self); + +gboolean _gtk_file_chooser_native_quartz_show (GtkFileChooserNative *self); +void _gtk_file_chooser_native_quartz_hide (GtkFileChooserNative *self); + +gboolean _gtk_file_chooser_native_portal_show (GtkFileChooserNative *self); +void _gtk_file_chooser_native_portal_hide (GtkFileChooserNative *self); + +/* the GtkFileChooserDialog after all, when a system dialog fails */ +void _gtk_file_chooser_native_show_fallback (GtkFileChooserNative *self); + +/* the labels without mnemonics, for the system dialogs */ +gchar *_gtk_file_chooser_native_strip_mnemonic (const gchar *label); + +G_END_DECLS + +#endif /* __GTK_FILE_CHOOSER_NATIVE_PRIVATE_H__ */ diff --git a/gtk/gtkfilechoosernativequartz.c b/gtk/gtkfilechoosernativequartz.c new file mode 100644 index 000000000..7c9262cd3 --- /dev/null +++ b/gtk/gtkfilechoosernativequartz.c @@ -0,0 +1,321 @@ +/* GTK - The GIMP Toolkit + * gtkfilechoosernativequartz.c: Quartz Native File selector dialog + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +/* NSOpenPanel and NSSavePanel for GtkFileChooserNative, from Mac OS X + * 10.4 on: run modal (GTK+ 3 has sheets, which need the blocks of + * 10.6), from the main loop once gtk_native_dialog_show() has + * returned. The types of the current filter are the ones offered; + * a filter with rules that are not "*.ext" leaves the GTK+ dialog. */ + +#include "config.h" + +#include + +#import + +#include "gtkfilechoosernativeprivate.h" +#include "gtknativedialogprivate.h" +#include "gtkfilechooser.h" +#include "gtkfilefilterprivate.h" +#include "gtkprivate.h" +#include + +#include "gtkalias.h" + +typedef struct { + GtkFileChooserNative *self; + + gboolean skip_response; + gboolean save; + gboolean folder; + gboolean select_multiple; + gboolean show_hidden; + gboolean create_folders; + NSWindow *parent; + + char *accept_label; + char *title; + char *directory; + char *name; + NSArray *types; /* extensions, nil for all */ + + guint idle; +} FileChooserQuartzData; + +static void +filechooser_quartz_data_free (FileChooserQuartzData *data) +{ + if (data->types) + [data->types release]; + if (data->self) + g_object_unref (data->self); + g_free (data->accept_label); + g_free (data->title); + g_free (data->directory); + g_free (data->name); + g_free (data); +} + +static GFile * +file_for_nsstring (NSString *path) +{ + if (path == nil) + return NULL; + return g_file_new_for_path ([path fileSystemRepresentation]); +} + +/* "*.png" -> "png"; nil if a pattern is anything else */ +static NSArray * +types_of_filter (GtkFileFilter *filter, + gboolean *ok) +{ + NSMutableArray *types; + char **patterns; + int i; + + *ok = TRUE; + if (filter == NULL) + return nil; + + patterns = _gtk_file_filter_get_as_patterns (filter); + if (patterns == NULL) + { + *ok = FALSE; + return nil; + } + + types = [[NSMutableArray alloc] init]; + for (i = 0; patterns[i]; i++) + { + const char *p = patterns[i]; + + if (strcmp (p, "*") == 0) + { + [types release]; + g_strfreev (patterns); + return nil; /* all files */ + } + if (strncmp (p, "*.", 2) != 0 || strpbrk (p + 2, "*?[") != NULL) + { + [types release]; + g_strfreev (patterns); + *ok = FALSE; + return nil; + } + [types addObject:[NSString stringWithUTF8String:p + 2]]; + } + g_strfreev (patterns); + + return types; +} + +static gboolean +filechooser_quartz_run (gpointer user_data) +{ + FileChooserQuartzData *data = user_data; + GtkFileChooserNative *self = data->self; + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + NSSavePanel *panel; + NSString *directory = data->directory ? [NSString stringWithUTF8String:data->directory] : nil; + NSString *name = data->name ? [NSString stringWithUTF8String:data->name] : nil; + NSInteger result; + GSList *files = NULL; + int response = GTK_RESPONSE_CANCEL; + + data->idle = 0; + + if (data->save && !data->folder) + { + panel = [NSSavePanel savePanel]; + if ([panel respondsToSelector:@selector(setCanCreateDirectories:)]) + [panel setCanCreateDirectories:data->create_folders]; + if (data->types) + [panel setAllowedFileTypes:data->types]; + } + else + { + NSOpenPanel *open = [NSOpenPanel openPanel]; + + [open setAllowsMultipleSelection:data->select_multiple]; + [open setCanChooseDirectories:data->folder]; + [open setCanChooseFiles:!data->folder]; + if (data->folder && [open respondsToSelector:@selector(setCanCreateDirectories:)]) + [open setCanCreateDirectories:YES]; + panel = open; + } + + if (data->show_hidden && [panel respondsToSelector:@selector(setShowsHiddenFiles:)]) + [panel setShowsHiddenFiles:YES]; + if (data->accept_label) + [panel setPrompt:[NSString stringWithUTF8String:data->accept_label]]; + if (data->title) + [panel setTitle:[NSString stringWithUTF8String:data->title]]; + + if ([panel respondsToSelector:@selector(setDirectoryURL:)]) + { + /* 10.6 and newer */ + if (directory) + [panel setDirectoryURL:[NSURL fileURLWithPath:directory]]; + if (name && [panel respondsToSelector:@selector(setNameFieldStringValue:)]) + [panel setNameFieldStringValue:name]; + if (!data->save && data->types) + [panel setAllowedFileTypes:data->types]; + result = [panel runModal]; + } + else if (data->save && !data->folder) + result = [panel runModalForDirectory:directory file:name]; + else + result = [(NSOpenPanel *) panel runModalForDirectory:directory file:name types:data->types]; + + if (result == NSOKButton) + { + response = GTK_RESPONSE_ACCEPT; + if (data->save && !data->folder) + { + GFile *file = file_for_nsstring ([panel filename]); + + if (file) + files = g_slist_prepend (files, file); + } + else + { + NSArray *names = [(NSOpenPanel *) panel filenames]; + NSUInteger i; + + for (i = 0; i < [names count]; i++) + { + GFile *file = file_for_nsstring ([names objectAtIndex:i]); + + if (file) + files = g_slist_prepend (files, file); + } + } + } + + if (data->parent) + [data->parent makeKeyAndOrderFront:nil]; + + [pool release]; + + self->mode_data = NULL; + + if (!data->skip_response) + { + g_slist_foreach (self->custom_files, (GFunc) g_object_unref, NULL); + g_slist_free (self->custom_files); + self->custom_files = g_slist_reverse (files); + files = NULL; + + _gtk_native_dialog_emit_response (GTK_NATIVE_DIALOG (self), response); + } + + g_slist_foreach (files, (GFunc) g_object_unref, NULL); + g_slist_free (files); + filechooser_quartz_data_free (data); + + return FALSE; +} + +gboolean +_gtk_file_chooser_native_quartz_show (GtkFileChooserNative *self) +{ + FileChooserQuartzData *data; + GtkFileChooserAction action; + GtkWindow *transient_for; + guint update_preview_signal; + NSArray *types; + gboolean ok; + + /* what only the GTK+ dialog can show */ + if (gtk_file_chooser_get_extra_widget (GTK_FILE_CHOOSER (self)) != NULL) + return FALSE; + + update_preview_signal = g_signal_lookup ("update-preview", GTK_TYPE_FILE_CHOOSER); + if (g_signal_has_handler_pending (self, update_preview_signal, 0, TRUE)) + return FALSE; + + types = types_of_filter (gtk_file_chooser_get_filter (GTK_FILE_CHOOSER (self)), &ok); + if (!ok) + return FALSE; + + data = g_new0 (FileChooserQuartzData, 1); + data->self = g_object_ref (self); + data->types = types; + + action = gtk_file_chooser_get_action (GTK_FILE_CHOOSER (self->dialog)); + data->save = action == GTK_FILE_CHOOSER_ACTION_SAVE || action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER; + data->folder = action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER || action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER; + data->select_multiple = !data->save && + gtk_file_chooser_get_select_multiple (GTK_FILE_CHOOSER (self->dialog)); + data->show_hidden = gtk_file_chooser_get_show_hidden (GTK_FILE_CHOOSER (self->dialog)); + data->create_folders = gtk_file_chooser_get_create_folders (GTK_FILE_CHOOSER (self->dialog)); + + data->accept_label = _gtk_file_chooser_native_strip_mnemonic (self->accept_label); + data->title = g_strdup (gtk_native_dialog_get_title (GTK_NATIVE_DIALOG (self))); + + if (self->current_file) + { + GFile *parent = g_file_get_parent (self->current_file); + + data->directory = parent ? g_file_get_path (parent) : NULL; + data->name = g_file_get_basename (self->current_file); + if (parent) + g_object_unref (parent); + } + else + { + if (self->current_folder) + data->directory = g_file_get_path (self->current_folder); + if (data->save) + data->name = g_strdup (self->current_name); + } + + transient_for = gtk_native_dialog_get_transient_for (GTK_NATIVE_DIALOG (self)); + if (transient_for && gtk_widget_get_realized (GTK_WIDGET (transient_for))) + data->parent = gdk_quartz_window_get_nswindow (gtk_widget_get_window (GTK_WIDGET (transient_for))); + + self->mode_data = data; + /* after gtk_native_dialog_show() has returned, which the response + * must not come before */ + data->idle = gdk_threads_add_idle (filechooser_quartz_run, data); + + return TRUE; +} + +void +_gtk_file_chooser_native_quartz_hide (GtkFileChooserNative *self) +{ + FileChooserQuartzData *data = self->mode_data; + + g_return_if_fail (data != NULL); + + data->skip_response = TRUE; + if (data->idle) + { + /* not shown yet */ + g_source_remove (data->idle); + self->mode_data = NULL; + filechooser_quartz_data_free (data); + } + else + [NSApp abortModal]; +} + +#define __GTK_FILE_CHOOSER_NATIVE_QUARTZ_C__ +#include "gtkaliasdef.c" diff --git a/gtk/gtkfilechoosernativewin32.c b/gtk/gtkfilechoosernativewin32.c new file mode 100644 index 000000000..ed305c2cd --- /dev/null +++ b/gtk/gtkfilechoosernativewin32.c @@ -0,0 +1,1055 @@ +/* GTK - The GIMP Toolkit + * gtkfilechoosernativewin32.c: Win32 Native File selector dialog + * Copyright (C) 2015, Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +/* The file dialog of Windows for GtkFileChooserNative: IFileDialog + * from Vista on, as GTK+ 3 has it, and the common dialogs of Windows + * 2000, XP and ReactOS (GetOpenFileName, GetSaveFileName and + * SHBrowseForFolder) before. The dialog runs in a thread of its own, + * so that the windows of the program go on drawing; the answer comes + * back to the main loop. */ + +#include "config.h" + +/* the declarations of Vista, which is looked for at run time */ +#undef _WIN32_WINNT +#define _WIN32_WINNT 0x0600 +#undef WINVER +#define WINVER _WIN32_WINNT +#define COBJMACROS + +#include + +#include "gtkfilechoosernativeprivate.h" +#include "gtknativedialogprivate.h" +#include "gtkfilechooser.h" +#include "gtkfilechooserprivate.h" +#include "gtkfilefilterprivate.h" +#include "gtkinvisible.h" +#include "gtkmain.h" +#include "gtkdialog.h" +#include "gtkprivate.h" + +#include +#include +#include +#include +#include + +#include "gtkalias.h" + +typedef struct { + GtkFileChooserNative *self; + + GtkWidget *grab_widget; + + IFileDialogEvents *events; /* Vista and newer */ + HWND parent; + gboolean skip_response; + gboolean save; + gboolean folder; + gboolean modal; + gboolean overwrite_confirmation; + gboolean select_multiple; + gboolean show_hidden; + + char *accept_label; + char *cancel_label; + char *title; + + GSList *shortcut_uris; + + GFile *current_folder; + GFile *current_file; + char *current_name; + + COMDLG_FILTERSPEC *filters; + int n_filters; + int filter_index; /* 1-based, of the filter shown first */ + int chosen_filter; /* 1-based, 0 for unknown */ + + /* the dialog of the older Windows, for hiding it */ + HWND old_dialog; + gboolean old_close; + + GSList *files; + int response; +} FilechooserWin32ThreadData; + +/* protects the window handles of the dialogs and their "close" flags */ +G_LOCK_DEFINE_STATIC (FileDialogEvents); + +/* {3CAFD12E-82AE-4184-8309-848C0104B4DC} */ +static const GUID myIID_IFileDialogEvents = +{ 0x3cafd12e, 0x82ae, 0x4184, { 0x83, 0x9, 0x84, 0x8c, 0x1, 0x4, 0xb4, 0xdc } }; + +typedef struct { + IFileDialogEvents iFileDialogEvents; + int ref_count; + gboolean enable_owner; + gboolean got_hwnd; + HWND dialog_hwnd; + gboolean do_close; /* hide came before dialog_hwnd */ + FilechooserWin32ThreadData *data; +} FileDialogEvents; + +static ULONG STDMETHODCALLTYPE +ifiledialogevents_AddRef (IFileDialogEvents *self) +{ + FileDialogEvents *events = (FileDialogEvents *) self; + ULONG ref_count; + + G_LOCK (FileDialogEvents); + ref_count = ++events->ref_count; + G_UNLOCK (FileDialogEvents); + + return ref_count; +} + +static ULONG STDMETHODCALLTYPE +ifiledialogevents_Release (IFileDialogEvents *self) +{ + FileDialogEvents *events = (FileDialogEvents *) self; + int ref_count; + + G_LOCK (FileDialogEvents); + ref_count = --events->ref_count; + G_UNLOCK (FileDialogEvents); + + if (ref_count == 0) + g_free (self); + + return ref_count; +} + +static HRESULT STDMETHODCALLTYPE +ifiledialogevents_QueryInterface (IFileDialogEvents *self, + REFIID riid, + LPVOID *ppvObject) +{ + if (IsEqualIID (riid, &IID_IUnknown) || + IsEqualIID (riid, &myIID_IFileDialogEvents)) + { + *ppvObject = self; + IUnknown_AddRef ((IUnknown *) self); + return NOERROR; + } + + *ppvObject = NULL; + return E_NOINTERFACE; +} + +static HRESULT STDMETHODCALLTYPE +ifiledialogevents_OnFileOk (IFileDialogEvents *self, + IFileDialog *pfd) +{ + return S_OK; +} + +static HRESULT STDMETHODCALLTYPE +ifiledialogevents_OnFolderChanging (IFileDialogEvents *self, + IFileDialog *pfd, + IShellItem *psiFolder) +{ + return S_OK; +} + +static HRESULT STDMETHODCALLTYPE +ifiledialogevents_OnFolderChange (IFileDialogEvents *self, + IFileDialog *pfd) +{ + FileDialogEvents *events = (FileDialogEvents *) self; + IOleWindow *olew = NULL; + HWND dialog_hwnd; + HRESULT hr; + + if (!events->got_hwnd) + { + events->got_hwnd = TRUE; + + hr = IFileDialog_QueryInterface (pfd, &IID_IOleWindow, (LPVOID *) &olew); + if (SUCCEEDED (hr)) + { + hr = IOleWindow_GetWindow (olew, &dialog_hwnd); + if (SUCCEEDED (hr)) + { + G_LOCK (FileDialogEvents); + events->dialog_hwnd = dialog_hwnd; + if (events->do_close) + SendMessage (events->dialog_hwnd, WM_CLOSE, 0, 0); + G_UNLOCK (FileDialogEvents); + } + IOleWindow_Release (olew); + } + + /* not modal: the parent stays usable */ + if (events->enable_owner && events->dialog_hwnd) + { + HWND owner = GetWindow (events->dialog_hwnd, GW_OWNER); + + if (owner) + EnableWindow (owner, TRUE); + } + } + + return S_OK; +} + +static HRESULT STDMETHODCALLTYPE +ifiledialogevents_OnSelectionChange (IFileDialogEvents *self, + IFileDialog *pfd) +{ + return S_OK; +} + +static HRESULT STDMETHODCALLTYPE +ifiledialogevents_OnShareViolation (IFileDialogEvents *self, + IFileDialog *pfd, + IShellItem *psi, + FDE_SHAREVIOLATION_RESPONSE *pResponse) +{ + return E_NOTIMPL; +} + +static HRESULT STDMETHODCALLTYPE +ifiledialogevents_OnTypeChange (IFileDialogEvents *self, + IFileDialog *pfd) +{ + FileDialogEvents *events = (FileDialogEvents *) self; + UINT file_type; + + /* read in the main thread, with the files */ + if (SUCCEEDED (IFileDialog_GetFileTypeIndex (pfd, &file_type))) + events->data->chosen_filter = file_type; + + return S_OK; +} + +static HRESULT STDMETHODCALLTYPE +ifiledialogevents_OnOverwrite (IFileDialogEvents *self, + IFileDialog *pfd, + IShellItem *psi, + FDE_OVERWRITE_RESPONSE *pResponse) +{ + return E_NOTIMPL; +} + +static IFileDialogEventsVtbl ifde_vtbl = { + ifiledialogevents_QueryInterface, + ifiledialogevents_AddRef, + ifiledialogevents_Release, + ifiledialogevents_OnFileOk, + ifiledialogevents_OnFolderChanging, + ifiledialogevents_OnFolderChange, + ifiledialogevents_OnSelectionChange, + ifiledialogevents_OnShareViolation, + ifiledialogevents_OnTypeChange, + ifiledialogevents_OnOverwrite +}; + +static IFileDialogEvents * +file_dialog_events_new (gboolean enable_owner, + FilechooserWin32ThreadData *data) +{ + FileDialogEvents *events; + + events = g_new0 (FileDialogEvents, 1); + events->iFileDialogEvents.lpVtbl = &ifde_vtbl; + events->ref_count = 1; + events->enable_owner = enable_owner; + events->data = data; + + return &events->iFileDialogEvents; +} + +static void +filechooser_win32_send_close (FilechooserWin32ThreadData *data) +{ + G_LOCK (FileDialogEvents); + + if (data->events) + { + FileDialogEvents *events = (FileDialogEvents *) data->events; + + if (events->dialog_hwnd) + PostMessage (events->dialog_hwnd, WM_CLOSE, 0, 0); + else + events->do_close = TRUE; + } + if (data->old_dialog) + PostMessage (data->old_dialog, WM_CLOSE, 0, 0); + else + data->old_close = TRUE; + + G_UNLOCK (FileDialogEvents); +} + +static void +filechooser_win32_thread_data_free (FilechooserWin32ThreadData *data) +{ + int i; + + if (data->filters) + { + for (i = 0; data->filters[i].pszName != NULL; i++) + { + g_free ((char *) data->filters[i].pszName); + g_free ((char *) data->filters[i].pszSpec); + } + g_free (data->filters); + } + + if (data->events) + IFileDialogEvents_Release (data->events); + + if (data->grab_widget) + { + gtk_grab_remove (data->grab_widget); + gtk_widget_destroy (data->grab_widget); + } + + if (data->current_folder) + g_object_unref (data->current_folder); + if (data->current_file) + g_object_unref (data->current_file); + g_free (data->current_name); + + g_slist_foreach (data->shortcut_uris, (GFunc) g_free, NULL); + g_slist_free (data->shortcut_uris); + g_slist_foreach (data->files, (GFunc) g_object_unref, NULL); + g_slist_free (data->files); + if (data->self) + g_object_unref (data->self); + g_free (data->accept_label); + g_free (data->cancel_label); + g_free (data->title); + g_free (data); +} + +static gboolean +filechooser_win32_thread_done (gpointer _data) +{ + FilechooserWin32ThreadData *data = _data; + GtkFileChooserNative *self = data->self; + + self->mode_data = NULL; + + if (!data->skip_response) + { + if (data->chosen_filter > 0) + { + GSList *filters = gtk_file_chooser_list_filters (GTK_FILE_CHOOSER (self)); + GtkFileFilter *filter = g_slist_nth_data (filters, data->chosen_filter - 1); + + if (filter) + gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (self), filter); + g_slist_free (filters); + } + + g_slist_foreach (self->custom_files, (GFunc) g_object_unref, NULL); + g_slist_free (self->custom_files); + self->custom_files = g_slist_reverse (data->files); + data->files = NULL; + + _gtk_native_dialog_emit_response (GTK_NATIVE_DIALOG (data->self), + data->response); + } + + filechooser_win32_thread_data_free (data); + + return FALSE; +} + +static void +data_add_path_w (FilechooserWin32ThreadData *data, + const wchar_t *pathw) +{ + char *path = g_utf16_to_utf8 (pathw, -1, NULL, NULL, NULL); + + if (path != NULL) + { + data->files = g_slist_prepend (data->files, g_file_new_for_path (path)); + data->response = GTK_RESPONSE_ACCEPT; + g_free (path); + } +} + +static void +data_add_shell_item (FilechooserWin32ThreadData *data, + IShellItem *item) +{ + PWSTR pathw = NULL; + + if (SUCCEEDED (IShellItem_GetDisplayName (item, SIGDN_FILESYSPATH, &pathw))) + { + data_add_path_w (data, pathw); + CoTaskMemFree (pathw); + } +} + +/* SHCreateItemFromParsingName is from Vista on: looked up, so that + * the DLL loads on XP */ +typedef HRESULT (WINAPI *CreateItemFunc) (PCWSTR, IBindCtx *, REFIID, void **); + +static IShellItem * +get_shell_item_for_path (const char *path) +{ + static CreateItemFunc create_item; + static gboolean looked_up; + IShellItem *item = NULL; + gunichar2 *path_w; + + if (!looked_up) + { + create_item = (CreateItemFunc) GetProcAddress (GetModuleHandleW (L"shell32.dll"), + "SHCreateItemFromParsingName"); + looked_up = TRUE; + } + if (create_item == NULL || path == NULL) + return NULL; + + path_w = g_utf8_to_utf16 (path, -1, NULL, NULL, NULL); + if (path_w == NULL || FAILED (create_item (path_w, NULL, &IID_IShellItem, (void **) &item))) + item = NULL; + g_free (path_w); + + return item; +} + +static IShellItem * +get_shell_item_for_file (GFile *file) +{ + char *path = g_file_get_path (file); + IShellItem *item = get_shell_item_for_path (path); + + g_free (path); + return item; +} + +/* The dialog of Vista and newer; FALSE if there is none */ +static gboolean +run_file_dialog (FilechooserWin32ThreadData *data) +{ + HRESULT hr; + IFileDialog *pfd = NULL; + IFileDialog2 *pfd2 = NULL; + DWORD flags; + DWORD cookie; + GSList *l; + + /* the dialogs of XP also where there is the newer one, for trying them */ + if (g_getenv ("GTK_WIN32_OLD_FILE_DIALOGS")) + return FALSE; + + if (data->save && !data->folder) + hr = CoCreateInstance (&CLSID_FileSaveDialog, + NULL, CLSCTX_INPROC_SERVER, + &IID_IFileSaveDialog, (LPVOID *) &pfd); + else + hr = CoCreateInstance (&CLSID_FileOpenDialog, + NULL, CLSCTX_INPROC_SERVER, + &IID_IFileOpenDialog, (LPVOID *) &pfd); + if (FAILED (hr)) + return FALSE; + + if (FAILED (IFileDialog_GetOptions (pfd, &flags))) + flags = 0; + + flags |= FOS_FORCEFILESYSTEM; + if (data->folder) + flags |= FOS_PICKFOLDERS; + if (data->folder && data->save) + flags &= ~(FOS_FILEMUSTEXIST); + if (data->select_multiple) + flags |= FOS_ALLOWMULTISELECT; + if (data->show_hidden) + flags |= FOS_FORCESHOWHIDDEN; + if (data->overwrite_confirmation) + flags |= FOS_OVERWRITEPROMPT; + else + flags &= ~(FOS_OVERWRITEPROMPT); + + IFileDialog_SetOptions (pfd, flags); + + if (data->title) + { + gunichar2 *label = g_utf8_to_utf16 (data->title, -1, NULL, NULL, NULL); + IFileDialog_SetTitle (pfd, label); + g_free (label); + } + + if (data->accept_label) + { + gunichar2 *label = g_utf8_to_utf16 (data->accept_label, -1, NULL, NULL, NULL); + IFileDialog_SetOkButtonLabel (pfd, label); + g_free (label); + } + + if (data->cancel_label) + { + gunichar2 *label = g_utf8_to_utf16 (data->cancel_label, -1, NULL, NULL, NULL); + + if (SUCCEEDED (IFileDialog_QueryInterface (pfd, &IID_IFileDialog2, (LPVOID *) &pfd2))) + { + IFileDialog2_SetCancelButtonLabel (pfd2, label); + IFileDialog2_Release (pfd2); + } + g_free (label); + } + + for (l = data->shortcut_uris; l != NULL; l = l->next) + { + char *path = g_filename_from_uri (l->data, NULL, NULL); + IShellItem *item = get_shell_item_for_path (path); + + g_free (path); + if (item) + { + IFileDialog_AddPlace (pfd, item, FDAP_BOTTOM); + IShellItem_Release (item); + } + } + + if (data->current_file) + { + IFileSaveDialog *pfsd; + + if (SUCCEEDED (IFileDialog_QueryInterface (pfd, &IID_IFileSaveDialog, (LPVOID *) &pfsd))) + { + IShellItem *item = get_shell_item_for_file (data->current_file); + + if (item) + { + IFileSaveDialog_SetSaveAsItem (pfsd, item); + IShellItem_Release (item); + } + IFileSaveDialog_Release (pfsd); + } + } + + if (data->current_folder) + { + IShellItem *item = get_shell_item_for_file (data->current_folder); + + if (item) + { + IFileDialog_SetFolder (pfd, item); + IShellItem_Release (item); + } + } + + if (data->current_name) + { + gunichar2 *name = g_utf8_to_utf16 (data->current_name, -1, NULL, NULL, NULL); + IFileDialog_SetFileName (pfd, name); + g_free (name); + } + + if (data->n_filters > 0) + { + IFileDialog_SetFileTypes (pfd, data->n_filters, data->filters); + IFileDialog_SetDefaultExtension (pfd, L""); + IFileDialog_SetFileTypeIndex (pfd, data->filter_index); + } + + data->response = GTK_RESPONSE_CANCEL; + + data->events = file_dialog_events_new (!data->modal, data); + if (FAILED (IFileDialog_Advise (pfd, data->events, &cookie))) + cookie = 0; + + hr = IFileDialog_Show (pfd, data->parent); + if (SUCCEEDED (hr)) + { + IFileOpenDialog *pfod = NULL; + + if (SUCCEEDED (IFileDialog_QueryInterface (pfd, &IID_IFileOpenDialog, (LPVOID *) &pfod))) + { + IShellItemArray *res; + DWORD i, count; + + if (SUCCEEDED (IFileOpenDialog_GetResults (pfod, &res))) + { + if (SUCCEEDED (IShellItemArray_GetCount (res, &count))) + for (i = 0; i < count; i++) + { + IShellItem *item; + + if (SUCCEEDED (IShellItemArray_GetItemAt (res, i, &item))) + { + data_add_shell_item (data, item); + IShellItem_Release (item); + } + } + IShellItemArray_Release (res); + } + IFileOpenDialog_Release (pfod); + } + else + { + IShellItem *item; + + if (SUCCEEDED (IFileDialog_GetResult (pfd, &item))) + { + data_add_shell_item (data, item); + IShellItem_Release (item); + } + } + } + + if (cookie) + IFileDialog_Unadvise (pfd, cookie); + + IFileDialog_Release (pfd); + + return TRUE; +} + +/* The dialogs of Windows 2000, XP and ReactOS */ + +static UINT_PTR CALLBACK +old_dialog_hook (HWND hdlg, + UINT msg, + WPARAM wparam, + LPARAM lparam) +{ + if (msg == WM_INITDIALOG) + { + OPENFILENAMEW *ofn = (OPENFILENAMEW *) lparam; + FilechooserWin32ThreadData *data = (FilechooserWin32ThreadData *) ofn->lCustData; + HWND dialog = GetParent (hdlg); /* the hook has a child of the dialog */ + + G_LOCK (FileDialogEvents); + data->old_dialog = dialog; + if (data->old_close) + PostMessage (dialog, WM_CLOSE, 0, 0); + G_UNLOCK (FileDialogEvents); + + if (data->accept_label) + { + gunichar2 *label = g_utf8_to_utf16 (data->accept_label, -1, NULL, NULL, NULL); + SendMessageW (dialog, CDM_SETCONTROLTEXT, IDOK, (LPARAM) label); + g_free (label); + } + if (data->cancel_label) + { + gunichar2 *label = g_utf8_to_utf16 (data->cancel_label, -1, NULL, NULL, NULL); + SendMessageW (dialog, CDM_SETCONTROLTEXT, IDCANCEL, (LPARAM) label); + g_free (label); + } + } + + return 0; +} + +static int CALLBACK +browse_callback (HWND hwnd, + UINT msg, + LPARAM lparam, + LPARAM lpdata) +{ + FilechooserWin32ThreadData *data = (FilechooserWin32ThreadData *) lpdata; + + if (msg == BFFM_INITIALIZED) + { + G_LOCK (FileDialogEvents); + data->old_dialog = hwnd; + if (data->old_close) + PostMessage (hwnd, WM_CLOSE, 0, 0); + G_UNLOCK (FileDialogEvents); + + /* the title goes above the tree; the window gets it too */ + if (data->title) + { + gunichar2 *title = g_utf8_to_utf16 (data->title, -1, NULL, NULL, NULL); + SetWindowTextW (hwnd, title); + g_free (title); + } + + if (data->current_folder) + { + char *path = g_file_get_path (data->current_folder); + gunichar2 *path_w = path ? g_utf8_to_utf16 (path, -1, NULL, NULL, NULL) : NULL; + + if (path_w) + SendMessageW (hwnd, BFFM_SETSELECTIONW, TRUE, (LPARAM) path_w); + g_free (path_w); + g_free (path); + } + } + + return 0; +} + +static void +run_old_folder_dialog (FilechooserWin32ThreadData *data) +{ + BROWSEINFOW bi; + LPITEMIDLIST pidl; + gunichar2 *title = data->title ? g_utf8_to_utf16 (data->title, -1, NULL, NULL, NULL) : NULL; + wchar_t path[MAX_PATH]; + + memset (&bi, 0, sizeof bi); + bi.hwndOwner = data->parent; + bi.lpszTitle = title; + bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE; + bi.lpfn = browse_callback; + bi.lParam = (LPARAM) data; + + data->response = GTK_RESPONSE_CANCEL; + pidl = SHBrowseForFolderW (&bi); + if (pidl) + { + if (SHGetPathFromIDListW (pidl, path)) + data_add_path_w (data, path); + CoTaskMemFree (pidl); + } + g_free (title); +} + +static void +run_old_file_dialog (FilechooserWin32ThreadData *data) +{ + OPENFILENAMEW ofn; + GString *filter = NULL; + gunichar2 *filter_w = NULL, *title = NULL, *initial_dir = NULL; + const int buffer_len = 32768; + wchar_t *buffer = g_new0 (wchar_t, buffer_len); + BOOL ok; + int i; + + memset (&ofn, 0, sizeof ofn); + ofn.lStructSize = sizeof ofn; + ofn.hwndOwner = data->parent; + + /* "name\0pattern;pattern\0...\0\0", as UTF-16 */ + if (data->n_filters > 0) + { + glong len = 0; + gunichar2 *p; + + for (i = 0; i < data->n_filters; i++) + len += wcslen (data->filters[i].pszName) + 1 + wcslen (data->filters[i].pszSpec) + 1; + filter_w = p = g_new0 (gunichar2, len + 1); + for (i = 0; i < data->n_filters; i++) + { + wcscpy ((wchar_t *) p, data->filters[i].pszName); + p += wcslen (data->filters[i].pszName) + 1; + wcscpy ((wchar_t *) p, data->filters[i].pszSpec); + p += wcslen (data->filters[i].pszSpec) + 1; + } + ofn.lpstrFilter = filter_w; + ofn.nFilterIndex = data->filter_index; + ofn.lpstrDefExt = L""; /* the extension of the filter where none is typed */ + } + (void) filter; + + if (data->current_file) + { + char *path = g_file_get_path (data->current_file); + gunichar2 *path_w = path ? g_utf8_to_utf16 (path, -1, NULL, NULL, NULL) : NULL; + + if (path_w && wcslen (path_w) < (size_t) buffer_len) + wcscpy (buffer, path_w); + g_free (path_w); + g_free (path); + } + else + { + if (data->current_folder) + { + char *path = g_file_get_path (data->current_folder); + + if (path) + initial_dir = g_utf8_to_utf16 (path, -1, NULL, NULL, NULL); + g_free (path); + } + if (data->current_name) + { + gunichar2 *name = g_utf8_to_utf16 (data->current_name, -1, NULL, NULL, NULL); + + if (name && wcslen (name) < (size_t) buffer_len) + wcscpy (buffer, name); + g_free (name); + } + } + + ofn.lpstrFile = buffer; + ofn.nMaxFile = buffer_len; + ofn.lpstrInitialDir = initial_dir; + if (data->title) + title = g_utf8_to_utf16 (data->title, -1, NULL, NULL, NULL); + ofn.lpstrTitle = title; + ofn.Flags = OFN_EXPLORER | OFN_ENABLEHOOK | OFN_ENABLESIZING | OFN_NOCHANGEDIR | + OFN_HIDEREADONLY | OFN_PATHMUSTEXIST; + if (!data->save) + ofn.Flags |= OFN_FILEMUSTEXIST; + if (data->select_multiple) + ofn.Flags |= OFN_ALLOWMULTISELECT; + if (data->save && data->overwrite_confirmation) + ofn.Flags |= OFN_OVERWRITEPROMPT; + ofn.lpfnHook = old_dialog_hook; + ofn.lCustData = (LPARAM) data; + + data->response = GTK_RESPONSE_CANCEL; + ok = data->save ? GetSaveFileNameW (&ofn) : GetOpenFileNameW (&ofn); + if (ok) + { + /* one path, or the folder and the names, each ended by a 0 */ + wchar_t *first = buffer, *name = buffer + wcslen (buffer) + 1; + + if (!data->select_multiple || *name == 0) + data_add_path_w (data, first); + else + for (; *name; name += wcslen (name) + 1) + { + wchar_t *full = g_new (wchar_t, wcslen (first) + 1 + wcslen (name) + 1); + + wcscpy (full, first); + wcscat (full, L"\\"); + wcscat (full, name); + data_add_path_w (data, full); + g_free (full); + } + data->chosen_filter = ofn.nFilterIndex; + } + + g_free (buffer); + g_free (filter_w); + g_free (initial_dir); + g_free (title); +} + +static gpointer +filechooser_win32_thread (gpointer _data) +{ + FilechooserWin32ThreadData *data = _data; + + /* OLE, not just COM: the folder dialog of XP wants it for its + * newer style */ + OleInitialize (NULL); + + if (!run_file_dialog (data)) + { + if (data->folder) + run_old_folder_dialog (data); + else + run_old_file_dialog (data); + } + + OleUninitialize (); + + g_main_context_invoke (NULL, filechooser_win32_thread_done, data); + + return NULL; +} + +static gboolean +file_filter_to_win32 (GtkFileFilter *filter, + COMDLG_FILTERSPEC *spec) +{ + const char *name; + char **patterns; + char *pattern_list; + + patterns = _gtk_file_filter_get_as_patterns (filter); + if (patterns == NULL) + return FALSE; + + pattern_list = g_strjoinv (";", patterns); + g_strfreev (patterns); + + name = gtk_file_filter_get_name (filter); + if (name == NULL) + name = pattern_list; + spec->pszName = g_utf8_to_utf16 (name, -1, NULL, NULL, NULL); + spec->pszSpec = g_utf8_to_utf16 (pattern_list, -1, NULL, NULL, NULL); + + g_free (pattern_list); + + return TRUE; +} + +/* "_Save" -> "&Save", "__" -> "_", "&" -> "&&" */ +static char * +translate_mnemonics (const char *src) +{ + GString *s; + const char *p; + + if (src == NULL) + return NULL; + + s = g_string_sized_new (strlen (src)); + + for (p = src; *p; p++) + { + switch (*p) + { + case '_': + if (p[1] == '_') + { + g_string_append_c (s, '_'); + p++; + } + else + g_string_append_c (s, '&'); + break; + case '&': + g_string_append (s, "&&"); + break; + default: + g_string_append_c (s, *p); + break; + } + } + + return g_string_free (s, FALSE); +} + +gboolean +_gtk_file_chooser_native_win32_show (GtkFileChooserNative *self) +{ + GThread *thread; + FilechooserWin32ThreadData *data; + GtkWindow *transient_for; + GtkFileChooserAction action; + guint update_preview_signal; + GSList *filters, *l; + int n_filters, i; + + /* what only the GTK+ dialog can show */ + if (gtk_file_chooser_get_extra_widget (GTK_FILE_CHOOSER (self)) != NULL) + return FALSE; + + update_preview_signal = g_signal_lookup ("update-preview", GTK_TYPE_FILE_CHOOSER); + if (g_signal_has_handler_pending (self, update_preview_signal, 0, TRUE)) + return FALSE; + + data = g_new0 (FilechooserWin32ThreadData, 1); + data->filter_index = 1; + + filters = gtk_file_chooser_list_filters (GTK_FILE_CHOOSER (self)); + n_filters = g_slist_length (filters); + if (n_filters > 0) + { + GtkFileFilter *current = gtk_file_chooser_get_filter (GTK_FILE_CHOOSER (self)); + + data->filters = g_new0 (COMDLG_FILTERSPEC, n_filters + 1); + data->n_filters = n_filters; + + for (l = filters, i = 0; l != NULL; l = l->next, i++) + { + if (!file_filter_to_win32 (l->data, &data->filters[i])) + { + g_slist_free (filters); + filechooser_win32_thread_data_free (data); + return FALSE; + } + if (l->data == current) + data->filter_index = i + 1; + } + } + g_slist_free (filters); + + self->mode_data = data; + data->self = g_object_ref (self); + + data->shortcut_uris = + gtk_file_chooser_list_shortcut_folder_uris (GTK_FILE_CHOOSER (self->dialog)); + + data->accept_label = translate_mnemonics (self->accept_label); + data->cancel_label = translate_mnemonics (self->cancel_label); + + action = gtk_file_chooser_get_action (GTK_FILE_CHOOSER (self->dialog)); + if (action == GTK_FILE_CHOOSER_ACTION_SAVE || + action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER) + data->save = TRUE; + + if (action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER || + action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER) + data->folder = TRUE; + + if ((action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER || + action == GTK_FILE_CHOOSER_ACTION_OPEN) && + gtk_file_chooser_get_select_multiple (GTK_FILE_CHOOSER (self->dialog))) + data->select_multiple = TRUE; + + if (gtk_file_chooser_get_do_overwrite_confirmation (GTK_FILE_CHOOSER (self->dialog))) + data->overwrite_confirmation = TRUE; + + if (gtk_file_chooser_get_show_hidden (GTK_FILE_CHOOSER (self->dialog))) + data->show_hidden = TRUE; + + transient_for = gtk_native_dialog_get_transient_for (GTK_NATIVE_DIALOG (self)); + if (transient_for) + { + gtk_widget_realize (GTK_WIDGET (transient_for)); + data->parent = GDK_WINDOW_HWND (gtk_widget_get_window (GTK_WIDGET (transient_for))); + + if (gtk_native_dialog_get_modal (GTK_NATIVE_DIALOG (self))) + data->modal = TRUE; + } + + data->title = g_strdup (gtk_native_dialog_get_title (GTK_NATIVE_DIALOG (self))); + + if (self->current_file) + data->current_file = g_object_ref (self->current_file); + else + { + if (self->current_folder) + data->current_folder = g_object_ref (self->current_folder); + + if (action == GTK_FILE_CHOOSER_ACTION_SAVE || + action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER) + data->current_name = g_strdup (self->current_name); + } + + thread = g_thread_try_new ("win32 filechooser", filechooser_win32_thread, data, NULL); + if (thread == NULL) + { + self->mode_data = NULL; + filechooser_win32_thread_data_free (data); + return FALSE; + } + g_thread_unref (thread); + + if (gtk_native_dialog_get_modal (GTK_NATIVE_DIALOG (self))) + { + data->grab_widget = gtk_invisible_new (); + gtk_grab_add (data->grab_widget); + } + + return TRUE; +} + +void +_gtk_file_chooser_native_win32_hide (GtkFileChooserNative *self) +{ + FilechooserWin32ThreadData *data = self->mode_data; + + /* set while the dialog is visible */ + g_return_if_fail (data != NULL); + + data->skip_response = TRUE; + filechooser_win32_send_close (data); +} + +#define __GTK_FILE_CHOOSER_NATIVE_WIN32_C__ +#include "gtkaliasdef.c" diff --git a/gtk/gtkfilechooserprivate.h b/gtk/gtkfilechooserprivate.h index bebb17687..4191348fa 100644 --- a/gtk/gtkfilechooserprivate.h +++ b/gtk/gtkfilechooserprivate.h @@ -138,7 +138,9 @@ typedef enum { typedef enum { VIEW_MODE_LIST, - VIEW_MODE_ICON + VIEW_MODE_ICON, + /* only in the settings: the icon view, compact */ + VIEW_MODE_COMPACT } ViewMode; typedef enum { @@ -175,18 +177,44 @@ struct _GtkFileChooserDefault GtkWidget *browse_shortcuts_popup_menu; GtkWidget *browse_shortcuts_popup_menu_remove_item; GtkWidget *browse_shortcuts_popup_menu_rename_item; + GtkWidget *browse_shortcuts_popup_menu_unmount_item; + GtkWidget *browse_shortcuts_popup_menu_eject_item; + GtkCellRenderer *shortcuts_eject_renderer; + GtkWidget *connect_dialog; + guint connect_timeout; + + /* the free space of a place, for its tooltip */ + GFile *place_space_file; + gchar *place_space_text; + gint64 place_space_time; GtkWidget *browse_files_tree_view; GtkWidget *browse_files_scrolled_window; + GtkWidget *file_operations_box; /* rows of copies and moves */ + GSList *file_operations; /* GtkFileOperation, running */ + gpointer cut_files; /* CopiedFiles on the clipboard, cut here */ GtkWidget *browse_files_current_view; GtkWidget *browse_files_icon_view; GtkWidget *browse_files_popup_menu; GtkWidget *browse_files_popup_menu_add_shortcut_item; + GtkWidget *browse_files_popup_menu_cut_item; + GtkWidget *browse_files_popup_menu_copy_item; + GtkWidget *browse_files_popup_menu_paste_item; + GtkWidget *browse_files_popup_menu_paste_into_item; GtkWidget *browse_files_popup_menu_copy_location_item; + GtkWidget *browse_files_popup_menu_undo_item; + GtkWidget *browse_files_popup_menu_redo_item; + GtkWidget *browse_files_popup_menu_rename_item; + GtkWidget *browse_files_popup_menu_trash_item; + GtkWidget *browse_files_popup_menu_visit_item; + GtkWidget *browse_files_popup_menu_preview_item; GtkWidget *browse_files_popup_menu_hidden_files_item; + GtkWidget *browse_files_popup_menu_thumbnails_item; GtkWidget *browse_files_popup_menu_size_column_item; + GtkWidget *browse_files_popup_menu_type_column_item; GtkWidget *browse_files_popup_menu_sort_by_name_item; GtkWidget *browse_files_popup_menu_sort_by_size_item; GtkWidget *browse_files_popup_menu_sort_by_mtime_item; + GtkWidget *browse_files_popup_menu_sort_by_type_item; GtkWidget *browse_files_popup_menu_sort_ascending_item; GtkWidget *browse_files_popup_menu_sort_descending_item; GtkWidget *browse_new_folder_button; @@ -239,10 +267,32 @@ struct _GtkFileChooserDefault GQueue icon_queries_waiting; GList *icon_queries_running; guint icons_update_id; + GHashTable *thumbnail_requests; /* GFile -> ThumbnailRequest, while made */ gint icon_view_scale_visible_overscan; ViewMode view_mode; GtkWidget *location_button; + /* dragging files over the file chooser */ + GFile *dnd_folder; /* where a drop now would go */ + gint dnd_action; /* what it would do */ + GFile *dnd_hover_folder; /* opened when a drag stays on it */ + guint dnd_hover_id; + guint dnd_scroll_id; + gint dnd_scroll_step; + GtkWidget *dnd_scroll_view; + GtkWidget *dnd_highlighted; /* a button of the path bar */ + GFile *dnd_xds_file; /* where a file saved by the source goes */ + GHashTable *dnd_filesystems; /* folder URI -> id::filesystem, per drag */ + gchar **drag_uris; /* what our own drag carries */ + + GtkWidget *history_back_button; + GtkWidget *history_forward_button; + + /* the folders that were shown, most recent first */ + GList *history_back; + GList *history_forward; + GFile *history_target; /* where Back or Forward is going */ + gint history_step; /* -1 back, 1 forward, 0 other changes */ GtkWidget *location_entry_box; GtkWidget *location_label; GtkWidget *location_entry; @@ -259,6 +309,7 @@ struct _GtkFileChooserDefault GSList *loading_shortcuts; GSList *reload_icon_cancellables; GCancellable *file_list_drag_data_received_cancellable; + GtkTreeRowReference *drag_press_row; /* pressed among several selected files */ GCancellable *update_current_folder_cancellable; GCancellable *should_respond_get_info_cancellable; GCancellable *file_exists_get_info_cancellable; @@ -289,15 +340,47 @@ struct _GtkFileChooserDefault GFile *preview_file; char *preview_display_name; + /* the preview of GTK+ itself, for programs without one; made only + * while shown */ + GtkWidget *preview_panel; + GtkWidget *preview_panel_image; + GtkWidget *preview_panel_name; + GtkWidget *preview_panel_info; + + /* thumbnails of files up to these sizes, in MB; of none on network + * shares if 0 */ + gint thumbnail_max_size; + gint thumbnail_max_size_remote; + + GtkWidget *preferences_dialog; + guint preferences_apply_id; + guint preview_panel_update_id; + GCancellable *preview_panel_cancellable; + GtkTreeViewColumn *list_name_column; GtkCellRenderer *list_name_renderer; GtkCellRenderer *list_icon_renderer; GtkTreeViewColumn *list_mtime_column; GtkTreeViewColumn *list_size_column; + GtkTreeViewColumn *list_type_column; + GHashTable *type_texts; /* content type -> what the Type column shows */ + gint type_format; GSource *edited_idle; char *edited_new_text; + /* renaming a file in place, and selecting it afterwards */ + GFile *rename_file; + GCancellable *rename_cancellable; + GFile *rename_select; + GtkFileSystemModel *rename_select_model; + gulong rename_select_handler; + + /* the last name a tooltip was considered for */ + GFile *tooltip_file; + gint tooltip_width; + guint tooltip_ellipsized : 1; + gulong settings_signal_id; int list_view_icon_size; int icon_view_icon_size; @@ -325,6 +408,7 @@ struct _GtkFileChooserDefault guint use_preview_label : 1; guint select_multiple : 1; guint show_hidden : 1; + guint show_hidden_set : 1; /* show-hidden was set, not loaded from the settings */ guint do_overwrite_confirmation : 1; guint list_sort_ascending : 1; guint changing_folder : 1; @@ -333,8 +417,15 @@ struct _GtkFileChooserDefault guint has_home : 1; guint has_desktop : 1; guint has_search : 1; + guint has_connect : 1; guint show_size_column : 1; + guint show_type_column : 1; + guint show_thumbnails : 1; + guint compact_view : 1; /* the icon view with small icons beside the names */ + guint show_preview_panel : 1; + guint drag_several : 1; /* a drag of all selected files */ guint create_folders : 1; + guint auto_selecting_first_row : 1; #if 0 guint shortcuts_drag_outside : 1; diff --git a/gtk/gtkfilechoosersettings.c b/gtk/gtkfilechoosersettings.c index ce34291ef..e573baf8b 100644 --- a/gtk/gtkfilechoosersettings.c +++ b/gtk/gtkfilechoosersettings.c @@ -43,6 +43,12 @@ #define ICON_VIEW_SCALE_KEY "IconViewScale" #define SHOW_HIDDEN_KEY "ShowHidden" #define SHOW_SIZE_COLUMN_KEY "ShowSizeColumn" +#define SHOW_TYPE_COLUMN_KEY "ShowTypeColumn" +#define TYPE_FORMAT_KEY "TypeFormat" +#define SHOW_THUMBNAILS_KEY "ShowThumbnails" +#define SHOW_PREVIEW_PANEL_KEY "ShowPreviewPanel" +#define THUMBNAIL_MAX_SIZE_KEY "ThumbnailMaxSize" +#define THUMBNAIL_MAX_SIZE_REMOTE_KEY "ThumbnailMaxSizeRemote" #define GEOMETRY_X_KEY "GeometryX" #define GEOMETRY_Y_KEY "GeometryY" #define GEOMETRY_WIDTH_KEY "GeometryWidth" @@ -54,6 +60,11 @@ #define COLUMN_NAME_STRING "name" #define COLUMN_MTIME_STRING "modified" #define COLUMN_SIZE_STRING "size" +#define COLUMN_TYPE_STRING "type" + +#define TYPE_FORMAT_CATEGORY_STRING "category" +#define TYPE_FORMAT_DESCRIPTION_STRING "description" +#define TYPE_FORMAT_MIME_STRING "mime" #define SORT_ASCENDING_STRING "ascending" #define SORT_DESCENDING_STRING "descending" @@ -65,6 +76,7 @@ #define MODE_LIST_VIEW "list-view" #define MODE_ICON_VIEW "icon-view" +#define MODE_COMPACT_VIEW "compact-view" #define EQ(a, b) (g_ascii_strcasecmp ((a), (b)) == 0) @@ -174,6 +186,8 @@ ensure_settings_read (GtkFileChooserSettings *settings) settings->view_mode = VIEW_MODE_LIST; else if (EQ (view_mode_str, MODE_ICON_VIEW)) settings->view_mode = VIEW_MODE_ICON; + else if (EQ (view_mode_str, MODE_COMPACT_VIEW)) + settings->view_mode = VIEW_MODE_COMPACT; else g_warning ("Unknown view mode '%s' encountered in filechooser settings", view_mode_str); @@ -185,6 +199,12 @@ ensure_settings_read (GtkFileChooserSettings *settings) get_int_key (key_file, SETTINGS_GROUP, ICON_VIEW_SCALE_KEY, &settings->icon_view_scale); + /* Thumbnails of files up to these sizes */ + + get_int_key (key_file, SETTINGS_GROUP, THUMBNAIL_MAX_SIZE_KEY, &settings->thumbnail_max_size); + get_int_key (key_file, SETTINGS_GROUP, THUMBNAIL_MAX_SIZE_REMOTE_KEY, + &settings->thumbnail_max_size_remote); + /* Show hidden */ value = g_key_file_get_boolean (key_file, SETTINGS_GROUP, @@ -203,6 +223,50 @@ ensure_settings_read (GtkFileChooserSettings *settings) else settings->show_size_column = value != FALSE; + /* Show type column */ + + value = g_key_file_get_boolean (key_file, SETTINGS_GROUP, + SHOW_TYPE_COLUMN_KEY, &error); + if (error) + warn_if_invalid_key_and_clear_error (SHOW_TYPE_COLUMN_KEY, &error); + else + settings->show_type_column = value != FALSE; + + /* What the type column shows; only read, as GTK+ 3 has it in + * dconf-editor only */ + { + gchar *format = g_key_file_get_string (key_file, SETTINGS_GROUP, + TYPE_FORMAT_KEY, NULL); + + if (format == NULL) + ; + else if (EQ (format, TYPE_FORMAT_DESCRIPTION_STRING)) + settings->type_format = TYPE_FORMAT_DESCRIPTION; + else if (EQ (format, TYPE_FORMAT_MIME_STRING)) + settings->type_format = TYPE_FORMAT_MIME; + else if (EQ (format, TYPE_FORMAT_CATEGORY_STRING)) + settings->type_format = TYPE_FORMAT_CATEGORY; + g_free (format); + } + + /* Show thumbnails */ + + value = g_key_file_get_boolean (key_file, SETTINGS_GROUP, + SHOW_THUMBNAILS_KEY, &error); + if (error) + warn_if_invalid_key_and_clear_error (SHOW_THUMBNAILS_KEY, &error); + else + settings->show_thumbnails = value != FALSE; + + /* Show the preview panel */ + + value = g_key_file_get_boolean (key_file, SETTINGS_GROUP, + SHOW_PREVIEW_PANEL_KEY, &error); + if (error) + warn_if_invalid_key_and_clear_error (SHOW_PREVIEW_PANEL_KEY, &error); + else + settings->show_preview_panel = value != FALSE; + /* Geometry */ get_int_key (key_file, SETTINGS_GROUP, GEOMETRY_X_KEY, &settings->geometry_x); @@ -222,6 +286,8 @@ ensure_settings_read (GtkFileChooserSettings *settings) settings->sort_column = FILE_LIST_COL_MTIME; else if (EQ (COLUMN_SIZE_STRING, sort_column)) settings->sort_column = FILE_LIST_COL_SIZE; + else if (EQ (COLUMN_TYPE_STRING, sort_column)) + settings->sort_column = FILE_LIST_COL_TYPE; else g_warning ("Unknown sort column name '%s' encountered in filechooser settings", sort_column); @@ -288,6 +354,11 @@ _gtk_file_chooser_settings_init (GtkFileChooserSettings *settings) settings->sort_column = FILE_LIST_COL_NAME; settings->show_hidden = FALSE; settings->show_size_column = TRUE; + settings->show_type_column = TRUE; + settings->type_format = TYPE_FORMAT_CATEGORY; + settings->show_thumbnails = TRUE; + settings->thumbnail_max_size = 64; + settings->thumbnail_max_size_remote = 0; settings->geometry_x = -1; settings->geometry_y = -1; settings->geometry_width = -1; @@ -371,6 +442,61 @@ _gtk_file_chooser_settings_get_show_size_column (GtkFileChooserSettings *setting return settings->show_size_column; } +void +_gtk_file_chooser_settings_set_show_thumbnails (GtkFileChooserSettings *settings, + gboolean show_thumbnails) +{ + settings->show_thumbnails = show_thumbnails != FALSE; +} + +void +_gtk_file_chooser_settings_set_show_preview_panel (GtkFileChooserSettings *settings, + gboolean show_preview_panel) +{ + settings->show_preview_panel = show_preview_panel != FALSE; +} + +gint +_gtk_file_chooser_settings_get_thumbnail_max_size (GtkFileChooserSettings *settings, + gboolean remote) +{ + gint megabytes; + + ensure_settings_read (settings); + megabytes = remote ? settings->thumbnail_max_size_remote : settings->thumbnail_max_size; + + /* not in the file (-1): the default */ + if (megabytes < 0) + megabytes = remote ? 0 : 64; + + return megabytes; +} + +void +_gtk_file_chooser_settings_set_thumbnail_max_size (GtkFileChooserSettings *settings, + gboolean remote, + gint megabytes) +{ + if (remote) + settings->thumbnail_max_size_remote = megabytes; + else + settings->thumbnail_max_size = megabytes; +} + +gboolean +_gtk_file_chooser_settings_get_show_preview_panel (GtkFileChooserSettings *settings) +{ + ensure_settings_read (settings); + return settings->show_preview_panel; +} + +gboolean +_gtk_file_chooser_settings_get_show_thumbnails (GtkFileChooserSettings *settings) +{ + ensure_settings_read (settings); + return settings->show_thumbnails; +} + void _gtk_file_chooser_settings_get_geometry (GtkFileChooserSettings *settings, int *out_x, @@ -399,6 +525,27 @@ _gtk_file_chooser_settings_set_geometry (GtkFileChooserSettings *settings, settings->geometry_height = height; } +gboolean +_gtk_file_chooser_settings_get_show_type_column (GtkFileChooserSettings *settings) +{ + ensure_settings_read (settings); + return settings->show_type_column; +} + +void +_gtk_file_chooser_settings_set_show_type_column (GtkFileChooserSettings *settings, + gboolean show_column) +{ + settings->show_type_column = show_column != FALSE; +} + +TypeFormat +_gtk_file_chooser_settings_get_type_format (GtkFileChooserSettings *settings) +{ + ensure_settings_read (settings); + return settings->type_format; +} + gint _gtk_file_chooser_settings_get_sort_column (GtkFileChooserSettings *settings) { @@ -477,6 +624,8 @@ _gtk_file_chooser_settings_save (GtkFileChooserSettings *settings, view_mode_str = MODE_LIST_VIEW; else if (settings->view_mode == VIEW_MODE_ICON) view_mode_str = MODE_ICON_VIEW; + else if (settings->view_mode == VIEW_MODE_COMPACT) + view_mode_str = MODE_COMPACT_VIEW; else { g_assert_not_reached (); @@ -497,6 +646,10 @@ _gtk_file_chooser_settings_save (GtkFileChooserSettings *settings, sort_column = COLUMN_SIZE_STRING; break; + case FILE_LIST_COL_TYPE: + sort_column = COLUMN_TYPE_STRING; + break; + default: g_assert_not_reached (); sort_column = NULL; @@ -547,6 +700,16 @@ _gtk_file_chooser_settings_save (GtkFileChooserSettings *settings, SHOW_HIDDEN_KEY, settings->show_hidden); g_key_file_set_boolean (key_file, SETTINGS_GROUP, SHOW_SIZE_COLUMN_KEY, settings->show_size_column); + g_key_file_set_boolean (key_file, SETTINGS_GROUP, + SHOW_TYPE_COLUMN_KEY, settings->show_type_column); + g_key_file_set_boolean (key_file, SETTINGS_GROUP, + SHOW_THUMBNAILS_KEY, settings->show_thumbnails); + g_key_file_set_boolean (key_file, SETTINGS_GROUP, + SHOW_PREVIEW_PANEL_KEY, settings->show_preview_panel); + g_key_file_set_integer (key_file, SETTINGS_GROUP, + THUMBNAIL_MAX_SIZE_KEY, settings->thumbnail_max_size); + g_key_file_set_integer (key_file, SETTINGS_GROUP, + THUMBNAIL_MAX_SIZE_REMOTE_KEY, settings->thumbnail_max_size_remote); g_key_file_set_integer (key_file, SETTINGS_GROUP, GEOMETRY_X_KEY, settings->geometry_x); g_key_file_set_integer (key_file, SETTINGS_GROUP, @@ -570,7 +733,6 @@ _gtk_file_chooser_settings_save (GtkFileChooserSettings *settings, if (!g_file_set_contents (filename, contents, len, NULL)) { - char *dirname; int saved_errno; /* Directory is not there? */ diff --git a/gtk/gtkfilechoosersettings.h b/gtk/gtkfilechoosersettings.h index b987fca8c..7b499fe01 100644 --- a/gtk/gtkfilechoosersettings.h +++ b/gtk/gtkfilechoosersettings.h @@ -34,9 +34,18 @@ enum { FILE_LIST_COL_NAME, FILE_LIST_COL_SIZE, FILE_LIST_COL_MTIME, + FILE_LIST_COL_TYPE, FILE_LIST_COL_NUM_COLUMNS }; +/* What the Type column shows, as in GTK+ 3: a kind of file ("Image", + * "Text"), the description of the type ("PNG image") or the MIME type */ +typedef enum { + TYPE_FORMAT_CATEGORY, + TYPE_FORMAT_DESCRIPTION, + TYPE_FORMAT_MIME +} TypeFormat; + typedef struct _GtkFileChooserSettings GtkFileChooserSettings; typedef struct _GtkFileChooserSettingsClass GtkFileChooserSettingsClass; @@ -49,7 +58,9 @@ struct _GtkFileChooserSettings GtkSortType sort_order; gint sort_column, icon_view_scale; + gint thumbnail_max_size, thumbnail_max_size_remote; /* MB */ StartupMode startup_mode; + TypeFormat type_format; int geometry_x; int geometry_y; @@ -59,6 +70,9 @@ struct _GtkFileChooserSettings guint settings_read : 1; guint show_hidden : 1; guint show_size_column : 1; + guint show_type_column : 1; + guint show_thumbnails : 1; + guint show_preview_panel : 1; }; struct _GtkFileChooserSettingsClass @@ -66,7 +80,7 @@ struct _GtkFileChooserSettingsClass GObjectClass parent_class; }; -GType _gtk_file_chooser_settings_get_type (void) G_GNUC_CONST; +GType _gtk_file_chooser_settings_get_type (void); GtkFileChooserSettings *_gtk_file_chooser_settings_new (void); @@ -86,10 +100,30 @@ gboolean _gtk_file_chooser_settings_get_show_hidden (GtkFileChooserSettings *set void _gtk_file_chooser_settings_set_show_hidden (GtkFileChooserSettings *settings, gboolean show_hidden); +gboolean _gtk_file_chooser_settings_get_show_preview_panel (GtkFileChooserSettings *settings); +void _gtk_file_chooser_settings_set_show_preview_panel (GtkFileChooserSettings *settings, + gboolean show_preview_panel); + +gint _gtk_file_chooser_settings_get_thumbnail_max_size (GtkFileChooserSettings *settings, + gboolean remote); +void _gtk_file_chooser_settings_set_thumbnail_max_size (GtkFileChooserSettings *settings, + gboolean remote, + gint megabytes); + +gboolean _gtk_file_chooser_settings_get_show_thumbnails (GtkFileChooserSettings *settings); +void _gtk_file_chooser_settings_set_show_thumbnails (GtkFileChooserSettings *settings, + gboolean show_thumbnails); + gboolean _gtk_file_chooser_settings_get_show_size_column (GtkFileChooserSettings *settings); void _gtk_file_chooser_settings_set_show_size_column (GtkFileChooserSettings *settings, gboolean show_column); +gboolean _gtk_file_chooser_settings_get_show_type_column (GtkFileChooserSettings *settings); +void _gtk_file_chooser_settings_set_show_type_column (GtkFileChooserSettings *settings, + gboolean show_column); + +TypeFormat _gtk_file_chooser_settings_get_type_format (GtkFileChooserSettings *settings); + gint _gtk_file_chooser_settings_get_sort_column (GtkFileChooserSettings *settings); void _gtk_file_chooser_settings_set_sort_column (GtkFileChooserSettings *settings, gint sort_column); diff --git a/gtk/gtkfilechooserutils.h b/gtk/gtkfilechooserutils.h index 2f5526207..d780f6061 100644 --- a/gtk/gtkfilechooserutils.h +++ b/gtk/gtkfilechooserutils.h @@ -51,7 +51,7 @@ void _gtk_file_chooser_delegate_iface_init (GtkFileChooserIface *iface); void _gtk_file_chooser_set_delegate (GtkFileChooser *receiver, GtkFileChooser *delegate); -GQuark _gtk_file_chooser_delegate_get_quark (void) G_GNUC_CONST; +GQuark _gtk_file_chooser_delegate_get_quark (void); GList *_gtk_file_chooser_extract_recent_folders (GList *infos); diff --git a/gtk/gtkfilechooserwidget.h b/gtk/gtkfilechooserwidget.h index 4d3fa3bcb..2e8cf3ef2 100644 --- a/gtk/gtkfilechooserwidget.h +++ b/gtk/gtkfilechooserwidget.h @@ -53,7 +53,7 @@ struct _GtkFileChooserWidgetClass GtkVBoxClass parent_class; }; -GType gtk_file_chooser_widget_get_type (void) G_GNUC_CONST; +GType gtk_file_chooser_widget_get_type (void); GtkWidget *gtk_file_chooser_widget_new (GtkFileChooserAction action); diff --git a/gtk/gtkfilefilter.c b/gtk/gtkfilefilter.c index 1c8f4e8c7..aa3ad4990 100644 --- a/gtk/gtkfilefilter.c +++ b/gtk/gtkfilefilter.c @@ -20,8 +20,10 @@ #include "config.h" #include +#include #include "gtkfilefilter.h" +#include "gtkfilefilterprivate.h" #include "gtkintl.h" #include "gtkprivate.h" @@ -383,7 +385,11 @@ gtk_file_filter_filter (GtkFileFilter *filter, filter_content_type = g_content_type_from_mime_type (filter_info->mime_type); rule_content_type = g_content_type_from_mime_type (rule->u.mime_type); - match = g_content_type_is_a (filter_content_type, rule_content_type); + /* there may be no content type for a MIME type, + * e.g. one that is unknown on Windows */ + match = filter_content_type != NULL && + rule_content_type != NULL && + g_content_type_is_a (filter_content_type, rule_content_type); g_free (filter_content_type); g_free (rule_content_type); @@ -433,5 +439,174 @@ gtk_file_filter_filter (GtkFileFilter *filter, return FALSE; } +/** + * gtk_file_filter_to_gvariant: + * @filter: a #GtkFileFilter + * + * Serializes a file filter to a GVariant of the type (sa(us)) that + * the file chooser of the desktop portal takes: the name, and the + * patterns (0) and MIME types (1) of the filter. Custom rules cannot + * be serialized and are left out. + * + * Returns: (transfer none): a new, floating, #GVariant + * + * Since: 2.24 (as in GTK+ 3.22) + */ +GVariant * +gtk_file_filter_to_gvariant (GtkFileFilter *filter) +{ + GVariantBuilder builder; + GSList *l; + + g_return_val_if_fail (GTK_IS_FILE_FILTER (filter), NULL); + + g_variant_builder_init (&builder, G_VARIANT_TYPE ("a(us)")); + for (l = filter->rules; l; l = l->next) + { + FilterRule *rule = l->data; + + switch (rule->type) + { + case FILTER_RULE_PATTERN: + g_variant_builder_add (&builder, "(us)", 0, rule->u.pattern); + break; + case FILTER_RULE_MIME_TYPE: + g_variant_builder_add (&builder, "(us)", 1, rule->u.mime_type); + break; + case FILTER_RULE_PIXBUF_FORMATS: + { + GSList *f; + + for (f = rule->u.pixbuf_formats; f; f = f->next) + { + gchar **mime_types = gdk_pixbuf_format_get_mime_types (f->data); + int i; + + for (i = 0; mime_types && mime_types[i]; i++) + g_variant_builder_add (&builder, "(us)", 1, mime_types[i]); + g_strfreev (mime_types); + } + } + break; + case FILTER_RULE_CUSTOM: + default: + break; + } + } + + return g_variant_new ("(s@a(us))", filter->name ? filter->name : "", + g_variant_builder_end (&builder)); +} + +/** + * gtk_file_filter_new_from_gvariant: + * @variant: a #GVariant of the type (sa(us)) + * + * Makes a file filter of a GVariant in the form that + * gtk_file_filter_to_gvariant() gives. + * + * Returns: a new #GtkFileFilter, as gtk_file_filter_new() + * + * Since: 2.24 (as in GTK+ 3.22) + */ +GtkFileFilter * +gtk_file_filter_new_from_gvariant (GVariant *variant) +{ + GtkFileFilter *filter; + GVariantIter *iter; + const char *name; + guint32 type; + char *tmp; + + g_return_val_if_fail (variant != NULL && + g_variant_is_of_type (variant, G_VARIANT_TYPE ("(sa(us))")), NULL); + + filter = gtk_file_filter_new (); + + g_variant_get (variant, "(&sa(us))", &name, &iter); + + gtk_file_filter_set_name (filter, name); + + while (g_variant_iter_next (iter, "(u&s)", &type, &tmp)) + { + switch (type) + { + case 0: + gtk_file_filter_add_pattern (filter, tmp); + break; + case 1: + gtk_file_filter_add_mime_type (filter, tmp); + break; + default: + break; + } + } + g_variant_iter_free (iter); + + return filter; +} + +/* The filter as patterns, for the file dialogs of Windows and Mac OS X; + * NULL if a rule cannot be one. MIME types become the extension the + * system knows for them, where it knows one. */ +char ** +_gtk_file_filter_get_as_patterns (GtkFileFilter *filter) +{ + GPtrArray *array = g_ptr_array_new (); + GSList *l; + + for (l = filter->rules; l; l = l->next) + { + FilterRule *rule = l->data; + + switch (rule->type) + { + case FILTER_RULE_PATTERN: + g_ptr_array_add (array, g_strdup (rule->u.pattern)); + break; + case FILTER_RULE_MIME_TYPE: + { + gchar *type = g_content_type_from_mime_type (rule->u.mime_type); + + /* GIO on Windows has extensions for content types */ + if (type == NULL || type[0] != '.') + { + g_free (type); + goto none; + } + g_ptr_array_add (array, g_strconcat ("*", type, NULL)); + g_free (type); + } + break; + case FILTER_RULE_PIXBUF_FORMATS: + { + GSList *f; + + for (f = rule->u.pixbuf_formats; f; f = f->next) + { + gchar **extensions = gdk_pixbuf_format_get_extensions (f->data); + int i; + + for (i = 0; extensions && extensions[i]; i++) + g_ptr_array_add (array, g_strdup_printf ("*.%s", extensions[i])); + g_strfreev (extensions); + } + } + break; + case FILTER_RULE_CUSTOM: + default: + goto none; + } + } + + g_ptr_array_add (array, NULL); + return (char **) g_ptr_array_free (array, FALSE); + + none: + g_ptr_array_foreach (array, (GFunc) g_free, NULL); + g_ptr_array_free (array, TRUE); + return NULL; +} + #define __GTK_FILE_FILTER_C__ #include "gtkaliasdef.c" diff --git a/gtk/gtkfilefilter.h b/gtk/gtkfilefilter.h index 491143d4b..caaa29e37 100644 --- a/gtk/gtkfilefilter.h +++ b/gtk/gtkfilefilter.h @@ -56,7 +56,7 @@ struct _GtkFileFilterInfo const gchar *mime_type; }; -GType gtk_file_filter_get_type (void) G_GNUC_CONST; +GType gtk_file_filter_get_type (void); GtkFileFilter * gtk_file_filter_new (void); void gtk_file_filter_set_name (GtkFileFilter *filter, @@ -75,6 +75,9 @@ void gtk_file_filter_add_custom (GtkFileFilter *filter, GDestroyNotify notify); GtkFileFilterFlags gtk_file_filter_get_needed (GtkFileFilter *filter); + +GVariant *gtk_file_filter_to_gvariant (GtkFileFilter *filter); +GtkFileFilter *gtk_file_filter_new_from_gvariant (GVariant *variant); gboolean gtk_file_filter_filter (GtkFileFilter *filter, const GtkFileFilterInfo *filter_info); diff --git a/gdk/gdkmedialib.h b/gtk/gtkfilefilterprivate.h similarity index 54% rename from gdk/gdkmedialib.h rename to gtk/gtkfilefilterprivate.h index 1912e9d70..4cec69fae 100644 --- a/gdk/gdkmedialib.h +++ b/gtk/gtkfilefilterprivate.h @@ -1,6 +1,5 @@ -/* GDK - The GIMP Drawing Kit - * Copyright (C) 2001-2007 Sun Microsystems, Inc. All rights reserved. - * (Brian Cameron, Dmitriy Demin, James Cheng, Padraig O'Briain) +/* GTK - The GIMP Toolkit + * gtkfilefilterprivate.h * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -18,28 +17,15 @@ * Boston, MA 02111-1307, USA. */ -/* - * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS - * file for a list of people on the GTK+ Team. See the ChangeLog - * files for a list of changes. These files are distributed with - * GTK+ at ftp://ftp.gtk.org/pub/gtk/. - */ +#ifndef __GTK_FILE_FILTER_PRIVATE_H__ +#define __GTK_FILE_FILTER_PRIVATE_H__ -#ifndef __GDK_MEDIALIB_H__ -#define __GDK_MEDIALIB_H__ - -#ifdef USE_MEDIALIB -#include -#include - -#include +#include G_BEGIN_DECLS -gboolean _gdk_use_medialib (void); +char **_gtk_file_filter_get_as_patterns (GtkFileFilter *filter); G_END_DECLS -#endif /* USE_MEDIALIB */ -#endif /* __GDK_MEDIALIB_H__ */ - +#endif /* __GTK_FILE_FILTER_PRIVATE_H__ */ diff --git a/gtk/gtkfileoperation.c b/gtk/gtkfileoperation.c new file mode 100644 index 000000000..695dd79f7 --- /dev/null +++ b/gtk/gtkfileoperation.c @@ -0,0 +1,2962 @@ +/* GTK - The GIMP Toolkit + * gtkfileoperation.c: copying, moving, linking and trashing files for + * the file chooser, and undoing it + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +/* + * The work runs in a thread of its own with the synchronous calls of + * GIO, so that a large copy neither blocks the dialog nor needs a + * callback per block. The thread touches no widget: it counts into + * the operation under a mutex, and a timeout of the main loop shows + * that ten times a second. When it has a question (a file of the same + * name is there, something failed), it hands it to the main loop and + * waits for the answer. Cancel cancels the GCancellable, which ends + * the copy of the file in progress at once; a file that was being + * written anew is removed again. + * + * Moving tries a rename first, which is instant on the same file + * system, and copies and deletes otherwise. Folders are copied with + * everything in them, symbolic links as links. + * + * Every step that changed something is noted (a file or folder made, a + * file moved, a folder removed after its contents went, a file put + * into the trash). Undo goes through these steps backwards and does + * the opposite of each, in the same kind of thread with progress and + * questions; Redo goes through them forwards again. Files that were + * replaced are not noted, as their old contents are gone: undoing such + * a copy leaves them. A file in the trash is put back by the + * information of the trash (freedesktop.org: the trash:// of GVfs, or + * the folders themselves without it), or where the Mac said it went; + * from the Recycle Bin of Windows the shell puts it back, as Restore + * there does. + */ + +#include "config.h" + +#include +#include +#include +#include +#include +#ifdef HAVE_UNISTD_H +#include +#endif + +#ifdef G_OS_WIN32 +#define COBJMACROS +#include +#include +#include +#endif + +#include "gtkfileoperation.h" +#include "gtkintl.h" +#include "gtkbox.h" +#include "gtkhbox.h" +#include "gtkvbox.h" +#include "gtklabel.h" +#include "gtkprogressbar.h" +#include "gtkbutton.h" +#include "gtkstock.h" +#include "gtkmessagedialog.h" +#include "gtkcheckbutton.h" +#include "gtkentry.h" +#include "gtkmain.h" +#include "gdk/gdk.h" +#include "gtkalias.h" + +#ifdef GDK_WINDOWING_QUARTZ +/* in gtkquartz.c, where Cocoa is (gtkquartz.h is Objective-C) */ +gboolean _gtk_quartz_trash_file (GFile *file, + GFile **trashed, + GError **error); +#endif + +/* what a question can be answered with */ +typedef enum +{ + ANSWER_NONE, + ANSWER_CANCEL, + ANSWER_SKIP, + ANSWER_REPLACE, /* a file over a file; folders are merged */ + ANSWER_RENAME +} Answer; + +typedef enum +{ + QUESTION_CONFLICT, + QUESTION_ERROR, + QUESTION_SPACE +} QuestionKind; + +/* ---------------------------------------------------------------- */ +/* what was done, for Undo */ + +typedef enum +{ + STEP_CREATED, /* @target made: a copy of @source, or a link to @link */ + STEP_MADE_FOLDER, /* the folder @target made, for what is moved into it */ + STEP_MOVED, /* @source moved to @target */ + STEP_REMOVED_FOLDER, /* the folder @source removed after its contents went */ + STEP_TRASHED /* @source into the trash, to @target if that is known */ +} StepKind; + +typedef struct +{ + StepKind kind; + GFile *source; + GFile *target; + gchar *link; + gint64 time; /* STEP_TRASHED: just before, by g_get_real_time() */ +} Step; + +typedef enum +{ + UNDO_COPY, + UNDO_MOVE, + UNDO_LINK, + UNDO_TRASH, + UNDO_RENAME, + UNDO_NEW_FOLDER +} UndoKind; + +typedef struct +{ + UndoKind kind; + GList *steps; /* in the order they were done */ + gboolean possible; /* FALSE: trashed where it can not be put back */ +} UndoEntry; + +#define UNDO_LENGTH 30 + +/* most recent first; only touched in the main loop */ +static GList *undo_stack = NULL; +static GList *redo_stack = NULL; + +struct _GtkFileOperation +{ + GtkFileOperationKind kind; + GList *sources; + GFile *destination; + GCancellable *cancellable; + + /* main loop side */ + GtkWidget *box; + GtkWidget *row; + GtkWidget *bar; + GtkWidget *label; + GtkWindow *parent; + guint update_id; + guint show_id; + GtkFileOperationDoneFunc done; + gpointer user_data; + + /* shared, under mutex */ + GMutex mutex; + GCond cond; + guint64 total_bytes; + guint64 done_bytes; + guint64 current_bytes; /* of the file being copied */ + guint total_files; + guint done_files; + gchar *current_name; + gboolean counting; + + QuestionKind question; + gchar *question_name; + gchar *question_folder; + gchar *question_text; + gchar *suggested_name; + gboolean question_both_folders; + gboolean question_can_replace; + Answer answer; + gchar *answer_name; + gboolean answered; + + /* thread side */ + Answer conflict_for_all; /* ANSWER_NONE until "for all" */ + Answer error_for_all; + gboolean all_moved; + GList *steps; /* what was done, most recent first */ + gint own_depth; /* in a folder this copy made: not noted */ + gboolean restorable; /* all trashed files can be put back */ + + /* Undo and Redo: the entry, taken off its stack meanwhile, and how + * many of its steps were gone through */ + UndoEntry *replay; + guint replayed; +}; + +/* operations that run; Undo and Redo wait for them, as they may depend + * on what is being done; only touched in the main loop */ +static guint operations_running = 0; + +static void +step_free (Step *step) +{ + if (step->source) + g_object_unref (step->source); + if (step->target) + g_object_unref (step->target); + g_free (step->link); + g_slice_free (Step, step); +} + +static void +undo_entry_free (UndoEntry *entry) +{ + g_list_free_full (entry->steps, (GDestroyNotify) step_free); + g_slice_free (UndoEntry, entry); +} + +static void +undo_push (GList **stack, + UndoEntry *entry) +{ + *stack = g_list_prepend (*stack, entry); + if (g_list_length (*stack) > UNDO_LENGTH) + { + GList *last = g_list_last (*stack); + + undo_entry_free (last->data); + *stack = g_list_delete_link (*stack, last); + } +} + +/* Something new was done: what was undone can not be done again */ +static void +undo_add (UndoEntry *entry) +{ + g_list_free_full (redo_stack, (GDestroyNotify) undo_entry_free); + redo_stack = NULL; + undo_push (&undo_stack, entry); +} + +static UndoEntry * +undo_entry_new (UndoKind kind) +{ + UndoEntry *entry = g_slice_new0 (UndoEntry); + + entry->kind = kind; + entry->possible = TRUE; + return entry; +} + +static Step * +step_new (StepKind kind, + GFile *source, + GFile *target, + const gchar *link) +{ + Step *step = g_slice_new0 (Step); + + step->kind = kind; + step->source = source ? g_object_ref (source) : NULL; + step->target = target ? g_object_ref (target) : NULL; + step->link = g_strdup (link); + return step; +} + +/* In the thread: notes a step of a copy, move, link or trash */ +static void +note (GtkFileOperation *op, + StepKind kind, + GFile *source, + GFile *target, + const gchar *link) +{ + if (op->replay || op->own_depth > 0) + return; + op->steps = g_list_prepend (op->steps, step_new (kind, source, target, link)); +} + +void +_gtk_file_operation_add_rename (GFile *from, + GFile *to) +{ + UndoEntry *entry; + + g_return_if_fail (G_IS_FILE (from) && G_IS_FILE (to)); + + entry = undo_entry_new (UNDO_RENAME); + entry->steps = g_list_prepend (NULL, step_new (STEP_MOVED, from, to, NULL)); + undo_add (entry); +} + +void +_gtk_file_operation_add_new_folder (GFile *folder) +{ + UndoEntry *entry; + + g_return_if_fail (G_IS_FILE (folder)); + + entry = undo_entry_new (UNDO_NEW_FOLDER); + entry->steps = g_list_prepend (NULL, step_new (STEP_MADE_FOLDER, NULL, folder, NULL)); + undo_add (entry); +} + +/* What Undo (or Redo) would take away of @folder: the file of a step + * that removes or moves @folder or a folder above it, or NULL */ +GFile * +_gtk_file_operation_undo_removes (gboolean redo, + GFile *folder) +{ + UndoEntry *entry = redo ? (redo_stack ? redo_stack->data : NULL) + : (undo_stack ? undo_stack->data : NULL); + GList *l; + + if (entry == NULL || folder == NULL) + return NULL; + + for (l = entry->steps; l; l = l->next) + { + Step *step = l->data; + GFile *gone = NULL; + + switch (step->kind) + { + case STEP_CREATED: + case STEP_MADE_FOLDER: + gone = redo ? NULL : step->target; + break; + case STEP_MOVED: + gone = redo ? step->source : step->target; + break; + case STEP_REMOVED_FOLDER: + case STEP_TRASHED: + gone = redo ? step->source : NULL; + break; + } + + if (gone && (g_file_equal (gone, folder) || g_file_has_prefix (folder, gone))) + return gone; + } + + return NULL; +} + +const gchar * +_gtk_file_operation_undo_label (gboolean redo, + gboolean *possible) +{ + UndoEntry *entry = redo ? (redo_stack ? redo_stack->data : NULL) + : (undo_stack ? undo_stack->data : NULL); + + if (possible) + *possible = entry != NULL && entry->possible && operations_running == 0; + + if (entry == NULL) + return redo ? _("_Redo") : _("_Undo"); + + switch (entry->kind) + { + case UNDO_COPY: + return redo ? _("_Redo Copy") : _("_Undo Copy"); + case UNDO_MOVE: + return redo ? _("_Redo Move") : _("_Undo Move"); + case UNDO_LINK: + return redo ? _("_Redo Link") : _("_Undo Link"); + case UNDO_TRASH: + return redo ? _("_Redo Move to Trash") : _("_Undo Move to Trash"); + case UNDO_RENAME: + return redo ? _("_Redo Rename") : _("_Undo Rename"); + case UNDO_NEW_FOLDER: + return redo ? _("_Redo Create Folder") : _("_Undo Create Folder"); + default: + g_assert_not_reached (); + return NULL; + } +} + +/* ---------------------------------------------------------------- */ +/* names */ + +static gchar * +file_display_name (GFile *file) +{ + gchar *basename = g_file_get_basename (file); + gchar *name = g_filename_display_name (basename ? basename : ""); + + g_free (basename); + return name; +} + +/* "name (2).ext": the first of these that is not there yet in @dir. + * Copies into the same folder start at "name (copy).ext". */ +static GFile * +free_name_in (GFile *dir, + const gchar *basename, + gboolean as_copy, + gchar **display) +{ + const gchar *dot = strrchr (basename, '.'); + gchar *stem, *ext; + gint i; + + /* ".hidden" and "folder" have no extension; "a.tar.gz" keeps ".gz" */ + if (dot && dot != basename && dot[1] != '\0') + { + stem = g_strndup (basename, dot - basename); + ext = g_strdup (dot); + } + else + { + stem = g_strdup (basename); + ext = g_strdup (""); + } + + for (i = as_copy ? 1 : 2; i < 10000; i++) + { + gchar *candidate; + GFile *file; + + if (as_copy && i == 1) + /* Translators: the name of a copy of a file in the same folder, + * "%s" is the name without its extension */ + candidate = g_strdup_printf (_("%s (copy)"), stem); + else if (as_copy) + /* Translators: the name of a further copy of a file in the same + * folder, "%s" is the name without its extension, "%d" the number */ + candidate = g_strdup_printf (_("%s (copy %d)"), stem, i); + else + candidate = g_strdup_printf ("%s (%d)", stem, i); + + { + gchar *full = g_strconcat (candidate, ext, NULL); + + g_free (candidate); + file = g_file_get_child (dir, full); + if (!g_file_query_exists (file, NULL)) + { + if (display) + *display = g_filename_display_name (full); + g_free (full); + g_free (stem); + g_free (ext); + return file; + } + g_free (full); + g_object_unref (file); + } + } + + g_free (stem); + g_free (ext); + return NULL; +} + +GFile * +_gtk_file_operation_free_name (GFile *folder, + const gchar *basename) +{ + GFile *file; + + g_return_val_if_fail (G_IS_FILE (folder), NULL); + + file = g_file_get_child (folder, basename); + if (!g_file_query_exists (file, NULL)) + return file; + g_object_unref (file); + + return free_name_in (folder, basename, FALSE, NULL); +} + +/* ---------------------------------------------------------------- */ +/* progress, main loop side */ + +static void +update_row (GtkFileOperation *op) +{ + gchar *text, *name, *done_size, *total_size; + guint64 done, total; + guint files, total_files, number; + gboolean counting; + + g_mutex_lock (&op->mutex); + done = op->done_bytes + op->current_bytes; + total = op->total_bytes; + files = op->done_files; + total_files = op->total_files; + counting = op->counting; + name = g_strdup (op->current_name ? op->current_name : ""); + g_mutex_unlock (&op->mutex); + + number = MIN (files + 1, total_files); + + if (counting) + { + gtk_progress_bar_pulse (GTK_PROGRESS_BAR (op->bar)); + text = g_strdup (op->kind == GTK_FILE_OPERATION_COPY ? _("Preparing to copy…") + : op->kind == GTK_FILE_OPERATION_MOVE ? _("Preparing to move…") + : _("Preparing…")); + } + else + { + switch (op->kind) + { + case GTK_FILE_OPERATION_COPY: + case GTK_FILE_OPERATION_MOVE: + done_size = g_format_size (done); + total_size = g_format_size (total); + text = g_strdup_printf (op->kind == GTK_FILE_OPERATION_COPY + /* Translators: "Copying 'name': 3 of 10 files, 1.2 MB of 4.5 MB" */ + ? _("Copying “%s”: %u of %u files, %s of %s") + /* Translators: "Moving 'name': 3 of 10 files, 1.2 MB of 4.5 MB" */ + : _("Moving “%s”: %u of %u files, %s of %s"), + name, number, total_files, done_size, total_size); + g_free (done_size); + g_free (total_size); + break; + case GTK_FILE_OPERATION_LINK: + /* Translators: "Linking 'name': 3 of 10 files" */ + text = g_strdup_printf (_("Linking “%s”: %u of %u files"), name, number, total_files); + break; + case GTK_FILE_OPERATION_TRASH: + /* Translators: "Moving 'name' to the Trash: 3 of 10 files" */ + text = g_strdup_printf (_("Moving “%s” to the Trash: %u of %u files"), + name, number, total_files); + break; + case GTK_FILE_OPERATION_UNDO: + /* Translators: "Undoing: 'name', 3 of 10" */ + text = g_strdup_printf (_("Undoing: “%s”, %u of %u"), name, number, total_files); + break; + default: + /* Translators: "Redoing: 'name', 3 of 10" */ + text = g_strdup_printf (_("Redoing: “%s”, %u of %u"), name, number, total_files); + break; + } + + if (total > 0) + gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (op->bar), + CLAMP ((gdouble) done / total, 0.0, 1.0)); + else if (total_files > 0) + gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (op->bar), + CLAMP ((gdouble) files / total_files, 0.0, 1.0)); + } + + gtk_label_set_text (GTK_LABEL (op->label), text); + g_free (text); + g_free (name); +} + +static gboolean +update_timeout (gpointer data) +{ + GtkFileOperation *op = data; + + if (op->row && gtk_widget_get_visible (op->row)) + update_row (op); + + return TRUE; +} + +static gboolean +show_timeout (gpointer data) +{ + GtkFileOperation *op = data; + + op->show_id = 0; + if (op->row) + { + update_row (op); + gtk_widget_show (op->row); + } + + return FALSE; +} + +static void +cancel_clicked (GtkButton *button, + GtkFileOperation *op) +{ + _gtk_file_operation_cancel (op); +} + +static void +row_destroyed (GtkWidget *row, + GtkFileOperation *op) +{ + /* the file chooser went away: the operation goes on to its end + * without a row, and stops at the next question */ + op->row = NULL; + op->bar = NULL; + op->label = NULL; + op->done = NULL; + g_cancellable_cancel (op->cancellable); +} + +static void +make_row (GtkFileOperation *op) +{ + GtkWidget *vbox, *button; + + op->row = gtk_hbox_new (FALSE, 6); + vbox = gtk_vbox_new (FALSE, 2); + gtk_box_pack_start (GTK_BOX (op->row), vbox, TRUE, TRUE, 0); + + op->label = gtk_label_new (NULL); + gtk_misc_set_alignment (GTK_MISC (op->label), 0.0, 0.5); + gtk_label_set_ellipsize (GTK_LABEL (op->label), PANGO_ELLIPSIZE_MIDDLE); + gtk_box_pack_start (GTK_BOX (vbox), op->label, FALSE, FALSE, 0); + + op->bar = gtk_progress_bar_new (); + gtk_progress_bar_set_pulse_step (GTK_PROGRESS_BAR (op->bar), 0.1); + gtk_box_pack_start (GTK_BOX (vbox), op->bar, FALSE, FALSE, 0); + + button = gtk_button_new_from_stock (GTK_STOCK_CANCEL); + g_signal_connect (button, "clicked", G_CALLBACK (cancel_clicked), op); + gtk_box_pack_start (GTK_BOX (op->row), button, FALSE, FALSE, 0); + + gtk_widget_show_all (vbox); + gtk_widget_show (button); + /* the row itself only after half a second */ + gtk_box_pack_start (GTK_BOX (op->box), op->row, FALSE, FALSE, 0); + g_signal_connect (op->row, "destroy", G_CALLBACK (row_destroyed), op); +} + +/* ---------------------------------------------------------------- */ +/* questions */ + +enum +{ + RESPONSE_SKIP = 1, + RESPONSE_REPLACE, + RESPONSE_RENAME +}; + +typedef struct +{ + GtkFileOperation *op; + GtkWidget *all_check; + GtkWidget *entry; + gboolean answered; +} AskData; + +static void +answer (GtkFileOperation *op, + Answer value, + const gchar *name, + gboolean for_all) +{ + g_mutex_lock (&op->mutex); + op->answer = value; + g_free (op->answer_name); + op->answer_name = g_strdup (name); + if (for_all) + { + if (op->question == QUESTION_CONFLICT) + op->conflict_for_all = value; + else + op->error_for_all = value; + } + op->answered = TRUE; + g_cond_broadcast (&op->cond); + g_mutex_unlock (&op->mutex); +} + +static void +ask_response (GtkDialog *dialog, + gint response, + AskData *ask) +{ + GtkFileOperation *op = ask->op; + gboolean for_all = ask->all_check && + gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (ask->all_check)); + const gchar *name = ask->entry ? gtk_entry_get_text (GTK_ENTRY (ask->entry)) : NULL; + Answer value; + + switch (response) + { + case RESPONSE_SKIP: + value = ANSWER_SKIP; + break; + case RESPONSE_REPLACE: + value = ANSWER_REPLACE; + break; + case RESPONSE_RENAME: + if (name == NULL || *name == '\0' || strchr (name, '/') != NULL +#ifdef G_OS_WIN32 + || strchr (name, '\\') != NULL +#endif + ) + return; + value = ANSWER_RENAME; + break; + default: + value = ANSWER_CANCEL; + break; + } + + /* the name of the user is for this file only */ + answer (op, value, name, for_all && value != ANSWER_RENAME ? TRUE : FALSE); + if (for_all && value == ANSWER_RENAME) + { + g_mutex_lock (&op->mutex); + op->conflict_for_all = ANSWER_RENAME; + g_mutex_unlock (&op->mutex); + } + ask->answered = TRUE; + + gtk_widget_destroy (GTK_WIDGET (dialog)); +} + +/* The dialog went: with its window, too, without an answer, which then + * is Cancel, as the thread waits for one */ +static void +ask_destroyed (GtkWidget *dialog, + AskData *ask) +{ + if (!ask->answered) + answer (ask->op, ANSWER_CANCEL, NULL, FALSE); + g_slice_free (AskData, ask); +} + +static void +all_toggled (GtkToggleButton *check, + GtkWidget *entry) +{ + /* "for all" renames to free names, not to one */ + gtk_widget_set_sensitive (entry, !gtk_toggle_button_get_active (check)); +} + +static const gchar * +error_title (GtkFileOperationKind kind) +{ + switch (kind) + { + case GTK_FILE_OPERATION_COPY: + return _("“%s” could not be copied."); + case GTK_FILE_OPERATION_MOVE: + return _("“%s” could not be moved."); + case GTK_FILE_OPERATION_LINK: + return _("No link to “%s” could be made."); + case GTK_FILE_OPERATION_TRASH: + return _("“%s” could not be moved to the Trash."); + case GTK_FILE_OPERATION_UNDO: + return _("Undoing failed for “%s”."); + default: + return _("Redoing failed for “%s”."); + } +} + +static gboolean +ask_in_main_loop (gpointer data) +{ + GtkFileOperation *op = data; + GtkWidget *dialog, *area; + AskData *ask; + gchar *name, *folder, *text, *suggested; + gboolean both_folders, can_replace; + QuestionKind kind; + + g_mutex_lock (&op->mutex); + kind = op->question; + name = g_strdup (op->question_name); + folder = g_strdup (op->question_folder); + text = g_strdup (op->question_text); + suggested = g_strdup (op->suggested_name); + both_folders = op->question_both_folders; + can_replace = op->question_can_replace; + g_mutex_unlock (&op->mutex); + + if (op->row == NULL) + { + /* nothing to ask in any more */ + answer (op, ANSWER_CANCEL, NULL, FALSE); + goto out; + } + + ask = g_slice_new0 (AskData); + ask->op = op; + + if (kind == QUESTION_CONFLICT) + { + dialog = gtk_message_dialog_new (op->parent, + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_QUESTION, + GTK_BUTTONS_NONE, + both_folders + ? _("A folder named “%s” already exists in “%s”.") + : _("A file named “%s” already exists in “%s”."), + name, folder); + gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s", + both_folders + ? _("Merging adds the contents to the folder there; files of the same name are asked for.") + : can_replace + ? _("Replacing it overwrites its contents.") + : _("It can be kept under another name.")); + + area = gtk_message_dialog_get_message_area (GTK_MESSAGE_DIALOG (dialog)); + { + GtkWidget *hbox = gtk_hbox_new (FALSE, 6); + GtkWidget *label = gtk_label_new_with_mnemonic (_("_New name:")); + + ask->entry = gtk_entry_new (); + gtk_entry_set_text (GTK_ENTRY (ask->entry), suggested ? suggested : ""); + gtk_entry_set_activates_default (GTK_ENTRY (ask->entry), FALSE); + gtk_label_set_mnemonic_widget (GTK_LABEL (label), ask->entry); + gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX (hbox), ask->entry, TRUE, TRUE, 0); + gtk_box_pack_start (GTK_BOX (area), hbox, FALSE, FALSE, 0); + gtk_widget_show_all (hbox); + } + + ask->all_check = gtk_check_button_new_with_mnemonic (_("Do this for _all further conflicts")); + gtk_box_pack_start (GTK_BOX (area), ask->all_check, FALSE, FALSE, 0); + gtk_widget_show (ask->all_check); + g_signal_connect (ask->all_check, "toggled", G_CALLBACK (all_toggled), ask->entry); + + gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL); + gtk_dialog_add_button (GTK_DIALOG (dialog), _("_Skip"), RESPONSE_SKIP); + gtk_dialog_add_button (GTK_DIALOG (dialog), _("Re_name"), RESPONSE_RENAME); + if (can_replace) + gtk_dialog_add_button (GTK_DIALOG (dialog), + both_folders ? _("_Merge") : _("_Replace"), + RESPONSE_REPLACE); + gtk_dialog_set_default_response (GTK_DIALOG (dialog), + can_replace ? RESPONSE_REPLACE : RESPONSE_RENAME); + } + else if (kind == QUESTION_SPACE) + { + dialog = gtk_message_dialog_new (op->parent, + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_WARNING, + GTK_BUTTONS_NONE, + _("There is not enough space in “%s”."), + name); + gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s", text); + gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL); + gtk_dialog_add_button (GTK_DIALOG (dialog), _("_Continue Anyway"), RESPONSE_SKIP); + gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_CANCEL); + } + else + { + dialog = gtk_message_dialog_new (op->parent, + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR, + GTK_BUTTONS_NONE, + error_title (op->kind), + name); + gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s", text); + + area = gtk_message_dialog_get_message_area (GTK_MESSAGE_DIALOG (dialog)); + ask->all_check = gtk_check_button_new_with_mnemonic (_("Skip _all further errors")); + gtk_box_pack_start (GTK_BOX (area), ask->all_check, FALSE, FALSE, 0); + gtk_widget_show (ask->all_check); + + gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL); + gtk_dialog_add_button (GTK_DIALOG (dialog), _("_Skip"), RESPONSE_SKIP); + gtk_dialog_set_default_response (GTK_DIALOG (dialog), RESPONSE_SKIP); + } + + gtk_window_set_title (GTK_WINDOW (dialog), ""); + gtk_window_set_modal (GTK_WINDOW (dialog), TRUE); + g_signal_connect (dialog, "response", G_CALLBACK (ask_response), ask); + g_signal_connect (dialog, "destroy", G_CALLBACK (ask_destroyed), ask); + gtk_widget_show (dialog); + + out: + g_free (name); + g_free (folder); + g_free (text); + g_free (suggested); + return FALSE; +} + +/* In the thread: asks and waits. Returns the answer; for a rename the + * new basename goes into @new_name. */ +static Answer +ask (GtkFileOperation *op, + QuestionKind kind, + GFile *file, + const gchar *text, + GFile *suggestion, + gboolean both_folders, + gboolean can_replace, + gchar **new_name) +{ + GFile *parent; + Answer value; + + if (g_cancellable_is_cancelled (op->cancellable)) + return ANSWER_CANCEL; + + g_mutex_lock (&op->mutex); + op->question = kind; + g_free (op->question_name); + op->question_name = file_display_name (file); + g_free (op->question_folder); + parent = g_file_get_parent (file); + op->question_folder = parent ? file_display_name (parent) : g_strdup ("/"); + if (parent) + g_object_unref (parent); + g_free (op->question_text); + op->question_text = g_strdup (text); + g_free (op->suggested_name); + op->suggested_name = suggestion ? file_display_name (suggestion) : NULL; + op->question_both_folders = both_folders; + op->question_can_replace = can_replace; + op->answered = FALSE; + g_mutex_unlock (&op->mutex); + + gdk_threads_add_idle (ask_in_main_loop, op); + + g_mutex_lock (&op->mutex); + while (!op->answered) + g_cond_wait (&op->cond, &op->mutex); + value = op->answer; + if (new_name) + *new_name = g_strdup (op->answer_name); + g_mutex_unlock (&op->mutex); + + if (value == ANSWER_CANCEL) + g_cancellable_cancel (op->cancellable); + + return value; +} + +/* ---------------------------------------------------------------- */ +/* the trash */ + +#ifdef G_OS_WIN32 +#ifndef FOF_WANTNUKEWARNING +#define FOF_WANTNUKEWARNING 0x4000 /* shell32 5.0, Windows 2000 */ +#endif + +/* Into the Recycle Bin, as Delete does in Explorer: GLib asks the shell + * with nothing but FOF_ALLOWUNDO, so Windows asks for confirmation in a + * box of its own, from a thread, for every file. FALSE with @error set + * when the shell refuses; a file that is not local is left to GIO. */ +static gboolean +win32_trash_file (GFile *file, + gboolean *handled, + GError **error) +{ + SHFILEOPSTRUCTW op = { 0 }; + gchar *path = g_file_get_path (file); + gunichar2 *wpath; + glong len; + int result; + + *handled = path != NULL; + if (path == NULL) + return FALSE; + + wpath = g_utf8_to_utf16 (path, -1, NULL, &len, NULL); + g_free (path); + if (wpath == NULL) + { + g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_INVALID_FILENAME, + _("Invalid file name")); + return FALSE; + } + + /* a file that is gone is reported here: the shell would offer to + * delete it for good instead */ + if (GetFileAttributesW ((wchar_t *) wpath) == INVALID_FILE_ATTRIBUTES) + { + gchar *message = g_win32_error_message (GetLastError ()); + + g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, message); + g_free (message); + g_free (wpath); + return FALSE; + } + + /* the list of files ends with two zeros */ + wpath = g_renew (gunichar2, wpath, len + 2); + wpath[len + 1] = 0; + + op.wFunc = FO_DELETE; + op.pFrom = wpath; + /* without asking, but never deleting for good instead: for a file + * that cannot go into the Recycle Bin (a network share, a drive + * without one, a file too big for it) the shell asks after all */ + op.fFlags = FOF_ALLOWUNDO | FOF_NOCONFIRMATION | FOF_WANTNUKEWARNING | + FOF_NOERRORUI | FOF_SILENT; + result = SHFileOperationW (&op); + g_free (wpath); + + if (result != 0 || op.fAnyOperationsAborted) + { + g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, + _("The shell could not move the file to the Recycle Bin (error %d)"), + result); + return FALSE; + } + + return TRUE; +} + +#define GTK_CMIC_MASK_NOASYNC 0x00000100 /* CMIC_MASK_NOASYNC of Vista */ + +/* the interfaces, here so that no uuid library is needed */ +static const GUID gtk_IID_IShellFolder2 = + { 0x93f2f68c, 0x1d1b, 0x11d3, { 0xa3, 0x0e, 0x00, 0xc0, 0x4f, 0x79, 0xab, 0xd1 } }; +static const GUID gtk_IID_IContextMenu = + { 0x000214e4, 0x0000, 0x0000, { 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46 } }; +/* the column Date Deleted of the Recycle Bin */ +static const SHCOLUMNID gtk_SCID_DateDeleted = + { { 0x9b174b33, 0x40ff, 0x11d2, { 0xa2, 0x7e, 0x00, 0xc0, 0x4f, 0xc3, 0x08, 0x71 } }, 3 }; + +/* A STRRET as UTF-8, freed: StrRetToStrW() without shlwapi */ +static gchar * +win32_strret (STRRET *str, + LPITEMIDLIST item) +{ + gchar *result = NULL; + + switch (str->uType) + { + case STRRET_WSTR: + result = g_utf16_to_utf8 ((gunichar2 *) str->pOleStr, -1, NULL, NULL, NULL); + CoTaskMemFree (str->pOleStr); + break; + case STRRET_CSTR: + result = g_locale_to_utf8 (str->cStr, -1, NULL, NULL, NULL); + break; + case STRRET_OFFSET: + result = g_locale_to_utf8 ((const gchar *) item + str->uOffset, -1, NULL, NULL, NULL); + break; + } + return result; +} + +/* A detail of an item in the Recycle Bin as UTF-8: 0 the name, 1 the + * folder it came from */ +static gchar * +win32_bin_detail (IShellFolder2 *bin, + LPITEMIDLIST item, + UINT column) +{ + SHELLDETAILS details = { 0 }; + + if (FAILED (IShellFolder2_GetDetailsOf (bin, item, column, &details))) + return NULL; + return win32_strret (&details.str, item); +} + +/* The extension of the name the Recycle Bin keeps @item under (Dc1.txt + * on XP, $R1A2B3C.txt later: that of the file), or NULL */ +static gchar * +win32_bin_extension (IShellFolder2 *bin, + LPITEMIDLIST item) +{ + STRRET name; + gchar *parsing, *dot, *result = NULL; + + if (FAILED (IShellFolder2_GetDisplayNameOf (bin, item, SHGDN_INFOLDER | SHGDN_FORPARSING, &name))) + return NULL; + parsing = win32_strret (&name, item); + if (parsing && (dot = strrchr (parsing, '.')) != NULL && + strchr (dot, '\\') == NULL && strchr (dot, '/') == NULL) + result = g_utf8_casefold (dot, -1); + g_free (parsing); + return result; +} + +/* @usec of g_get_real_time() as a date of the shell: days since 30 + * December 1899, of the local time */ +static gdouble +win32_ole_date (gint64 usec) +{ + GDateTime *local = g_date_time_new_from_unix_local (usec / G_USEC_PER_SEC); + GDate *day, *base; + gdouble result; + + if (local == NULL) + return 0; + day = g_date_new_dmy (g_date_time_get_day_of_month (local), + g_date_time_get_month (local), + g_date_time_get_year (local)); + base = g_date_new_dmy (30, G_DATE_DECEMBER, 1899); + result = g_date_days_between (base, day) + + (g_date_time_get_hour (local) * 3600 + + g_date_time_get_minute (local) * 60 + + g_date_time_get_second (local)) / 86400.0; + g_date_free (day); + g_date_free (base); + g_date_time_unref (local); + return result; +} + +/* How well the item in the Recycle Bin of @name from @folder is the file + * @path: 2 for the same name and folder, 1 when only the extension is + * missing (Explorer hides those it knows), 0 when it is another file */ +static gint +win32_bin_match (const gchar *path, + const gchar *folder, + const gchar *name) +{ + gchar *dir, *base, *a, *b, *dot; + gint result = 0; + + if (folder == NULL || name == NULL) + return 0; + + dir = g_path_get_dirname (path); + base = g_path_get_basename (path); + a = g_utf8_casefold (dir, -1); + b = g_utf8_casefold (folder, -1); + /* "C:\" and "C:" for the root */ + if (g_str_has_suffix (a, "\\")) + a[strlen (a) - 1] = '\0'; + if (g_str_has_suffix (b, "\\")) + b[strlen (b) - 1] = '\0'; + + if (strcmp (a, b) == 0) + { + g_free (a); + g_free (b); + a = g_utf8_casefold (base, -1); + b = g_utf8_casefold (name, -1); + if (strcmp (a, b) == 0) + result = 2; + else if ((dot = strrchr (a, '.')) != NULL && dot != a && + strncmp (a, b, dot - a) == 0 && b[dot - a] == '\0') + result = 1; + } + + g_free (a); + g_free (b); + g_free (dir); + g_free (base); + return result; +} + +/* Restore of the context menu of @item in the Recycle Bin: the item of + * the verb "undelete"; a shell that names no verbs (Wine) has it first */ +static gboolean +win32_bin_restore (IShellFolder2 *bin, + LPITEMIDLIST item) +{ + IContextMenu *menu = NULL; + HMENU hmenu; + UINT id = 0; + gboolean named = FALSE, result = FALSE; + gint i, n; + + if (FAILED (IShellFolder2_GetUIObjectOf (bin, NULL, 1, (LPCITEMIDLIST *) &item, + >k_IID_IContextMenu, NULL, (void **) &menu))) + return FALSE; + + hmenu = CreatePopupMenu (); + if (hmenu && SUCCEEDED (IContextMenu_QueryContextMenu (menu, hmenu, 0, 1, 0x7fff, CMF_NORMAL))) + { + n = GetMenuItemCount (hmenu); + for (i = 0; i < n && id == 0; i++) + { + UINT item_id = GetMenuItemID (hmenu, i); + WCHAR verb[64]; + + if (item_id == 0 || item_id == (UINT) -1) + continue; + verb[0] = 0; + if (SUCCEEDED (IContextMenu_GetCommandString (menu, item_id - 1, GCS_VERBW, NULL, + (LPSTR) verb, G_N_ELEMENTS (verb))) && + verb[0]) + { + named = TRUE; + if (_wcsicmp (verb, L"undelete") == 0) + id = item_id; + } + } + if (id == 0 && !named && n > 0) + id = GetMenuItemID (hmenu, 0); + + if (id != 0 && id != (UINT) -1) + { + CMINVOKECOMMANDINFO invoke = { 0 }; + + invoke.cbSize = sizeof (invoke); + /* done when it returns (Vista and later; XP does it so) */ + invoke.fMask = CMIC_MASK_FLAG_NO_UI | GTK_CMIC_MASK_NOASYNC; + invoke.lpVerb = MAKEINTRESOURCEA (id - 1); + invoke.nShow = SW_SHOWNORMAL; + result = SUCCEEDED (IContextMenu_InvokeCommand (menu, &invoke)); + } + } + + if (hmenu) + DestroyMenu (hmenu); + IContextMenu_Release (menu); + return result; +} + +/* Puts @file back from the Recycle Bin, as Restore there does: the item + * that came from its place, trashed at @since or later, the last one; + * never over a file that is there now */ +static gboolean +win32_restore_file (GFile *file, + gint64 since, + GError **error) +{ + gchar *path = g_file_get_path (file); + wchar_t *wpath = path ? g_utf8_to_utf16 (path, -1, NULL, NULL, NULL) : NULL; + gchar *extension = NULL; + HRESULT init; + IShellFolder *desktop = NULL; + IShellFolder2 *bin = NULL; + IEnumIDList *items = NULL; + LPITEMIDLIST bin_pidl = NULL, item, best = NULL; + gint best_match = 0, i; + gdouble best_date = 0, since_date; + gboolean done = FALSE, found = FALSE; + + if (wpath == NULL) + { + g_free (path); + g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_INVALID_FILENAME, _("Invalid file name")); + return FALSE; + } + if (GetFileAttributesW (wpath) != INVALID_FILE_ATTRIBUTES) + { + g_free (wpath); + g_free (path); + g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_EXISTS, g_strerror (EEXIST)); + return FALSE; + } + + { + gchar *base = g_path_get_basename (path), *dot = strrchr (base, '.'); + + if (dot && dot != base) + extension = g_utf8_casefold (dot, -1); + g_free (base); + } + /* a little earlier, as the clocks round */ + since_date = since > 0 ? win32_ole_date (since) - 2.0 / 86400 : 0; + + init = CoInitialize (NULL); + if (SUCCEEDED (SHGetDesktopFolder (&desktop)) && + SUCCEEDED (SHGetSpecialFolderLocation (NULL, CSIDL_BITBUCKET, &bin_pidl)) && + SUCCEEDED (IShellFolder_BindToObject (desktop, bin_pidl, NULL, >k_IID_IShellFolder2, (void **) &bin)) && + IShellFolder2_EnumObjects (bin, NULL, SHCONTF_FOLDERS | SHCONTF_NONFOLDERS | SHCONTF_INCLUDEHIDDEN, &items) == S_OK) + { + while (IEnumIDList_Next (items, 1, &item, NULL) == S_OK) + { + gchar *name = win32_bin_detail (bin, item, 0); + gchar *folder = win32_bin_detail (bin, item, 1); + gint match = win32_bin_match (path, folder, name); + VARIANT date; + gdouble when = 0; + + /* without its extension in the name: the one the Recycle Bin + * keeps it under tells, so that photo.jpg is not photo.png */ + if (match == 1) + { + gchar *kept = win32_bin_extension (bin, item); + + if (kept == NULL || extension == NULL || strcmp (kept, extension) != 0) + match = 0; + g_free (kept); + } + + /* without oleaut32: PropVariantClear() of ole32 clears it */ + memset (&date, 0, sizeof (date)); + if (match > 0 && + SUCCEEDED (IShellFolder2_GetDetailsEx (bin, item, >k_SCID_DateDeleted, &date)) && + V_VT (&date) == VT_DATE) + { + when = V_DATE (&date); + /* trashed before: another file of that name, the one + * trashed was deleted for good after all */ + if (since_date > 0 && when < since_date) + match = 0; + } + PropVariantClear ((PROPVARIANT *) &date); + + /* the better name, then the later one (the order of the shell + * where it does not tell the date) */ + if (match > best_match || (match > 0 && match == best_match && when >= best_date)) + { + if (best) + CoTaskMemFree (best); + best = item; + best_match = match; + best_date = when; + } + else + CoTaskMemFree (item); + g_free (name); + g_free (folder); + } + } + + if (best) + { + found = TRUE; + if (win32_bin_restore (bin, best)) + /* the shell may be slow to say so */ + for (i = 0; i < 20 && !done; i++) + { + done = GetFileAttributesW (wpath) != INVALID_FILE_ATTRIBUTES; + if (!done) + Sleep (100); + } + CoTaskMemFree (best); + } + + if (items) + IEnumIDList_Release (items); + if (bin) + IShellFolder2_Release (bin); + if (bin_pidl) + CoTaskMemFree (bin_pidl); + if (desktop) + IShellFolder_Release (desktop); + if (SUCCEEDED (init)) + CoUninitialize (); + g_free (extension); + g_free (wpath); + g_free (path); + + if (!done) + g_set_error_literal (error, G_IO_ERROR, found ? G_IO_ERROR_FAILED : G_IO_ERROR_NOT_FOUND, + found ? _("The shell could not put the file back from the Recycle Bin") + : _("It is no longer in the Trash.")); + return done; +} +#endif + +#if defined (G_OS_WIN32) || defined (GDK_WINDOWING_QUARTZ) +/* The shell of Windows and Cocoa want the main thread: the thread + * hands the file over and waits */ +typedef struct +{ + GtkFileOperation *op; + GFile *file; + GFile *trashed; + GError *error; + gboolean restore; /* Windows: put @file back */ + gint64 since; /* trashed after that */ + gboolean result; + gboolean handled; + gboolean finished; +} TrashCall; + +static gboolean +trash_in_main_loop (gpointer data) +{ + TrashCall *call = data; + +#ifdef G_OS_WIN32 + if (call->restore) + { + call->handled = TRUE; + call->result = win32_restore_file (call->file, call->since, &call->error); + } + else + call->result = win32_trash_file (call->file, &call->handled, &call->error); +#else + call->handled = TRUE; + call->result = _gtk_quartz_trash_file (call->file, &call->trashed, &call->error); +#endif + + g_mutex_lock (&call->op->mutex); + call->finished = TRUE; + g_cond_broadcast (&call->op->cond); + g_mutex_unlock (&call->op->mutex); + return FALSE; +} +#endif + +/* In the thread: @file into the trash. @trashed is where it went, when + * that is known; @restorable whether it can be put back. */ +static gboolean +trash_file (GtkFileOperation *op, + GFile *file, + GFile **trashed, + gboolean *restorable, + GError **error) +{ + *trashed = NULL; + *restorable = FALSE; + +#if defined (G_OS_WIN32) || defined (GDK_WINDOWING_QUARTZ) + { + TrashCall call = { 0 }; + gboolean use_shell = TRUE; + +#ifdef GDK_WINDOWING_QUARTZ + /* GLib before 2.90 puts the files into ~/.local/share/Trash, which + * the Finder does not show; the trash of the Mac it is, then */ + use_shell = glib_check_version (2, 90, 0) != NULL; +#endif + + if (use_shell) + { + call.op = op; + call.file = file; + gdk_threads_add_idle (trash_in_main_loop, &call); + g_mutex_lock (&op->mutex); + while (!call.finished) + g_cond_wait (&op->cond, &op->mutex); + g_mutex_unlock (&op->mutex); + + if (call.handled) + { + if (call.error) + g_propagate_error (error, call.error); + *trashed = call.trashed; +#ifdef G_OS_WIN32 + /* the shell finds it in the Recycle Bin again */ + *restorable = call.result; +#else + *restorable = call.trashed != NULL; +#endif + return call.result; + } + } + } +#endif + + if (!g_file_trash (file, op->cancellable, error)) + return FALSE; + + /* the trash of freedesktop.org says where things came from, the + * Recycle Bin too */ + *restorable = TRUE; + return TRUE; +} + +#ifndef G_OS_WIN32 +/* The freedesktop.org trash folders @path can be in: the one in the + * home folder, and those at the top of its file system */ +static GPtrArray * +trash_folders_for (const gchar *path, + gchar **topdir) +{ + GPtrArray *dirs = g_ptr_array_new_with_free_func (g_free); + gchar *dir, *top, *uid; + struct stat st; + dev_t dev; + + g_ptr_array_add (dirs, g_build_filename (g_get_user_data_dir (), "Trash", NULL)); + + *topdir = NULL; + dir = g_path_get_dirname (path); + if (g_stat (dir, &st) != 0) + { + g_free (dir); + return dirs; + } + dev = st.st_dev; + top = dir; + while (strcmp (top, "/") != 0) + { + gchar *up = g_path_get_dirname (top); + + if (g_stat (up, &st) != 0 || st.st_dev != dev) + { + g_free (up); + break; + } + g_free (top); + top = up; + } + + uid = g_strdup_printf ("%lu", (gulong) getuid ()); + g_ptr_array_add (dirs, g_build_filename (top, ".Trash", uid, NULL)); + g_ptr_array_add (dirs, g_strdup_printf ("%s/.Trash-%s", strcmp (top, "/") == 0 ? "" : top, uid)); + g_free (uid); + *topdir = top; + + return dirs; +} + +/* Puts @path back from the trash folders themselves, as GLib without + * GVfs knows no trash:// */ +static gboolean +restore_local (const gchar *path, + GError **error) +{ + GPtrArray *dirs; + gchar *topdir, *best_info = NULL, *best_file = NULL, *best_date = NULL; + guint i; + gboolean done = FALSE; + + dirs = trash_folders_for (path, &topdir); + + for (i = 0; i < dirs->len; i++) + { + gchar *info_dir = g_build_filename (dirs->pdata[i], "info", NULL); + GDir *dir = g_dir_open (info_dir, 0, NULL); + const gchar *name; + + while (dir && (name = g_dir_read_name (dir))) + { + GKeyFile *key_file; + gchar *info, *escaped, *original, *date; + + if (!g_str_has_suffix (name, ".trashinfo")) + continue; + + info = g_build_filename (info_dir, name, NULL); + key_file = g_key_file_new (); + if (!g_key_file_load_from_file (key_file, info, 0, NULL)) + { + g_key_file_free (key_file); + g_free (info); + continue; + } + + escaped = g_key_file_get_string (key_file, "Trash Info", "Path", NULL); + date = g_key_file_get_string (key_file, "Trash Info", "DeletionDate", NULL); + g_key_file_free (key_file); + original = escaped ? g_uri_unescape_string (escaped, NULL) : NULL; + + /* relative to the top of the file system in its own trash */ + if (original && !g_path_is_absolute (original) && i > 0 && topdir) + { + gchar *full = g_build_filename (topdir, original, NULL); + + g_free (original); + original = full; + } + + /* the newest one of that name: the one just trashed */ + if (original && strcmp (original, path) == 0 && + (best_date == NULL || g_strcmp0 (date, best_date) > 0)) + { + g_free (best_info); + g_free (best_file); + g_free (best_date); + best_info = g_strdup (info); + best_file = g_build_filename (dirs->pdata[i], "files", NULL); + { + gchar *base = g_strndup (name, strlen (name) - strlen (".trashinfo")); + gchar *file = g_build_filename (best_file, base, NULL); + + g_free (base); + g_free (best_file); + best_file = file; + } + best_date = g_strdup (date ? date : ""); + } + + g_free (original); + g_free (escaped); + g_free (date); + g_free (info); + } + + if (dir) + g_dir_close (dir); + g_free (info_dir); + } + + if (best_file && g_file_test (path, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_SYMLINK)) + { + /* rename() would replace it */ + g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_EXISTS, g_strerror (EEXIST)); + } + else if (best_file) + { + if (g_rename (best_file, path) == 0) + { + g_unlink (best_info); + done = TRUE; + } + else + { + int saved_errno = errno; + + g_set_error (error, G_IO_ERROR, g_io_error_from_errno (saved_errno), + "%s", g_strerror (saved_errno)); + } + } + + g_free (best_info); + g_free (best_file); + g_free (best_date); + g_free (topdir); + g_ptr_array_free (dirs, TRUE); + + if (!done && error && *error == NULL) + g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, + _("It is no longer in the Trash.")); + return done; +} + +/* Through trash:// of GVfs, which knows all the trash folders */ +static gboolean +restore_gvfs (GtkFileOperation *op, + GFile *original, + gboolean *found, + GError **error) +{ + const gchar * const *schemes = g_vfs_get_supported_uri_schemes (g_vfs_get_default ()); + gchar *path = g_file_get_path (original); + GFile *trash, *best = NULL; + GFileEnumerator *children; + GFileInfo *info; + gchar *best_date = NULL; + gboolean done = FALSE; + gint i; + + *found = FALSE; + for (i = 0; schemes && schemes[i]; i++) + if (strcmp (schemes[i], "trash") == 0) + break; + if (path == NULL || schemes == NULL || schemes[i] == NULL) + { + g_free (path); + return FALSE; + } + + trash = g_file_new_for_uri ("trash:///"); + children = g_file_enumerate_children (trash, + G_FILE_ATTRIBUTE_STANDARD_NAME "," + G_FILE_ATTRIBUTE_TRASH_ORIG_PATH "," + G_FILE_ATTRIBUTE_TRASH_DELETION_DATE, + G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, + op->cancellable, NULL); + while (children && (info = g_file_enumerator_next_file (children, op->cancellable, NULL))) + { + const gchar *orig = g_file_info_get_attribute_byte_string (info, G_FILE_ATTRIBUTE_TRASH_ORIG_PATH); + const gchar *date = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_TRASH_DELETION_DATE); + + if (orig && strcmp (orig, path) == 0 && + (best == NULL || g_strcmp0 (date, best_date) > 0)) + { + if (best) + g_object_unref (best); + best = g_file_get_child (trash, g_file_info_get_name (info)); + g_free (best_date); + best_date = g_strdup (date ? date : ""); + } + g_object_unref (info); + } + if (children) + g_object_unref (children); + + if (best) + { + *found = TRUE; + /* not over what is there now */ + done = g_file_move (best, original, G_FILE_COPY_NOFOLLOW_SYMLINKS, + op->cancellable, NULL, NULL, error); + g_object_unref (best); + } + + g_free (best_date); + g_object_unref (trash); + g_free (path); + return done; +} +#endif + +/* In the thread: puts @original back from the trash, from @trashed if + * it is known where it went */ +static gboolean +restore_from_trash (GtkFileOperation *op, + GFile *original, + GFile *trashed, + gint64 since, + GError **error) +{ + if (trashed) + return g_file_move (trashed, original, G_FILE_COPY_NOFOLLOW_SYMLINKS, + op->cancellable, NULL, NULL, error); + +#ifndef G_OS_WIN32 + { + gboolean found; + gchar *path; + + /* what GVfs found it says itself, without a second try that might + * overwrite what is there now */ + if (restore_gvfs (op, original, &found, error) || found) + return found && (error == NULL || *error == NULL); + + path = g_file_get_path (original); + if (path) + { + gboolean done = restore_local (path, error); + + g_free (path); + return done; + } + } +#else + { + /* the shell, in the main thread */ + TrashCall call = { 0 }; + + call.op = op; + call.file = original; + call.restore = TRUE; + call.since = since; + gdk_threads_add_idle (trash_in_main_loop, &call); + g_mutex_lock (&op->mutex); + while (!call.finished) + g_cond_wait (&op->cond, &op->mutex); + g_mutex_unlock (&op->mutex); + + if (call.error) + g_propagate_error (error, call.error); + return call.result; + } +#endif + + g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, + _("It is no longer in the Trash.")); + return FALSE; +} + +/* ---------------------------------------------------------------- */ +/* the work, in the thread */ + +static void +set_current (GtkFileOperation *op, + GFile *file) +{ + gchar *name = file_display_name (file); + + g_mutex_lock (&op->mutex); + g_free (op->current_name); + op->current_name = name; + op->current_bytes = 0; + g_mutex_unlock (&op->mutex); +} + +static void +add_done (GtkFileOperation *op, + guint64 bytes, + guint files) +{ + g_mutex_lock (&op->mutex); + op->done_bytes += bytes; + op->done_files += files; + op->current_bytes = 0; + g_mutex_unlock (&op->mutex); +} + +static void +set_totals (GtkFileOperation *op, + guint64 bytes, + guint files) +{ + g_mutex_lock (&op->mutex); + op->total_bytes = bytes; + op->total_files = files; + op->counting = FALSE; + g_mutex_unlock (&op->mutex); +} + +static void +copy_progress (goffset current, + goffset total, + gpointer data) +{ + GtkFileOperation *op = data; + + g_mutex_lock (&op->mutex); + op->current_bytes = current; + g_mutex_unlock (&op->mutex); +} + +/* the size and number of files of @file, folders with what is in them */ +static void +count (GtkFileOperation *op, + GFile *file, + GFileInfo *info, + guint64 *bytes, + guint *files) +{ + if (g_cancellable_is_cancelled (op->cancellable)) + return; + + if (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY) + { + GFileEnumerator *children; + GFileInfo *child_info; + + *files += 1; + children = g_file_enumerate_children (file, + G_FILE_ATTRIBUTE_STANDARD_NAME "," + G_FILE_ATTRIBUTE_STANDARD_TYPE "," + G_FILE_ATTRIBUTE_STANDARD_SIZE, + G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, + op->cancellable, NULL); + if (!children) + return; + + while ((child_info = g_file_enumerator_next_file (children, op->cancellable, NULL))) + { + GFile *child = g_file_get_child (file, g_file_info_get_name (child_info)); + + count (op, child, child_info, bytes, files); + g_object_unref (child); + g_object_unref (child_info); + } + g_object_unref (children); + } + else + { + *files += 1; + if (g_file_info_get_file_type (info) == G_FILE_TYPE_REGULAR) + *bytes += g_file_info_get_size (info); + } +} + +static GFileInfo * +query (GFile *file, + GCancellable *cancellable, + GError **error) +{ + return g_file_query_info (file, + G_FILE_ATTRIBUTE_STANDARD_NAME "," + G_FILE_ATTRIBUTE_STANDARD_TYPE "," + G_FILE_ATTRIBUTE_STANDARD_SIZE, + G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, + cancellable, error); +} + +/* What to do with an error: TRUE to go on (skipped), FALSE to stop */ +static gboolean +handle_error (GtkFileOperation *op, + GFile *file, + GError *error) +{ + Answer value; + + op->all_moved = FALSE; + + if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED) || + g_cancellable_is_cancelled (op->cancellable)) + return FALSE; + + if (op->error_for_all == ANSWER_SKIP) + return TRUE; + + value = ask (op, QUESTION_ERROR, file, error->message, NULL, FALSE, FALSE, NULL); + + return value == ANSWER_SKIP; +} + +/* The folder @file is in, made if it is not there (for Undo) */ +static void +make_parent (GtkFileOperation *op, + GFile *file) +{ + GFile *parent = g_file_get_parent (file); + + if (parent) + { + g_file_make_directory_with_parents (parent, op->cancellable, NULL); + g_object_unref (parent); + } +} + +/* @file and, for a folder, everything in it, for good */ +static gboolean +delete_tree (GtkFileOperation *op, + GFile *file, + GError **error) +{ + GFileInfo *info = query (file, op->cancellable, error); + + if (info == NULL) + return FALSE; + + if (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY) + { + GFileEnumerator *children; + GFileInfo *child_info; + + children = g_file_enumerate_children (file, G_FILE_ATTRIBUTE_STANDARD_NAME, + G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, + op->cancellable, error); + if (children == NULL) + { + g_object_unref (info); + return FALSE; + } + + while ((child_info = g_file_enumerator_next_file (children, op->cancellable, NULL))) + { + GFile *child = g_file_get_child (file, g_file_info_get_name (child_info)); + gboolean done = delete_tree (op, child, error); + + g_object_unref (child); + g_object_unref (child_info); + if (!done) + { + g_object_unref (children); + g_object_unref (info); + return FALSE; + } + } + g_object_unref (children); + } + g_object_unref (info); + + return g_file_delete (file, op->cancellable, error); +} + +static gboolean transfer (GtkFileOperation *op, GFile *source, GFileInfo *info, + GFile *target, gboolean move); + +/* Counts @source as done (all of it, folders with what is in them): + * for what is skipped or failed, or moved at once */ +static void +add_done_tree (GtkFileOperation *op, + GFile *source, + GFileInfo *info) +{ + guint64 bytes = 0; + guint files = 0; + + count (op, source, info, &bytes, &files); + add_done (op, bytes, files); +} + +/* Copies (or moves, by copying) the contents of the folder @source + * into the folder @target. FALSE when the operation is to stop. */ +static gboolean +transfer_children (GtkFileOperation *op, + GFile *source, + GFile *target, + gboolean move) +{ + GFileEnumerator *children; + GFileInfo *child_info; + GError *error = NULL; + gboolean go_on = TRUE; + + children = g_file_enumerate_children (source, + G_FILE_ATTRIBUTE_STANDARD_NAME "," + G_FILE_ATTRIBUTE_STANDARD_TYPE "," + G_FILE_ATTRIBUTE_STANDARD_SIZE, + G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, + op->cancellable, &error); + if (!children) + { + go_on = handle_error (op, source, error); + g_error_free (error); + return go_on; + } + + while (go_on) + { + GFile *child, *child_target; + + child_info = g_file_enumerator_next_file (children, op->cancellable, &error); + if (!child_info) + { + if (error) + { + go_on = handle_error (op, source, error); + g_clear_error (&error); + } + break; + } + + child = g_file_get_child (source, g_file_info_get_name (child_info)); + child_target = g_file_get_child (target, g_file_info_get_name (child_info)); + go_on = transfer (op, child, child_info, child_target, move); + g_object_unref (child_target); + g_object_unref (child); + g_object_unref (child_info); + } + + g_object_unref (children); + return go_on; +} + +/* What to do where @target is there already: ANSWER_REPLACE (merge + * for folders), ANSWER_RENAME with the new target in @renamed, + * ANSWER_SKIP, ANSWER_CANCEL; ANSWER_NONE when nothing is there. + * @can_replace is FALSE for links, which are not put over files. */ +static Answer +resolve_conflict (GtkFileOperation *op, + GFileInfo *info, + GFile *target, + gboolean replace_possible, + GFile **renamed) +{ + GFileInfo *there; + gboolean is_folder, there_folder, both_folders, can_replace; + GFile *parent, *suggestion; + gchar *name = NULL; + Answer value; + + *renamed = NULL; + + there = query (target, op->cancellable, NULL); + if (!there) + return ANSWER_NONE; + + is_folder = g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY; + there_folder = g_file_info_get_file_type (there) == G_FILE_TYPE_DIRECTORY; + g_object_unref (there); + both_folders = replace_possible && is_folder && there_folder; + /* a folder over a file or the other way round: only another name */ + can_replace = replace_possible && (both_folders || (!is_folder && !there_folder)); + + parent = g_file_get_parent (target); + suggestion = free_name_in (parent, g_file_info_get_name (info), FALSE, NULL); + + value = op->conflict_for_all; + if (value == ANSWER_REPLACE && !can_replace) + value = ANSWER_NONE; + if (value == ANSWER_NONE) + value = ask (op, QUESTION_CONFLICT, target, NULL, suggestion, + both_folders, can_replace, &name); + + if (value == ANSWER_RENAME) + { + if (name && *name) + { + gchar *filename = g_filename_from_utf8 (name, -1, NULL, NULL, NULL); + + if (filename) + *renamed = g_file_get_child (parent, filename); + g_free (filename); + } + if (*renamed && g_file_query_exists (*renamed, op->cancellable)) + { + /* the name given is taken as well */ + g_object_unref (*renamed); + *renamed = NULL; + } + if (!*renamed && suggestion) + *renamed = g_object_ref (suggestion); + if (!*renamed) + value = ANSWER_SKIP; + } + + g_free (name); + if (suggestion) + g_object_unref (suggestion); + g_object_unref (parent); + + return value; +} + +/* One file or folder: FALSE when the operation is to stop */ +static gboolean +transfer (GtkFileOperation *op, + GFile *source, + GFileInfo *info, + GFile *target, + gboolean move) +{ + gboolean is_folder = g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY; + GFileCopyFlags flags = G_FILE_COPY_NOFOLLOW_SYMLINKS; + GError *error = NULL; + GFile *renamed = NULL; + gboolean replace = FALSE, go_on = TRUE; + + if (g_cancellable_is_cancelled (op->cancellable)) + return FALSE; + + set_current (op, source); + + switch (resolve_conflict (op, info, target, TRUE, &renamed)) + { + case ANSWER_NONE: + break; + case ANSWER_REPLACE: + replace = TRUE; + break; + case ANSWER_RENAME: + target = renamed; + break; + case ANSWER_SKIP: + op->all_moved = FALSE; + add_done_tree (op, source, info); + return TRUE; + default: + return FALSE; + } + + /* moving: a rename first, instant on the same file system; a folder + * that is merged into another one can not be renamed onto it */ + if (move && !(is_folder && replace)) + { + if (g_file_move (source, target, + flags | G_FILE_COPY_NO_FALLBACK_FOR_MOVE | + (replace ? G_FILE_COPY_OVERWRITE : 0), + op->cancellable, NULL, NULL, &error)) + { + note (op, STEP_MOVED, source, target, NULL); + add_done_tree (op, target, info); + goto out; + } + + if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED) && + !g_error_matches (error, G_IO_ERROR, G_IO_ERROR_WOULD_RECURSE) && + !g_error_matches (error, G_IO_ERROR, G_IO_ERROR_WOULD_MERGE)) + { + go_on = handle_error (op, source, error); + g_clear_error (&error); + add_done_tree (op, source, info); + goto out; + } + g_clear_error (&error); + } + + if (is_folder) + { + gboolean whole, own = !replace && !move; + + if (!replace && !g_file_make_directory (target, op->cancellable, &error)) + { + go_on = handle_error (op, source, error); + g_clear_error (&error); + add_done_tree (op, source, info); + goto out; + } + add_done (op, 0, 1); + + /* a copy into a new folder is undone with the folder; what is + * moved into one goes back file by file, and the folder after */ + if (own) + note (op, STEP_CREATED, source, target, NULL); + else if (!replace) + note (op, STEP_MADE_FOLDER, NULL, target, NULL); + + whole = op->all_moved; + op->all_moved = TRUE; + if (own) + op->own_depth++; + go_on = transfer_children (op, source, target, move); + if (own) + op->own_depth--; + + /* moving: the folder goes once everything in it went */ + if (go_on && move && op->all_moved && + g_file_delete (source, op->cancellable, NULL)) + note (op, STEP_REMOVED_FOLDER, source, NULL, NULL); + op->all_moved = op->all_moved && whole; + goto out; + } + + /* a file or a link */ + if (!g_file_copy (source, target, + flags | (replace ? G_FILE_COPY_OVERWRITE : 0) | + (move ? G_FILE_COPY_ALL_METADATA : 0), + op->cancellable, copy_progress, op, &error)) + { + if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) + { + /* a file being written anew goes again; one that was being + * replaced is written beside it by GIO and stays as it was */ + if (!replace) + g_file_delete (target, NULL, NULL); + go_on = FALSE; + } + else + go_on = handle_error (op, source, error); + + g_clear_error (&error); + add_done_tree (op, source, info); + goto out; + } + + add_done (op, g_file_info_get_file_type (info) == G_FILE_TYPE_REGULAR + ? g_file_info_get_size (info) : 0, 1); + + if (move) + { + if (g_file_delete (source, op->cancellable, &error)) + note (op, STEP_MOVED, source, target, NULL); + else + { + /* it is a copy now */ + if (!replace) + note (op, STEP_CREATED, source, target, NULL); + go_on = handle_error (op, source, error); + g_clear_error (&error); + } + } + else if (!replace) + note (op, STEP_CREATED, source, target, NULL); + + out: + if (renamed) + g_object_unref (renamed); + return go_on; +} + +/* A symbolic link to @source in the destination */ +static gboolean +make_link (GtkFileOperation *op, + GFile *source) +{ + gchar *basename = g_file_get_basename (source); + gchar *path = g_file_get_path (source); + GFile *target = g_file_get_child (op->destination, basename), *renamed = NULL; + GFileInfo *info; + GError *error = NULL; + gboolean go_on = TRUE; + + set_current (op, source); + + info = query (source, op->cancellable, &error); + if (info == NULL || path == NULL) + { + if (error == NULL) + error = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, + _("Links can only be made to local files.")); + go_on = handle_error (op, source, error); + goto out; + } + + switch (resolve_conflict (op, info, target, FALSE, &renamed)) + { + case ANSWER_NONE: + break; + case ANSWER_RENAME: + g_object_unref (target); + target = renamed; + break; + case ANSWER_SKIP: + if (renamed) + g_object_unref (renamed); + goto out; + default: + if (renamed) + g_object_unref (renamed); + go_on = FALSE; + goto out; + } + + if (g_file_make_symbolic_link (target, path, op->cancellable, &error)) + note (op, STEP_CREATED, NULL, target, path); + else + go_on = handle_error (op, source, error); + + out: + add_done (op, 0, 1); + g_clear_error (&error); + if (info) + g_object_unref (info); + g_object_unref (target); + g_free (path); + g_free (basename); + return go_on; +} + +/* Before copying @bytes: whether they fit where they go, as far as the + * file system tells; if not, the user is asked */ +static gboolean +check_space (GtkFileOperation *op, + guint64 bytes) +{ + GFileInfo *info; + guint64 free_space; + gchar *needed, *available, *text; + Answer value; + + if (bytes == 0 || op->sources == NULL) + return TRUE; + + /* moving within one file system needs no space */ + if (op->kind == GTK_FILE_OPERATION_MOVE) + { + GFileInfo *a = g_file_query_info (op->sources->data, G_FILE_ATTRIBUTE_ID_FILESYSTEM, + G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, op->cancellable, NULL); + GFileInfo *b = g_file_query_info (op->destination, G_FILE_ATTRIBUTE_ID_FILESYSTEM, + G_FILE_QUERY_INFO_NONE, op->cancellable, NULL); + gboolean same = a && b && + g_strcmp0 (g_file_info_get_attribute_string (a, G_FILE_ATTRIBUTE_ID_FILESYSTEM), + g_file_info_get_attribute_string (b, G_FILE_ATTRIBUTE_ID_FILESYSTEM)) == 0; + + if (a) + g_object_unref (a); + if (b) + g_object_unref (b); + if (same) + return TRUE; + } + + info = g_file_query_filesystem_info (op->destination, G_FILE_ATTRIBUTE_FILESYSTEM_FREE, + op->cancellable, NULL); + if (info == NULL || !g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_FILESYSTEM_FREE)) + { + if (info) + g_object_unref (info); + return TRUE; + } + free_space = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_FILESYSTEM_FREE); + g_object_unref (info); + if (free_space >= bytes) + return TRUE; + + needed = g_format_size (bytes); + available = g_format_size (free_space); + /* Translators: "4.5 GB are needed, 1.2 GB are free." */ + text = g_strdup_printf (_("%s are needed, %s are free. What fits can be copied anyway."), + needed, available); + value = ask (op, QUESTION_SPACE, op->destination, text, NULL, FALSE, FALSE, NULL); + g_free (text); + g_free (needed); + g_free (available); + + return value == ANSWER_SKIP; +} + +static void +copy_or_move (GtkFileOperation *op) +{ + gboolean move = op->kind == GTK_FILE_OPERATION_MOVE; + GList *l; + guint64 bytes = 0; + guint files = 0; + + /* Moving within one file system is a rename, at once: those are done + * first, without looking into folders; what is left is counted and + * copied. Names that are there already wait for their question. */ + if (move) + { + GList *rest = NULL; + + for (l = op->sources; l; l = l->next) + { + GFile *source = l->data, *parent = g_file_get_parent (source), *target; + gchar *basename = g_file_get_basename (source); + gboolean moved = FALSE; + + if (parent && !g_file_equal (parent, op->destination) && + !g_file_equal (op->destination, source) && + !g_file_has_prefix (op->destination, source)) + { + target = g_file_get_child (op->destination, basename); + moved = g_file_move (source, target, + G_FILE_COPY_NOFOLLOW_SYMLINKS | G_FILE_COPY_NO_FALLBACK_FOR_MOVE, + op->cancellable, NULL, NULL, NULL); + if (moved) + note (op, STEP_MOVED, source, target, NULL); + g_object_unref (target); + } + + if (moved) + g_object_unref (source); + else + rest = g_list_prepend (rest, source); + + g_free (basename); + if (parent) + g_object_unref (parent); + } + + g_list_free (op->sources); + op->sources = g_list_reverse (rest); + } + + /* what there is to do, for the progress */ + for (l = op->sources; l; l = l->next) + { + GFileInfo *info = query (l->data, op->cancellable, NULL); + + if (info) + { + count (op, l->data, info, &bytes, &files); + g_object_unref (info); + } + } + set_totals (op, bytes, files); + + if (!check_space (op, bytes)) + { + g_cancellable_cancel (op->cancellable); + return; + } + + for (l = op->sources; l; l = l->next) + { + GFile *source = l->data, *target, *parent; + GFileInfo *info; + GError *error = NULL; + gchar *basename; + + if (g_cancellable_is_cancelled (op->cancellable)) + break; + + info = query (source, op->cancellable, &error); + if (!info) + { + if (!handle_error (op, source, error)) + { + g_error_free (error); + break; + } + g_error_free (error); + continue; + } + + parent = g_file_get_parent (source); + basename = g_file_get_basename (source); + + /* into itself or one of its own folders: not possible */ + if (g_file_equal (op->destination, source) || + g_file_has_prefix (op->destination, source)) + { + GError *loop = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_WOULD_RECURSE, + _("A folder can not be copied or moved into itself.")); + gboolean go_on = handle_error (op, source, loop); + + g_error_free (loop); + g_free (basename); + if (parent) + g_object_unref (parent); + g_object_unref (info); + if (!go_on) + break; + continue; + } + + if (parent && g_file_equal (parent, op->destination)) + { + /* into the folder it is in: a copy gets a name of its own, + * a move has nothing to do */ + if (move) + { + guint64 b = 0; + guint f = 0; + + count (op, source, info, &b, &f); + add_done (op, b, f); + g_free (basename); + g_object_unref (parent); + g_object_unref (info); + continue; + } + target = free_name_in (op->destination, basename, TRUE, NULL); + } + else + target = g_file_get_child (op->destination, basename); + + if (target) + { + gboolean go_on = transfer (op, source, info, target, move); + + g_object_unref (target); + if (!go_on) + { + g_free (basename); + if (parent) + g_object_unref (parent); + g_object_unref (info); + break; + } + } + + g_free (basename); + if (parent) + g_object_unref (parent); + g_object_unref (info); + } +} + +static void +link_all (GtkFileOperation *op) +{ + GList *l; + + set_totals (op, 0, g_list_length (op->sources)); + for (l = op->sources; l; l = l->next) + if (g_cancellable_is_cancelled (op->cancellable) || !make_link (op, l->data)) + break; +} + +static void +trash_all (GtkFileOperation *op) +{ + GList *l; + + set_totals (op, 0, g_list_length (op->sources)); + op->restorable = TRUE; + for (l = op->sources; l; l = l->next) + { + GFile *trashed; + GError *error = NULL; + gboolean restorable; + gint64 before; + + if (g_cancellable_is_cancelled (op->cancellable)) + break; + + set_current (op, l->data); + before = g_get_real_time (); + if (trash_file (op, l->data, &trashed, &restorable, &error)) + { + note (op, STEP_TRASHED, l->data, trashed, NULL); + if (op->steps) + ((Step *) op->steps->data)->time = before; + op->restorable = op->restorable && restorable; + } + else + { + gboolean go_on = handle_error (op, l->data, error); + + g_error_free (error); + if (!go_on) + { + if (trashed) + g_object_unref (trashed); + break; + } + } + if (trashed) + g_object_unref (trashed); + add_done (op, 0, 1); + } +} + +/* Undo of one step: its opposite */ +static gboolean +undo_step (GtkFileOperation *op, + Step *step, + GError **error) +{ + GFileInfo *info; + GFile *trashed = NULL; + gboolean restorable, done; + + switch (step->kind) + { + case STEP_CREATED: + /* a copy into the trash, as it may have been changed since; for + * good where there is no trash */ + set_current (op, step->target); + if (trash_file (op, step->target, &trashed, &restorable, error)) + done = TRUE; + else if (*error && g_error_matches (*error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED)) + { + g_clear_error (error); + done = delete_tree (op, step->target, error); + } + else + done = FALSE; + if (trashed) + g_object_unref (trashed); + return done; + + case STEP_MADE_FOLDER: + set_current (op, step->target); + /* only when nothing else went into it meanwhile */ + g_file_delete (step->target, op->cancellable, NULL); + return TRUE; + + case STEP_MOVED: + set_current (op, step->target); + info = query (step->target, op->cancellable, error); + if (info == NULL) + return FALSE; + make_parent (op, step->source); + /* errors are asked for there */ + if (!transfer (op, step->target, info, step->source, TRUE)) + g_cancellable_cancel (op->cancellable); + g_object_unref (info); + return TRUE; + + case STEP_REMOVED_FOLDER: + set_current (op, step->source); + make_parent (op, step->source); + if (!g_file_make_directory (step->source, op->cancellable, error)) + { + if (!g_error_matches (*error, G_IO_ERROR, G_IO_ERROR_EXISTS)) + return FALSE; + g_clear_error (error); + } + return TRUE; + + case STEP_TRASHED: + set_current (op, step->source); + make_parent (op, step->source); + return restore_from_trash (op, step->source, step->target, step->time, error); + + default: + g_assert_not_reached (); + return FALSE; + } +} + +/* Redo of one step: the same again */ +static gboolean +redo_step (GtkFileOperation *op, + Step *step, + GError **error) +{ + GFileInfo *info; + GFile *trashed = NULL; + gboolean restorable; + gint64 before; + + switch (step->kind) + { + case STEP_CREATED: + set_current (op, step->target); + make_parent (op, step->target); + if (step->link) + return g_file_make_symbolic_link (step->target, step->link, op->cancellable, error); + info = query (step->source, op->cancellable, error); + if (info == NULL) + return FALSE; + if (!transfer (op, step->source, info, step->target, FALSE)) + g_cancellable_cancel (op->cancellable); + g_object_unref (info); + return TRUE; + + case STEP_MADE_FOLDER: + set_current (op, step->target); + make_parent (op, step->target); + if (!g_file_make_directory (step->target, op->cancellable, error)) + { + if (!g_error_matches (*error, G_IO_ERROR, G_IO_ERROR_EXISTS)) + return FALSE; + g_clear_error (error); + } + return TRUE; + + case STEP_MOVED: + set_current (op, step->source); + info = query (step->source, op->cancellable, error); + if (info == NULL) + return FALSE; + make_parent (op, step->target); + if (!transfer (op, step->source, info, step->target, TRUE)) + g_cancellable_cancel (op->cancellable); + g_object_unref (info); + return TRUE; + + case STEP_REMOVED_FOLDER: + set_current (op, step->source); + g_file_delete (step->source, op->cancellable, NULL); + return TRUE; + + case STEP_TRASHED: + set_current (op, step->source); + before = g_get_real_time (); + if (!trash_file (op, step->source, &trashed, &restorable, error)) + { + if (trashed) + g_object_unref (trashed); + return FALSE; + } + if (step->target) + g_object_unref (step->target); + step->target = trashed; + step->time = before; + /* where it went must be known again for another Undo */ + op->restorable = op->restorable && restorable; + return TRUE; + + default: + g_assert_not_reached (); + return FALSE; + } +} + +static void +replay (GtkFileOperation *op) +{ + gboolean undo = op->kind == GTK_FILE_OPERATION_UNDO; + GList *steps, *l; + + steps = g_list_copy (op->replay->steps); + if (undo) + steps = g_list_reverse (steps); + + set_totals (op, 0, g_list_length (steps)); + op->restorable = TRUE; + for (l = steps; l; l = l->next) + { + Step *step = l->data; + GError *error = NULL; + gboolean done; + + if (g_cancellable_is_cancelled (op->cancellable)) + break; + + done = undo ? undo_step (op, step, &error) : redo_step (op, step, &error); + if (!done) + { + gboolean go_on; + + if (error == NULL) + error = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_FAILED, ""); + go_on = handle_error (op, step->kind == STEP_CREATED || step->kind == STEP_MADE_FOLDER + ? step->target : step->source, + error); + g_error_free (error); + if (!go_on) + break; + } + /* gone through, also when skipped or cancelled in it */ + op->replayed++; + add_done (op, 0, 1); + } + + g_list_free (steps); +} + +static gboolean finish_in_main_loop (gpointer data); + +static gpointer +operation_thread (gpointer data) +{ + GtkFileOperation *op = data; + + switch (op->kind) + { + case GTK_FILE_OPERATION_COPY: + case GTK_FILE_OPERATION_MOVE: + copy_or_move (op); + break; + case GTK_FILE_OPERATION_LINK: + link_all (op); + break; + case GTK_FILE_OPERATION_TRASH: + trash_all (op); + break; + default: + replay (op); + break; + } + + gdk_threads_add_idle (finish_in_main_loop, op); + return NULL; +} + +/* ---------------------------------------------------------------- */ +/* start and end */ + +static void +operation_free (GtkFileOperation *op) +{ + g_list_foreach (op->sources, (GFunc) g_object_unref, NULL); + g_list_free (op->sources); + if (op->destination) + g_object_unref (op->destination); + g_object_unref (op->cancellable); + g_mutex_clear (&op->mutex); + g_cond_clear (&op->cond); + g_free (op->current_name); + g_free (op->question_name); + g_free (op->question_folder); + g_free (op->question_text); + g_free (op->suggested_name); + g_free (op->answer_name); + g_list_free_full (op->steps, (GDestroyNotify) step_free); + g_slice_free (GtkFileOperation, op); +} + +/* What was done goes on the stack of Undo; what was undone on the one + * of Redo, and back */ +static void +keep_for_undo (GtkFileOperation *op) +{ + UndoEntry *entry; + + switch (op->kind) + { + case GTK_FILE_OPERATION_UNDO: + case GTK_FILE_OPERATION_REDO: + { + gboolean undo = op->kind == GTK_FILE_OPERATION_UNDO; + GList **own = undo ? &undo_stack : &redo_stack; + GList **other = undo ? &redo_stack : &undo_stack; + UndoEntry *rest = op->replay, *done; + guint n = g_list_length (rest->steps); + GList *cut; + + op->replay = NULL; + if (op->replayed == 0) + { + /* nothing done: as it was */ + undo_push (own, rest); + return; + } + if (op->replayed >= n) + { + done = rest; + rest = NULL; + } + else + { + /* stopped halfway: what was gone through can be done the + * other way, the rest stays (Undo goes from the last step + * backwards, Redo from the first) */ + done = undo_entry_new (rest->kind); + cut = g_list_nth (rest->steps, undo ? n - op->replayed : op->replayed); + cut->prev->next = NULL; + cut->prev = NULL; + if (undo) + done->steps = cut; + else + { + done->steps = rest->steps; + rest->steps = cut; + } + } + /* a Redo of the trash must know where things went again */ + done->possible = undo ? TRUE : op->restorable; + if (rest) + undo_push (own, rest); + undo_push (other, done); + return; + } + default: + break; + } + + if (op->steps == NULL) + return; + + entry = undo_entry_new (op->kind == GTK_FILE_OPERATION_COPY ? UNDO_COPY + : op->kind == GTK_FILE_OPERATION_MOVE ? UNDO_MOVE + : op->kind == GTK_FILE_OPERATION_LINK ? UNDO_LINK + : UNDO_TRASH); + entry->steps = g_list_reverse (op->steps); + op->steps = NULL; + if (op->kind == GTK_FILE_OPERATION_TRASH) + entry->possible = op->restorable; + undo_add (entry); +} + +static gboolean +finish_in_main_loop (gpointer data) +{ + GtkFileOperation *op = data; + gboolean cancelled = g_cancellable_is_cancelled (op->cancellable); + + if (op->update_id) + g_source_remove (op->update_id); + if (op->show_id) + g_source_remove (op->show_id); + if (op->parent) + g_object_remove_weak_pointer (G_OBJECT (op->parent), (gpointer *) &op->parent); + + if (op->row) + { + g_signal_handlers_disconnect_by_func (op->row, row_destroyed, op); + gtk_widget_destroy (op->row); + op->row = NULL; + } + + /* a cancelled copy can be undone as well: what was copied goes */ + keep_for_undo (op); + operations_running--; + + if (op->done) + op->done (op, cancelled, op->all_moved && !cancelled, op->user_data); + + operation_free (op); + return FALSE; +} + +static GtkFileOperation * +operation_start (GtkFileOperationKind kind, + GList *sources, + GFile *destination, + UndoEntry *replay_entry, + GtkWidget *box, + GtkWindow *parent, + GtkFileOperationDoneFunc done, + gpointer user_data) +{ + GtkFileOperation *op; + GThread *thread; + GList *l; + + op = g_slice_new0 (GtkFileOperation); + op->kind = kind; + for (l = sources; l; l = l->next) + op->sources = g_list_prepend (op->sources, g_object_ref (l->data)); + op->sources = g_list_reverse (op->sources); + op->destination = destination ? g_object_ref (destination) : NULL; + op->replay = replay_entry; + op->cancellable = g_cancellable_new (); + op->box = box; + op->parent = parent; + if (parent) + g_object_add_weak_pointer (G_OBJECT (parent), (gpointer *) &op->parent); + op->done = done; + op->user_data = user_data; + op->counting = TRUE; + op->all_moved = TRUE; + op->conflict_for_all = ANSWER_NONE; + op->error_for_all = ANSWER_NONE; + g_mutex_init (&op->mutex); + g_cond_init (&op->cond); + + make_row (op); + op->show_id = gdk_threads_add_timeout (500, show_timeout, op); + op->update_id = gdk_threads_add_timeout (100, update_timeout, op); + + operations_running++; + thread = g_thread_new ("gtk-file-operation", operation_thread, op); + g_thread_unref (thread); + + return op; +} + +GtkFileOperation * +_gtk_file_operation_start (GtkFileOperationKind kind, + GList *sources, + GFile *destination, + GtkWidget *box, + GtkWindow *parent, + GtkFileOperationDoneFunc done, + gpointer user_data) +{ + g_return_val_if_fail (sources != NULL, NULL); + g_return_val_if_fail (kind == GTK_FILE_OPERATION_COPY || kind == GTK_FILE_OPERATION_MOVE || + kind == GTK_FILE_OPERATION_LINK || kind == GTK_FILE_OPERATION_TRASH, NULL); + g_return_val_if_fail (kind == GTK_FILE_OPERATION_TRASH || G_IS_FILE (destination), NULL); + g_return_val_if_fail (GTK_IS_BOX (box), NULL); + + return operation_start (kind, sources, + kind == GTK_FILE_OPERATION_TRASH ? NULL : destination, + NULL, box, parent, done, user_data); +} + +GtkFileOperation * +_gtk_file_operation_undo (gboolean redo, + GtkWidget *box, + GtkWindow *parent, + GtkFileOperationDoneFunc done, + gpointer user_data) +{ + GList **stack = redo ? &redo_stack : &undo_stack; + UndoEntry *entry; + + g_return_val_if_fail (GTK_IS_BOX (box), NULL); + + /* one at a time, after what is being done */ + if (*stack == NULL || !((UndoEntry *) (*stack)->data)->possible || operations_running > 0) + return NULL; + + entry = (*stack)->data; + *stack = g_list_delete_link (*stack, *stack); + + return operation_start (redo ? GTK_FILE_OPERATION_REDO : GTK_FILE_OPERATION_UNDO, + NULL, NULL, entry, box, parent, done, user_data); +} + +void +_gtk_file_operation_cancel (GtkFileOperation *operation) +{ + g_cancellable_cancel (operation->cancellable); +} diff --git a/gtk/gtkfileoperation.h b/gtk/gtkfileoperation.h new file mode 100644 index 000000000..c41a4acad --- /dev/null +++ b/gtk/gtkfileoperation.h @@ -0,0 +1,106 @@ +/* GTK - The GIMP Toolkit + * gtkfileoperation.h: copying, moving, linking and trashing files for + * the file chooser, and undoing it + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +/* Not installed: for the file chooser of libgtk only */ + +#ifndef __GTK_FILE_OPERATION_H__ +#define __GTK_FILE_OPERATION_H__ + +#include +#include "gtkwidget.h" +#include "gtkwindow.h" + +G_BEGIN_DECLS + +typedef enum +{ + GTK_FILE_OPERATION_COPY, + GTK_FILE_OPERATION_MOVE, + GTK_FILE_OPERATION_LINK, /* symbolic links to the sources */ + GTK_FILE_OPERATION_TRASH, /* the sources into the trash; no destination */ + GTK_FILE_OPERATION_UNDO, /* only through _gtk_file_operation_undo() */ + GTK_FILE_OPERATION_REDO +} GtkFileOperationKind; + +typedef struct _GtkFileOperation GtkFileOperation; + +/* Called in the main loop when the operation is over: @moved tells + * whether all sources of a move went (none was skipped or failed) */ +typedef void (*GtkFileOperationDoneFunc) (GtkFileOperation *operation, + gboolean cancelled, + gboolean moved, + gpointer user_data); + +/* Copies, moves or links @sources (a list of GFile) into the folder + * @destination, or moves them to the trash, in a thread of its own. + * Its progress and a Cancel button are shown in a row that is packed + * into @box half a second after the start, if it runs that long; + * questions (a file of the same name, an error) are asked in dialogs + * transient for @parent. What was done can be undone afterwards. The + * operation frees itself after @done. */ +GtkFileOperation *_gtk_file_operation_start (GtkFileOperationKind kind, + GList *sources, + GFile *destination, + GtkWidget *box, + GtkWindow *parent, + GtkFileOperationDoneFunc done, + gpointer user_data); + +void _gtk_file_operation_cancel (GtkFileOperation *operation); + +/* Undo and Redo, for all file choosers of the program, as the files are + * the same: the last copy, move, link, trash, rename or new folder is + * undone (or what was undone is done again) like an operation above. + * NULL when there is nothing to undo. */ +GtkFileOperation *_gtk_file_operation_undo (gboolean redo, + GtkWidget *box, + GtkWindow *parent, + GtkFileOperationDoneFunc done, + gpointer user_data); + +/* The label for a menu item, as "_Undo Copy"; @possible tells whether + * there is something that can be undone */ +const gchar * _gtk_file_operation_undo_label (gboolean redo, + gboolean *possible); + +/* What Undo (or Redo) would take away of @folder, which is shown: the + * file of a step that removes or moves it or a folder above it, or NULL; + * a folder that is shown cannot go away on Windows */ +GFile * _gtk_file_operation_undo_removes (gboolean redo, + GFile *folder); + +/* @basename in @folder, or "name (2).ext" and so on when it is taken */ +GFile * _gtk_file_operation_free_name (GFile *folder, + const gchar *basename); + +/* What the file chooser does itself, for Undo */ +void _gtk_file_operation_add_rename (GFile *from, + GFile *to); +void _gtk_file_operation_add_new_folder (GFile *folder); + +/* The clipboard of file managers: x-special/gnome-copied-files ("copy" + * or "cut" and URIs, as Nautilus, Caja, Thunar and PCManFM use it) and + * text/uri-list with application/x-kde-cutselection (Dolphin) */ +#define GTK_FILE_CLIPBOARD_GNOME "x-special/gnome-copied-files" +#define GTK_FILE_CLIPBOARD_KDE_CUT "application/x-kde-cutselection" + +G_END_DECLS + +#endif /* __GTK_FILE_OPERATION_H__ */ diff --git a/gtk/gtkfilesel.c b/gtk/gtkfilesel.c index e76d91429..c925b9d62 100644 --- a/gtk/gtkfilesel.c +++ b/gtk/gtkfilesel.c @@ -86,6 +86,7 @@ #define WANT_HPANED 1 #include "gtkhpaned.h" +#include "gtktimeprivate.h" #include "gtkalias.h" @@ -156,9 +157,9 @@ typedef struct _PossibleCompletion PossibleCompletion; struct _CompletionDirSent { #ifndef G_PLATFORM_WIN32 - ino_t inode; + guint64 inode; gint64 mtime; - dev_t device; + guint64 device; #endif gint entry_count; @@ -329,7 +330,7 @@ static CompletionDir* open_ref_dir (gchar* text_to_complete, CompletionState* cmpl_state); #ifndef G_PLATFORM_WIN32 static gboolean check_dir (gchar *dir_name, - GStatBuf *result, + GtkStatBuf *result, gboolean *stat_subdirs); #endif static CompletionDir* open_dir (gchar* dir_name, @@ -341,11 +342,11 @@ static CompletionDir* open_user_dir (const gchar* text_to_complete, static CompletionDir* open_relative_dir (gchar* dir_name, CompletionDir* dir, CompletionState *cmpl_state); static CompletionDirSent* open_new_dir (gchar* dir_name, - GStatBuf *sbuf, + GtkStatBuf *sbuf, gboolean stat_subdirs); static gint correct_dir_fullname (CompletionDir* cmpl_dir); static gint correct_parent (CompletionDir* cmpl_dir, - GStatBuf *sbuf); + GtkStatBuf *sbuf); #ifndef G_PLATFORM_WIN32 static gchar* find_parent_dir_fullname (gchar* dirname); #endif @@ -2989,7 +2990,7 @@ open_relative_dir (gchar *dir_name, /* after the cache lookup fails, really open a new directory */ static CompletionDirSent* open_new_dir (gchar *dir_name, - GStatBuf *sbuf, + GtkStatBuf *sbuf, gboolean stat_subdirs) { CompletionDirSent *sent; @@ -2999,15 +3000,15 @@ open_new_dir (gchar *dir_name, gint entry_count = 0; gint n_entries = 0; gint i; - GStatBuf ent_sbuf; + GtkStatBuf ent_sbuf; GString *path; gchar *sys_dir_name; sent = g_new (CompletionDirSent, 1); #ifndef G_PLATFORM_WIN32 - sent->mtime = (gint64) sbuf->st_mtime; - sent->inode = sbuf->st_ino; - sent->device = sbuf->st_dev; + sent->mtime = sbuf->mtime; + sent->inode = sbuf->ino; + sent->device = sbuf->dev; #endif path = g_string_sized_new (2*MAXPATHLEN + 10); @@ -3079,7 +3080,7 @@ open_new_dir (gchar *dir_name, if (stat_subdirs) { /* Here we know path->str is a "system charset" string */ - if (g_stat (path->str, &ent_sbuf) >= 0 && S_ISDIR (ent_sbuf.st_mode)) + if (_gtk_stat (path->str, TRUE, &ent_sbuf) >= 0 && S_ISDIR (ent_sbuf.mode)) sent->entries[n_entries].is_dir = TRUE; else /* stat may fail, and we don't mind, since it could be a @@ -3106,7 +3107,7 @@ open_new_dir (gchar *dir_name, static gboolean check_dir (gchar *dir_name, - GStatBuf *result, + GtkStatBuf *result, gboolean *stat_subdirs) { /* A list of directories that we know only contain other directories. @@ -3117,7 +3118,7 @@ check_dir (gchar *dir_name, static struct { const gchar name[5]; gboolean present; - GStatBuf statbuf; + GtkStatBuf statbuf; } no_stat_dirs[] = { { "/afs", FALSE, { 0 } }, { "/net", FALSE, { 0 } } @@ -3133,7 +3134,7 @@ check_dir (gchar *dir_name, initialized = TRUE; for (i = 0; i < n_no_stat_dirs; i++) { - if (g_stat (no_stat_dirs[i].name, &no_stat_dirs[i].statbuf) == 0) + if (_gtk_stat (no_stat_dirs[i].name, TRUE, &no_stat_dirs[i].statbuf) == 0) no_stat_dirs[i].present = TRUE; } } @@ -3145,7 +3146,7 @@ check_dir (gchar *dir_name, return FALSE; } - if (g_stat (sys_dir_name, result) < 0) + if (_gtk_stat (sys_dir_name, TRUE, result) < 0) { g_free (sys_dir_name); cmpl_errno = errno; @@ -3157,8 +3158,8 @@ check_dir (gchar *dir_name, for (i = 0; i < n_no_stat_dirs; i++) { if (no_stat_dirs[i].present && - (no_stat_dirs[i].statbuf.st_dev == result->st_dev) && - (no_stat_dirs[i].statbuf.st_ino == result->st_ino)) + (no_stat_dirs[i].statbuf.dev == result->dev) && + (no_stat_dirs[i].statbuf.ino == result->ino)) { *stat_subdirs = FALSE; break; @@ -3176,7 +3177,7 @@ open_dir (gchar *dir_name, CompletionState *cmpl_state) { #ifndef G_PLATFORM_WIN32 - GStatBuf sbuf; + GtkStatBuf sbuf; gboolean stat_subdirs; GList* cdsl; #endif @@ -3192,9 +3193,9 @@ open_dir (gchar *dir_name, { sent = cdsl->data; - if (sent->inode == sbuf.st_ino && - sent->mtime == (gint64) sbuf.st_mtime && - sent->device == sbuf.st_dev) + if (sent->inode == sbuf.ino && + sent->mtime == sbuf.mtime && + sent->device == sbuf.dev) return attach_dir (sent, dir_name, cmpl_state); cdsl = cdsl->next; @@ -3242,7 +3243,7 @@ correct_dir_fullname (CompletionDir* cmpl_dir) gint length = strlen (cmpl_dir->fullname); gchar *first_slash = strchr (cmpl_dir->fullname, G_DIR_SEPARATOR); gchar *sys_filename; - GStatBuf sbuf; + GtkStatBuf sbuf; /* Does it end with /. (\.) ? */ if (length >= 2 && @@ -3287,7 +3288,7 @@ correct_dir_fullname (CompletionDir* cmpl_dir) return FALSE; } - if (g_stat (sys_filename, &sbuf) < 0) + if (_gtk_stat (sys_filename, TRUE, &sbuf) < 0) { g_free (sys_filename); cmpl_errno = errno; @@ -3321,7 +3322,7 @@ correct_dir_fullname (CompletionDir* cmpl_dir) return FALSE; } - if (g_stat (sys_filename, &sbuf) < 0) + if (_gtk_stat (sys_filename, TRUE, &sbuf) < 0) { g_free (sys_filename); cmpl_errno = errno; @@ -3342,9 +3343,9 @@ correct_dir_fullname (CompletionDir* cmpl_dir) static gint correct_parent (CompletionDir *cmpl_dir, - GStatBuf *sbuf) + GtkStatBuf *sbuf) { - GStatBuf parbuf; + GtkStatBuf parbuf; gchar *last_slash; gchar *first_slash; #ifndef G_PLATFORM_WIN32 @@ -3379,7 +3380,7 @@ correct_parent (CompletionDir *cmpl_dir, return FALSE; } - if (g_stat (sys_filename, &parbuf) < 0) + if (_gtk_stat (sys_filename, TRUE, &parbuf) < 0) { g_free (sys_filename); cmpl_errno = errno; @@ -3390,7 +3391,7 @@ correct_parent (CompletionDir *cmpl_dir, g_free (sys_filename); #ifndef G_PLATFORM_WIN32 /* No inode numbers on Win32 */ - if (parbuf.st_ino == sbuf->st_ino && parbuf.st_dev == sbuf->st_dev) + if (parbuf.ino == sbuf->ino && parbuf.dev == sbuf->dev) /* it wasn't a link */ return TRUE; diff --git a/gtk/gtkfilesel.h b/gtk/gtkfilesel.h index 1e5c98e67..03bc35406 100644 --- a/gtk/gtkfilesel.h +++ b/gtk/gtkfilesel.h @@ -99,7 +99,7 @@ struct _GtkFileSelectionClass #define gtk_file_selection_get_selections gtk_file_selection_get_selections_utf8 #endif -GType gtk_file_selection_get_type (void) G_GNUC_CONST; +GType gtk_file_selection_get_type (void); GtkWidget* gtk_file_selection_new (const gchar *title); void gtk_file_selection_set_filename (GtkFileSelection *filesel, const gchar *filename); diff --git a/gtk/gtkfilesystem.c b/gtk/gtkfilesystem.c index 9834033ed..9fcbbbf8e 100644 --- a/gtk/gtkfilesystem.c +++ b/gtk/gtkfilesystem.c @@ -1853,6 +1853,17 @@ get_pixbuf_from_gicon (GIcon *icon, return pixbuf; } +/* The GDrive, GVolume or GMount of @volume, for unmounting and ejecting; + * NULL for the file system itself */ +GObject * +_gtk_file_system_volume_get_object (GtkFileSystemVolume *volume) +{ + if (volume == NULL || IS_ROOT_VOLUME (volume)) + return NULL; + + return G_OBJECT (volume); +} + GdkPixbuf * _gtk_file_system_volume_render_icon (GtkFileSystemVolume *volume, GtkWidget *widget, @@ -1922,10 +1933,38 @@ _gtk_file_info_render_icon (GFileInfo *info, thumbnail_path = g_file_info_get_attribute_byte_string (info, G_FILE_ATTRIBUTE_THUMBNAIL_PATH); + /* A thumbnail is shown from the next larger size there is (normal or + * large, see the file chooser) made smaller with the quick bilinear + * filter, as a page of them is decoded at once; one smaller than + * @icon_size, of a small picture, is shown as it is, not enlarged */ if (thumbnail_path) - pixbuf = gdk_pixbuf_new_from_file_at_size (thumbnail_path, - icon_size, icon_size, - NULL); + { + pixbuf = gdk_pixbuf_new_from_file (thumbnail_path, NULL); + if (pixbuf) + { + gint width = gdk_pixbuf_get_width (pixbuf); + gint height = gdk_pixbuf_get_height (pixbuf); + + if (width > icon_size || height > icon_size) + { + GdkPixbuf *scaled; + + if (width > height) + { + height = MAX (1, (gint) ((gint64) height * icon_size / width)); + width = icon_size; + } + else + { + width = MAX (1, (gint) ((gint64) width * icon_size / height)); + height = icon_size; + } + scaled = gdk_pixbuf_scale_simple (pixbuf, width, height, GDK_INTERP_BILINEAR); + g_object_unref (pixbuf); + pixbuf = scaled; + } + } + } if (!pixbuf) { diff --git a/gtk/gtkfilesystem.h b/gtk/gtkfilesystem.h index 75f1c97e8..1b89bdb55 100644 --- a/gtk/gtkfilesystem.h +++ b/gtk/gtkfilesystem.h @@ -93,7 +93,7 @@ typedef void (* GtkFileSystemVolumeMountCallback) (GCancellable *cancell gpointer data); /* GtkFileSystem methods */ -GType _gtk_file_system_get_type (void) G_GNUC_CONST; +GType _gtk_file_system_get_type (void); GtkFileSystem * _gtk_file_system_new (void); @@ -147,6 +147,7 @@ gboolean _gtk_folder_is_finished_loading (GtkFolder *folder); gchar * _gtk_file_system_volume_get_display_name (GtkFileSystemVolume *volume); gboolean _gtk_file_system_volume_is_mounted (GtkFileSystemVolume *volume); GFile * _gtk_file_system_volume_get_root (GtkFileSystemVolume *volume); +GObject * _gtk_file_system_volume_get_object (GtkFileSystemVolume *volume); GdkPixbuf * _gtk_file_system_volume_render_icon (GtkFileSystemVolume *volume, GtkWidget *widget, gint icon_size, diff --git a/gtk/gtkfilesystemmodel.c b/gtk/gtkfilesystemmodel.c index 426650ff0..d01cf7e0e 100644 --- a/gtk/gtkfilesystemmodel.c +++ b/gtk/gtkfilesystemmodel.c @@ -2152,6 +2152,74 @@ gtk_file_system_model_dispose (GObject *object) } +/* The model of a large folder takes a while to free: a GFile and a + * GFileInfo for every file. When a file dialog closes, that was a pause + * just as the program goes on (90 ms for 20 000 files here); the nodes of + * such a model are freed in slices when the program is idle instead. */ +#define FREE_AT_ONCE_MAX 2000 +#define FREE_SLICE 1000 + +typedef struct +{ + GArray *files; + guint pos; +} NodeGrave; + +static GQueue node_graves = G_QUEUE_INIT; +static guint node_graves_id; + +static gboolean +node_graves_work (gpointer data) +{ + NodeGrave *grave = g_queue_peek_head (&node_graves); + guint end; + + if (!grave) + { + node_graves_id = 0; + return FALSE; + } + + end = MIN (grave->pos + FREE_SLICE, grave->files->len); + for (; grave->pos < end; grave->pos++) + file_model_node_clear (&g_array_index (grave->files, FileModelNode, grave->pos)); + + if (grave->pos >= grave->files->len) + { + g_queue_pop_head (&node_graves); + g_array_free (grave->files, TRUE); + g_slice_free (NodeGrave, grave); + } + + if (g_queue_is_empty (&node_graves)) + { + node_graves_id = 0; + return FALSE; + } + return TRUE; +} + +static void +free_nodes (GArray *files) +{ + NodeGrave *grave; + + if (files->len <= FREE_AT_ONCE_MAX) + { + g_array_free (files, TRUE); + return; + } + + /* cleared here slice by slice, not by the array */ + g_array_set_clear_func (files, NULL); + grave = g_slice_new (NodeGrave); + grave->files = files; + grave->pos = 0; + g_queue_push_tail (&node_graves, grave); + if (!node_graves_id) + node_graves_id = g_idle_add_full (G_PRIORITY_LOW, node_graves_work, NULL, NULL); +} + static void gtk_file_system_model_finalize (GObject *object) { @@ -2163,7 +2231,7 @@ gtk_file_system_model_finalize (GObject *object) g_ptr_array_free (model->value_pages[i], TRUE); g_free (model->value_pages); - g_array_free (model->files, TRUE); + free_nodes (model->files); g_array_free (model->order, TRUE); g_array_free (model->visible_order, TRUE); g_clear_pointer (&model->sort_buf, g_array_unref); diff --git a/gtk/gtkfilesystemmodel.h b/gtk/gtkfilesystemmodel.h index 1f00d1f14..01cc70426 100644 --- a/gtk/gtkfilesystemmodel.h +++ b/gtk/gtkfilesystemmodel.h @@ -33,7 +33,7 @@ G_BEGIN_DECLS typedef struct _GtkFileSystemModel GtkFileSystemModel; -GType _gtk_file_system_model_get_type (void) G_GNUC_CONST; +GType _gtk_file_system_model_get_type (void); typedef gboolean (*GtkFileSystemModelGetValue) (GtkFileSystemModel *model, GFile *file, diff --git a/gtk/gtkfilethumbnail.c b/gtk/gtkfilethumbnail.c new file mode 100644 index 000000000..b9582b9af --- /dev/null +++ b/gtk/gtkfilethumbnail.c @@ -0,0 +1,1035 @@ +/* GTK - The GIMP Toolkit + * gtkfilethumbnail.c: thumbnails made in the background + * + * Thumbnails of images go where every program that follows the + * freedesktop.org thumbnail specification finds them, and where GIO's + * thumbnail::path points to: $XDG_CACHE_HOME/thumbnails, which GLib + * gives on Linux, the BSDs, macOS and Windows alike. + * + * One thread makes them, newest request first, so a slow machine only + * ever decodes one image at a time. Images are decoded straight to + * the size of the thumbnail where the loader can (JPEG), never larger + * than they are, and not at all when they would need too much memory. + * Files on network shares are left alone: reading every picture there + * would be slow, and the user may not want copies of them. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + */ + +#include "config.h" + +#include +#include +#include +#include +#include +#include + +#include "gtkfilethumbnail.h" +#include "gtktimeprivate.h" + +#ifdef G_OS_WIN32 +#include +#include +#endif +#ifdef GDK_WINDOWING_QUARTZ +#include +#include +#import /* libgtk is Objective-C there */ +#endif +#ifdef __linux__ +#include +#endif + +#ifndef O_BINARY +#define O_BINARY 0 +#endif + +#define MAX_PIXELS (3840 * 2400) /* decoded whole: a 4K screenshot, 37 MB */ +#define MAX_JPEG_PIXELS (128 * 1024 * 1024) /* decoded at 1/8, a few rows at a time */ +#define MAX_GIF_SIZE (4 * 1024 * 1024) /* older loaders keep every frame */ +#define READ_CHUNK (64 * 1024) +#define FAIL_DIR "gtk2-ng" + +typedef struct +{ + GFile *file; + gchar *path; + gchar *uri; + guint64 mtime; + goffset size; + goffset max_remote_size; /* 0: none of network shares */ + gint thumbnail_size; /* 128 or 256 */ + gint orientation; /* of a JPEG, from its Exif data; 0: none */ + GCancellable *cancellable; + GtkFileThumbnailDone done; + gpointer data; + GDestroyNotify destroy; + guint serial; + gchar *result; +} Job; + +static GThreadPool *pool; +static guint serial; + +static void +job_free (Job *job) +{ + g_object_unref (job->file); + g_free (job->path); + g_free (job->uri); + if (job->cancellable) + g_object_unref (job->cancellable); + if (job->destroy) + job->destroy (job->data); + g_free (job->result); + g_slice_free (Job, job); +} + +/* the newest request first: that is what came on screen last */ +static gint +job_compare (gconstpointer a, + gconstpointer b, + gpointer user_data) +{ + const Job *ja = a, *jb = b; + + return ja->serial < jb->serial ? 1 : ja->serial > jb->serial ? -1 : 0; +} + +static gchar * +thumbnail_name (const gchar *uri) +{ + gchar *md5 = g_compute_checksum_for_string (G_CHECKSUM_MD5, uri, -1); + gchar *name = g_strconcat (md5, ".png", NULL); + + g_free (md5); + + return name; +} + +static gchar * +thumbnail_path (const gchar *subdir, + const gchar *uri) +{ + gchar *name = thumbnail_name (uri); + gchar *path = g_build_filename (g_get_user_cache_dir (), "thumbnails", subdir, name, NULL); + + g_free (name); + + return path; +} + +/* Whether the thumbnail or failure at @path is one of this version of + * the file, as GLib checks it (thumbnail-verify.c): Thumb::URI and + * Thumb::MTime must be there and match, Thumb::Size if it is there. The + * text chunks come before the picture, which is not decoded. + * @width and @height get the size of the picture it shows, if told. */ +static gboolean +thumbnail_matches (const gchar *path, + Job *job, + gint *width, + gint *height) +{ + static const guchar signature[8] = { 0x89, 'P', 'N', 'G', '\r', '\n', 0x1a, '\n' }; + gboolean uri = FALSE, mtime = FALSE, size = TRUE; + guchar head[8]; + FILE *f; + gint i; + + f = g_fopen (path, "rb"); + if (f == NULL) + return FALSE; + + if (fread (head, 1, 8, f) == 8 && memcmp (head, signature, 8) == 0) + for (i = 0; i < 64 && fread (head, 1, 8, f) == 8; i++) + { + guint32 length = ((guint32) head[0] << 24) | (head[1] << 16) | (head[2] << 8) | head[3]; + + if (memcmp (head + 4, "IDAT", 4) == 0 || memcmp (head + 4, "IEND", 4) == 0) + break; + + if (memcmp (head + 4, "tEXt", 4) == 0 && length < 8192) + { + gchar *text = g_malloc (length + 1); + const gchar *value; + + if (fread (text, 1, length, f) != length) + { + g_free (text); + break; + } + text[length] = '\0'; + value = text + strlen (text) + 1; + if (value <= text + length) + { + if (strcmp (text, "Thumb::URI") == 0) + uri = strcmp (value, job->uri) == 0; + else if (strcmp (text, "Thumb::MTime") == 0) + mtime = g_ascii_strtoull (value, NULL, 10) == job->mtime; + else if (strcmp (text, "Thumb::Size") == 0) + size = g_ascii_strtoull (value, NULL, 10) == (guint64) job->size; + else if (width && strcmp (text, "Thumb::Image::Width") == 0) + *width = atoi (value); + else if (height && strcmp (text, "Thumb::Image::Height") == 0) + *height = atoi (value); + } + g_free (text); + length = 0; + } + + if (fseek (f, (long) length + 4, SEEK_CUR) != 0) + break; + } + fclose (f); + + return uri && mtime && size; +} + +/* The same for the chooser, where GLib cannot tell (before 2.40) */ +gboolean +_gtk_file_thumbnail_valid (const gchar *thumbnail, + GFile *file, + GFileInfo *info) +{ + Job job; + gboolean valid; + + if (!g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_TIME_MODIFIED)) + return FALSE; + + memset (&job, 0, sizeof job); + job.uri = g_file_get_uri (file); + job.mtime = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_TIME_MODIFIED); + job.size = g_file_info_get_size (info); + valid = thumbnail_matches (thumbnail, &job, NULL, NULL); + g_free (job.uri); + + return valid; +} + +#ifndef G_OS_WIN32 +/* Filesystem types of network shares and FUSE mounts, as statfs() names + * them on the BSDs and macOS, and GIO on Linux: smbfs, smb2, nfs4, + * fusefs.sshfs, perfuse|sshfs, macfuse... GLib itself knows only a few + * of them as remote. */ +static const gchar *const remote_types[] = { + "nfs", "smb", "cifs", "afpfs", "webdav", "ncp", "coda", "afs", "9p", + "ceph", "fuse", "puffs", "perfuse", "macfuse", "osxfuse" +}; + +#ifdef __linux__ +/* Linux calls every FUSE mount "fuse"; those on a disk of their own, + * fuseblk with NTFS or exFAT, have the device number of the disk, + * where sshfs and the like have one of major 0 */ +static gboolean +local_fuse_mount (const gchar *path) +{ + GtkStatBuf buf; + + return _gtk_stat (path, TRUE, &buf) == 0 && major (buf.dev) != 0; +} +#endif +#endif + +/* Network shares, and FUSE mounts like sshfs, are left alone; the + * answer is kept per folder */ +static gboolean +on_remote_filesystem (Job *job) +{ + static gchar *last_folder; + static gboolean last_remote; + gchar *folder = g_path_get_dirname (job->path); + + if (g_strcmp0 (folder, last_folder) == 0) + { + g_free (folder); + return last_remote; + } + +#ifdef G_OS_WIN32 + /* GIO tells nothing of the kind here: \\server\share, and drives + * that are mapped to one */ + if (G_IS_DIR_SEPARATOR (folder[0]) && G_IS_DIR_SEPARATOR (folder[1])) + last_remote = TRUE; + else + { + wchar_t root[4] = { 0, L':', L'\\', 0 }; + + root[0] = g_ascii_isalpha (folder[0]) && folder[1] == ':' ? folder[0] : 0; + last_remote = root[0] == 0 || GetDriveTypeW (root) == DRIVE_REMOTE; + } +#else + { + GFileInfo *info = g_file_query_filesystem_info (job->file, + G_FILE_ATTRIBUTE_FILESYSTEM_REMOTE "," + G_FILE_ATTRIBUTE_FILESYSTEM_TYPE, + job->cancellable, NULL); + const gchar *type; + guint i; + + /* no answer, as when cancelled: not kept */ + if (info == NULL) + { + g_free (folder); + return TRUE; + } + + type = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_FILESYSTEM_TYPE); + last_remote = g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_FILESYSTEM_REMOTE); + for (i = 0; type && !last_remote && i < G_N_ELEMENTS (remote_types); i++) + last_remote = g_str_has_prefix (type, remote_types[i]); +#ifdef __linux__ + if (last_remote && g_strcmp0 (type, "fuse") == 0) + last_remote = !local_fuse_mount (job->path); +#endif + g_object_unref (info); + } +#endif + + g_free (last_folder); + last_folder = folder; + + return last_remote; +} + +static void +size_prepared (GdkPixbufLoader *loader, + gint width, + gint height, + gpointer data) +{ + gint size = GPOINTER_TO_INT (data); + + /* only ever smaller, keeping the shape */ + if (width > size || height > size) + { + if (width > height) + { + height = MAX (1, (gint) ((gint64) height * size / width)); + width = size; + } + else + { + width = MAX (1, (gint) ((gint64) width * size / height)); + height = size; + } + gdk_pixbuf_loader_set_size (loader, width, height); + } +} + +/* The orientation (1-8) in the Exif data of an APP1 segment, 0 if none */ +static gint +exif_orientation (const guchar *d, + gsize len) +{ + gboolean le; + guint32 ifd; + guint n, i; + +#define U16(p) (le ? (guint) ((p)[0] | (p)[1] << 8) : (guint) ((p)[0] << 8 | (p)[1])) +#define U32(p) (le ? ((guint32) (p)[0] | (guint32) (p)[1] << 8 | (guint32) (p)[2] << 16 | (guint32) (p)[3] << 24) \ + : ((guint32) (p)[0] << 24 | (guint32) (p)[1] << 16 | (guint32) (p)[2] << 8 | (guint32) (p)[3])) + + if (len < 6 + 8 || memcmp (d, "Exif\0\0", 6) != 0) + return 0; + d += 6; + len -= 6; + if (d[0] == 'I' && d[1] == 'I') + le = TRUE; + else if (d[0] == 'M' && d[1] == 'M') + le = FALSE; + else + return 0; + if (U16 (d + 2) != 42) + return 0; + ifd = U32 (d + 4); + if (ifd > len - 2) + return 0; + n = U16 (d + ifd); + for (i = 0; i < n && ifd + 2 + (i + 1) * 12 <= len; i++) + { + const guchar *e = d + ifd + 2 + i * 12; + + /* Orientation, a SHORT */ + if (U16 (e) == 0x0112 && U16 (e + 2) == 3) + { + guint o = U16 (e + 8); + return o >= 1 && o <= 8 ? (gint) o : 0; + } + } + +#undef U16 +#undef U32 + return 0; +} + +/* A progressive JPEG needs memory for the whole picture, however small + * it is decoded; its frame header (SOFn) tells. On the way there, the + * Exif orientation is read: not every image loader reports it (the one + * of GDI+ under Wine, gdk-pixbuf before 2.12), and without it photos + * taken upright show lying on their side */ +static gboolean +jpeg_scan (const gchar *path, + gint *orientation) +{ + FILE *f = g_fopen (path, "rb"); + gboolean progressive = TRUE; /* not found: the careful answer */ + guchar m[4]; + gint i; + + *orientation = 0; + if (f == NULL) + return TRUE; + + if (fread (m, 1, 2, f) == 2 && m[0] == 0xff && m[1] == 0xd8) + for (i = 0; i < 64 && fread (m, 1, 4, f) == 4 && m[0] == 0xff; i++) + { + gsize len = (m[2] << 8) | m[3]; + + /* SOF0 to SOF15, but for DHT, JPG and DAC */ + if (m[1] >= 0xc0 && m[1] <= 0xcf && m[1] != 0xc4 && m[1] != 0xc8 && m[1] != 0xcc) + { + progressive = m[1] == 0xc2 || m[1] == 0xc6 || m[1] == 0xca || m[1] == 0xce; + break; + } + if (len < 2) + break; + if (m[1] == 0xe1 && *orientation == 0) + { + guchar *app1 = g_malloc (len - 2); + gboolean read = fread (app1, 1, len - 2, f) == len - 2; + + if (read) + *orientation = exif_orientation (app1, len - 2); + g_free (app1); + if (!read) + break; + } + else if (fseek (f, len - 2, SEEK_CUR) != 0) + break; + } + fclose (f); + + return progressive; +} + +static GdkPixbuf * +decode (Job *job) +{ + GdkPixbufLoader *loader; + GdkPixbuf *pixbuf = NULL; + guchar *buffer; + gboolean ok = TRUE; + FILE *f; + gsize n; + + f = g_fopen (job->path, "rb"); + if (f == NULL) + return NULL; + + loader = gdk_pixbuf_loader_new (); + g_signal_connect (loader, "size-prepared", G_CALLBACK (size_prepared), + GINT_TO_POINTER (job->thumbnail_size)); + + buffer = g_malloc (READ_CHUNK); + while (ok && (n = fread (buffer, 1, READ_CHUNK, f)) > 0) + ok = !g_cancellable_is_cancelled (job->cancellable) && + gdk_pixbuf_loader_write (loader, buffer, n, NULL); + g_free (buffer); + fclose (f); + + if (gdk_pixbuf_loader_close (loader, NULL) && ok) + { + pixbuf = gdk_pixbuf_loader_get_pixbuf (loader); + if (pixbuf && job->orientation > 1 && + gdk_pixbuf_get_option (pixbuf, "orientation") == NULL) + { + gchar o[2] = { '0' + job->orientation, 0 }; + + gdk_pixbuf_set_option (pixbuf, "orientation", o); + } + if (pixbuf) + pixbuf = gdk_pixbuf_apply_embedded_orientation (pixbuf); + } + g_object_unref (loader); + + return pixbuf; +} + +/* Saves @pixbuf as the thumbnail @path, readable by the user only, and + * in one step, so nobody finds half a thumbnail */ +static gboolean +save (GdkPixbuf *pixbuf, + const gchar *path, + Job *job, + gint width, + gint height) +{ + gchar *dir = g_path_get_dirname (path); + gchar *tmp = g_build_filename (dir, "gtk2-ng-XXXXXX.png", NULL); + gchar *mtime = g_strdup_printf ("%" G_GUINT64_FORMAT, job->mtime); + gchar *size = g_strdup_printf ("%" G_GINT64_FORMAT, (gint64) job->size); + gchar *w = g_strdup_printf ("%d", width), *h = g_strdup_printf ("%d", height); + gboolean saved = FALSE; + gint fd; + + if (g_mkdir_with_parents (dir, 0700) == 0 && + (fd = g_mkstemp_full (tmp, O_RDWR | O_BINARY, 0600)) >= 0) + { + gchar *keys[] = { "tEXt::Thumb::URI", "tEXt::Thumb::MTime", "tEXt::Thumb::Size", + "tEXt::Software", "tEXt::Thumb::Image::Width", + "tEXt::Thumb::Image::Height", NULL }; + gchar *values[] = { job->uri, mtime, size, "GTK+ 2", w, h, NULL }; + + /* the size of the picture, where known */ + if (width <= 0 || height <= 0) + keys[4] = values[4] = NULL; + + g_close (fd, NULL); + saved = gdk_pixbuf_savev (pixbuf, tmp, "png", keys, values, NULL) && + g_rename (tmp, path) == 0; + if (!saved) + g_unlink (tmp); + } + + g_free (dir); + g_free (tmp); + g_free (mtime); + g_free (size); + g_free (w); + g_free (h); + + return saved; +} + +/* Remembers that this version of the file gives no thumbnail */ +static void +save_failure (Job *job) +{ + GdkPixbuf *pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, 1, 1); + gchar *path = thumbnail_path ("fail" G_DIR_SEPARATOR_S FAIL_DIR, job->uri); + + gdk_pixbuf_fill (pixbuf, 0); + save (pixbuf, path, job, 0, 0); + g_object_unref (pixbuf); + g_free (path); +} + +/* The sizes of the specification; Dolphin and newer GNOME make the + * bigger ones too */ +static const struct { const gchar *dir; gint size; } sizes[] = { + { "normal", 128 }, { "large", 256 }, { "x-large", 512 }, { "xx-large", 1024 } +}; + +/* The picture of a thumbnail of the native file manager, at most @size + * big: one Explorer has in its cache (Vista and later), one of Quick Look + * (10.5 and later), which has its own cache */ +#ifdef G_OS_WIN32 + +/* IShellItemImageFactory, declared here, as not all headers have it */ +typedef struct _ImageFactory ImageFactory; +typedef struct +{ + HRESULT (STDMETHODCALLTYPE *QueryInterface) (ImageFactory *, REFIID, void **); + ULONG (STDMETHODCALLTYPE *AddRef) (ImageFactory *); + ULONG (STDMETHODCALLTYPE *Release) (ImageFactory *); + HRESULT (STDMETHODCALLTYPE *GetImage) (ImageFactory *, SIZE, int, HBITMAP *); +} ImageFactoryVtbl; +struct _ImageFactory { const ImageFactoryVtbl *lpVtbl; }; + +#define THUMBNAIL_ONLY 0x08 /* SIIGBF_THUMBNAILONLY */ +#define IN_CACHE_ONLY 0x10 /* SIIGBF_INCACHEONLY */ + +static const GUID iid_image_factory = + { 0xbcc18b79, 0xba16, 0x442f, { 0x80, 0xc4, 0x8a, 0x59, 0xc3, 0x0c, 0x46, 0x3b } }; + +typedef HRESULT (WINAPI *CreateItemFunc) (PCWSTR, void *, REFIID, void **); + +/* A 32-bit DIB, with alpha premultiplied, or none at all */ +static GdkPixbuf * +pixbuf_of_bitmap (HBITMAP bitmap) +{ + BITMAPINFOHEADER header; + GdkPixbuf *pixbuf = NULL; + guchar *bits, *row; + gboolean alpha = FALSE; + gint width, height, x, y; + BITMAP info; + HDC dc; + + if (!GetObjectW (bitmap, sizeof info, &info) || info.bmWidth <= 0 || info.bmHeight == 0) + return NULL; + width = info.bmWidth; + height = ABS (info.bmHeight); + + memset (&header, 0, sizeof header); + header.biSize = sizeof header; + header.biWidth = width; + header.biHeight = -height; /* top row first */ + header.biPlanes = 1; + header.biBitCount = 32; + header.biCompression = BI_RGB; + + bits = g_try_malloc ((gsize) width * height * 4); + if (bits == NULL) + return NULL; + dc = GetDC (NULL); + if (GetDIBits (dc, bitmap, 0, height, bits, (BITMAPINFO *) &header, DIB_RGB_COLORS) == height) + pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, width, height); + ReleaseDC (NULL, dc); + + for (x = 0; pixbuf && x < width * height; x++) + alpha |= bits[x * 4 + 3] != 0; + + for (y = 0; pixbuf && y < height; y++) + { + guchar *src = bits + (gsize) y * width * 4; + + row = gdk_pixbuf_get_pixels (pixbuf) + (gsize) y * gdk_pixbuf_get_rowstride (pixbuf); + for (x = 0; x < width; x++, src += 4, row += 4) + { + guint a = alpha ? src[3] : 255; + + /* B, G, R, A to R, G, B, A, not premultiplied */ + row[0] = a ? MIN (255, src[2] * 255 / a) : 0; + row[1] = a ? MIN (255, src[1] * 255 / a) : 0; + row[2] = a ? MIN (255, src[0] * 255 / a) : 0; + row[3] = a; + } + } + g_free (bits); + + return pixbuf; +} + +static GdkPixbuf * +native_thumbnail (Job *job) +{ + static CreateItemFunc create_item; + static gsize looked_up; + ImageFactory *factory; + GdkPixbuf *pixbuf = NULL; + wchar_t *wpath; + HRESULT init; + + if (g_once_init_enter (&looked_up)) + { + HMODULE shell = LoadLibraryW (L"shell32.dll"); + + if (shell) + create_item = (CreateItemFunc) GetProcAddress (shell, "SHCreateItemFromParsingName"); + g_once_init_leave (&looked_up, 1); + } + if (create_item == NULL) + return NULL; /* Windows XP */ + + wpath = g_utf8_to_utf16 (job->path, -1, NULL, NULL, NULL); + if (wpath == NULL) + return NULL; + + init = CoInitializeEx (NULL, COINIT_MULTITHREADED); + if (SUCCEEDED (create_item (wpath, NULL, &iid_image_factory, (void **) &factory))) + { + SIZE size = { job->thumbnail_size, job->thumbnail_size }; + HBITMAP bitmap; + + if (SUCCEEDED (factory->lpVtbl->GetImage (factory, size, THUMBNAIL_ONLY | IN_CACHE_ONLY, &bitmap))) + { + pixbuf = pixbuf_of_bitmap (bitmap); + DeleteObject (bitmap); + + /* some shells (Wine, and handlers with nothing cached) answer + * with a dot of a bitmap: then the thumbnail is made here */ + if (pixbuf && gdk_pixbuf_get_width (pixbuf) < 16 && gdk_pixbuf_get_height (pixbuf) < 16) + { + g_object_unref (pixbuf); + pixbuf = NULL; + } + } + factory->lpVtbl->Release (factory); + } + if (SUCCEEDED (init)) + CoUninitialize (); + g_free (wpath); + + return pixbuf; +} + +#elif defined (GDK_WINDOWING_QUARTZ) + +typedef CGImageRef (*ThumbnailCreateFunc) (CFAllocatorRef, CFURLRef, CGSize, CFDictionaryRef); + +static GdkPixbuf * +native_thumbnail (Job *job) +{ + static ThumbnailCreateFunc create_thumbnail; + static gsize looked_up; + CGColorSpaceRef space; + CGContextRef context; + GdkPixbuf *pixbuf; + CGImageRef image; + CFURLRef url; + gint width, height, x, y; + + if (g_once_init_enter (&looked_up)) + { + void *quick_look = dlopen ("/System/Library/Frameworks/QuickLook.framework/QuickLook", + RTLD_LAZY | RTLD_LOCAL); + + if (quick_look) + create_thumbnail = (ThumbnailCreateFunc) dlsym (quick_look, "QLThumbnailImageCreate"); + g_once_init_leave (&looked_up, 1); + } + if (create_thumbnail == NULL) + return NULL; /* before 10.5 */ + + url = CFURLCreateFromFileSystemRepresentation (NULL, (const UInt8 *) job->path, + strlen (job->path), false); + if (url == NULL) + return NULL; + { + /* Quick Look autoreleases; this thread of the pool has no pool of + * its own */ + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + + image = create_thumbnail (kCFAllocatorDefault, url, + CGSizeMake (job->thumbnail_size, job->thumbnail_size), NULL); + [pool release]; + } + CFRelease (url); + if (image == NULL) + return NULL; + + width = CGImageGetWidth (image); + height = CGImageGetHeight (image); + pixbuf = width > 0 && height > 0 ? + gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, width, height) : NULL; + if (pixbuf) + { + /* drawn as R, G, B, A, premultiplied */ + gdk_pixbuf_fill (pixbuf, 0); + space = CGColorSpaceCreateDeviceRGB (); + context = CGBitmapContextCreate (gdk_pixbuf_get_pixels (pixbuf), width, height, 8, + gdk_pixbuf_get_rowstride (pixbuf), space, + kCGImageAlphaPremultipliedLast); + CGColorSpaceRelease (space); + if (context) + { + CGContextDrawImage (context, CGRectMake (0, 0, width, height), image); + CGContextRelease (context); + for (y = 0; y < height; y++) + { + guchar *p = gdk_pixbuf_get_pixels (pixbuf) + (gsize) y * gdk_pixbuf_get_rowstride (pixbuf); + + for (x = 0; x < width; x++, p += 4) + if (p[3] && p[3] < 255) + { + p[0] = MIN (255, p[0] * 255 / p[3]); + p[1] = MIN (255, p[1] * 255 / p[3]); + p[2] = MIN (255, p[2] * 255 / p[3]); + } + } + } + else + { + g_object_unref (pixbuf); + pixbuf = NULL; + } + } + CGImageRelease (image); + + return pixbuf; +} + +#endif + +#if defined (G_OS_WIN32) || defined (GDK_WINDOWING_QUARTZ) +/* Not bigger than @size, keeping the shape */ +static GdkPixbuf * +fit (GdkPixbuf *pixbuf, + gint size) +{ + gint width = gdk_pixbuf_get_width (pixbuf), height = gdk_pixbuf_get_height (pixbuf); + GdkPixbuf *scaled; + + if (width <= size && height <= size) + return pixbuf; + + if (width > height) + { + height = MAX (1, (gint) ((gint64) height * size / width)); + width = size; + } + else + { + width = MAX (1, (gint) ((gint64) width * size / height)); + height = size; + } + scaled = gdk_pixbuf_scale_simple (pixbuf, width, height, GDK_INTERP_BILINEAR); + g_object_unref (pixbuf); + + return scaled; +} +#endif + +static gchar * +make_thumbnail (Job *job) +{ + gint own = job->thumbnail_size > 128 ? 1 : 0; + gchar *path = thumbnail_path (sizes[own].dir, job->uri); + gchar *fail = thumbnail_path ("fail" G_DIR_SEPARATOR_S FAIL_DIR, job->uri); + GdkPixbufFormat *format; + GdkPixbuf *pixbuf = NULL; + gint width, height, i; + + /* made meanwhile, by us or another program */ + if (thumbnail_matches (path, job, NULL, NULL)) + goto done; + + if (g_cancellable_is_cancelled (job->cancellable)) + goto none; + + /* a bigger one of another program, made smaller: no need to read the + * picture, which may be on a network share too */ + for (i = own + 1; i < (gint) G_N_ELEMENTS (sizes); i++) + { + gchar *bigger = thumbnail_path (sizes[i].dir, job->uri); + gint w, h; + + width = height = 0; + /* smaller than wanted (of a small picture): as it is */ + if (thumbnail_matches (bigger, job, &width, &height)) + pixbuf = gdk_pixbuf_get_file_info (bigger, &w, &h) && + w <= job->thumbnail_size && h <= job->thumbnail_size ? + gdk_pixbuf_new_from_file (bigger, NULL) : + gdk_pixbuf_new_from_file_at_size (bigger, job->thumbnail_size, + job->thumbnail_size, NULL); + g_free (bigger); + if (pixbuf) + { + if (!save (pixbuf, path, job, width, height)) + goto none; + g_object_unref (pixbuf); + goto done; + } + } + + if (thumbnail_matches (fail, job, NULL, NULL) || + (job->size > job->max_remote_size && on_remote_filesystem (job))) + goto none; + +#if defined (G_OS_WIN32) || defined (GDK_WINDOWING_QUARTZ) + pixbuf = native_thumbnail (job); + if (pixbuf) + { + pixbuf = fit (pixbuf, job->thumbnail_size); + if (!save (pixbuf, path, job, 0, 0)) + goto none; + g_object_unref (pixbuf); + goto done; + } +#endif + + format = gdk_pixbuf_get_file_info (job->path, &width, &height); + if (format == NULL || width <= 0 || height <= 0) + { + save_failure (job); + goto none; + } + + /* JPEG decodes at a fraction of its size, unless progressive; the + * others decode whole */ + { + gchar *name = gdk_pixbuf_format_get_name (format); + gint64 pixels = (gint64) width * height; + gboolean fits; + + if (g_strcmp0 (name, "jpeg") == 0) + fits = pixels <= (jpeg_scan (job->path, &job->orientation) ? MAX_PIXELS : MAX_JPEG_PIXELS); + else if (g_strcmp0 (name, "gif") == 0) + fits = pixels <= MAX_PIXELS && job->size <= MAX_GIF_SIZE; + else + fits = pixels <= MAX_PIXELS; + g_free (name); + if (!fits) + goto none; + } + + pixbuf = decode (job); + if (pixbuf == NULL) + { + if (!g_cancellable_is_cancelled (job->cancellable)) + save_failure (job); + goto none; + } + + if (!save (pixbuf, path, job, width, height)) + goto none; + + g_object_unref (pixbuf); + done: + g_free (fail); + return path; + + none: + if (pixbuf) + g_object_unref (pixbuf); + g_free (fail); + g_free (path); + return NULL; +} + +static gboolean +job_finish (gpointer data) +{ + Job *job = data; + + if (!g_cancellable_is_cancelled (job->cancellable)) + job->done (job->file, job->result, job->data); + job_free (job); + + return FALSE; +} + +static void +job_run (gpointer data, + gpointer user_data) +{ + Job *job = data; + + if (!g_cancellable_is_cancelled (job->cancellable)) + job->result = make_thumbnail (job); + + gdk_threads_add_idle (job_finish, job); +} + +#ifdef G_OS_WIN32 +/* Whether gdk-pixbuf has a loader for the extension of @file, for when + * the registry has no Content Type for the extension, which GIO takes + * the MIME type from on Windows */ +static gboolean +pixbuf_reads_extension (GFile *file) +{ + static GHashTable *extensions; + gchar *base, *dot, *ext; + gboolean known; + + if (g_once_init_enter (&extensions)) + { + GHashTable *table = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); + GSList *formats = gdk_pixbuf_get_formats (), *l; + + for (l = formats; l; l = l->next) + { + gchar **exts = gdk_pixbuf_format_get_extensions (l->data); + gint i; + + for (i = 0; exts && exts[i]; i++) + g_hash_table_insert (table, g_ascii_strdown (exts[i], -1), GINT_TO_POINTER (1)); + g_strfreev (exts); + } + g_slist_free (formats); + g_once_init_leave (&extensions, table); + } + + base = g_file_get_basename (file); + dot = base ? strrchr (base, '.') : NULL; + if (dot == NULL || dot[1] == 0) + { + g_free (base); + return FALSE; + } + + ext = g_ascii_strdown (dot + 1, -1); + known = g_hash_table_lookup (extensions, ext) != NULL; + g_free (ext); + g_free (base); + + return known; +} +#endif + +/* Whether a thumbnail could be made for @file, of which @info knows the + * fast content type, size and modification time */ +gboolean +_gtk_file_thumbnail_wanted (GFile *file, + GFileInfo *info, + goffset max_size) +{ + const gchar *type = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE); + gchar *mime, *path; + gboolean wanted; + + if (type == NULL) + type = g_file_info_get_content_type (info); + if (type == NULL || + !g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_SIZE) || + !g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_TIME_MODIFIED) || + g_file_info_get_size (info) > max_size) + return FALSE; + + mime = g_content_type_get_mime_type (type); + wanted = mime && g_str_has_prefix (mime, "image/"); + g_free (mime); +#ifdef G_OS_WIN32 + if (!wanted) + wanted = pixbuf_reads_extension (file); +#endif + if (!wanted) + return FALSE; + + /* local files, but not the thumbnails themselves */ + path = g_file_get_path (file); + if (path) + { + gchar *cache = g_build_filename (g_get_user_cache_dir (), "thumbnails", NULL); + + wanted = !g_str_has_prefix (path, cache); + g_free (cache); + g_free (path); + } + else + wanted = FALSE; + + return wanted; +} + +/* Makes a thumbnail of @size, 128 or 256, for @file in the background; + * @destroy frees @data when the request is over, made or not */ +void +_gtk_file_thumbnail_request (GFile *file, + GFileInfo *info, + gint size, + goffset max_remote_size, + GCancellable *cancellable, + GtkFileThumbnailDone done, + gpointer data, + GDestroyNotify destroy) +{ + Job *job = g_slice_new0 (Job); + + job->file = g_object_ref (file); + job->path = g_file_get_path (file); + job->uri = g_file_get_uri (file); + job->mtime = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_TIME_MODIFIED); + job->size = g_file_info_get_size (info); + job->max_remote_size = max_remote_size; + job->thumbnail_size = size > 128 ? 256 : 128; + job->cancellable = cancellable ? g_object_ref (cancellable) : NULL; + job->done = done; + job->data = data; + job->destroy = destroy; + job->serial = ++serial; + + if (pool == NULL) + { + pool = g_thread_pool_new (job_run, NULL, 1, FALSE, NULL); + g_thread_pool_set_sort_function (pool, job_compare, NULL); + } + + g_thread_pool_push (pool, job, NULL); +} diff --git a/gtk/gtkfilethumbnail.h b/gtk/gtkfilethumbnail.h new file mode 100644 index 000000000..2345ba3f6 --- /dev/null +++ b/gtk/gtkfilethumbnail.h @@ -0,0 +1,44 @@ +/* GTK - The GIMP Toolkit + * gtkfilethumbnail.h: thumbnails made in the background + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + */ + +#ifndef __GTK_FILE_THUMBNAIL_H__ +#define __GTK_FILE_THUMBNAIL_H__ + +#include + +G_BEGIN_DECLS + +/* Called in the main loop, with the GDK lock, unless @cancellable was + * cancelled: @thumbnail is the path of the new thumbnail, or NULL. */ +typedef void (*GtkFileThumbnailDone) (GFile *file, + const gchar *thumbnail, + gpointer data); + +/* @max_size and @max_remote_size in bytes: no thumbnails of bigger + * files, and of none on network shares if 0 */ +gboolean _gtk_file_thumbnail_wanted (GFile *file, + GFileInfo *info, + goffset max_size); +void _gtk_file_thumbnail_request (GFile *file, + GFileInfo *info, + gint size, + goffset max_remote_size, + GCancellable *cancellable, + GtkFileThumbnailDone done, + gpointer data, + GDestroyNotify destroy); + +/* Whether the thumbnail at @thumbnail is one of this version of @file */ +gboolean _gtk_file_thumbnail_valid (const gchar *thumbnail, + GFile *file, + GFileInfo *info); + +G_END_DECLS + +#endif /* __GTK_FILE_THUMBNAIL_H__ */ diff --git a/gtk/gtkfixed.h b/gtk/gtkfixed.h index 14aad5d02..8297e4fab 100644 --- a/gtk/gtkfixed.h +++ b/gtk/gtkfixed.h @@ -69,7 +69,7 @@ struct _GtkFixedChild }; -GType gtk_fixed_get_type (void) G_GNUC_CONST; +GType gtk_fixed_get_type (void); GtkWidget* gtk_fixed_new (void); void gtk_fixed_put (GtkFixed *fixed, GtkWidget *widget, diff --git a/gtk/gtkfontbutton.h b/gtk/gtkfontbutton.h index e5d97431f..7e273c8b5 100644 --- a/gtk/gtkfontbutton.h +++ b/gtk/gtkfontbutton.h @@ -71,7 +71,7 @@ struct _GtkFontButtonClass { }; -GType gtk_font_button_get_type (void) G_GNUC_CONST; +GType gtk_font_button_get_type (void); GtkWidget *gtk_font_button_new (void); GtkWidget *gtk_font_button_new_with_font (const gchar *fontname); diff --git a/gtk/gtkfontsel.c b/gtk/gtkfontsel.c index 28ede4eb4..7ac35373d 100644 --- a/gtk/gtkfontsel.c +++ b/gtk/gtkfontsel.c @@ -35,6 +35,7 @@ #include #include +#include #include "gdk/gdk.h" #include "gdk/gdkkeysyms.h" @@ -179,6 +180,21 @@ static const guint16 font_sizes[] = { 32, 36, 40, 48, 56, 64, 72 }; +typedef struct +{ + PangoFontMap *font_map; /* the fonts listed are from this map... */ + guint font_map_serial;/* ...in this state */ + guint preview_idle; + gboolean styles_pending; /* preview_idle also lists the styles */ + gint64 preview_done; /* when the last preview was made... */ + gint64 preview_time; /* ...and how long that took */ + GtkTreeViewColumn *family_column; + GtkCellRenderer *family_renderer; + struct _FamilyMeasuring *measuring; /* the family column, see family_list_measure() */ +} GtkFontSelectionPrivate; + +#define GET_PRIV(fontsel) ((GtkFontSelectionPrivate *) gtk_font_selection_get_instance_private (fontsel)) + enum { PROP_0, PROP_FONT_NAME, @@ -210,6 +226,11 @@ static void gtk_font_selection_get_property (GObject *object, GValue *value, GParamSpec *pspec); static void gtk_font_selection_finalize (GObject *object); +static void family_list_measure_stop (GtkFontSelection *fontsel); +static void family_list_style_set (GtkWidget *widget, + GtkStyle *previous_style, + GtkFontSelection *fontsel); +static void gtk_font_selection_destroy (GtkObject *object); static void gtk_font_selection_screen_changed (GtkWidget *widget, GdkScreen *previous_screen); static void gtk_font_selection_style_set (GtkWidget *widget, @@ -261,7 +282,7 @@ static void gtk_font_selection_ref_family (GtkFontSelection *font static void gtk_font_selection_ref_face (GtkFontSelection *fontsel, PangoFontFace *face); -G_DEFINE_TYPE (GtkFontSelection, gtk_font_selection, GTK_TYPE_VBOX) +G_DEFINE_TYPE_WITH_PRIVATE (GtkFontSelection, gtk_font_selection, GTK_TYPE_VBOX) static void gtk_font_selection_class_init (GtkFontSelectionClass *klass) @@ -269,6 +290,7 @@ gtk_font_selection_class_init (GtkFontSelectionClass *klass) GObjectClass *gobject_class = G_OBJECT_CLASS (klass); GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); + GTK_OBJECT_CLASS (klass)->destroy = gtk_font_selection_destroy; gobject_class->set_property = gtk_font_selection_set_property; gobject_class->get_property = gtk_font_selection_get_property; @@ -382,6 +404,7 @@ gtk_font_selection_init (GtkFontSelection *fontsel) GtkWidget *vbox; GtkListStore *model; GtkTreeViewColumn *column; + GtkCellRenderer *renderer; GList *focus_chain = NULL; AtkObject *atk_obj; @@ -457,12 +480,20 @@ gtk_font_selection_init (GtkFontSelection *fontsel) g_signal_connect (fontsel->family_list, "row-activated", G_CALLBACK (list_row_activated), fontsel); - column = gtk_tree_view_column_new_with_attributes ("Family", - gtk_cell_renderer_text_new (), + /* The column is as wide as the widest family, as an autosized one + * would be, but measured in one go by family_list_measure() instead of + * by the tree view walking every row; with thousands of fonts that + * walk is most of the time the dialog takes to open. */ + renderer = gtk_cell_renderer_text_new (); + column = gtk_tree_view_column_new_with_attributes ("Family", renderer, "text", FAMILY_NAME_COLUMN, NULL); - gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_AUTOSIZE); + gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_FIXED); gtk_tree_view_append_column (GTK_TREE_VIEW (fontsel->family_list), column); + GET_PRIV (fontsel)->family_column = column; + GET_PRIV (fontsel)->family_renderer = renderer; + g_signal_connect (fontsel->family_list, "style-set", + G_CALLBACK (family_list_style_set), fontsel); gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (fontsel->family_list), FALSE); gtk_tree_selection_set_mode (gtk_tree_view_get_selection (GTK_TREE_VIEW (fontsel->family_list)), @@ -672,6 +703,21 @@ gtk_font_selection_finalize (GObject *object) G_OBJECT_CLASS (gtk_font_selection_parent_class)->finalize (object); } +static void +gtk_font_selection_destroy (GtkObject *object) +{ + GtkFontSelectionPrivate *priv = GET_PRIV (GTK_FONT_SELECTION (object)); + + if (priv->preview_idle) + { + g_source_remove (priv->preview_idle); + priv->preview_idle = 0; + } + family_list_measure_stop (GTK_FONT_SELECTION (object)); + + GTK_OBJECT_CLASS (gtk_font_selection_parent_class)->destroy (object); +} + static void gtk_font_selection_ref_family (GtkFontSelection *fontsel, PangoFontFamily *family) @@ -698,7 +744,21 @@ gtk_font_selection_reload_fonts (GtkFontSelection *fontsel) { if (gtk_widget_has_screen (GTK_WIDGET (fontsel))) { + GtkFontSelectionPrivate *priv = GET_PRIV (fontsel); + PangoFontMap *font_map; PangoFontDescription *desc; + + /* Both the screen and the style change when the widget is put into a + * window; listing thousands of fonts once is enough. */ + font_map = pango_context_get_font_map (gtk_widget_get_pango_context (GTK_WIDGET (fontsel))); +#if PANGO_VERSION_CHECK (1, 34, 0) + if (font_map == priv->font_map && + pango_font_map_get_serial (font_map) == priv->font_map_serial) + return; + priv->font_map_serial = pango_font_map_get_serial (font_map); +#endif + priv->font_map = font_map; + desc = gtk_font_selection_get_font_description (fontsel); gtk_font_selection_show_available_fonts (fontsel); @@ -811,58 +871,401 @@ gtk_font_selection_select_font (GtkTreeSelection *selection, gtk_entry_set_text (GTK_ENTRY (fontsel->font_entry), family_name); #endif - gtk_font_selection_show_available_styles (fontsel); - gtk_font_selection_select_best_style (fontsel, TRUE); + /* Listing the styles takes long with many fonts; it is done with + * the preview (see gtk_font_selection_load_font()). */ + GET_PRIV (fontsel)->styles_pending = TRUE; + gtk_font_selection_load_font (fontsel); } g_object_unref (family); } } +typedef struct +{ + PangoFontFamily *family; + gchar *key; +} FamilyEntry; + +/* The family column gets the width that an autosized column would get + * after the tree view had measured every row (the widest name, with the + * padding of the cell, the focus line and the separator, as in + * validate_row() of gtktreeview.c), and the tree view takes the height + * of one row for all when all names are of one height, which is what it + * would find measuring them one by one. So the list looks as with an + * autosized column, but: + * + * - the names are measured with one layout, without the tree view and + * the renderer around each of them; + * - what was measured is kept with the font map, so the next font + * selection of the program, with the same fonts, does not measure; + * - with many fonts the measuring goes on in slices when nothing else + * is to be done, and the column grows meanwhile, as an autosized one + * does while the tree view measures its rows. + */ + +#define MEASURE_SLICE 8000 /* microseconds of measuring at a time */ + +typedef struct +{ + guint serial; + gchar *font; + gdouble resolution; + gulong options_hash; + gint n_names; + gint xpad, ypad; + gint max_width; + gboolean same_height; +} FamilyMeasure; + +typedef struct _FamilyMeasuring +{ + PangoLayout *layout; + const gchar **names; /* owned by the families in the model */ + gint n_names; + gint pos; + gint max_width; + gint height; + gboolean same_height; + guint idle; + FamilyMeasure key; /* to keep with the font map when done */ + PangoFontMap *font_map; +} FamilyMeasuring; + +static void +family_measure_free (gpointer data) +{ + FamilyMeasure *measure = data; + + g_free (measure->font); + g_slice_free (FamilyMeasure, measure); +} + +static GQuark +family_measure_quark (void) +{ + static GQuark quark; + + if (!quark) + quark = g_quark_from_static_string ("gtk-font-selection-family-measure"); + return quark; +} + +static void +family_list_apply (GtkFontSelection *fontsel, + gint max_width, + gboolean same_height) +{ + GtkFontSelectionPrivate *priv = GET_PRIV (fontsel); + GtkTreeView *list = GTK_TREE_VIEW (fontsel->family_list); + gint focus_line_width, horizontal_separator; + + gtk_widget_style_get (GTK_WIDGET (list), + "focus-line-width", &focus_line_width, + "horizontal-separator", &horizontal_separator, + NULL); + gtk_tree_view_column_set_fixed_width (priv->family_column, + MAX (1, max_width + 2 * focus_line_width + horizontal_separator)); + + if (gtk_tree_view_get_fixed_height_mode (list) != same_height) + gtk_tree_view_set_fixed_height_mode (list, same_height); +} + +static void +family_list_measure_stop (GtkFontSelection *fontsel) +{ + GtkFontSelectionPrivate *priv = GET_PRIV (fontsel); + FamilyMeasuring *m = priv->measuring; + + if (!m) + return; + if (m->idle) + g_source_remove (m->idle); + if (m->layout) + g_object_unref (m->layout); + g_free (m->names); + g_free (m->key.font); + g_slice_free (FamilyMeasuring, m); + priv->measuring = NULL; +} + +/* Measures for up to @budget microseconds; TRUE when all are measured */ +static gboolean +family_list_measure_some (FamilyMeasuring *m, + GtkCellRenderer *cell, + gint64 budget) +{ + gint64 start = g_get_monotonic_time (); + + while (m->pos < m->n_names) + { + PangoRectangle rect; + gint height; + + /* The layout the renderer makes for a plain text (no markup, no + * attributes, no wrapping) is the one of the widget */ + pango_layout_set_text (m->layout, m->names[m->pos++], -1); + pango_layout_get_pixel_extents (m->layout, NULL, &rect); + m->max_width = MAX (m->max_width, cell->xpad * 2 + rect.x + rect.width); + height = cell->ypad * 2 + rect.height; + if (m->height < 0) + m->height = height; + else if (height != m->height) + m->same_height = FALSE; + + if ((m->pos & 15) == 0 && g_get_monotonic_time () - start >= budget) + break; + } + + return m->pos >= m->n_names; +} + +static void +family_list_measure_done (GtkFontSelection *fontsel) +{ + GtkFontSelectionPrivate *priv = GET_PRIV (fontsel); + FamilyMeasuring *m = priv->measuring; + + family_list_apply (fontsel, m->max_width, m->same_height); + + if (m->font_map) + { + FamilyMeasure *measure = g_slice_new (FamilyMeasure); + + *measure = m->key; + m->key.font = NULL; + measure->max_width = m->max_width; + measure->same_height = m->same_height; + g_object_set_qdata_full (G_OBJECT (m->font_map), family_measure_quark (), + measure, family_measure_free); + } + + m->idle = 0; + family_list_measure_stop (fontsel); +} + +static gboolean +family_list_measure_idle (gpointer data) +{ + GtkFontSelection *fontsel = data; + GtkFontSelectionPrivate *priv = GET_PRIV (fontsel); + FamilyMeasuring *m = priv->measuring; + + if (family_list_measure_some (m, priv->family_renderer, MEASURE_SLICE)) + { + family_list_measure_done (fontsel); + return FALSE; + } + + /* as an autosized column grows while the rows are measured */ + family_list_apply (fontsel, m->max_width, TRUE); + return TRUE; +} + +/* What the measure depends on: the fonts there are, the font of the + * list and how it is rendered, the padding of the cells. Returns the + * font map to keep the measure with, NULL if it cannot be kept. */ +static PangoFontMap * +family_measure_key (GtkFontSelection *fontsel, + gint n_names, + FamilyMeasure *key) +{ + GtkWidget *list = fontsel->family_list; + GtkCellRenderer *cell = GET_PRIV (fontsel)->family_renderer; + PangoContext *context = gtk_widget_get_pango_context (list); + PangoFontMap *font_map = NULL; + const cairo_font_options_t *options; + + memset (key, 0, sizeof (FamilyMeasure)); +#if PANGO_VERSION_CHECK (1, 34, 0) + font_map = pango_context_get_font_map (context); + key->serial = pango_font_map_get_serial (font_map); +#endif + key->font = pango_font_description_to_string (list->style->font_desc); + key->resolution = pango_cairo_context_get_resolution (context); + options = pango_cairo_context_get_font_options (context); + key->options_hash = options ? cairo_font_options_hash (options) : 0; + key->n_names = n_names; + key->xpad = cell->xpad; + key->ypad = cell->ypad; + + return font_map; +} + +/* Gives the column the measure kept for @key, if there is one */ +static gboolean +family_list_apply_known (GtkFontSelection *fontsel, + PangoFontMap *font_map, + FamilyMeasure *key) +{ + FamilyMeasure *known; + + if (!font_map) + return FALSE; + + known = g_object_get_qdata (G_OBJECT (font_map), family_measure_quark ()); + if (!known || known->serial != key->serial || known->n_names != key->n_names || + known->resolution != key->resolution || known->options_hash != key->options_hash || + known->xpad != key->xpad || known->ypad != key->ypad || + strcmp (known->font, key->font) != 0) + return FALSE; + + family_list_apply (fontsel, known->max_width, known->same_height); + return TRUE; +} + +/* Takes @names */ +static void +family_list_measure (GtkFontSelection *fontsel, + const gchar **names, + gint n_names) +{ + GtkFontSelectionPrivate *priv = GET_PRIV (fontsel); + GtkCellRenderer *cell = priv->family_renderer; + FamilyMeasuring *m; + FamilyMeasure key; + PangoFontMap *font_map; + + family_list_measure_stop (fontsel); + + font_map = family_measure_key (fontsel, n_names, &key); + if (family_list_apply_known (fontsel, font_map, &key)) + { + g_free (key.font); + g_free (names); + return; + } + + m = g_slice_new0 (FamilyMeasuring); + m->layout = gtk_widget_create_pango_layout (fontsel->family_list, NULL); + m->names = names; + m->n_names = n_names; + m->height = -1; + m->same_height = TRUE; + m->key = key; + m->font_map = font_map; + priv->measuring = m; + + if (family_list_measure_some (m, cell, MEASURE_SLICE)) + { + family_list_measure_done (fontsel); + return; + } + + family_list_apply (fontsel, m->max_width, TRUE); + m->idle = gdk_threads_add_idle (family_list_measure_idle, fontsel); +} + +/* Another font or other separators: an autosized column would be + * measured again as well */ +static void +family_list_style_set (GtkWidget *widget, + GtkStyle *previous_style, + GtkFontSelection *fontsel) +{ + GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW (widget)); + const gchar **names; + GtkTreeIter iter; + gboolean valid; + gint n = 0; + + FamilyMeasure key; + PangoFontMap *font_map; + + /* also the first style of the list (previous_style NULL), which may + * come after the families were listed and measured */ + if (!model) + return; + + n = gtk_tree_model_iter_n_children (model, NULL); + font_map = family_measure_key (fontsel, n, &key); + if (family_list_apply_known (fontsel, font_map, &key)) + { + g_free (key.font); + return; + } + g_free (key.font); + + n = 0; + names = g_new (const gchar *, gtk_tree_model_iter_n_children (model, NULL) + 1); + for (valid = gtk_tree_model_get_iter_first (model, &iter); valid; + valid = gtk_tree_model_iter_next (model, &iter)) + { + PangoFontFamily *family; + + /* the model keeps the family, and with it the name */ + gtk_tree_model_get (model, &iter, FAMILY_COLUMN, &family, -1); + names[n++] = pango_font_family_get_name (family); + g_object_unref (family); + } + family_list_measure (fontsel, names, n); +} + static int cmp_families (const void *a, const void *b) { - const char *a_name = pango_font_family_get_name (*(PangoFontFamily **)a); - const char *b_name = pango_font_family_get_name (*(PangoFontFamily **)b); - - return g_utf8_collate (a_name, b_name); + return strcmp (((const FamilyEntry *) a)->key, ((const FamilyEntry *) b)->key); } static void gtk_font_selection_show_available_fonts (GtkFontSelection *fontsel) { + GtkTreeView *view = GTK_TREE_VIEW (fontsel->family_list); GtkListStore *model; PangoFontFamily **families; PangoFontFamily *match_family = NULL; + FamilyEntry *entries; + const gchar **names; gint n_families, i; GtkTreeIter match_row; - model = GTK_LIST_STORE (gtk_tree_view_get_model (GTK_TREE_VIEW (fontsel->family_list))); + model = GTK_LIST_STORE (gtk_tree_view_get_model (view)); + /* the names it would measure go with the families in the list */ + family_list_measure_stop (fontsel); + + /* Collation keys are made once per family instead of in every comparison. */ pango_context_list_families (gtk_widget_get_pango_context (GTK_WIDGET (fontsel)), &families, &n_families); - qsort (families, n_families, sizeof (PangoFontFamily *), cmp_families); + entries = g_new (FamilyEntry, n_families); + for (i = 0; i < n_families; i++) + { + entries[i].family = families[i]; + entries[i].key = g_utf8_collate_key (pango_font_family_get_name (families[i]), -1); + } + qsort (entries, n_families, sizeof (FamilyEntry), cmp_families); + /* The view would follow every row otherwise. */ + g_object_ref (model); + gtk_tree_view_set_model (view, NULL); gtk_list_store_clear (model); - for (i=0; idesc, + ((const FaceEntry *) b)->desc); } static gboolean @@ -929,12 +1331,14 @@ gtk_font_selection_show_available_styles (GtkFontSelection *fontsel) { gint n_faces, i; PangoFontFace **faces; + FaceEntry *entries; PangoFontDescription *old_desc; GtkListStore *model; GtkTreeIter match_row; PangoFontFace *match_face = NULL; model = GTK_LIST_STORE (gtk_tree_view_get_model (GTK_TREE_VIEW (fontsel->face_list))); + GET_PRIV (fontsel)->styles_pending = FALSE; if (fontsel->face) old_desc = pango_font_face_describe (fontsel->face); @@ -942,39 +1346,36 @@ gtk_font_selection_show_available_styles (GtkFontSelection *fontsel) old_desc= NULL; pango_font_family_list_faces (fontsel->family, &faces, &n_faces); - qsort (faces, n_faces, sizeof (PangoFontFace *), faces_sort_func); + entries = g_new (FaceEntry, n_faces); + for (i = 0; i < n_faces; i++) + { + entries[i].face = faces[i]; + entries[i].desc = pango_font_face_describe (faces[i]); + } + qsort (entries, n_faces, sizeof (FaceEntry), faces_sort_func); gtk_list_store_clear (model); for (i=0; i < n_faces; i++) { GtkTreeIter iter; - const gchar *str = pango_font_face_get_face_name (faces[i]); + const gchar *str = pango_font_face_get_face_name (entries[i].face); - gtk_list_store_append (model, &iter); - gtk_list_store_set (model, &iter, - FACE_COLUMN, faces[i], - FACE_NAME_COLUMN, _gtk_font_style_name_translate (str), - -1); + gtk_list_store_insert_with_values (model, &iter, i, + FACE_COLUMN, entries[i].face, + FACE_NAME_COLUMN, _gtk_font_style_name_translate (str), + -1); - if (i == 0) + if (i == 0 || + (old_desc && font_description_style_equal (entries[i].desc, old_desc))) { match_row = iter; - match_face = faces[i]; + match_face = entries[i].face; } - else if (old_desc) - { - PangoFontDescription *tmp_desc = pango_font_face_describe (faces[i]); - if (font_description_style_equal (tmp_desc, old_desc)) - { - match_row = iter; - match_face = faces[i]; - } - - pango_font_description_free (tmp_desc); - } + pango_font_description_free (entries[i].desc); } + g_free (entries); if (old_desc) pango_font_description_free (old_desc); @@ -993,25 +1394,15 @@ gtk_font_selection_show_available_styles (GtkFontSelection *fontsel) g_free (faces); } -/* This selects a style when the user selects a font. It just uses the first - available style at present. I was thinking of trying to maintain the - selected style, e.g. bold italic, when the user selects different fonts. - However, the interface is so easy to use now I'm not sure it's worth it. +/* This is called when the user selects a font. The style stays what it + was if the new family has it (see gtk_font_selection_show_available_styles()), + so bold stays bold while going through the families. Note: This will load a font. */ static void gtk_font_selection_select_best_style (GtkFontSelection *fontsel, gboolean use_first) { - GtkTreeIter iter; - GtkTreeModel *model; - - model = gtk_tree_view_get_model (GTK_TREE_VIEW (fontsel->face_list)); - - if (gtk_tree_model_get_iter_first (model, &iter)) - { - set_cursor_to_iter (GTK_TREE_VIEW (fontsel->face_list), &iter); - scroll_to_selection (GTK_TREE_VIEW (fontsel->face_list)); - } + scroll_to_selection (GTK_TREE_VIEW (fontsel->face_list)); gtk_font_selection_show_available_sizes (fontsel, FALSE); gtk_font_selection_select_best_size (fontsel); @@ -1188,14 +1579,67 @@ gtk_font_selection_select_size (GtkTreeSelection *selection, } } +static gboolean +gtk_font_selection_preview_timeout (gpointer data) +{ + GtkFontSelection *fontsel = data; + GtkFontSelectionPrivate *priv = GET_PRIV (fontsel); + gint64 start = g_get_monotonic_time (); + + priv->preview_idle = 0; + if (priv->styles_pending) + { + gtk_font_selection_show_available_styles (fontsel); + gtk_font_selection_select_best_style (fontsel, TRUE); + if (priv->preview_idle) + { + g_source_remove (priv->preview_idle); + priv->preview_idle = 0; + } + } + gtk_font_selection_update_preview (fontsel); + + priv->preview_done = g_get_monotonic_time (); + priv->preview_time = priv->preview_done - start; + + return FALSE; +} + +/* Brings the styles and the preview up to date now. */ +static void +gtk_font_selection_flush (GtkFontSelection *fontsel) +{ + GtkFontSelectionPrivate *priv = GET_PRIV (fontsel); + + if (priv->preview_idle) + { + g_source_remove (priv->preview_idle); + gtk_font_selection_preview_timeout (fontsel); + } +} + static void gtk_font_selection_load_font (GtkFontSelection *fontsel) { + GtkFontSelectionPrivate *priv = GET_PRIV (fontsel); + gint64 wait; + if (fontsel->font) gdk_font_unref (fontsel->font); fontsel->font = NULL; - gtk_font_selection_update_preview (fontsel); + /* With many fonts installed, loading a font for the preview takes long on + * a slow machine. It is done once the lists are redrawn, for the font + * selected by then. While the user goes through the list quickly, at + * least as much time as the last preview took is left for the list. */ + if (priv->preview_idle) + return; + + wait = priv->preview_done + priv->preview_time - g_get_monotonic_time (); + priv->preview_idle = gdk_threads_add_timeout_full (GDK_PRIORITY_REDRAW + 10, + MAX (wait, 0) / 1000, + gtk_font_selection_preview_timeout, + fontsel, NULL); } static PangoFontDescription * @@ -1203,6 +1647,8 @@ gtk_font_selection_get_font_description (GtkFontSelection *fontsel) { PangoFontDescription *font_desc; + gtk_font_selection_flush (fontsel); + if (fontsel->face) { font_desc = pango_font_face_describe (fontsel->face); @@ -1402,6 +1848,8 @@ gtk_font_selection_get_face (GtkFontSelection *fontsel) { g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), NULL); + gtk_font_selection_flush (fontsel); + return fontsel->face; } diff --git a/gtk/gtkfontsel.h b/gtk/gtkfontsel.h index c6cd788c0..054fcabf8 100644 --- a/gtk/gtkfontsel.h +++ b/gtk/gtkfontsel.h @@ -142,7 +142,7 @@ struct _GtkFontSelectionDialogClass * see the comments in the GtkFontSelectionDialog functions. *****************************************************************************/ -GType gtk_font_selection_get_type (void) G_GNUC_CONST; +GType gtk_font_selection_get_type (void); GtkWidget * gtk_font_selection_new (void); GtkWidget * gtk_font_selection_get_family_list (GtkFontSelection *fontsel); GtkWidget * gtk_font_selection_get_face_list (GtkFontSelection *fontsel); @@ -172,7 +172,7 @@ void gtk_font_selection_set_preview_text (GtkFontSelection *fontsel, * GtkFontSelection. *****************************************************************************/ -GType gtk_font_selection_dialog_get_type (void) G_GNUC_CONST; +GType gtk_font_selection_dialog_get_type (void); GtkWidget *gtk_font_selection_dialog_new (const gchar *title); GtkWidget *gtk_font_selection_dialog_get_ok_button (GtkFontSelectionDialog *fsd); diff --git a/gtk/gtkframe.h b/gtk/gtkframe.h index 7164f6736..5e76e8d73 100644 --- a/gtk/gtkframe.h +++ b/gtk/gtkframe.h @@ -69,7 +69,7 @@ struct _GtkFrameClass }; -GType gtk_frame_get_type (void) G_GNUC_CONST; +GType gtk_frame_get_type (void); GtkWidget* gtk_frame_new (const gchar *label); void gtk_frame_set_label (GtkFrame *frame, diff --git a/gtk/gtkgamma.h b/gtk/gtkgamma.h index 0173f960a..90e181e1e 100644 --- a/gtk/gtkgamma.h +++ b/gtk/gtkgamma.h @@ -71,7 +71,7 @@ struct _GtkGammaCurveClass }; -GType gtk_gamma_curve_get_type (void) G_GNUC_CONST; +GType gtk_gamma_curve_get_type (void); GtkWidget* gtk_gamma_curve_new (void); diff --git a/gtk/gtkhandlebox.h b/gtk/gtkhandlebox.h index 2dd96b286..fcd416afd 100644 --- a/gtk/gtkhandlebox.h +++ b/gtk/gtkhandlebox.h @@ -94,7 +94,7 @@ struct _GtkHandleBoxClass }; -GType gtk_handle_box_get_type (void) G_GNUC_CONST; +GType gtk_handle_box_get_type (void); GtkWidget* gtk_handle_box_new (void); void gtk_handle_box_set_shadow_type (GtkHandleBox *handle_box, GtkShadowType type); diff --git a/gtk/gtkhbbox.h b/gtk/gtkhbbox.h index bbd05bcac..5bc651f94 100644 --- a/gtk/gtkhbbox.h +++ b/gtk/gtkhbbox.h @@ -59,7 +59,7 @@ struct _GtkHButtonBoxClass }; -GType gtk_hbutton_box_get_type (void) G_GNUC_CONST; +GType gtk_hbutton_box_get_type (void); GtkWidget* gtk_hbutton_box_new (void); /* buttons can be added by gtk_container_add() */ diff --git a/gtk/gtkhbox.h b/gtk/gtkhbox.h index e547aa359..9a026dec3 100644 --- a/gtk/gtkhbox.h +++ b/gtk/gtkhbox.h @@ -59,7 +59,7 @@ struct _GtkHBoxClass }; -GType gtk_hbox_get_type (void) G_GNUC_CONST; +GType gtk_hbox_get_type (void); GtkWidget * gtk_hbox_new (gboolean homogeneous, gint spacing); diff --git a/gtk/gtkhpaned.h b/gtk/gtkhpaned.h index 2f10427b2..38e5edb41 100644 --- a/gtk/gtkhpaned.h +++ b/gtk/gtkhpaned.h @@ -57,7 +57,7 @@ struct _GtkHPanedClass }; -GType gtk_hpaned_get_type (void) G_GNUC_CONST; +GType gtk_hpaned_get_type (void); GtkWidget * gtk_hpaned_new (void); G_END_DECLS diff --git a/gtk/gtkhruler.h b/gtk/gtkhruler.h index c0e2118b7..9fae3c559 100644 --- a/gtk/gtkhruler.h +++ b/gtk/gtkhruler.h @@ -72,7 +72,7 @@ struct _GtkHRulerClass }; -GType gtk_hruler_get_type (void) G_GNUC_CONST; +GType gtk_hruler_get_type (void); GtkWidget* gtk_hruler_new (void); diff --git a/gtk/gtkhscale.h b/gtk/gtkhscale.h index a90fd4517..7c8e4b712 100644 --- a/gtk/gtkhscale.h +++ b/gtk/gtkhscale.h @@ -59,7 +59,7 @@ struct _GtkHScaleClass }; -GType gtk_hscale_get_type (void) G_GNUC_CONST; +GType gtk_hscale_get_type (void); GtkWidget* gtk_hscale_new (GtkAdjustment *adjustment); GtkWidget* gtk_hscale_new_with_range (gdouble min, gdouble max, diff --git a/gtk/gtkhscrollbar.h b/gtk/gtkhscrollbar.h index e12941ad5..373f1b01e 100644 --- a/gtk/gtkhscrollbar.h +++ b/gtk/gtkhscrollbar.h @@ -60,7 +60,7 @@ struct _GtkHScrollbarClass }; -GType gtk_hscrollbar_get_type (void) G_GNUC_CONST; +GType gtk_hscrollbar_get_type (void); GtkWidget* gtk_hscrollbar_new (GtkAdjustment *adjustment); diff --git a/gtk/gtkhseparator.h b/gtk/gtkhseparator.h index 464f6bcd1..82951c999 100644 --- a/gtk/gtkhseparator.h +++ b/gtk/gtkhseparator.h @@ -59,7 +59,7 @@ struct _GtkHSeparatorClass }; -GType gtk_hseparator_get_type (void) G_GNUC_CONST; +GType gtk_hseparator_get_type (void); GtkWidget* gtk_hseparator_new (void); diff --git a/gtk/gtkhsv.c b/gtk/gtkhsv.c index 2bee85844..ab910896e 100644 --- a/gtk/gtkhsv.c +++ b/gtk/gtkhsv.c @@ -873,6 +873,8 @@ gtk_hsv_motion (GtkWidget *widget, /* Redrawing */ /* Paints the hue ring */ +static const cairo_user_data_key_t pixels_key; + static void paint_ring (GtkHSV *hsv, cairo_t *cr, @@ -953,6 +955,9 @@ paint_ring (GtkHSV *hsv, source = cairo_image_surface_create_for_data ((unsigned char *)buf, CAIRO_FORMAT_RGB24, width, height, stride); + /* the pixels live as long as the surface: cairo may still use them + * after the drawing here, as cairo-quartz does (Ardour found it) */ + cairo_surface_set_user_data (source, &pixels_key, buf, g_free); /* Now draw the value marker onto the source image, so that it * will get properly clipped at the edges of the ring @@ -992,8 +997,6 @@ paint_ring (GtkHSV *hsv, cairo_stroke (cr); cairo_restore (cr); - - g_free (buf); } /* Converts an HSV triplet to an integer RGB triplet */ @@ -1165,6 +1168,9 @@ paint_triangle (GtkHSV *hsv, source = cairo_image_surface_create_for_data ((unsigned char *)buf, CAIRO_FORMAT_RGB24, width, height, stride); + /* the pixels live as long as the surface: cairo may still use them + * after the drawing here, as cairo-quartz does (Ardour found it) */ + cairo_surface_set_user_data (source, &pixels_key, buf, g_free); /* Draw a triangle with the image as a source */ @@ -1177,8 +1183,6 @@ paint_triangle (GtkHSV *hsv, cairo_close_path (cr); cairo_fill (cr); - g_free (buf); - /* Draw value marker */ xx = floor (sx + (vx - sx) * priv->v + (hx - vx) * priv->s * priv->v + 0.5); diff --git a/gtk/gtkhsv.h b/gtk/gtkhsv.h index c352b9922..ad035fafc 100644 --- a/gtk/gtkhsv.h +++ b/gtk/gtkhsv.h @@ -78,7 +78,7 @@ struct _GtkHSVClass }; -GType gtk_hsv_get_type (void) G_GNUC_CONST; +GType gtk_hsv_get_type (void); GtkWidget* gtk_hsv_new (void); void gtk_hsv_set_color (GtkHSV *hsv, double h, diff --git a/gtk/gtkiconcache.c b/gtk/gtkiconcache.c index 7a363f6ac..c73e45b6f 100644 --- a/gtk/gtkiconcache.c +++ b/gtk/gtkiconcache.c @@ -22,6 +22,7 @@ #include "gtkdebug.h" #include "gtkiconcache.h" #include "gtkiconcachevalidator.h" +#include "gtktimeprivate.h" #include "gtkalias.h" #include @@ -101,9 +102,8 @@ _gtk_icon_cache_new_for_path (const gchar *path) GMappedFile *map; gchar *cache_filename; - gint fd = -1; - GStatBuf st; - GStatBuf path_st; + GtkStatBuf st; + GtkStatBuf path_st; /* Check if we have a cache file */ cache_filename = g_build_filename (path, "icon-theme.cache", NULL); @@ -111,44 +111,16 @@ _gtk_icon_cache_new_for_path (const gchar *path) GTK_NOTE (ICONTHEME, g_print ("look for cache in %s\n", path)); - if (g_stat (path, &path_st) < 0) + if (_gtk_stat (path, TRUE, &path_st) < 0) goto done; - /* Open the file and map it into memory */ - fd = g_open (cache_filename, O_RDONLY|_O_BINARY, 0); - - if (fd < 0) + /* The times as 64-bit seconds, where the stat of 32-bit Windows and + * of a 32-bit time_t ends in 2038 */ + if (_gtk_stat (cache_filename, TRUE, &st) < 0 || st.size < 4) goto done; - /* We need to know the correct function to call for the GStatBuf st we are using here, - * because GStatBuf may not be stat on Windows - */ -#ifdef G_OS_WIN32 - if (GLIB_CHECK_VERSION (2, 57, 3)) - { -# ifdef __MINGW64_VERSION_MAJOR -# ifdef _WIN64 -# define gtk_fstat _fstat64 -# else -# define gtk_fstat _fstat32 -# endif -# elif defined (_MSC_VER) && !defined (_WIN64) -# define gtk_fstat _fstat32 -# endif - } -#endif - -#ifndef gtk_fstat -#define gtk_fstat fstat -#endif - - if (gtk_fstat (fd, &st) < 0 || st.st_size < 4) - goto done; - -#undef gtk_fstat - /* Verify cache is uptodate */ - if ((gint64) st.st_mtime < (gint64) path_st.st_mtime) + if (st.mtime < path_st.mtime) { GTK_NOTE (ICONTHEME, g_print ("cache outdated\n")); @@ -189,8 +161,6 @@ _gtk_icon_cache_new_for_path (const gchar *path) done: g_free (cache_filename); - if (fd >= 0) - close (fd); return cache; } @@ -263,6 +233,9 @@ find_image_offset (GtkIconCache *cache, guint32 image_list_offset, n_images; int i; + if (!icon_name) + return 0; + chain_offset = cache->last_chain_offset; if (chain_offset) { @@ -576,6 +549,9 @@ _gtk_icon_cache_get_icon (GtkIconCache *cache, offset = find_image_offset (cache, icon_name, directory_index); + if (!offset) + return NULL; + image_data_offset = GET_UINT32 (cache->buffer, offset + 4); if (!image_data_offset) diff --git a/gtk/gtkiconfactory.c b/gtk/gtkiconfactory.c index dbafe01c0..dae753ef4 100644 --- a/gtk/gtkiconfactory.c +++ b/gtk/gtkiconfactory.c @@ -36,6 +36,7 @@ #include "gtkstock.h" #include "gtkwidget.h" #include "gtkintl.h" +#include "gtkprivate.h" #include "gtkbuildable.h" #include "gtkbuilderprivate.h" #include "gtkalias.h" @@ -1374,6 +1375,7 @@ ensure_filename_pixbuf (GtkIconSet *icon_set, GError *error = NULL; source->filename_pixbuf = gdk_pixbuf_new_from_file (source->source.filename, &error); + _gtk_icon_pixbuf_mark_shared (source->filename_pixbuf); if (source->filename_pixbuf == NULL) { @@ -1394,6 +1396,64 @@ ensure_filename_pixbuf (GtkIconSet *icon_set, return TRUE; } +gint _gtk_loading_hires; + +/* HiDPI: @big becomes the picture GDK draws for @pixbuf on drawables of + * @scale (see _gdk_pixbuf_get_hires()), made to fit exactly; one smaller + * than that would be blurry, its own pixels as blocks are sharper */ +/* HiDPI: the largest scale of the screen's monitors, for which icons + * get a picture of more pixels */ +gint +_gtk_screen_get_hires_scale (GdkScreen *screen) +{ + gint i, n, scale = 1; + + n = gdk_screen_get_n_monitors (screen); + for (i = 0; i < n; i++) + scale = MAX (scale, gdk_screen_get_monitor_scale_factor (screen, i)); + + return scale; +} + +void +_gtk_pixbuf_attach_hires (GdkPixbuf *pixbuf, + GdkPixbuf *big, + gint scale) +{ + gint width, height; + GdkPixbuf *fit; + gchar key[32]; + + if (scale <= 1 || !pixbuf || !big || big == pixbuf) + return; + + width = gdk_pixbuf_get_width (pixbuf) * scale; + height = gdk_pixbuf_get_height (pixbuf) * scale; + if (gdk_pixbuf_get_width (big) < width || gdk_pixbuf_get_height (big) < height || + gdk_pixbuf_get_colorspace (big) != gdk_pixbuf_get_colorspace (pixbuf) || + gdk_pixbuf_get_bits_per_sample (big) != 8) + return; + + if (gdk_pixbuf_get_has_alpha (pixbuf) && !gdk_pixbuf_get_has_alpha (big)) + big = gdk_pixbuf_add_alpha (big, FALSE, 0, 0, 0); + else if (gdk_pixbuf_get_has_alpha (pixbuf) != gdk_pixbuf_get_has_alpha (big)) + return; + else + g_object_ref (big); + + if (gdk_pixbuf_get_width (big) == width && gdk_pixbuf_get_height (big) == height) + fit = g_object_ref (big); + else + fit = gdk_pixbuf_scale_simple (big, width, height, GDK_INTERP_HYPER); + g_object_unref (big); + + if (fit) + { + g_snprintf (key, sizeof key, "gdk-pixbuf-hires-%d", scale); + g_object_set_data_full (G_OBJECT (pixbuf), g_intern_string (key), fit, g_object_unref); + } +} + static GdkPixbuf * render_icon_name_pixbuf (GtkIconSource *icon_source, GtkStyle *style, @@ -1629,6 +1689,109 @@ render_fallback_image (GtkStyle *style, detail); } +/* the icon size of @width by @height pixels, registered for the pictures + * of a higher scale */ +static GtkIconSize +hires_icon_size (gint width, + gint height) +{ + gchar *name = g_strdup_printf ("gtk-hires-%dx%d", width, height); + GtkIconSize size = gtk_icon_size_from_name (name); + + if (size == GTK_ICON_SIZE_INVALID) + size = gtk_icon_size_register (name, width, height); + g_free (name); + + return size; +} + +/* HiDPI: the icon of the set as well in as many more pixels as the + * scale of the screen, attached to @icon, where a source has them (a + * themed or built-in icon, or a picture big enough) */ +static void +attach_icon_set_hires (GtkIconSet *icon_set, + GtkStyle *style, + GtkTextDirection direction, + GtkStateType state, + GtkIconSize size, + GtkWidget *widget, + const char *detail, + GdkPixbuf *icon) +{ + GdkScreen *screen; + GtkSettings *settings; + GtkIconSource *source; + GtkIconSize big_size; + GdkPixbuf *big; + gint scale, width, height; + + if (_gtk_loading_hires || !icon) + return; + + /* given by the rendering of the source already */ + { + gint i; + + for (i = 2; i <= 4; i++) + { + gchar key[32]; + + g_snprintf (key, sizeof key, "gdk-pixbuf-hires-%d", i); + if (g_object_get_data (G_OBJECT (icon), key)) + return; + } + } + + if (widget && gtk_widget_has_screen (widget)) + screen = gtk_widget_get_screen (widget); + else if (style && style->colormap) + screen = gdk_colormap_get_screen (style->colormap); + else + screen = gdk_screen_get_default (); + if (!screen || (scale = _gtk_screen_get_hires_scale (screen)) <= 1) + return; + + settings = gtk_settings_get_for_screen (screen); + if (size == (GtkIconSize) -1 || + !gtk_icon_size_lookup_for_settings (settings, size, &width, &height) || + width * scale > 512 || height * scale > 512) + return; + + big_size = hires_icon_size (width * scale, height * scale); + + /* only a picture of the same source: a theme giving its own picture + * for some sizes keeps it (not the icon theme's, which may differ) */ + source = find_best_matching_source (icon_set, direction, state, big_size, NULL); + if (!source || + source != find_best_matching_source (icon_set, direction, state, size, NULL)) + return; + if (source->type == GTK_ICON_SOURCE_FILENAME && !ensure_filename_pixbuf (icon_set, source)) + return; + if ((source->type == GTK_ICON_SOURCE_FILENAME || source->type == GTK_ICON_SOURCE_PIXBUF) && + (gdk_pixbuf_get_width (source->filename_pixbuf ? source->filename_pixbuf + : source->source.pixbuf) < width * scale)) + return; + if ((source->type == GTK_ICON_SOURCE_ICON_NAME || + source->type == GTK_ICON_SOURCE_STATIC_ICON_NAME) && + !_gtk_icon_theme_same_icon_at_sizes (gtk_icon_theme_get_for_screen (screen), + source->source.icon_name, + MIN (width, height), MIN (width, height) * scale, + source->direction != GTK_TEXT_DIR_NONE + ? GTK_ICON_LOOKUP_USE_BUILTIN : 0)) + return; + + _gtk_loading_hires++; + big = find_and_render_icon_source (icon_set, style, direction, state, big_size, + widget, detail); + _gtk_loading_hires--; + + if (big) + { + _gtk_pixbuf_attach_hires (icon, big, scale); + g_object_unref (big); + } +} + /** * gtk_icon_set_render_icon: * @icon_set: a #GtkIconSet @@ -1688,6 +1851,8 @@ gtk_icon_set_render_icon (GtkIconSet *icon_set, if (icon == NULL) icon = render_fallback_image (style, direction, state, size, widget, detail); + else + attach_icon_set_hires (icon_set, style, direction, state, size, widget, detail, icon); if (detail == NULL) add_to_cache (icon_set, style, direction, state, size, icon); @@ -2495,6 +2660,15 @@ find_in_cache (GtkIconSet *icon_set, return NULL; } +/* Marks a pixbuf GTK made for its icon caches, which no one may change, + * so that gdk_cairo_set_source_pixbuf() can keep its cairo surface. */ +void +_gtk_icon_pixbuf_mark_shared (GdkPixbuf *pixbuf) +{ + if (pixbuf) + g_object_set_data (G_OBJECT (pixbuf), I_("gdk-pixbuf-shared"), GINT_TO_POINTER (TRUE)); +} + static void add_to_cache (GtkIconSet *icon_set, GtkStyle *style, @@ -2504,11 +2678,24 @@ add_to_cache (GtkIconSet *icon_set, GdkPixbuf *pixbuf) { CachedIcon *icon; + GSList *l; ensure_cache_up_to_date (icon_set); g_object_ref (pixbuf); + /* what is cached here is handed out to everyone, but a pixbuf + * the application gave as a source stays its own */ + for (l = icon_set->sources; l; l = l->next) + { + GtkIconSource *source = l->data; + + if (source->type == GTK_ICON_SOURCE_PIXBUF && source->source.pixbuf == pixbuf) + break; + } + if (!l) + _gtk_icon_pixbuf_mark_shared (pixbuf); + /* We have to ref the style, since if the style was finalized * its address could be reused by another style, creating a * really weird bug diff --git a/gtk/gtkiconfactory.h b/gtk/gtkiconfactory.h index ea97123bd..a27962172 100644 --- a/gtk/gtkiconfactory.h +++ b/gtk/gtkiconfactory.h @@ -71,7 +71,7 @@ struct _GtkIconFactoryClass #define gtk_icon_source_get_filename gtk_icon_source_get_filename_utf8 #endif -GType gtk_icon_factory_get_type (void) G_GNUC_CONST; +GType gtk_icon_factory_get_type (void); GtkIconFactory* gtk_icon_factory_new (void); void gtk_icon_factory_add (GtkIconFactory *factory, const gchar *stock_id, @@ -116,7 +116,7 @@ const gchar * gtk_icon_size_get_name (GtkIconSize size); /* Icon sets */ -GType gtk_icon_set_get_type (void) G_GNUC_CONST; +GType gtk_icon_set_get_type (void); GtkIconSet* gtk_icon_set_new (void); GtkIconSet* gtk_icon_set_new_from_pixbuf (GdkPixbuf *pixbuf); @@ -143,7 +143,7 @@ void gtk_icon_set_get_sizes (GtkIconSet *icon_set, GtkIconSize **sizes, gint *n_sizes); -GType gtk_icon_source_get_type (void) G_GNUC_CONST; +GType gtk_icon_source_get_type (void); GtkIconSource* gtk_icon_source_new (void); GtkIconSource* gtk_icon_source_copy (const GtkIconSource *source); void gtk_icon_source_free (GtkIconSource *source); @@ -183,6 +183,7 @@ GtkIconSize gtk_icon_source_get_size (const GtkIconSource * void _gtk_icon_set_invalidate_caches (void); GList* _gtk_icon_factory_list_ids (void); void _gtk_icon_factory_ensure_default_icons (void); +void _gtk_icon_pixbuf_mark_shared (GdkPixbuf *pixbuf); G_END_DECLS diff --git a/gtk/gtkicontheme.c b/gtk/gtkicontheme.c index f8aaf9a3b..23acac11e 100644 --- a/gtk/gtkicontheme.c +++ b/gtk/gtkicontheme.c @@ -26,6 +26,7 @@ #endif #include #include +#include #include #include @@ -46,6 +47,7 @@ #include "gtkmain.h" #include "gtksettings.h" #include "gtkprivate.h" +#include "gtktimeprivate.h" #include "gtkalias.h" #define DEFAULT_THEME_NAME "hicolor" @@ -98,13 +100,27 @@ struct _GtkIconThemePrivate */ GdkScreen *screen; - /* time when we last stat:ed for theme changes */ + /* time when we last stat:ed for theme changes (monotonic seconds) */ gint64 last_stat_time; GList *dir_mtimes; gulong reset_styles_idle; + + /* the icons loaded last with gtk_icon_theme_load_icon(), most recent + * first, as tree views and menus load the same few again and again */ + struct { + gchar *name; + gint size; + GtkIconLookupFlags flags; + GdkPixbuf *pixbuf; + } loaded[32]; + guint n_loaded; + guint loaded_builtin_serial; }; +/* icons small enough to be kept: 48 × 48 */ +#define MAX_LOADED_PIXELS (48 * 48) + struct _GtkIconInfo { /* Information about the source @@ -198,6 +214,7 @@ typedef struct gboolean exists; GtkIconCache *cache; + gboolean cache_tried; /* a theme reads its cache once, not per directory */ } IconThemeDirMtime; static void gtk_icon_theme_finalize (GObject *object); @@ -246,6 +263,7 @@ static BuiltinIcon *find_builtin_icon (const gchar *icon_name, static guint signal_changed = 0; static GHashTable *icon_theme_builtin_icons; +static guint icon_theme_builtin_serial; /* changes as builtin icons are added */ /* also used in gtkiconfactory.c */ GtkIconCache *_builtin_cache = NULL; @@ -638,11 +656,24 @@ do_theme_change (GtkIconTheme *icon_theme) reset_styles_idle, icon_theme, NULL); } +static void +forget_loaded_icons (GtkIconThemePrivate *priv) +{ + while (priv->n_loaded > 0) + { + priv->n_loaded--; + g_free (priv->loaded[priv->n_loaded].name); + g_object_unref (priv->loaded[priv->n_loaded].pixbuf); + } +} + static void blow_themes (GtkIconTheme *icon_theme) { GtkIconThemePrivate *priv = icon_theme->priv; + forget_loaded_icons (priv); + if (priv->themes_valid) { g_hash_table_destroy (priv->all_icons); @@ -899,7 +930,7 @@ insert_theme (GtkIconTheme *icon_theme, const char *theme_name) GKeyFile *theme_file; GError *error = NULL; IconThemeDirMtime *dir_mtime; - GStatBuf stat_buf; + GtkStatBuf stat_buf; priv = icon_theme->priv; @@ -917,10 +948,11 @@ insert_theme (GtkIconTheme *icon_theme, const char *theme_name) NULL); dir_mtime = g_slice_new (IconThemeDirMtime); dir_mtime->cache = NULL; + dir_mtime->cache_tried = FALSE; dir_mtime->dir = path; - if (g_stat (path, &stat_buf) == 0 && S_ISDIR (stat_buf.st_mode)) + if (_gtk_stat (path, TRUE, &stat_buf) == 0 && S_ISDIR (stat_buf.mode)) { - dir_mtime->mtime = (gint64) stat_buf.st_mtime; + dir_mtime->mtime = stat_buf.mtime; dir_mtime->exists = TRUE; } else @@ -1048,7 +1080,7 @@ load_themes (GtkIconTheme *icon_theme) UnthemedIcon *unthemed_icon; IconSuffix old_suffix, new_suffix; IconThemeDirMtime *dir_mtime; - GStatBuf stat_buf; + GtkStatBuf stat_buf; priv = icon_theme->priv; @@ -1078,10 +1110,11 @@ load_themes (GtkIconTheme *icon_theme) dir_mtime->mtime = 0; dir_mtime->exists = FALSE; dir_mtime->cache = NULL; + dir_mtime->cache_tried = TRUE; - if (g_stat (dir, &stat_buf) != 0 || !S_ISDIR (stat_buf.st_mode)) + if (_gtk_stat (dir, TRUE, &stat_buf) != 0 || !S_ISDIR (stat_buf.mode)) continue; - dir_mtime->mtime = (gint64) stat_buf.st_mtime; + dir_mtime->mtime = stat_buf.mtime; dir_mtime->exists = TRUE; dir_mtime->cache = _gtk_icon_cache_new_for_path (dir); @@ -1155,7 +1188,7 @@ load_themes (GtkIconTheme *icon_theme) priv->themes_valid = TRUE; - priv->last_stat_time = g_get_real_time () / G_USEC_PER_SEC; + priv->last_stat_time = g_get_monotonic_time () / G_USEC_PER_SEC; } void @@ -1163,9 +1196,11 @@ _gtk_icon_theme_ensure_builtin_cache (void) { static gboolean initialized = FALSE; IconThemeDir *dir; - static IconThemeDir dirs[5] = + /* all the sizes GTK+ asks for, rendered from the SVGs (render-sizes.py) */ + static IconThemeDir dirs[6] = { { ICON_THEME_DIR_THRESHOLD, 0, 16, 16, 16, 2, NULL, "16", -1, NULL, NULL, NULL }, + { ICON_THEME_DIR_THRESHOLD, 0, 18, 18, 18, 2, NULL, "18", -1, NULL, NULL, NULL }, { ICON_THEME_DIR_THRESHOLD, 0, 20, 20, 20, 2, NULL, "20", -1, NULL, NULL, NULL }, { ICON_THEME_DIR_THRESHOLD, 0, 24, 24, 24, 2, NULL, "24", -1, NULL, NULL, NULL }, { ICON_THEME_DIR_THRESHOLD, 0, 32, 32, 32, 2, NULL, "32", -1, NULL, NULL, NULL }, @@ -1205,7 +1240,7 @@ ensure_valid_themes (GtkIconTheme *icon_theme) if (priv->themes_valid) { - now = g_get_real_time () / G_USEC_PER_SEC; + now = g_get_monotonic_time () / G_USEC_PER_SEC; if (ABS (now - priv->last_stat_time) > 5 && rescan_themes (icon_theme)) @@ -1497,6 +1532,89 @@ gtk_icon_theme_error_quark (void) return g_quark_from_static_string ("gtk-icon-theme-error-quark"); } +static GdkPixbuf * +load_icon_unscaled (GtkIconTheme *icon_theme, + const gchar *icon_name, + gint size, + GtkIconLookupFlags flags, + GError **error) +{ + GtkIconThemePrivate *priv; + GtkIconInfo *icon_info; + GdkPixbuf *pixbuf = NULL; + guint i; + + g_return_val_if_fail (GTK_IS_ICON_THEME (icon_theme), NULL); + g_return_val_if_fail (icon_name != NULL, NULL); + g_return_val_if_fail ((flags & GTK_ICON_LOOKUP_NO_SVG) == 0 || + (flags & GTK_ICON_LOOKUP_FORCE_SVG) == 0, NULL); + g_return_val_if_fail (error == NULL || *error == NULL, NULL); + + priv = icon_theme->priv; + + /* notices changed themes, which forget the loaded icons */ + ensure_valid_themes (icon_theme); + + if (priv->loaded_builtin_serial != icon_theme_builtin_serial) + { + forget_loaded_icons (priv); + priv->loaded_builtin_serial = icon_theme_builtin_serial; + } + + /* A copy of the one loaded last time, instead of reading and + * scaling the file again; a copy, as programs may change it, which + * the documentation forbids, but which worked before. */ + for (i = 0; i < priv->n_loaded; i++) + if (priv->loaded[i].size == size && priv->loaded[i].flags == flags && + strcmp (priv->loaded[i].name, icon_name) == 0) + { + if (i > 0) + { + __typeof__ (priv->loaded[0]) hit = priv->loaded[i]; + + memmove (priv->loaded + 1, priv->loaded, i * sizeof (priv->loaded[0])); + priv->loaded[0] = hit; + } + + return gdk_pixbuf_copy (priv->loaded[0].pixbuf); + } + + icon_info = gtk_icon_theme_lookup_icon (icon_theme, icon_name, size, + flags | GTK_ICON_LOOKUP_USE_BUILTIN); + if (!icon_info) + { + g_set_error (error, GTK_ICON_THEME_ERROR, GTK_ICON_THEME_NOT_FOUND, + _("Icon '%s' not present in theme"), icon_name); + return NULL; + } + + pixbuf = gtk_icon_info_load_icon (icon_info, error); + gtk_icon_info_free (icon_info); + + if (pixbuf && + gdk_pixbuf_get_width (pixbuf) * gdk_pixbuf_get_height (pixbuf) <= MAX_LOADED_PIXELS) + { + if (priv->n_loaded == G_N_ELEMENTS (priv->loaded)) + { + priv->n_loaded--; + g_free (priv->loaded[priv->n_loaded].name); + g_object_unref (priv->loaded[priv->n_loaded].pixbuf); + } + + memmove (priv->loaded + 1, priv->loaded, priv->n_loaded * sizeof (priv->loaded[0])); + priv->loaded[0].name = g_strdup (icon_name); + priv->loaded[0].size = size; + priv->loaded[0].flags = flags; + priv->loaded[0].pixbuf = gdk_pixbuf_copy (pixbuf); + priv->n_loaded++; + } + + return pixbuf; +} + +/* HiDPI: on a screen of a higher scale the icon carries one of that + * many more pixels (_gtk_pixbuf_attach_hires()), which GDK draws then */ + /** * gtk_icon_theme_load_icon: * @icon_theme: a #GtkIconTheme @@ -1526,6 +1644,70 @@ gtk_icon_theme_error_quark (void) * * Since: 2.4 **/ +/* HiDPI: whether the icon of @icon_name looked up at @size and at + * @big_size is the same picture: from the same theme, of the same file + * name, or both built into GTK+ (a theme may have one icon at some + * sizes, another one, or none, at others) */ +static gchar * +icon_info_theme_dir (const gchar *filename) +{ + gchar *a = g_path_get_dirname (filename), *b, *c; + + /* /// */ + b = g_path_get_dirname (a); + c = g_path_get_dirname (b); + g_free (a); + g_free (b); + return c; +} + +gboolean +_gtk_icon_theme_same_icon_at_sizes (GtkIconTheme *icon_theme, + const gchar *icon_name, + gint size, + gint big_size, + GtkIconLookupFlags flags) +{ + GtkIconInfo *small, *big; + gboolean same = FALSE; + + small = gtk_icon_theme_lookup_icon (icon_theme, icon_name, size, flags); + big = gtk_icon_theme_lookup_icon (icon_theme, icon_name, big_size, flags); + + if (small && big) + { + const gchar *sf = gtk_icon_info_get_filename (small); + const gchar *bf = gtk_icon_info_get_filename (big); + + if (!sf && !bf) + same = gtk_icon_info_get_builtin_pixbuf (small) != NULL && + gtk_icon_info_get_builtin_pixbuf (big) != NULL; + else if (sf && bf) + { + gchar *sd = icon_info_theme_dir (sf), *bd = icon_info_theme_dir (bf); + gchar *sb = g_path_get_basename (sf), *bb = g_path_get_basename (bf); + gchar *dot; + + if ((dot = strrchr (sb, '.'))) + *dot = '\0'; + if ((dot = strrchr (bb, '.'))) + *dot = '\0'; + same = strcmp (sd, bd) == 0 && strcmp (sb, bb) == 0; + g_free (sd); + g_free (bd); + g_free (sb); + g_free (bb); + } + } + + if (small) + gtk_icon_info_free (small); + if (big) + gtk_icon_info_free (big); + + return same; +} + GdkPixbuf * gtk_icon_theme_load_icon (GtkIconTheme *icon_theme, const gchar *icon_name, @@ -1533,27 +1715,26 @@ gtk_icon_theme_load_icon (GtkIconTheme *icon_theme, GtkIconLookupFlags flags, GError **error) { - GtkIconInfo *icon_info; - GdkPixbuf *pixbuf = NULL; + GdkPixbuf *pixbuf, *big; + gint scale; - g_return_val_if_fail (GTK_IS_ICON_THEME (icon_theme), NULL); - g_return_val_if_fail (icon_name != NULL, NULL); - g_return_val_if_fail ((flags & GTK_ICON_LOOKUP_NO_SVG) == 0 || - (flags & GTK_ICON_LOOKUP_FORCE_SVG) == 0, NULL); - g_return_val_if_fail (error == NULL || *error == NULL, NULL); + pixbuf = load_icon_unscaled (icon_theme, icon_name, size, flags, error); - icon_info = gtk_icon_theme_lookup_icon (icon_theme, icon_name, size, - flags | GTK_ICON_LOOKUP_USE_BUILTIN); - if (!icon_info) + if (pixbuf && !_gtk_loading_hires && icon_theme->priv->screen && size > 0 && + (scale = _gtk_screen_get_hires_scale (icon_theme->priv->screen)) > 1 && + size * scale <= 512 && + _gtk_icon_theme_same_icon_at_sizes (icon_theme, icon_name, size, size * scale, flags)) { - g_set_error (error, GTK_ICON_THEME_ERROR, GTK_ICON_THEME_NOT_FOUND, - _("Icon '%s' not present in theme"), icon_name); - return NULL; + _gtk_loading_hires++; + big = load_icon_unscaled (icon_theme, icon_name, size * scale, flags, NULL); + _gtk_loading_hires--; + if (big) + { + _gtk_pixbuf_attach_hires (pixbuf, big, scale); + g_object_unref (big); + } } - pixbuf = gtk_icon_info_load_icon (icon_info, error); - gtk_icon_info_free (icon_info); - return pixbuf; } @@ -1893,7 +2074,7 @@ rescan_themes (GtkIconTheme *icon_theme) IconThemeDirMtime *dir_mtime; GList *d; int stat_res; - GStatBuf stat_buf; + GtkStatBuf stat_buf; priv = icon_theme->priv; @@ -1901,22 +2082,22 @@ rescan_themes (GtkIconTheme *icon_theme) { dir_mtime = d->data; - stat_res = g_stat (dir_mtime->dir, &stat_buf); + stat_res = _gtk_stat (dir_mtime->dir, TRUE, &stat_buf); /* dir mtime didn't change */ if (stat_res == 0 && dir_mtime->exists && - S_ISDIR (stat_buf.st_mode) && - dir_mtime->mtime == (gint64) stat_buf.st_mtime) + S_ISDIR (stat_buf.mode) && + dir_mtime->mtime == stat_buf.mtime) continue; /* didn't exist before, and still doesn't */ if (!dir_mtime->exists && - (stat_res != 0 || !S_ISDIR (stat_buf.st_mode))) + (stat_res != 0 || !S_ISDIR (stat_buf.mode))) continue; return TRUE; } - priv->last_stat_time = g_get_real_time () / G_USEC_PER_SEC; + priv->last_stat_time = g_get_monotonic_time () / G_USEC_PER_SEC; return FALSE; } @@ -2097,17 +2278,19 @@ theme_lookup_icon (IconTheme *theme, gboolean use_builtin) { GList *dirs, *l; - IconThemeDir *dir, *min_dir; + IconThemeDir *dir, *min_dir, *double_dir; char *file; int min_difference, difference; BuiltinIcon *closest_builtin = NULL; - gboolean smaller, has_larger, match; + gboolean smaller, has_larger, match, scalable_match; IconSuffix suffix; min_difference = G_MAXINT; min_dir = NULL; + double_dir = NULL; has_larger = FALSE; match = FALSE; + scalable_match = FALSE; /* Builtin icons are logically part of the default theme and * are searched before other subdirectories of the default theme. @@ -2149,6 +2332,7 @@ theme_lookup_icon (IconTheme *theme, if (!match) { min_dir = dir; + scalable_match = TRUE; break; } } @@ -2169,6 +2353,11 @@ theme_lookup_icon (IconTheme *theme, } } + /* the smallest bitmap of twice the size or more */ + if (dir->type != ICON_THEME_DIR_SCALABLE && dir->size >= 2 * size && + (double_dir == NULL || dir->size < double_dir->size)) + double_dir = dir; + if (!match) { if (!has_larger) @@ -2200,6 +2389,12 @@ theme_lookup_icon (IconTheme *theme, } } + /* A size there is no picture of is made, as Mac OS X does, from one of + * twice the size or more where there is one, made smaller: sharper than + * from the next larger one, or enlarged from a smaller one */ + if (!match && !scalable_match && double_dir != NULL) + min_dir = double_dir; + if (min_dir) { GtkIconInfo *icon_info = icon_info_new (); @@ -2267,6 +2462,7 @@ theme_lookup_icon (IconTheme *theme, { icon_info->cache_pixbuf = _gtk_icon_cache_get_icon (min_dir->cache, icon_name, min_dir->subdir_index); + _gtk_icon_pixbuf_mark_shared (icon_info->cache_pixbuf); } icon_info->dir_type = min_dir->type; @@ -2327,8 +2523,12 @@ theme_list_contexts (IconTheme *theme, { dir = l->data; - context = g_quark_to_string (dir->context); - g_hash_table_replace (contexts, (gpointer) context, NULL); + /* the Context key is optional */ + if (dir->context != 0) + { + context = g_quark_to_string (dir->context); + g_hash_table_replace (contexts, (gpointer) context, NULL); + } l = l->next; } @@ -2487,6 +2687,37 @@ theme_subdir_load (GtkIconTheme *icon_theme, GError *error = NULL; IconThemeDirMtime *dir_mtime; + /* Most directories an index.theme names are not there: those cost no + * reading of their keys */ + for (d = icon_theme->priv->dir_mtimes; d; d = d->next) + { + gboolean there; + + dir_mtime = (IconThemeDirMtime *)d->data; + if (!dir_mtime->exists) + continue; + + if (!dir_mtime->cache_tried) + { + /* NULL if there is no cache, or an outdated one */ + dir_mtime->cache = _gtk_icon_cache_new_for_path (dir_mtime->dir); + dir_mtime->cache_tried = TRUE; + } + + if (dir_mtime->cache) + there = _gtk_icon_cache_get_directory_index (dir_mtime->cache, subdir) >= 0; + else + { + full_dir = g_build_filename (dir_mtime->dir, subdir, NULL); + there = g_file_test (full_dir, G_FILE_TEST_IS_DIR); + g_free (full_dir); + } + if (there) + break; + } + if (d == NULL) + return; + size = g_key_file_get_integer (theme_file, subdir, "Size", &error); if (error) { @@ -2554,15 +2785,9 @@ theme_subdir_load (GtkIconTheme *icon_theme, full_dir = g_build_filename (dir_mtime->dir, subdir, NULL); - /* First, see if we have a cache for the directory */ + /* the cache was read above */ if (dir_mtime->cache != NULL || g_file_test (full_dir, G_FILE_TEST_IS_DIR)) { - if (dir_mtime->cache == NULL) - { - /* This will return NULL if the cache doesn't exist or is outdated */ - dir_mtime->cache = _gtk_icon_cache_new_for_path (dir_mtime->dir); - } - dir = g_new (IconThemeDir, 1); dir->type = type; dir->context = context; @@ -2585,7 +2810,14 @@ theme_subdir_load (GtkIconTheme *icon_theme, scan_directory (icon_theme->priv, dir, full_dir); } - theme->dirs = g_list_prepend (theme->dirs, dir); + /* An index.theme names hundreds of directories (hicolor 649), + * of which a theme fills a few; empty ones would only be walked + * at every lookup. With a cache, it has those that exist. */ + if (dir->cache ? dir->subdir_index < 0 : + g_hash_table_size (dir->icons) == 0 && dir->icon_data == NULL) + theme_dir_destroy (dir); + else + theme->dirs = g_list_prepend (theme->dirs, dir); } else g_free (full_dir); @@ -2691,6 +2923,8 @@ gtk_icon_info_free (GtkIconInfo *icon_info) g_object_unref (icon_info->pixbuf); if (icon_info->cache_pixbuf) g_object_unref (icon_info->cache_pixbuf); + if (icon_info->load_error) + g_error_free (icon_info->load_error); g_slice_free (GtkIconInfo, icon_info); } @@ -2853,34 +3087,219 @@ apply_emblems (GtkIconInfo *info) { g_object_unref (info->pixbuf); info->pixbuf = icon; + _gtk_icon_pixbuf_mark_shared (icon); } info->emblems_applied = TRUE; } -static GdkInterpType -icon_info_get_scale_interp_type (gint image_width, - gint image_height, - gdouble scale) +/* The weights of a Lanczos-3 filter that makes @src samples into @dst + * (fewer) ones: for each output sample, the first input sample and + * three times the reduction worth of weights */ +typedef struct { - gint image_size; + gint first; + gint n; + gfloat *w; +} ReduceTaps; - image_size = MAX (image_width, image_height); +static gfloat +lanczos3 (gdouble t) +{ + if (t < 0) + t = -t; + if (t < 1e-6) + return 1.f; + if (t >= 3.0) + return 0.f; + return (gfloat) (3.0 * sin (G_PI * t) * sin (G_PI * t / 3.0) / (G_PI * G_PI * t * t)); +} - /* - * Strongly upscaling small bitmap icons with bilinear filtering makes - * them blurry and costs more CPU. Keep bilinear filtering for larger - * sources and moderate scaling, but use nearest-neighbour scaling for - * tiny bitmap icons that are enlarged substantially. - * - * This decision is made only when the icon pixbuf is created. Cached - * pixbufs are reused while scrolling and drawing. - */ -/*if (image_size > 0 && image_size <= 64 && scale >= 3.0) */ - if (image_size > 0 && image_size <= 64 && scale >= 2.0) - return GDK_INTERP_NEAREST; +static ReduceTaps * +reduce_taps (gint src, + gint dst) +{ + ReduceTaps *taps = g_new (ReduceTaps, dst); + gdouble scale = (gdouble) dst / src; + gdouble support = 3.0 / scale; + gint x, i; - return GDK_INTERP_BILINEAR; + for (x = 0; x < dst; x++) + { + gdouble center = (x + 0.5) / scale; + gint first = (gint) floor (center - support); + gint last = (gint) ceil (center + support); + gfloat sum = 0.f; + + taps[x].first = first; + taps[x].n = last - first; + taps[x].w = g_new (gfloat, taps[x].n); + for (i = 0; i < taps[x].n; i++) + { + taps[x].w[i] = lanczos3 ((first + i + 0.5 - center) * scale); + sum += taps[x].w[i]; + } + for (i = 0; i < taps[x].n; i++) + taps[x].w[i] /= sum; + } + + return taps; +} + +static void +reduce_taps_free (ReduceTaps *taps, + gint n) +{ + gint i; + + for (i = 0; i < n; i++) + g_free (taps[i].w); + g_free (taps); +} + +/* Makes an icon smaller with a Lanczos filter, as Mac OS X makes a + * picture of twice the size smaller: sharper than the bilinear filter + * of gdk-pixbuf, which averages. In premultiplied colour, so the + * colours of transparent pixels do not bleed into the edges. */ +static GdkPixbuf * +icon_reduce (GdkPixbuf *source, + gint dest_width, + gint dest_height) +{ + gint sw = gdk_pixbuf_get_width (source); + gint sh = gdk_pixbuf_get_height (source); + gint n_channels = gdk_pixbuf_get_n_channels (source); + gboolean alpha = gdk_pixbuf_get_has_alpha (source); + gint srs = gdk_pixbuf_get_rowstride (source); + const guchar *spix = gdk_pixbuf_get_pixels (source); + ReduceTaps *htaps, *vtaps; + GdkPixbuf *dest; + gfloat *in, *tmp; + gint x, y, c, i; + + if (dest_width >= sw || dest_height >= sh || + gdk_pixbuf_get_bits_per_sample (source) != 8 || (n_channels != 3 && n_channels != 4)) + return gdk_pixbuf_scale_simple (source, dest_width, dest_height, GDK_INTERP_BILINEAR); + + dest = gdk_pixbuf_new (GDK_COLORSPACE_RGB, alpha, 8, dest_width, dest_height); + if (dest == NULL) + return NULL; + + in = g_new (gfloat, (gsize) sw * sh * 4); + for (y = 0; y < sh; y++) + for (x = 0; x < sw; x++) + { + const guchar *p = spix + y * srs + x * n_channels; + gfloat a = alpha ? p[3] / 255.f : 1.f; + gfloat *q = in + ((gsize) y * sw + x) * 4; + + q[0] = p[0] * a; + q[1] = p[1] * a; + q[2] = p[2] * a; + q[3] = a; + } + + /* across, then down */ + htaps = reduce_taps (sw, dest_width); + tmp = g_new0 (gfloat, (gsize) dest_width * sh * 4); + for (y = 0; y < sh; y++) + for (x = 0; x < dest_width; x++) + { + gfloat *q = tmp + ((gsize) y * dest_width + x) * 4; + + for (i = 0; i < htaps[x].n; i++) + { + gint sx = CLAMP (htaps[x].first + i, 0, sw - 1); + const gfloat *s = in + ((gsize) y * sw + sx) * 4; + + for (c = 0; c < 4; c++) + q[c] += htaps[x].w[i] * s[c]; + } + } + reduce_taps_free (htaps, dest_width); + g_free (in); + + vtaps = reduce_taps (sh, dest_height); + for (y = 0; y < dest_height; y++) + { + guchar *row = gdk_pixbuf_get_pixels (dest) + y * gdk_pixbuf_get_rowstride (dest); + + for (x = 0; x < dest_width; x++) + { + gfloat v[4] = { 0.f, 0.f, 0.f, 0.f }; + guchar *p = row + x * (alpha ? 4 : 3); + + for (i = 0; i < vtaps[y].n; i++) + { + gint sy = CLAMP (vtaps[y].first + i, 0, sh - 1); + const gfloat *s = tmp + ((gsize) sy * dest_width + x) * 4; + + for (c = 0; c < 4; c++) + v[c] += vtaps[y].w[i] * s[c]; + } + v[3] = CLAMP (v[3], 0.f, 1.f); + for (c = 0; c < 3; c++) + { + gfloat u = v[3] > 0.f ? v[c] / v[3] : 0.f; + p[c] = (guchar) CLAMP (u + 0.5f, 0.f, 255.f); + } + if (alpha) + p[3] = (guchar) (v[3] * 255.f + 0.5f); + } + } + reduce_taps_free (vtaps, dest_height); + g_free (tmp); + + return dest; +} + +/* Scales an icon to @dest_width x @dest_height: smaller with + * icon_reduce(). + * + * Strongly upscaling small bitmap icons with bilinear filtering makes + * them blurry. For tiny bitmap icons enlarged two times or more, each + * source pixel becomes a block of whole pixels instead (nearest), as + * many as fit, and only what is left of the factor is filtered + * (bilinear): at 2x and 3x the blocks are all alike, and at 2.5x they + * do not alternate between two and three pixels as with nearest alone. + * Larger sources and moderate scaling keep bilinear filtering. + * + * This is done only when the icon pixbuf is created. Cached pixbufs + * are reused while scrolling and drawing. + */ +static GdkPixbuf * +icon_scale_pixbuf (GdkPixbuf *source, + gint dest_width, + gint dest_height, + gdouble scale) +{ + gint width = gdk_pixbuf_get_width (source); + gint height = gdk_pixbuf_get_height (source); + gint image_size = MAX (width, height); + GdkPixbuf *blocks, *scaled; + gint k; + + if (dest_width < width && dest_height < height) + return icon_reduce (source, dest_width, dest_height); + + if (image_size <= 0 || image_size > 64 || scale < 2.0) + return gdk_pixbuf_scale_simple (source, dest_width, dest_height, + GDK_INTERP_BILINEAR); + + k = MIN (dest_width / width, dest_height / height); + if (k < 2 || (width * k == dest_width && height * k == dest_height)) + return gdk_pixbuf_scale_simple (source, dest_width, dest_height, + GDK_INTERP_NEAREST); + + blocks = gdk_pixbuf_scale_simple (source, width * k, height * k, + GDK_INTERP_NEAREST); + if (!blocks) + return NULL; + scaled = gdk_pixbuf_scale_simple (blocks, dest_width, dest_height, + GDK_INTERP_BILINEAR); + g_object_unref (blocks); + + return scaled; } /* This function contains the complicated logic for deciding @@ -2923,12 +3342,19 @@ icon_info_ensure_scale_and_pixbuf (GtkIconInfo *icon_info, } is_svg = FALSE; - if (G_IS_FILE_ICON (icon_info->loadable)) + if (icon_info->filename) + { + /* Themed and unthemed theme icons: the suffix is already known, + * no need for a blocking content type query per load. + */ + is_svg = suffix_from_name (icon_info->filename) == ICON_SUFFIX_SVG; + } + else if (G_IS_FILE_ICON (icon_info->loadable)) { GFile *file; GFileInfo *file_info; const gchar *content_type; - const gchar *mime_type; + gchar *mime_type; file = g_file_icon_get_file (G_FILE_ICON (icon_info->loadable)); file_info = g_file_query_info (file, @@ -2949,6 +3375,7 @@ icon_info_ensure_scale_and_pixbuf (GtkIconInfo *icon_info, else if (content_type && strcmp (content_type, ".svg") == 0) is_svg = TRUE; #endif + g_free (mime_type); } g_object_unref (file_info); @@ -2970,12 +3397,21 @@ icon_info_ensure_scale_and_pixbuf (GtkIconInfo *icon_info, &icon_info->load_error); if (stream) { - icon_info->pixbuf = gdk_pixbuf_new_from_stream_at_scale (stream, - icon_info->desired_size, - icon_info->desired_size, - TRUE, - NULL, - &icon_info->load_error); + /* As Mac OS X does: drawn at twice the size, then made smaller */ + GdkPixbuf *twice = gdk_pixbuf_new_from_stream_at_scale (stream, + 2 * icon_info->desired_size, + 2 * icon_info->desired_size, + TRUE, + NULL, + &icon_info->load_error); + if (twice) + { + icon_info->pixbuf = icon_reduce (twice, + MAX (1, (gdk_pixbuf_get_width (twice) + 1) / 2), + MAX (1, (gdk_pixbuf_get_height (twice) + 1) / 2)); + g_object_unref (twice); + } + _gtk_icon_pixbuf_mark_shared (icon_info->pixbuf); g_object_unref (stream); } @@ -3032,6 +3468,7 @@ icon_info_ensure_scale_and_pixbuf (GtkIconInfo *icon_info, source_pixbuf = gdk_pixbuf_new_from_stream (stream, NULL, &icon_info->load_error); + _gtk_icon_pixbuf_mark_shared (source_pixbuf); g_object_unref (stream); } } @@ -3068,12 +3505,12 @@ icon_info_ensure_scale_and_pixbuf (GtkIconInfo *icon_info, icon_info->pixbuf = source_pixbuf; else { - icon_info->pixbuf = gdk_pixbuf_scale_simple (source_pixbuf, - 0.5 + image_width * icon_info->scale, - 0.5 + image_height * icon_info->scale, - icon_info_get_scale_interp_type (image_width, - image_height, - icon_info->scale)); + /* never 0 pixels, even for a very long and thin image */ + icon_info->pixbuf = icon_scale_pixbuf (source_pixbuf, + MAX (1, 0.5 + image_width * icon_info->scale), + MAX (1, 0.5 + image_height * icon_info->scale), + icon_info->scale); + _gtk_icon_pixbuf_mark_shared (icon_info->pixbuf); g_object_unref (source_pixbuf); } @@ -3116,8 +3553,9 @@ gtk_icon_info_load_icon (GtkIconInfo *icon_info, if (!icon_info_ensure_scale_and_pixbuf (icon_info, FALSE)) { + /* the info keeps its error for the next call */ if (icon_info->load_error) - g_propagate_error (error, icon_info->load_error); + g_propagate_error (error, g_error_copy (icon_info->load_error)); else g_set_error_literal (error, GTK_ICON_THEME_ERROR, @@ -3381,6 +3819,7 @@ gtk_icon_theme_add_builtin_icon (const gchar *icon_name, /* Replaces value, leaves key untouched */ g_hash_table_insert (icon_theme_builtin_icons, key, icons); + icon_theme_builtin_serial++; } /* Look up a builtin icon; the min_difference_p and @@ -3421,11 +3860,25 @@ find_builtin_icon (const gchar *icon_name, else difference = 0; + /* within the threshold: a match, but one of exactly the size + * (the builtin icons come in all the sizes GTK+ asks for) is + * looked for further */ if (difference == 0) { + if (min_difference != 0 || default_icon->size == size) + min_icon = default_icon; min_difference = 0; - min_icon = default_icon; - break; + if (default_icon->size == size) + break; + icons = icons->next; + continue; + } + + /* a match within the threshold beats any icon to be scaled */ + if (min_difference == 0) + { + icons = icons->next; + continue; } if (!has_larger) @@ -3510,7 +3963,11 @@ gtk_icon_theme_lookup_by_gicon (GtkIconTheme *icon_theme, g_return_val_if_fail (GTK_IS_ICON_THEME (icon_theme), NULL); g_return_val_if_fail (G_IS_ICON (icon), NULL); - if (G_IS_LOADABLE_ICON (icon)) + /* Newer gdk-pixbuf makes GdkPixbuf a GLoadableIcon; handle pixbufs in + * the GDK_IS_PIXBUF() branch below instead of round-tripping them + * through a PNG stream (which is slow and rescales them to @size). + */ + if (G_IS_LOADABLE_ICON (icon) && !GDK_IS_PIXBUF (icon)) { info = icon_info_new (); info->loadable = G_LOADABLE_ICON (g_object_ref (icon)); @@ -3572,12 +4029,10 @@ gtk_icon_theme_lookup_by_gicon (GtkIconTheme *icon_theme, max = MAX (width, height); scale = (gdouble) size / (gdouble) max; - scaled = gdk_pixbuf_scale_simple (pixbuf, - 0.5 + width * scale, - 0.5 + height * scale, - icon_info_get_scale_interp_type (width, - height, - scale)); + scaled = icon_scale_pixbuf (pixbuf, + MAX (1, 0.5 + width * scale), + MAX (1, 0.5 + height * scale), + scale); info = gtk_icon_info_new_for_pixbuf (icon_theme, scaled); diff --git a/gtk/gtkicontheme.h b/gtk/gtkicontheme.h index e511c205b..ffa92fd5d 100644 --- a/gtk/gtkicontheme.h +++ b/gtk/gtkicontheme.h @@ -111,7 +111,7 @@ GQuark gtk_icon_theme_error_quark (void); #define gtk_icon_info_get_filename gtk_icon_info_get_filename_utf8 #endif -GType gtk_icon_theme_get_type (void) G_GNUC_CONST; +GType gtk_icon_theme_get_type (void); GtkIconTheme *gtk_icon_theme_new (void); GtkIconTheme *gtk_icon_theme_get_default (void); @@ -167,7 +167,7 @@ void gtk_icon_theme_add_builtin_icon (const gchar *icon_name, gint size, GdkPixbuf *pixbuf); -GType gtk_icon_info_get_type (void) G_GNUC_CONST; +GType gtk_icon_info_get_type (void); GtkIconInfo * gtk_icon_info_copy (GtkIconInfo *icon_info); void gtk_icon_info_free (GtkIconInfo *icon_info); diff --git a/gtk/gtkiconview.c b/gtk/gtkiconview.c index 78e415478..6528905a7 100644 --- a/gtk/gtkiconview.c +++ b/gtk/gtkiconview.c @@ -2244,8 +2244,9 @@ gtk_icon_view_button_press (GtkWidget *widget, icon_view->priv->press_start_y = event->y; } - if (!icon_view->priv->last_single_clicked) - icon_view->priv->last_single_clicked = item; + /* the item of this click, not of one long ago, or a double click + * after a click on another item does nothing */ + icon_view->priv->last_single_clicked = item; /* cancel the current editing, if it exists */ gtk_icon_view_stop_editing (icon_view, TRUE); @@ -3772,15 +3773,40 @@ gtk_icon_view_row_inserted (GtkTreeModel *model, item->index = index; - /* FIXME: We can be more efficient here, - we can store a tail pointer and use that when - appending (which is a rather common operation) - */ - icon_view->priv->items = g_list_insert (icon_view->priv->items, - item, index); + /* Rows usually come in order, so the row before this one is the one + * found last: with the cached link, appending is O(1), not O(n). */ + if (index == 0) + { + icon_view->priv->items = g_list_prepend (icon_view->priv->items, item); + list = icon_view->priv->items; + } + else + { + GList *prev; - list = g_list_nth (icon_view->priv->items, index + 1); - for (; list; list = list->next) + gtk_icon_view_nth_item (icon_view, index - 1); + prev = icon_view->priv->nth_cache_link; + + list = g_list_alloc (); + list->data = item; + if (prev == NULL) + { + /* past the end; g_list_insert() appended there too */ + icon_view->priv->items = g_list_concat (icon_view->priv->items, list); + } + else + { + list->prev = prev; + list->next = prev->next; + if (prev->next) + prev->next->prev = list; + prev->next = list; + } + } + + icon_view->priv->nth_cache_link = list; + + for (list = list->next; list; list = list->next) { item = list->data; @@ -6121,9 +6147,9 @@ gtk_icon_view_get_item_row (GtkIconView *icon_view, { GtkIconViewItem *item; - g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE); - g_return_val_if_fail (icon_view->priv->model != NULL, FALSE); - g_return_val_if_fail (path != NULL, FALSE); + g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1); + g_return_val_if_fail (icon_view->priv->model != NULL, -1); + g_return_val_if_fail (path != NULL, -1); item = g_list_nth_data (icon_view->priv->items, gtk_tree_path_get_indices(path)[0]); @@ -6152,9 +6178,9 @@ gtk_icon_view_get_item_column (GtkIconView *icon_view, { GtkIconViewItem *item; - g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE); - g_return_val_if_fail (icon_view->priv->model != NULL, FALSE); - g_return_val_if_fail (path != NULL, FALSE); + g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1); + g_return_val_if_fail (icon_view->priv->model != NULL, -1); + g_return_val_if_fail (path != NULL, -1); item = g_list_nth_data (icon_view->priv->items, gtk_tree_path_get_indices(path)[0]); @@ -8041,6 +8067,9 @@ gtk_icon_view_item_accessible_image_get_image_size (AtkImage *image, if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT)) return; + *width = 0; + *height = 0; + if (get_pixbuf_box (GTK_ICON_VIEW (item->widget), item->item, &box)) { *width = box.width; @@ -8065,7 +8094,7 @@ gtk_icon_view_item_accessible_image_get_image_position (AtkImage *image, if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT)) return; - atk_component_get_position (ATK_COMPONENT (image), x, y, coord_type); + atk_component_get_extents (ATK_COMPONENT (image), x, y, NULL, NULL, coord_type); if (get_pixbuf_box (GTK_ICON_VIEW (item->widget), item->item, &box)) { @@ -8749,7 +8778,7 @@ gtk_icon_view_item_accessible_get_extents (AtkComponent *component, if (gtk_icon_view_item_accessible_is_showing (item)) { parent_obj = gtk_widget_get_accessible (item->widget); - atk_component_get_position (ATK_COMPONENT (parent_obj), &l_x, &l_y, coord_type); + atk_component_get_extents (ATK_COMPONENT (parent_obj), &l_x, &l_y, NULL, NULL, coord_type); *x = l_x + item->item->x; *y = l_y + item->item->y; } diff --git a/gtk/gtkiconview.h b/gtk/gtkiconview.h index bc12c8f72..b5e39c756 100644 --- a/gtk/gtkiconview.h +++ b/gtk/gtkiconview.h @@ -87,7 +87,7 @@ struct _GtkIconViewClass gboolean (* activate_cursor_item) (GtkIconView *icon_view); }; -GType gtk_icon_view_get_type (void) G_GNUC_CONST; +GType gtk_icon_view_get_type (void); GtkWidget * gtk_icon_view_new (void); GtkWidget * gtk_icon_view_new_with_model (GtkTreeModel *model); diff --git a/gtk/gtkimage.h b/gtk/gtkimage.h index 2a3d2306f..163356c5c 100644 --- a/gtk/gtkimage.h +++ b/gtk/gtkimage.h @@ -187,7 +187,7 @@ struct _GtkImageClass #define gtk_image_set_from_file gtk_image_set_from_file_utf8 #endif -GType gtk_image_get_type (void) G_GNUC_CONST; +GType gtk_image_get_type (void); GtkWidget* gtk_image_new (void); GtkWidget* gtk_image_new_from_pixmap (GdkPixmap *pixmap, diff --git a/gtk/gtkimagemenuitem.h b/gtk/gtkimagemenuitem.h index b915712c9..83bac58b3 100644 --- a/gtk/gtkimagemenuitem.h +++ b/gtk/gtkimagemenuitem.h @@ -63,7 +63,7 @@ struct _GtkImageMenuItemClass }; -GType gtk_image_menu_item_get_type (void) G_GNUC_CONST; +GType gtk_image_menu_item_get_type (void); GtkWidget* gtk_image_menu_item_new (void); GtkWidget* gtk_image_menu_item_new_with_label (const gchar *label); GtkWidget* gtk_image_menu_item_new_with_mnemonic (const gchar *label); diff --git a/gtk/gtkimcontext.c b/gtk/gtkimcontext.c index 6b644ce5d..1ab28739b 100644 --- a/gtk/gtkimcontext.c +++ b/gtk/gtkimcontext.c @@ -23,6 +23,8 @@ #include "gtkmain.h" /* For _gtk_boolean_handled_accumulator */ #include "gtkmarshalers.h" #include "gtkintl.h" +#include "gtkprivate.h" +#include "gtktypebuiltins.h" #include "gtkalias.h" /** @@ -126,7 +128,74 @@ static void gtk_im_context_real_set_surrounding (GtkIMContext *context, gint len, gint cursor_index); -G_DEFINE_ABSTRACT_TYPE (GtkIMContext, gtk_im_context, G_TYPE_OBJECT) +/* the purpose and hints of GTK+ 3.6; private data, so that the + * structure of GtkIMContext, which input methods derive from, stays */ +typedef struct +{ + GtkInputPurpose purpose; + GtkInputHints hints; +} GtkIMContextPrivate; + +enum { + PROP_0, + PROP_INPUT_PURPOSE, + PROP_INPUT_HINTS +}; + +G_DEFINE_ABSTRACT_TYPE_WITH_CODE (GtkIMContext, gtk_im_context, G_TYPE_OBJECT, + G_ADD_PRIVATE (GtkIMContext)) + +static void +gtk_im_context_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + GtkIMContextPrivate *priv = gtk_im_context_get_instance_private (GTK_IM_CONTEXT (object)); + + switch (prop_id) + { + case PROP_INPUT_PURPOSE: + if (priv->purpose != (GtkInputPurpose) g_value_get_enum (value)) + { + priv->purpose = g_value_get_enum (value); + g_object_notify_by_pspec (object, pspec); + } + break; + case PROP_INPUT_HINTS: + if (priv->hints != (GtkInputHints) g_value_get_flags (value)) + { + priv->hints = g_value_get_flags (value); + g_object_notify_by_pspec (object, pspec); + } + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +gtk_im_context_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + GtkIMContextPrivate *priv = gtk_im_context_get_instance_private (GTK_IM_CONTEXT (object)); + + switch (prop_id) + { + case PROP_INPUT_PURPOSE: + g_value_set_enum (value, priv->purpose); + break; + case PROP_INPUT_HINTS: + g_value_set_flags (value, priv->hints); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} /** * GtkIMContextClass: @@ -188,11 +257,47 @@ G_DEFINE_ABSTRACT_TYPE (GtkIMContext, gtk_im_context, G_TYPE_OBJECT) static void gtk_im_context_class_init (GtkIMContextClass *klass) { + GObjectClass *object_class = G_OBJECT_CLASS (klass); + klass->get_preedit_string = gtk_im_context_real_get_preedit_string; klass->filter_keypress = gtk_im_context_real_filter_keypress; klass->get_surrounding = gtk_im_context_real_get_surrounding; klass->set_surrounding = gtk_im_context_real_set_surrounding; + object_class->set_property = gtk_im_context_set_property; + object_class->get_property = gtk_im_context_get_property; + + /** + * GtkIMContext:input-purpose: + * + * The purpose of the text field, for on-screen keyboards and input + * methods, as in GTK+ 3.6. + * + * Since: 2.24 + */ + g_object_class_install_property (object_class, PROP_INPUT_PURPOSE, + g_param_spec_enum ("input-purpose", + P_("Purpose"), + P_("Purpose of the text field"), + GTK_TYPE_INPUT_PURPOSE, + GTK_INPUT_PURPOSE_FREE_FORM, + GTK_PARAM_READWRITE)); + + /** + * GtkIMContext:input-hints: + * + * Hints for the text field behaviour, as in GTK+ 3.6. + * + * Since: 2.24 + */ + g_object_class_install_property (object_class, PROP_INPUT_HINTS, + g_param_spec_flags ("input-hints", + P_("hints"), + P_("Hints for the text field behaviour"), + GTK_TYPE_INPUT_HINTS, + GTK_INPUT_HINT_NONE, + GTK_PARAM_READWRITE)); + /** * GtkIMContext::preedit-start: * @context: the object on which the signal is emitted diff --git a/gtk/gtkimcontext.h b/gtk/gtkimcontext.h index 4ee0a1456..23dfde993 100644 --- a/gtk/gtkimcontext.h +++ b/gtk/gtkimcontext.h @@ -99,7 +99,7 @@ struct _GtkIMContextClass void (*_gtk_reserved6) (void); }; -GType gtk_im_context_get_type (void) G_GNUC_CONST; +GType gtk_im_context_get_type (void); void gtk_im_context_set_client_window (GtkIMContext *context, GdkWindow *window); diff --git a/gtk/gtkimcontextsimple.c b/gtk/gtkimcontextsimple.c index 0b57c9124..e4e207ff5 100644 --- a/gtk/gtkimcontextsimple.c +++ b/gtk/gtkimcontextsimple.c @@ -787,7 +787,7 @@ no_sequence_matches (GtkIMContextSimple *context_simple, } ch = gdk_keyval_to_unicode (event->keyval); - if (ch != 0) + if (ch != 0 && !g_unichar_iscntrl (ch)) { gtk_im_context_simple_commit_char (context, ch); return TRUE; @@ -1198,8 +1198,9 @@ gtk_im_context_simple_get_preedit_string (GtkIMContext *context, } } + /* in characters, not bytes */ if (cursor_pos) - *cursor_pos = len; + *cursor_pos = g_utf8_strlen (outbuf, len); } /** diff --git a/gtk/gtkimcontextsimple.h b/gtk/gtkimcontextsimple.h index a8db87646..07fddb8bb 100644 --- a/gtk/gtkimcontextsimple.h +++ b/gtk/gtkimcontextsimple.h @@ -62,7 +62,7 @@ struct _GtkIMContextSimpleClass GtkIMContextClass parent_class; }; -GType gtk_im_context_simple_get_type (void) G_GNUC_CONST; +GType gtk_im_context_simple_get_type (void); GtkIMContext *gtk_im_context_simple_new (void); void gtk_im_context_simple_add_table (GtkIMContextSimple *context_simple, diff --git a/gtk/gtkimmulticontext.c b/gtk/gtkimmulticontext.c index 1fccadea2..4a264bc19 100644 --- a/gtk/gtkimmulticontext.c +++ b/gtk/gtkimmulticontext.c @@ -92,6 +92,9 @@ static const gchar *global_context_id = NULL; G_DEFINE_TYPE_WITH_PRIVATE (GtkIMMulticontext, gtk_im_multicontext, GTK_TYPE_IM_CONTEXT) +static void gtk_im_multicontext_notify (GObject *object, + GParamSpec *pspec); + static void gtk_im_multicontext_class_init (GtkIMMulticontextClass *class) { @@ -110,6 +113,29 @@ gtk_im_multicontext_class_init (GtkIMMulticontextClass *class) im_context_class->get_surrounding = gtk_im_multicontext_get_surrounding; gobject_class->finalize = gtk_im_multicontext_finalize; + gobject_class->notify = gtk_im_multicontext_notify; +} + +/* the purpose and hints of the widget go to the input method */ +static void +gtk_im_multicontext_pass_purpose (GtkIMMulticontext *multicontext) +{ + GtkInputPurpose purpose; + GtkInputHints hints; + + if (multicontext->slave == NULL) + return; + + g_object_get (multicontext, "input-purpose", &purpose, "input-hints", &hints, NULL); + g_object_set (multicontext->slave, "input-purpose", purpose, "input-hints", hints, NULL); +} + +static void +gtk_im_multicontext_notify (GObject *object, + GParamSpec *pspec) +{ + if (strcmp (pspec->name, "input-purpose") == 0 || strcmp (pspec->name, "input-hints") == 0) + gtk_im_multicontext_pass_purpose (GTK_IM_MULTICONTEXT (object)); } static void @@ -173,6 +199,12 @@ gtk_im_multicontext_set_slave (GtkIMMulticontext *multicontext, g_signal_handlers_disconnect_by_func (multicontext->slave, gtk_im_multicontext_commit_cb, multicontext); + g_signal_handlers_disconnect_by_func (multicontext->slave, + gtk_im_multicontext_retrieve_surrounding_cb, + multicontext); + g_signal_handlers_disconnect_by_func (multicontext->slave, + gtk_im_multicontext_delete_surrounding_cb, + multicontext); g_object_unref (multicontext->slave); multicontext->slave = NULL; @@ -214,6 +246,7 @@ gtk_im_multicontext_set_slave (GtkIMMulticontext *multicontext, gtk_im_context_set_cursor_location (slave, &priv->cursor_location); if (priv->focus_in) gtk_im_context_focus_in (slave); + gtk_im_multicontext_pass_purpose (multicontext); } if (need_preedit_changed) @@ -335,7 +368,7 @@ gtk_im_multicontext_filter_keypress (GtkIMContext *context, gunichar ch; ch = gdk_keyval_to_unicode (event->keyval); - if (ch != 0) + if (ch != 0 && !g_unichar_iscntrl (ch)) { gint len; gchar buf[10]; diff --git a/gtk/gtkimmulticontext.h b/gtk/gtkimmulticontext.h index 80adff825..71a2c8d1e 100644 --- a/gtk/gtkimmulticontext.h +++ b/gtk/gtkimmulticontext.h @@ -63,7 +63,7 @@ struct _GtkIMMulticontextClass void (*_gtk_reserved4) (void); }; -GType gtk_im_multicontext_get_type (void) G_GNUC_CONST; +GType gtk_im_multicontext_get_type (void); GtkIMContext *gtk_im_multicontext_new (void); void gtk_im_multicontext_append_menuitems (GtkIMMulticontext *context, diff --git a/gtk/gtkinfobar.c b/gtk/gtkinfobar.c index 881715db6..cad5000db 100644 --- a/gtk/gtkinfobar.c +++ b/gtk/gtkinfobar.c @@ -997,6 +997,17 @@ typedef struct gchar *response_id; } ActionWidgetInfo; +static void +action_widget_info_free (gpointer data, + gpointer user_data) +{ + ActionWidgetInfo *item = data; + + g_free (item->widget_name); + g_free (item->response_id); + g_free (item); +} + typedef struct { GtkInfoBar *info_bar; @@ -1145,11 +1156,10 @@ gtk_info_bar_buildable_custom_finished (GtkBuildable *buildable, if (ad->response_id == GTK_RESPONSE_HELP) gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (info_bar->priv->action_area), GTK_WIDGET (object), TRUE); - - g_free (item->widget_name); - g_free (item->response_id); - g_free (item); } + + /* also the items of unknown objects, which were skipped above */ + g_slist_foreach (parser_data->items, action_widget_info_free, NULL); g_slist_free (parser_data->items); g_slice_free (ActionWidgetsSubParserData, parser_data); } diff --git a/gtk/gtkinfobar.h b/gtk/gtkinfobar.h index becbc3337..edb95eba5 100644 --- a/gtk/gtkinfobar.h +++ b/gtk/gtkinfobar.h @@ -84,7 +84,7 @@ struct _GtkInfoBarClass void (*_gtk_reserved6) (void); }; -GType gtk_info_bar_get_type (void) G_GNUC_CONST; +GType gtk_info_bar_get_type (void); GtkWidget *gtk_info_bar_new (void); GtkWidget *gtk_info_bar_new_with_buttons (const gchar *first_button_text, diff --git a/gtk/gtkinputdialog.h b/gtk/gtkinputdialog.h index 6e95356be..dbb579a40 100644 --- a/gtk/gtkinputdialog.h +++ b/gtk/gtkinputdialog.h @@ -90,7 +90,7 @@ struct _GtkInputDialogClass void (*_gtk_reserved4) (void); }; -GType gtk_input_dialog_get_type (void) G_GNUC_CONST; +GType gtk_input_dialog_get_type (void); GtkWidget* gtk_input_dialog_new (void); G_END_DECLS diff --git a/gtk/gtkinvisible.h b/gtk/gtkinvisible.h index 6cc193d60..2549a4493 100644 --- a/gtk/gtkinvisible.h +++ b/gtk/gtkinvisible.h @@ -65,7 +65,7 @@ struct _GtkInvisibleClass void (*_gtk_reserved4) (void); }; -GType gtk_invisible_get_type (void) G_GNUC_CONST; +GType gtk_invisible_get_type (void); GtkWidget* gtk_invisible_new (void); GtkWidget* gtk_invisible_new_for_screen (GdkScreen *screen); diff --git a/gtk/gtkitem.h b/gtk/gtkitem.h index 486aa1f26..0bdb04bc9 100644 --- a/gtk/gtkitem.h +++ b/gtk/gtkitem.h @@ -69,7 +69,7 @@ struct _GtkItemClass }; -GType gtk_item_get_type (void) G_GNUC_CONST; +GType gtk_item_get_type (void); #if !defined(GTK_DISABLE_DEPRECATED) || defined(GTK_COMPILATION) void gtk_item_select (GtkItem *item); void gtk_item_deselect (GtkItem *item); diff --git a/gtk/gtkitemfactory.h b/gtk/gtkitemfactory.h index 988450aa5..e276ec62d 100644 --- a/gtk/gtkitemfactory.h +++ b/gtk/gtkitemfactory.h @@ -135,7 +135,7 @@ struct _GtkItemFactoryItem }; -GType gtk_item_factory_get_type (void) G_GNUC_CONST; +GType gtk_item_factory_get_type (void); /* `container_type' must be of GTK_TYPE_MENU_BAR, GTK_TYPE_MENU, * or GTK_TYPE_OPTION_MENU. diff --git a/gtk/gtklabel.c b/gtk/gtklabel.c index b23c214c4..02b653eee 100644 --- a/gtk/gtklabel.c +++ b/gtk/gtklabel.c @@ -1758,11 +1758,18 @@ static void gtk_label_set_text_internal (GtkLabel *label, gchar *str) { + gboolean text_changed; + + text_changed = g_strcmp0 (label->text, str) != 0; + g_free (label->text); label->text = str; - gtk_label_select_region_index (label, 0, 0); + /* Re-setting the same text for internal reasons (e.g. when the + * mnemonics become visible upon Alt press) keeps the selection */ + if (text_changed) + gtk_label_select_region_index (label, 0, 0); } static void @@ -1905,9 +1912,22 @@ gtk_label_set_text (GtkLabel *label, { g_return_if_fail (GTK_IS_LABEL (label)); + if (str == NULL) + str = ""; + + /* The same plain text again changes nothing: no new layout and no + * resize of the window. Selectable labels go the whole way, as + * setting the text clears the selection. */ + if (!label->use_markup && !label->use_underline && !label->select_info && + g_strcmp0 (label->label, str) == 0 && g_strcmp0 (label->text, str) == 0) + { + g_object_notify (G_OBJECT (label), "label"); + return; + } + g_object_freeze_notify (G_OBJECT (label)); - gtk_label_set_label_internal (label, g_strdup (str ? str : "")); + gtk_label_set_label_internal (label, g_strdup (str)); gtk_label_set_use_markup_internal (label, FALSE); gtk_label_set_use_underline_internal (label, FALSE); @@ -2304,6 +2324,7 @@ gtk_label_set_markup_internal (GtkLabel *label, PangoAttrList *attrs = NULL; gunichar accel_char = 0; gchar *new_str; + gchar *str_for_accel = NULL; GList *links = NULL; if (!parse_uri_markup (label, str, &new_str, &links, &error)) @@ -2344,7 +2365,10 @@ gtk_label_set_markup_internal (GtkLabel *label, if (separate_uline_pattern (new_str, &key, &tmp, &pattern)) { - g_free (new_str); + /* Keep the unstripped string, the mnemonic keyval must + * be extracted even if the underline is not displayed. + */ + str_for_accel = new_str; new_str = tmp; g_free (pattern); } @@ -2362,12 +2386,33 @@ gtk_label_set_markup_internal (GtkLabel *label, g_warning ("Failed to set text from markup due to error parsing markup: %s", error->message); g_free (new_str); + g_free (str_for_accel); g_error_free (error); return; } g_free (new_str); + if (str_for_accel) + { + /* Extract the accelerator character from the unstripped string */ + accel_char = 0; + if (!pango_parse_markup (str_for_accel, + -1, + '_', + NULL, + NULL, + &accel_char, + &error)) + { + accel_char = 0; + g_error_free (error); + error = NULL; + } + + g_free (str_for_accel); + } + if (text) gtk_label_set_text_internal (label, text); @@ -2408,9 +2453,21 @@ gtk_label_set_markup (GtkLabel *label, { g_return_if_fail (GTK_IS_LABEL (label)); + if (str == NULL) + str = ""; + + /* the same markup again gives the same label; labels with links + * or a selection go the whole way, as for gtk_label_set_text() */ + if (label->use_markup && !label->use_underline && !label->select_info && + g_strcmp0 (label->label, str) == 0) + { + g_object_notify (G_OBJECT (label), "label"); + return; + } + g_object_freeze_notify (G_OBJECT (label)); - gtk_label_set_label_internal (label, g_strdup (str ? str : "")); + gtk_label_set_label_internal (label, g_strdup (str)); gtk_label_set_use_markup_internal (label, TRUE); gtk_label_set_use_underline_internal (label, FALSE); @@ -4303,8 +4360,10 @@ gtk_label_button_release (GtkWidget *widget, info->selection_anchor == info->selection_end && info->link_clicked) { - emit_activate_link (label, info->active_link); + /* reset first: a handler of ::activate-link may change the + * text of the label, which can free @info */ info->link_clicked = 0; + emit_activate_link (label, info->active_link); return TRUE; } @@ -4359,7 +4418,8 @@ drag_begin_cb (GtkWidget *widget, label = GTK_LABEL (widget); - if ((label->select_info->selection_anchor != + if (label->select_info && + (label->select_info->selection_anchor != label->select_info->selection_end) && label->text) { @@ -4581,7 +4641,9 @@ gtk_label_create_window (GtkLabel *label) GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK; attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_NOREDIR; - if (gtk_widget_is_sensitive (widget)) + /* the text cursor only where text can be selected, not over a label + * that only has links (as gtk_label_update_cursor() does) */ + if (gtk_widget_is_sensitive (widget) && label->select_info->selectable) { attributes.cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM); @@ -4793,7 +4855,8 @@ static void gtk_label_set_selection_text (GtkLabel *label, GtkSelectionData *selection_data) { - if ((label->select_info->selection_anchor != + if (label->select_info && + (label->select_info->selection_anchor != label->select_info->selection_end) && label->text) { @@ -4872,8 +4935,12 @@ gtk_label_select_region_index (GtkLabel *label, label->select_info->selection_anchor = anchor_index; label->select_info->selection_end = end_index; - clipboard = gtk_widget_get_clipboard (GTK_WIDGET (label), - GDK_SELECTION_PRIMARY); + /* The label may not be anchored to a toplevel (yet or anymore) */ + if (gtk_widget_has_screen (GTK_WIDGET (label))) + clipboard = gtk_widget_get_clipboard (GTK_WIDGET (label), + GDK_SELECTION_PRIMARY); + else + clipboard = NULL; if (anchor_index != end_index) { @@ -4885,18 +4952,20 @@ gtk_label_select_region_index (GtkLabel *label, gtk_target_list_add_text_targets (list, 0); targets = gtk_target_table_new_from_list (list, &n_targets); - gtk_clipboard_set_with_owner (clipboard, - targets, n_targets, - get_text_callback, - clear_text_callback, - G_OBJECT (label)); + if (clipboard) + gtk_clipboard_set_with_owner (clipboard, + targets, n_targets, + get_text_callback, + clear_text_callback, + G_OBJECT (label)); gtk_target_table_free (targets, n_targets); gtk_target_list_unref (list); } else { - if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (label)) + if (clipboard && + gtk_clipboard_get_owner (clipboard) == G_OBJECT (label)) gtk_clipboard_clear (clipboard); } @@ -5842,7 +5911,12 @@ emit_activate_link (GtkLabel *label, gboolean handled; g_signal_emit (label, signals[ACTIVATE_LINK], 0, link->uri, &handled); - if (handled && label->track_links && !link->visited) + + /* A handler may have changed the text of the label, freeing @link */ + if (handled && label->track_links && + label->select_info && + g_list_find (label->select_info->links, link) && + !link->visited) { link->visited = TRUE; /* FIXME: shouldn't have to redo everything here */ diff --git a/gtk/gtklabel.h b/gtk/gtklabel.h index 015108e63..30fe67609 100644 --- a/gtk/gtklabel.h +++ b/gtk/gtklabel.h @@ -106,7 +106,7 @@ struct _GtkLabelClass void (*_gtk_reserved3) (void); }; -GType gtk_label_get_type (void) G_GNUC_CONST; +GType gtk_label_get_type (void); GtkWidget* gtk_label_new (const gchar *str); GtkWidget* gtk_label_new_with_mnemonic (const gchar *str); void gtk_label_set_text (GtkLabel *label, diff --git a/gtk/gtklayout.h b/gtk/gtklayout.h index c1e404bb1..9c24d3ede 100644 --- a/gtk/gtklayout.h +++ b/gtk/gtklayout.h @@ -91,7 +91,7 @@ struct _GtkLayoutClass void (*_gtk_reserved4) (void); }; -GType gtk_layout_get_type (void) G_GNUC_CONST; +GType gtk_layout_get_type (void); GtkWidget* gtk_layout_new (GtkAdjustment *hadjustment, GtkAdjustment *vadjustment); GdkWindow* gtk_layout_get_bin_window (GtkLayout *layout); diff --git a/gtk/gtklinkbutton.c b/gtk/gtklinkbutton.c index fa9bc1178..f46cd1f57 100644 --- a/gtk/gtklinkbutton.c +++ b/gtk/gtklinkbutton.c @@ -384,6 +384,9 @@ copy_activate_cb (GtkWidget *widget, { GtkLinkButtonPrivate *priv = link_button->priv; + if (priv->uri == NULL) + return; + gtk_clipboard_set_text (gtk_widget_get_clipboard (GTK_WIDGET (link_button), GDK_SELECTION_CLIPBOARD), priv->uri, -1); @@ -451,7 +454,9 @@ gtk_link_button_button_press (GtkWidget *widget, if (!gtk_widget_has_focus (widget)) gtk_widget_grab_focus (widget); - if (_gtk_button_event_triggers_context_menu (event)) + /* Don't popup the menu if there's no URI set, there is nothing to copy */ + if (_gtk_button_event_triggers_context_menu (event) && + GTK_LINK_BUTTON (widget)->priv->uri != NULL) { gtk_link_button_do_popup (GTK_LINK_BUTTON (widget), event); @@ -633,18 +638,24 @@ gtk_link_button_query_tooltip_cb (GtkWidget *widget, { GtkLinkButton *link_button = GTK_LINK_BUTTON (widget); const gchar *label, *uri; + gchar *text, *markup; label = gtk_button_get_label (GTK_BUTTON (link_button)); uri = link_button->priv->uri; + text = gtk_widget_get_tooltip_text (widget); + markup = gtk_widget_get_tooltip_markup (widget); - if (!gtk_widget_get_tooltip_text (widget) - && !gtk_widget_get_tooltip_markup (widget) - && label && *label != '\0' && uri && strcmp (label, uri) != 0) + if (text == NULL && + markup == NULL && + label && *label != '\0' && uri && strcmp (label, uri) != 0) { gtk_tooltip_set_text (tooltip, uri); return TRUE; } + g_free (text); + g_free (markup); + return FALSE; } diff --git a/gtk/gtklinkbutton.h b/gtk/gtklinkbutton.h index 9a2e7a5c6..dac56283c 100644 --- a/gtk/gtklinkbutton.h +++ b/gtk/gtklinkbutton.h @@ -65,7 +65,7 @@ struct _GtkLinkButtonClass void (*_gtk_padding4) (void); }; -GType gtk_link_button_get_type (void) G_GNUC_CONST; +GType gtk_link_button_get_type (void); GtkWidget * gtk_link_button_new (const gchar *uri); GtkWidget * gtk_link_button_new_with_label (const gchar *uri, diff --git a/gtk/gtklist.h b/gtk/gtklist.h index 3a2f13f13..032151099 100644 --- a/gtk/gtklist.h +++ b/gtk/gtklist.h @@ -81,7 +81,7 @@ struct _GtkListClass }; -GType gtk_list_get_type (void) G_GNUC_CONST; +GType gtk_list_get_type (void); GtkWidget* gtk_list_new (void); void gtk_list_insert_items (GtkList *list, GList *items, diff --git a/gtk/gtklistitem.h b/gtk/gtklistitem.h index 1d9a0c8f2..e14a9f237 100644 --- a/gtk/gtklistitem.h +++ b/gtk/gtklistitem.h @@ -75,7 +75,7 @@ struct _GtkListItemClass }; -GType gtk_list_item_get_type (void) G_GNUC_CONST; +GType gtk_list_item_get_type (void); GtkWidget* gtk_list_item_new (void); GtkWidget* gtk_list_item_new_with_label (const gchar *label); void gtk_list_item_select (GtkListItem *list_item); diff --git a/gtk/gtkliststore.c b/gtk/gtkliststore.c index 167e330fa..b9f23d798 100644 --- a/gtk/gtkliststore.c +++ b/gtk/gtkliststore.c @@ -249,11 +249,13 @@ gtk_list_store_new (gint n_columns, { GType type = va_arg (args, GType); if (! _gtk_tree_data_list_check_type (type)) - { - g_warning ("%s: Invalid type %s\n", G_STRLOC, g_type_name (type)); - g_object_unref (retval); - return NULL; - } + { + g_warning ("%s: Invalid type %s\n", G_STRLOC, g_type_name (type)); + g_object_unref (retval); + va_end (args); + + return NULL; + } gtk_list_store_set_column_type (retval, i, type); } @@ -603,8 +605,7 @@ gtk_list_store_real_set_value (GtkListStore *list_store, if (! g_type_is_a (G_VALUE_TYPE (value), list_store->column_headers[column])) { - if (! (g_value_type_compatible (G_VALUE_TYPE (value), list_store->column_headers[column]) && - g_value_type_compatible (list_store->column_headers[column], G_VALUE_TYPE (value)))) + if (! (g_value_type_transformable (G_VALUE_TYPE (value), list_store->column_headers[column]))) { g_warning ("%s: Unable to convert from %s to %s\n", G_STRLOC, @@ -612,6 +613,8 @@ gtk_list_store_real_set_value (GtkListStore *list_store, g_type_name (list_store->column_headers[column])); return retval; } + + g_value_init (&real_value, list_store->column_headers[column]); if (!g_value_transform (value, &real_value)) { g_warning ("%s: Unable to make conversion from %s to %s\n", @@ -797,9 +800,7 @@ gtk_list_store_set_valist_internal (GtkListStore *list_store, g_warning ("%s: Invalid column number %d added to iter (remember to end your list of columns with a -1)", G_STRLOC, column); break; } - g_value_init (&value, list_store->column_headers[column]); - - G_VALUE_COLLECT (&value, var_args, 0, &error); + G_VALUE_COLLECT_INIT (&value, list_store->column_headers[column], var_args, 0, &error); if (error) { g_warning ("%s: %s", G_STRLOC, error); @@ -1688,9 +1689,6 @@ gtk_list_store_compare_func (GSequenceIter *a, iter_b.stamp = list_store->stamp; iter_b.user_data = (gpointer)b; - g_assert (VALID_ITER (&iter_a, list_store)); - g_assert (VALID_ITER (&iter_b, list_store)); - retval = (* func) (GTK_TREE_MODEL (list_store), &iter_a, &iter_b, data); if (list_store->order == GTK_SORT_DESCENDING) @@ -1704,6 +1702,58 @@ gtk_list_store_compare_func (GSequenceIter *a, return retval; } +/* sorting by a column with its own comparison, where the values can be + * read once (see _gtk_tree_data_list_sort_rows()); returns the new order + * or %NULL if the store is to be sorted with the comparison function */ +static gint * +gtk_list_store_sort_by_column (GtkListStore *list_store) +{ + GtkTreeDataSortHeader *header; + GSequenceIter *ptr; + GSequenceIter *end; + GtkTreeIter *iters; + gint *new_order; + gint n, i; + + if (list_store->sort_column_id == GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID) + return NULL; + + header = _gtk_tree_data_list_get_header (list_store->sort_list, + list_store->sort_column_id); + if (!header || header->func != _gtk_tree_data_list_compare_func) + return NULL; + + n = g_sequence_get_length (list_store->seq); + iters = g_new (GtkTreeIter, n); + new_order = g_new (gint, n); + + ptr = g_sequence_get_begin_iter (list_store->seq); + for (i = 0; i < n; i++) + { + iters[i].stamp = list_store->stamp; + iters[i].user_data = ptr; + ptr = g_sequence_iter_next (ptr); + } + + if (!_gtk_tree_data_list_sort_rows (GTK_TREE_MODEL (list_store), + GPOINTER_TO_INT (header->data), + list_store->order, + iters, n, new_order)) + { + g_free (iters); + g_free (new_order); + return NULL; + } + + /* append the rows to the end in their new order */ + end = g_sequence_get_end_iter (list_store->seq); + for (i = 0; i < n; i++) + g_sequence_move (iters[new_order[i]].user_data, end); + + g_free (iters); + return new_order; +} + static void gtk_list_store_sort (GtkListStore *list_store) { @@ -1715,12 +1765,17 @@ gtk_list_store_sort (GtkListStore *list_store) g_sequence_get_length (list_store->seq) <= 1) return; - old_positions = save_positions (list_store->seq); + new_order = gtk_list_store_sort_by_column (list_store); + if (!new_order) + { + old_positions = save_positions (list_store->seq); - g_sequence_sort_iter (list_store->seq, gtk_list_store_compare_func, list_store); + g_sequence_sort_iter (list_store->seq, gtk_list_store_compare_func, list_store); + + new_order = generate_order (list_store->seq, old_positions); + } /* Let the world know about our new order */ - new_order = generate_order (list_store->seq, old_positions); path = gtk_tree_path_new (); gtk_tree_model_rows_reordered (GTK_TREE_MODEL (list_store), diff --git a/gtk/gtkliststore.h b/gtk/gtkliststore.h index 89514016b..2d5247ab8 100644 --- a/gtk/gtkliststore.h +++ b/gtk/gtkliststore.h @@ -74,7 +74,7 @@ struct _GtkListStoreClass }; -GType gtk_list_store_get_type (void) G_GNUC_CONST; +GType gtk_list_store_get_type (void); GtkListStore *gtk_list_store_new (gint n_columns, ...); GtkListStore *gtk_list_store_newv (gint n_columns, diff --git a/gtk/gtkmain.c b/gtk/gtkmain.c index 9124f001c..21b870018 100644 --- a/gtk/gtkmain.c +++ b/gtk/gtkmain.c @@ -63,6 +63,13 @@ #include "gtkwindow.h" #include "gtktooltip.h" #include "gtkdebug.h" +#include "gtkrange.h" +#include "gtkscrollbar.h" +#include "gtkscrolledwindow.h" +#include "gtktextview.h" +#ifdef GDK_WINDOWING_X11 +#include "gtksocket.h" +#endif #include "gtkalias.h" #include "gtkmenu.h" #include "gdk/gdkkeysyms.h" @@ -678,6 +685,10 @@ do_pre_parse_initialization (int *argc, gdk_pre_parse_libgtk_only (); gdk_event_handler_set ((GdkEventFunc)gtk_main_do_event, NULL, NULL); + /* GDK makes smooth scroll events only for this handler, which knows + * who can take them, not for one a program puts in its place */ + g_object_set_data (G_OBJECT (gdk_display_manager_get ()), + "gdk-smooth-scroll-handler", gtk_main_do_event); #ifdef G_ENABLE_DEBUG env_string = g_getenv ("GTK_DEBUG"); @@ -712,8 +723,16 @@ gettext_initialization (void) setlocale_initialization (); #ifdef ENABLE_NLS - bindtextdomain (GETTEXT_PACKAGE, GTK_LOCALEDIR); - bindtextdomain (GETTEXT_PACKAGE "-properties", GTK_LOCALEDIR); + /* GTK_LOCALEDIR: the translations of GTK+ elsewhere, for programs + * that bring GTK+ along (as Ardour's YTK has it) */ + { + const gchar *localedir = g_getenv ("GTK_LOCALEDIR"); + + if (localedir == NULL || localedir[0] == '\0') + localedir = GTK_LOCALEDIR; + bindtextdomain (GETTEXT_PACKAGE, localedir); + bindtextdomain (GETTEXT_PACKAGE "-properties", localedir); + } # ifdef HAVE_BIND_TEXTDOMAIN_CODESET bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); bind_textdomain_codeset (GETTEXT_PACKAGE "-properties", "UTF-8"); @@ -1425,6 +1444,14 @@ rewrite_event_for_window (GdkEvent *event, new_window, &event->motion.x, &event->motion.y); break; + case GDK_TOUCH_BEGIN: + case GDK_TOUCH_UPDATE: + case GDK_TOUCH_END: + case GDK_TOUCH_CANCEL: + rewrite_events_translate (event->any.window, + new_window, + &event->touch.x, &event->touch.y); + break; case GDK_KEY_PRESS: case GDK_KEY_RELEASE: case GDK_PROXIMITY_IN: @@ -1441,6 +1468,232 @@ rewrite_event_for_window (GdkEvent *event, return event; } +/* Whether a program, or a widget's own "event", hears events of + * @widget before its scroll handler */ +static gboolean +hears_scroll (GtkWidget *widget) +{ + static guint event_id, scroll_event_id, event_after_id; + static gboolean (*text_view_event) (GtkWidget *, GdkEvent *); + GtkWidgetClass *class = GTK_WIDGET_GET_CLASS (widget); + + if (!event_id) + { + event_id = g_signal_lookup ("event", GTK_TYPE_WIDGET); + scroll_event_id = g_signal_lookup ("scroll-event", GTK_TYPE_WIDGET); + event_after_id = g_signal_lookup ("event-after", GTK_TYPE_WIDGET); + /* only for the "event" of text tags */ + text_view_event = GTK_WIDGET_CLASS (g_type_class_ref (GTK_TYPE_TEXT_VIEW))->event; + } + + return g_signal_has_handler_pending (widget, event_id, 0, FALSE) || + g_signal_has_handler_pending (widget, scroll_event_id, 0, FALSE) || + g_signal_has_handler_pending (widget, event_after_id, 0, FALSE) || + (class->event && class->event != text_view_event); +} + +/* Smooth scroll events go where GTK+ itself scrolls: to scrollbars + * and scrolled windows that nobody else hears a scroll event before. + * Everything else, most of all what programs do with scroll events, + * keeps the whole steps of the wheel, which X sends as well. */ +/* Which steps of the smooth event @event the widgets from @widget up + * would use, as in _gtk_scrolled_window_takes_scroll(); 0 for not + * wanted at all */ +static guint +smooth_scroll_wanted (GtkWidget *widget, + GdkEventScroll *event) +{ + static gboolean (*range_scroll) (GtkWidget *, GdkEventScroll *); + static gboolean (*scrolled_window_scroll) (GtkWidget *, GdkEventScroll *); + gdouble dx, dy; + + if (!range_scroll) + { + range_scroll = GTK_WIDGET_CLASS (g_type_class_ref (GTK_TYPE_RANGE))->scroll_event; + scrolled_window_scroll = GTK_WIDGET_CLASS (g_type_class_ref (GTK_TYPE_SCROLLED_WINDOW))->scroll_event; + } + +#ifdef GDK_WINDOWING_X11 + /* the window of another program inside, which hears the steps */ + if (GTK_IS_SOCKET (widget)) + return 0; +#endif + + if (!gdk_event_get_scroll_deltas ((GdkEvent *) event, &dx, &dy)) + return 0; + + for (; widget; widget = widget->parent) + { + GtkWidgetClass *class = GTK_WIDGET_GET_CLASS (widget); + + if (!gtk_widget_is_sensitive (widget)) + continue; + + if (hears_scroll (widget)) + return 0; + + if (class->scroll_event == scrolled_window_scroll) + { + guint taken = _gtk_scrolled_window_takes_scroll (widget, event); + + if (taken) + return taken; + } + else if (class->scroll_event) + { + /* scales keep their steps, which their digits may round; + * a scrollbar goes its own way, or else the other */ + if (class->scroll_event != range_scroll || !GTK_IS_SCROLLBAR (widget)) + return 0; + if (GTK_RANGE (widget)->orientation == GTK_ORIENTATION_HORIZONTAL) + return dx != 0 ? 1 : 2; + return dy != 0 ? 2 : 1; + } + } + + return 0; +} + +/* A scrolled window that the wheel has just moved keeps the wheel for + * a while, even when the pointer now stands over something inside that + * scrolls too, a list or a spin button that moved under it: browsers + * do the same. It lets go after a second without moving, or when the + * pointer moves or a button or key is pressed; outside it, nothing + * changes anyway. */ + +#define SCROLL_LATCH_TIME 1000 /* milliseconds */ +#define SCROLL_LATCH_MOVE 100 /* motion closer to the wheel is no motion */ + +static GtkWidget *scroll_latch; +static guint32 scroll_latch_time; + +static void +scroll_latch_release (void) +{ + if (scroll_latch) + g_object_remove_weak_pointer (G_OBJECT (scroll_latch), (gpointer *) &scroll_latch); + scroll_latch = NULL; +} + +void +_gtk_scroll_latch (GtkWidget *widget, + guint32 time) +{ + if (scroll_latch != widget) + { + scroll_latch_release (); + scroll_latch = widget; + g_object_add_weak_pointer (G_OBJECT (widget), (gpointer *) &scroll_latch); + } + scroll_latch_time = time; +} + +static void +scroll_latch_see (GdkEvent *event) +{ + switch (event->type) + { + case GDK_MOTION_NOTIFY: + if ((gint32) (event->motion.time - scroll_latch_time) > SCROLL_LATCH_MOVE) + scroll_latch_release (); + break; + case GDK_BUTTON_PRESS: + case GDK_KEY_PRESS: + scroll_latch_release (); + break; + default: + break; + } +} + +/* Whether the scroll handler of @class is one of GTK+'s own, not one + * that a program's subclass brings */ +static gboolean +scroll_handler_of_gtk (GtkWidgetClass *class) +{ + GType type = G_TYPE_FROM_CLASS (class), parent; + + /* the class that put the handler there */ + while ((parent = g_type_parent (type)) != G_TYPE_INVALID && + g_type_is_a (parent, GTK_TYPE_WIDGET) && + GTK_WIDGET_CLASS (g_type_class_peek (parent))->scroll_event == class->scroll_event) + type = parent; + + return g_str_has_prefix (g_type_name (type), "Gtk"); +} + +/* Only GTK+'s own widgets inside give way to the latch: where the + * program hears scroll events, it goes on hearing them. And only + * the way the latched window scrolls is kept. */ +static GtkWidget * +scroll_latch_target (GtkWidget *widget, + GdkEvent *event) +{ + GtkWidget *w; + gboolean inside = FALSE; + + if ((gint32) (event->scroll.time - scroll_latch_time) >= SCROLL_LATCH_TIME || + !gtk_widget_get_mapped (scroll_latch) || !gtk_widget_is_sensitive (scroll_latch) || + !_gtk_scrolled_window_takes_scroll (scroll_latch, &event->scroll)) + return widget; + + for (w = widget; w && w != scroll_latch; w = w->parent) + { + GtkWidgetClass *class = GTK_WIDGET_GET_CLASS (w); + + if (!gtk_widget_is_sensitive (w)) + continue; + if (hears_scroll (w) || (class->scroll_event && !scroll_handler_of_gtk (class))) + return widget; + inside |= class->scroll_event != NULL; + } + + return w && inside ? scroll_latch : widget; +} + +/* Whether to pass on a scroll event: either the smooth ones or the + * whole steps that X made of them, by direction */ +static gboolean +scroll_event_wanted (GtkWidget *widget, + GdkEvent *event) +{ + static guint32 smooth_time; + static guint taken; /* 1 across, 2 up and down */ + guint wanted; + + /* a window that asked for smooth scroll events (GDK_SMOOTH_SCROLL_MASK, + * as in GTK+ 3) gets them, and not the whole steps made of them */ + if (event->any.window && + (gdk_window_get_events (event->any.window) & GDK_SMOOTH_SCROLL_MASK)) + { + if (event->scroll.direction == GDK_SCROLL_SMOOTH) + { + smooth_time = event->scroll.time; + taken = 3; + return TRUE; + } + return !gdk_event_get_pointer_emulated (event); + } + + if (event->scroll.direction != GDK_SCROLL_SMOOTH) + { + guint axis = event->scroll.direction <= GDK_SCROLL_DOWN ? 2 : 1; + + return !(taken & axis) || event->scroll.time != smooth_time || + !gdk_event_get_pointer_emulated (event); + } + + if (event->scroll.time != smooth_time) + taken = 0; + smooth_time = event->scroll.time; + + /* the steps of a direction that the smooth event does not use stay */ + wanted = smooth_scroll_wanted (widget, &event->scroll); + taken |= wanted; + + return wanted != 0; +} + /* If there is a pointer or keyboard grab in effect with owner_events = TRUE, * then what X11 does is deliver the event normally if it was going to this * client, otherwise, delivers it in terms of the grab window. This function @@ -1552,6 +1805,9 @@ gtk_main_do_event (GdkEvent *event) window_group = gtk_main_get_window_group (event_widget); + if (scroll_latch) + scroll_latch_see (event); + /* Push the event onto a stack of current events for * gtk_current_event_get(). */ @@ -1576,6 +1832,13 @@ gtk_main_do_event (GdkEvent *event) grab_widget = event_widget; } + /* a finger that drags in a scrolled window scrolls it */ + if ((event->type == GDK_BUTTON_PRESS || event->type == GDK_2BUTTON_PRESS || + event->type == GDK_3BUTTON_PRESS || event->type == GDK_MOTION_NOTIFY || + event->type == GDK_BUTTON_RELEASE) && + _gtk_scrolled_window_touch_event (event_widget, grab_widget, event)) + goto done; + /* Not all events get sent to the grabbing widget. * The delete, destroy, expose, focus change and resize * events still get sent to the event widget because @@ -1650,6 +1913,13 @@ gtk_main_do_event (GdkEvent *event) break; case GDK_SCROLL: + /* a pinch on a touchpad goes where the pointer is, to zoom */ + if (scroll_latch && !gdk_event_get_touchpad_emulated (event)) + grab_widget = scroll_latch_target (grab_widget, event); + if (scroll_event_wanted (grab_widget, event)) + gtk_propagate_event (grab_widget, event); + break; + case GDK_BUTTON_PRESS: case GDK_2BUTTON_PRESS: case GDK_3BUTTON_PRESS: @@ -1692,6 +1962,10 @@ gtk_main_do_event (GdkEvent *event) case GDK_BUTTON_RELEASE: case GDK_PROXIMITY_IN: case GDK_PROXIMITY_OUT: + case GDK_TOUCH_BEGIN: + case GDK_TOUCH_UPDATE: + case GDK_TOUCH_END: + case GDK_TOUCH_CANCEL: gtk_propagate_event (grab_widget, event); break; @@ -1737,6 +2011,7 @@ gtk_main_do_event (GdkEvent *event) _gtk_tooltip_handle_event (event); } + done: tmp_list = current_events; current_events = g_list_remove_link (current_events, tmp_list); g_list_free_1 (tmp_list); diff --git a/gtk/gtkmenu.c b/gtk/gtkmenu.c index 08de60aea..5df104a97 100644 --- a/gtk/gtkmenu.c +++ b/gtk/gtkmenu.c @@ -3513,6 +3513,11 @@ gtk_menu_scroll (GtkWidget *widget, { GtkMenu *menu = GTK_MENU (widget); + /* a pinch on a touchpad (Ctrl with the wheel) is for programs that + * zoom, not for scrolling here */ + if (gdk_event_get_touchpad_emulated ((GdkEvent *) event)) + return FALSE; + switch (event->direction) { case GDK_SCROLL_RIGHT: @@ -3523,6 +3528,8 @@ gtk_menu_scroll (GtkWidget *widget, case GDK_SCROLL_UP: gtk_menu_scroll_by (menu, - MENU_SCROLL_STEP2); break; + default: + break; } return TRUE; @@ -4398,7 +4405,7 @@ gtk_menu_position (GtkMenu *menu, y = monitor.y; } - if (scroll_offset > 0) + if (scroll_offset != 0) { GtkBorder arrow_border; @@ -5187,9 +5194,9 @@ gtk_menu_real_move_scroll (GtkMenu *menu, { gint child_height; - compute_child_offset (menu, menu_shell->active_menu_item, - &child_offset, &child_height, NULL); - child_offset += child_height / 2; + if (compute_child_offset (menu, menu_shell->active_menu_item, + &child_offset, &child_height, NULL)) + child_offset += child_height / 2; } menu_shell->ignore_enter = TRUE; diff --git a/gtk/gtkmenu.h b/gtk/gtkmenu.h index edd375a3b..786485505 100644 --- a/gtk/gtkmenu.h +++ b/gtk/gtkmenu.h @@ -122,7 +122,7 @@ struct _GtkMenuClass }; -GType gtk_menu_get_type (void) G_GNUC_CONST; +GType gtk_menu_get_type (void); GtkWidget* gtk_menu_new (void); /* Display the menu onscreen */ diff --git a/gtk/gtkmenubar.h b/gtk/gtkmenubar.h index 95479010a..11a759cc2 100644 --- a/gtk/gtkmenubar.h +++ b/gtk/gtkmenubar.h @@ -65,7 +65,7 @@ struct _GtkMenuBarClass }; -GType gtk_menu_bar_get_type (void) G_GNUC_CONST; +GType gtk_menu_bar_get_type (void); GtkWidget* gtk_menu_bar_new (void); GtkPackDirection gtk_menu_bar_get_pack_direction (GtkMenuBar *menubar); diff --git a/gtk/gtkmenuitem.c b/gtk/gtkmenuitem.c index efad611ad..294679580 100644 --- a/gtk/gtkmenuitem.c +++ b/gtk/gtkmenuitem.c @@ -1504,7 +1504,7 @@ gtk_menu_item_real_popup_submenu (GtkWidget *widget, { gint64 *popup_time = g_slice_new0 (gint64); - *popup_time = g_get_real_time (); + *popup_time = g_get_monotonic_time (); g_object_set_data_full (G_OBJECT (menu_item->submenu), "gtk-menu-exact-popup-time", popup_time, diff --git a/gtk/gtkmenuitem.h b/gtk/gtkmenuitem.h index 5487cd539..9e2b2bff1 100644 --- a/gtk/gtkmenuitem.h +++ b/gtk/gtkmenuitem.h @@ -96,7 +96,7 @@ struct _GtkMenuItemClass }; -GType gtk_menu_item_get_type (void) G_GNUC_CONST; +GType gtk_menu_item_get_type (void); GtkWidget* gtk_menu_item_new (void); GtkWidget* gtk_menu_item_new_with_label (const gchar *label); GtkWidget* gtk_menu_item_new_with_mnemonic (const gchar *label); diff --git a/gtk/gtkmenushell.c b/gtk/gtkmenushell.c index 690f82c2a..40c9b8805 100644 --- a/gtk/gtkmenushell.c +++ b/gtk/gtkmenushell.c @@ -719,7 +719,7 @@ gtk_menu_shell_button_release (GtkWidget *widget, if (popup_time) { - usec_since_popup = g_get_real_time () - *popup_time; + usec_since_popup = g_get_monotonic_time () - *popup_time; g_object_set_data (G_OBJECT (submenu), "gtk-menu-exact-popup-time", NULL); @@ -1725,8 +1725,11 @@ gtk_menu_shell_activate_mnemonic (GtkMenuShell *menu_shell, event->group); if (entries) - result = _gtk_mnemonic_hash_activate (mnemonic_hash, - GPOINTER_TO_UINT (entries->data)); + { + result = _gtk_mnemonic_hash_activate (mnemonic_hash, + GPOINTER_TO_UINT (entries->data)); + g_slist_free (entries); + } return result; } diff --git a/gtk/gtkmenushell.h b/gtk/gtkmenushell.h index 53370f12c..3e5391061 100644 --- a/gtk/gtkmenushell.h +++ b/gtk/gtkmenushell.h @@ -97,7 +97,7 @@ struct _GtkMenuShellClass }; -GType gtk_menu_shell_get_type (void) G_GNUC_CONST; +GType gtk_menu_shell_get_type (void); void gtk_menu_shell_append (GtkMenuShell *menu_shell, GtkWidget *child); void gtk_menu_shell_prepend (GtkMenuShell *menu_shell, diff --git a/gtk/gtkmenutoolbutton.h b/gtk/gtkmenutoolbutton.h index 43ff84525..e83fb73ab 100644 --- a/gtk/gtkmenutoolbutton.h +++ b/gtk/gtkmenutoolbutton.h @@ -63,7 +63,7 @@ struct _GtkMenuToolButtonClass void (*_gtk_reserved4) (void); }; -GType gtk_menu_tool_button_get_type (void) G_GNUC_CONST; +GType gtk_menu_tool_button_get_type (void); GtkToolItem *gtk_menu_tool_button_new (GtkWidget *icon_widget, const gchar *label); GtkToolItem *gtk_menu_tool_button_new_from_stock (const gchar *stock_id); diff --git a/gtk/gtkmessagedialog.h b/gtk/gtkmessagedialog.h index b94f28cf5..99d76e5df 100644 --- a/gtk/gtkmessagedialog.h +++ b/gtk/gtkmessagedialog.h @@ -96,7 +96,7 @@ typedef enum GTK_BUTTONS_OK_CANCEL } GtkButtonsType; -GType gtk_message_dialog_get_type (void) G_GNUC_CONST; +GType gtk_message_dialog_get_type (void); GtkWidget* gtk_message_dialog_new (GtkWindow *parent, GtkDialogFlags flags, diff --git a/gtk/gtkmisc.c b/gtk/gtkmisc.c index 936e8fe70..3676204b2 100644 --- a/gtk/gtkmisc.c +++ b/gtk/gtkmisc.c @@ -339,5 +339,37 @@ gtk_misc_realize (GtkWidget *widget) } } +/* GTK+ 2.24.32 exported these marshallers by accident, through the + * glib-genmarshal it was made with, and programs built against it refer + * to them. Later releases lost them; they stay here for those programs. */ +#define COMPAT_MARSHALLER(name) \ +void gtk_marshal_ ## name (GClosure *closure, \ + GValue *return_value, \ + guint n_param_values, \ + const GValue *param_values, \ + gpointer invocation_hint, \ + gpointer marshal_data); \ +void \ +gtk_marshal_ ## name (GClosure *closure, \ + GValue *return_value, \ + guint n_param_values, \ + const GValue *param_values, \ + gpointer invocation_hint, \ + gpointer marshal_data) \ +{ \ + g_cclosure_marshal_ ## name (closure, return_value, n_param_values, \ + param_values, invocation_hint, marshal_data); \ +} + +COMPAT_MARSHALLER (VOID__BOOLEAN) +COMPAT_MARSHALLER (VOID__BOXED) +COMPAT_MARSHALLER (VOID__ENUM) +COMPAT_MARSHALLER (VOID__INT) +COMPAT_MARSHALLER (VOID__OBJECT) +COMPAT_MARSHALLER (VOID__POINTER) +COMPAT_MARSHALLER (VOID__STRING) +COMPAT_MARSHALLER (VOID__UINT) +COMPAT_MARSHALLER (VOID__VOID) + #define __GTK_MISC_C__ #include "gtkaliasdef.c" diff --git a/gtk/gtkmisc.h b/gtk/gtkmisc.h index 4246f5388..6fa565413 100644 --- a/gtk/gtkmisc.h +++ b/gtk/gtkmisc.h @@ -65,7 +65,7 @@ struct _GtkMiscClass }; -GType gtk_misc_get_type (void) G_GNUC_CONST; +GType gtk_misc_get_type (void); void gtk_misc_set_alignment (GtkMisc *misc, gfloat xalign, gfloat yalign); diff --git a/gtk/gtkmodules.c b/gtk/gtkmodules.c index a325b3e56..234380af9 100644 --- a/gtk/gtkmodules.c +++ b/gtk/gtkmodules.c @@ -123,49 +123,53 @@ split_file_list (const gchar *str) } static gchar ** -get_module_path (void) +get_module_path (gint *env_dirs) { const gchar *module_path_env; const gchar *exe_prefix; const gchar *home_dir; - gchar *home_gtk_dir = NULL; - gchar *module_path; - gchar *default_dir; + gchar **path; + gint count; static gchar **result = NULL; + static gint n_env_dirs = 0; if (result) - return result; - - home_dir = g_get_home_dir(); - if (home_dir) - home_gtk_dir = g_build_filename (home_dir, ".gtk-2.0", NULL); + { + *env_dirs = n_env_dirs; + return result; + } + home_dir = g_get_home_dir (); module_path_env = g_getenv ("GTK_PATH"); exe_prefix = g_getenv ("GTK_EXE_PREFIX"); + result = split_file_list (module_path_env); + + for (path = result; *path; path++) + n_env_dirs++; + + count = n_env_dirs; + result = g_renew (gchar *, result, count + (home_dir ? 4 : 3)); + + if (home_dir) + result[count++] = g_build_filename (home_dir, ".gtk-2.0", NULL); + if (exe_prefix) - default_dir = g_build_filename (exe_prefix, "lib", "gtk-2.0", NULL); + result[count++] = g_build_filename (exe_prefix, "lib", "gtk-2.0", NULL); else - default_dir = g_build_filename (GTK_LIBDIR, "gtk-2.0", NULL); + { + result[count++] = g_build_filename (GTK_LIBDIR, "gtk-2.0", NULL); +#ifdef __linux__ + /* where theme engines and input methods were installed before + * multiarch (/usr/lib/), as Debian's GTK+ 2 looks too */ + if (strcmp (GTK_LIBDIR, "/usr/lib") != 0 && + g_str_has_prefix (GTK_LIBDIR, "/usr/lib/")) + result[count++] = g_strdup ("/usr/lib/gtk-2.0"); +#endif + } - if (module_path_env && home_gtk_dir) - module_path = g_build_path (G_SEARCHPATH_SEPARATOR_S, - module_path_env, home_gtk_dir, default_dir, NULL); - else if (module_path_env) - module_path = g_build_path (G_SEARCHPATH_SEPARATOR_S, - module_path_env, default_dir, NULL); - else if (home_gtk_dir) - module_path = g_build_path (G_SEARCHPATH_SEPARATOR_S, - home_gtk_dir, default_dir, NULL); - else - module_path = g_build_path (G_SEARCHPATH_SEPARATOR_S, - default_dir, NULL); - - g_free (home_gtk_dir); - g_free (default_dir); - - result = split_file_list (module_path); - g_free (module_path); + result[count] = NULL; + *env_dirs = n_env_dirs; return result; } @@ -181,15 +185,18 @@ get_module_path (void) gchar ** _gtk_get_module_path (const gchar *type) { - gchar **paths = get_module_path(); gchar **path; + gchar **paths; gchar **result; gint count = 0; + gint env_dirs; + + paths = get_module_path (&env_dirs); for (path = paths; *path; path++) count++; - result = g_new (gchar *, count * 5 + 1); + result = g_new (gchar *, count * 4 + env_dirs + 1); count = 0; for (path = paths; *path; path++) @@ -219,10 +226,11 @@ _gtk_get_module_path (const gchar *type) * live directly in .../.libs directories, for example print backends, * theme engines or input modules. * - * Keep this limited to absolute paths so the removed fallback that could - * load modules from the current working directory is not reintroduced. + * Keep this limited to absolute GTK_PATH entries so the removed fallback + * that could load modules from the current working directory is not + * reintroduced for built-in default paths. */ - if (g_path_is_absolute (*path)) + if (path < paths + env_dirs && g_path_is_absolute (*path)) result[count++] = g_strdup (*path); } @@ -477,7 +485,7 @@ load_module (GSList *module_list, } } - if (success) + if (success && info) { if (!g_slist_find (module_list, info)) { diff --git a/gtk/gtkmountoperation-x11.c b/gtk/gtkmountoperation-x11.c index 6be3b65ad..0752c496b 100644 --- a/gtk/gtkmountoperation-x11.c +++ b/gtk/gtkmountoperation-x11.c @@ -658,7 +658,7 @@ pid_get_env (GPid pid, n = 0; while (TRUE) { - if (env[n] == '\0' || n >= env_len) + if (n >= env_len || env[n] == '\0') break; if (g_str_has_prefix (env + n, key) && (*(env + n + key_len) == '=')) @@ -671,7 +671,7 @@ pid_get_env (GPid pid, break; } - for (; env[n] != '\0' && n < env_len; n++) + for (; n < env_len && env[n] != '\0'; n++) ; n++; } diff --git a/gtk/gtkmountoperation.c b/gtk/gtkmountoperation.c index 618446354..cf182c476 100644 --- a/gtk/gtkmountoperation.c +++ b/gtk/gtkmountoperation.c @@ -1180,7 +1180,7 @@ on_button_press_event_for_process_tree_view (GtkWidget *widget, return ret; } -static void +static GtkWidget * create_show_processes_dialog (GMountOperation *op, const char *message, const char *choices[]) @@ -1308,9 +1308,9 @@ create_show_processes_dialog (GMountOperation *op, g_object_add_weak_pointer (G_OBJECT (tree_view), (gpointer *) &priv->process_tree_view); g_object_unref (list_store); - - gtk_widget_show_all (dialog); g_object_ref (op); + + return dialog; } static void @@ -1320,6 +1320,7 @@ gtk_mount_operation_show_processes (GMountOperation *op, const char *choices[]) { GtkMountOperationPrivate *priv; + GtkWidget *dialog = NULL; g_return_if_fail (GTK_IS_MOUNT_OPERATION (op)); g_return_if_fail (message != NULL); @@ -1331,7 +1332,7 @@ gtk_mount_operation_show_processes (GMountOperation *op, if (priv->process_list_store == NULL) { /* need to create the dialog */ - create_show_processes_dialog (op, message, choices); + dialog = create_show_processes_dialog (op, message, choices); } /* otherwise, we're showing the dialog, assume messages+choices hasn't changed */ @@ -1339,6 +1340,11 @@ gtk_mount_operation_show_processes (GMountOperation *op, update_process_list_store (GTK_MOUNT_OPERATION (op), priv->process_list_store, processes); + + if (dialog != NULL) + { + gtk_widget_show_all (dialog); + } } static void diff --git a/gtk/gtknativedialog.c b/gtk/gtknativedialog.c new file mode 100644 index 000000000..81ddfbfeb --- /dev/null +++ b/gtk/gtknativedialog.c @@ -0,0 +1,639 @@ +/* GTK - The GIMP Toolkit + * gtknativedialog.c: Native dialog + * Copyright (C) 2015, Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +/* The base class of dialogs that are not GTK+ windows - the file + * dialogs of Windows and Mac OS X, and of the desktop portal - with + * the API of GTK+ 3.20, so that programs written for it, or looking + * for it at run time as Pale Moon and Firefox do, find it here. */ + +#include "config.h" + +#include "gtknativedialog.h" +#include "gtknativedialogprivate.h" +#include "gtkdialog.h" +#include "gtkintl.h" +#include "gtkprivate.h" +#include "gtkmarshalers.h" +#include "gtkalias.h" + +typedef struct _GtkNativeDialogPrivate GtkNativeDialogPrivate; + +struct _GtkNativeDialogPrivate +{ + GtkWindow *transient_for; + char *title; + + guint visible : 1; + guint modal : 1; + + /* while in gtk_native_dialog_run() */ + gint run_response_id; + GMainLoop *run_loop; +}; + +enum { + PROP_0, + PROP_TITLE, + PROP_VISIBLE, + PROP_MODAL, + PROP_TRANSIENT_FOR, + LAST_ARG +}; + +enum { + RESPONSE, + LAST_SIGNAL +}; + +static GParamSpec *native_props[LAST_ARG] = { NULL, }; +static guint native_signals[LAST_SIGNAL]; + +G_DEFINE_ABSTRACT_TYPE_WITH_CODE (GtkNativeDialog, gtk_native_dialog, G_TYPE_OBJECT, + G_ADD_PRIVATE (GtkNativeDialog)) + +static void +gtk_native_dialog_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + GtkNativeDialog *self = GTK_NATIVE_DIALOG (object); + + switch (prop_id) + { + case PROP_TITLE: + gtk_native_dialog_set_title (self, g_value_get_string (value)); + break; + + case PROP_MODAL: + gtk_native_dialog_set_modal (self, g_value_get_boolean (value)); + break; + + case PROP_VISIBLE: + if (g_value_get_boolean (value)) + gtk_native_dialog_show (self); + else + gtk_native_dialog_hide (self); + break; + + case PROP_TRANSIENT_FOR: + gtk_native_dialog_set_transient_for (self, g_value_get_object (value)); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +gtk_native_dialog_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + GtkNativeDialog *self = GTK_NATIVE_DIALOG (object); + GtkNativeDialogPrivate *priv = gtk_native_dialog_get_instance_private (self); + + switch (prop_id) + { + case PROP_TITLE: + g_value_set_string (value, priv->title); + break; + + case PROP_MODAL: + g_value_set_boolean (value, priv->modal); + break; + + case PROP_VISIBLE: + g_value_set_boolean (value, priv->visible); + break; + + case PROP_TRANSIENT_FOR: + g_value_set_object (value, priv->transient_for); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +gtk_native_dialog_dispose (GObject *object) +{ + GtkNativeDialog *self = GTK_NATIVE_DIALOG (object); + GtkNativeDialogPrivate *priv = gtk_native_dialog_get_instance_private (self); + + if (priv->visible) + gtk_native_dialog_hide (self); + + G_OBJECT_CLASS (gtk_native_dialog_parent_class)->dispose (object); +} + +static void +gtk_native_dialog_finalize (GObject *object) +{ + GtkNativeDialog *self = GTK_NATIVE_DIALOG (object); + GtkNativeDialogPrivate *priv = gtk_native_dialog_get_instance_private (self); + + g_free (priv->title); + if (priv->transient_for) + g_object_unref (priv->transient_for); + + G_OBJECT_CLASS (gtk_native_dialog_parent_class)->finalize (object); +} + +static void +gtk_native_dialog_class_init (GtkNativeDialogClass *class) +{ + GObjectClass *gobject_class = G_OBJECT_CLASS (class); + + gobject_class->set_property = gtk_native_dialog_set_property; + gobject_class->get_property = gtk_native_dialog_get_property; + gobject_class->finalize = gtk_native_dialog_finalize; + gobject_class->dispose = gtk_native_dialog_dispose; + + /** + * GtkNativeDialog:title: + * + * The title of the dialog window + * + * Since: 2.24 + */ + native_props[PROP_TITLE] = + g_param_spec_string ("title", + P_("Dialog Title"), + P_("The title of the file chooser dialog"), + NULL, + GTK_PARAM_READWRITE); + + /** + * GtkNativeDialog:modal: + * + * Whether the window should be modal with respect to its transient parent. + * + * Since: 2.24 + */ + native_props[PROP_MODAL] = + g_param_spec_boolean ("modal", + P_("Modal"), + P_("If TRUE, the dialog is modal (other windows are not usable while this one is up)"), + FALSE, + GTK_PARAM_READWRITE); + + /** + * GtkNativeDialog:visible: + * + * Whether the window is currently visible. + * + * Since: 2.24 + */ + native_props[PROP_VISIBLE] = + g_param_spec_boolean ("visible", + P_("Visible"), + P_("Whether the dialog is currently visible"), + FALSE, + GTK_PARAM_READWRITE); + + /** + * GtkNativeDialog:transient-for: + * + * The transient parent of the dialog, or %NULL for none. + * + * Since: 2.24 + */ + native_props[PROP_TRANSIENT_FOR] = + g_param_spec_object ("transient-for", + P_("Transient for Window"), + P_("The transient parent of the dialog"), + GTK_TYPE_WINDOW, + GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT); + + g_object_class_install_properties (gobject_class, LAST_ARG, native_props); + + /** + * GtkNativeDialog::response: + * @self: the object on which the signal is emitted + * @response_id: the response ID + * + * Emitted when the user responds to the dialog. + * + * When this is called the dialog has been hidden. + * + * If you call gtk_native_dialog_hide() before the user responds to + * the dialog this signal will not be emitted. + * + * Since: 2.24 + */ + native_signals[RESPONSE] = + g_signal_new (I_("response"), + G_OBJECT_CLASS_TYPE (class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (GtkNativeDialogClass, response), + NULL, NULL, + _gtk_marshal_VOID__INT, + G_TYPE_NONE, 1, + G_TYPE_INT); +} + +static void +gtk_native_dialog_init (GtkNativeDialog *self) +{ +} + +/** + * gtk_native_dialog_show: + * @self: a #GtkNativeDialog + * + * Shows the dialog on the display, allowing the user to interact with + * it. When the user accepts the state of the dialog the dialog will + * be automatically hidden and the #GtkNativeDialog::response signal + * will be emitted. + * + * Multiple calls while the dialog is visible will be ignored. + * + * Since: 2.24 + **/ +void +gtk_native_dialog_show (GtkNativeDialog *self) +{ + GtkNativeDialogPrivate *priv; + GtkNativeDialogClass *klass; + + g_return_if_fail (GTK_IS_NATIVE_DIALOG (self)); + + priv = gtk_native_dialog_get_instance_private (self); + if (priv->visible) + return; + + klass = GTK_NATIVE_DIALOG_GET_CLASS (self); + + g_return_if_fail (klass->show != NULL); + + klass->show (self); + + priv->visible = TRUE; + g_object_notify_by_pspec (G_OBJECT (self), native_props[PROP_VISIBLE]); +} + +/** + * gtk_native_dialog_hide: + * @self: a #GtkNativeDialog + * + * Hides the dialog if it is visilbe, aborting any interaction. Once this + * is called the #GtkNativeDialog::response signal will not be emitted + * until after the next call to gtk_native_dialog_show(). + * + * If the dialog is not visible this does nothing. + * + * Since: 2.24 + **/ +void +gtk_native_dialog_hide (GtkNativeDialog *self) +{ + GtkNativeDialogPrivate *priv; + GtkNativeDialogClass *klass; + + g_return_if_fail (GTK_IS_NATIVE_DIALOG (self)); + + priv = gtk_native_dialog_get_instance_private (self); + if (!priv->visible) + return; + + priv->visible = FALSE; + + klass = GTK_NATIVE_DIALOG_GET_CLASS (self); + + g_return_if_fail (klass->hide != NULL); + + klass->hide (self); + + if (priv->run_loop && g_main_loop_is_running (priv->run_loop)) + g_main_loop_quit (priv->run_loop); + + g_object_notify_by_pspec (G_OBJECT (self), native_props[PROP_VISIBLE]); +} + +/** + * gtk_native_dialog_destroy: + * @self: a #GtkNativeDialog + * + * Destroys a dialog. + * + * When a dialog is destroyed, it will break any references it holds + * to other objects. If it is visible it will be hidden and any underlying + * window system resources will be destroyed. + * + * Note that this does not release any reference to the object (as opposed to + * destroying a GtkWindow) because there is no reference from the windowing + * system to the #GtkNativeDialog. + * + * Since: 2.24 + **/ +void +gtk_native_dialog_destroy (GtkNativeDialog *self) +{ + g_return_if_fail (GTK_IS_NATIVE_DIALOG (self)); + + g_object_run_dispose (G_OBJECT (self)); +} + +void +_gtk_native_dialog_emit_response (GtkNativeDialog *self, + int response_id) +{ + GtkNativeDialogPrivate *priv = gtk_native_dialog_get_instance_private (self); + + priv->visible = FALSE; + g_object_notify_by_pspec (G_OBJECT (self), native_props[PROP_VISIBLE]); + + g_signal_emit (self, native_signals[RESPONSE], 0, response_id); +} + +/** + * gtk_native_dialog_get_visible: + * @self: a #GtkNativeDialog + * + * Determines whether the dialog is visible. + * + * Returns: %TRUE if the dialog is visible + * + * Since: 2.24 + **/ +gboolean +gtk_native_dialog_get_visible (GtkNativeDialog *self) +{ + GtkNativeDialogPrivate *priv; + + g_return_val_if_fail (GTK_IS_NATIVE_DIALOG (self), FALSE); + + priv = gtk_native_dialog_get_instance_private (self); + return priv->visible; +} + +/** + * gtk_native_dialog_set_modal: + * @self: a #GtkNativeDialog + * @modal: whether the window is modal + * + * Sets a dialog modal or non-modal. Modal dialogs prevent interaction + * with other windows in the same application. To keep modal dialogs + * on top of main application windows, use + * gtk_native_dialog_set_transient_for() to make the dialog transient for the + * parent; most [window managers][gtk-X11-arch] + * will then disallow lowering the dialog below the parent. + * + * Since: 2.24 + **/ +void +gtk_native_dialog_set_modal (GtkNativeDialog *self, + gboolean modal) +{ + GtkNativeDialogPrivate *priv; + + g_return_if_fail (GTK_IS_NATIVE_DIALOG (self)); + + priv = gtk_native_dialog_get_instance_private (self); + modal = modal != FALSE; + + if (priv->modal == modal) + return; + + priv->modal = modal; + g_object_notify_by_pspec (G_OBJECT (self), native_props[PROP_MODAL]); +} + +/** + * gtk_native_dialog_get_modal: + * @self: a #GtkNativeDialog + * + * Returns whether the dialog is modal. See gtk_native_dialog_set_modal(). + * + * Returns: %TRUE if the dialog is set to be modal + * + * Since: 2.24 + **/ +gboolean +gtk_native_dialog_get_modal (GtkNativeDialog *self) +{ + GtkNativeDialogPrivate *priv; + + g_return_val_if_fail (GTK_IS_NATIVE_DIALOG (self), FALSE); + + priv = gtk_native_dialog_get_instance_private (self); + return priv->modal; +} + +/** + * gtk_native_dialog_set_title: + * @self: a #GtkNativeDialog + * @title: title of the dialog + * + * Sets the title of the #GtkNativeDialog. + * + * Since: 2.24 + **/ +void +gtk_native_dialog_set_title (GtkNativeDialog *self, + const char *title) +{ + GtkNativeDialogPrivate *priv; + + g_return_if_fail (GTK_IS_NATIVE_DIALOG (self)); + + priv = gtk_native_dialog_get_instance_private (self); + g_free (priv->title); + priv->title = g_strdup (title); + + g_object_notify_by_pspec (G_OBJECT (self), native_props[PROP_TITLE]); +} + +/** + * gtk_native_dialog_get_title: + * @self: a #GtkNativeDialog + * + * Gets the title of the #GtkNativeDialog. + * + * Returns: (nullable): the title of the dialog, or %NULL if none has + * been set explicitly. The returned string is owned by the widget + * and must not be modified or freed. + * + * Since: 2.24 + **/ +const char * +gtk_native_dialog_get_title (GtkNativeDialog *self) +{ + GtkNativeDialogPrivate *priv; + + g_return_val_if_fail (GTK_IS_NATIVE_DIALOG (self), NULL); + + priv = gtk_native_dialog_get_instance_private (self); + return priv->title; +} + +/** + * gtk_native_dialog_set_transient_for: + * @self: a #GtkNativeDialog + * @parent: (allow-none): parent window, or %NULL + * + * Dialog windows should be set transient for the main application + * window they were spawned from. This allows + * [window managers][gtk-X11-arch] to e.g. keep the + * dialog on top of the main window, or center the dialog over the + * main window. + * + * Passing %NULL for @parent unsets the current transient window. + * + * Since: 2.24 + */ +void +gtk_native_dialog_set_transient_for (GtkNativeDialog *self, + GtkWindow *parent) +{ + GtkNativeDialogPrivate *priv; + + g_return_if_fail (GTK_IS_NATIVE_DIALOG (self)); + + priv = gtk_native_dialog_get_instance_private (self); + if (priv->transient_for == parent) + return; + + if (parent) + g_object_ref (parent); + if (priv->transient_for) + g_object_unref (priv->transient_for); + priv->transient_for = parent; + + g_object_notify_by_pspec (G_OBJECT (self), native_props[PROP_TRANSIENT_FOR]); +} + +/** + * gtk_native_dialog_get_transient_for: + * @self: a #GtkNativeDialog + * + * Fetches the transient parent for this window. See + * gtk_native_dialog_set_transient_for(). + * + * Returns: (nullable) (transfer none): the transient parent for this window, + * or %NULL if no transient parent has been set. + * + * Since: 2.24 + **/ +GtkWindow * +gtk_native_dialog_get_transient_for (GtkNativeDialog *self) +{ + GtkNativeDialogPrivate *priv; + + g_return_val_if_fail (GTK_IS_NATIVE_DIALOG (self), NULL); + + priv = gtk_native_dialog_get_instance_private (self); + return priv->transient_for; +} + +static void +run_response_cb (GtkNativeDialog *self, + gint response_id, + gpointer data) +{ + GtkNativeDialogPrivate *priv = gtk_native_dialog_get_instance_private (self); + + priv->run_response_id = response_id; + if (priv->run_loop && g_main_loop_is_running (priv->run_loop)) + g_main_loop_quit (priv->run_loop); +} + +/** + * gtk_native_dialog_run: + * @self: a #GtkNativeDialog + * + * Blocks in a recursive main loop until @self emits the + * #GtkNativeDialog::response signal. It then returns the response ID + * from the ::response signal emission. + * + * Before entering the recursive main loop, gtk_native_dialog_run() + * calls gtk_native_dialog_show() on the dialog for you. + * + * After gtk_native_dialog_run() returns, then dialog will be hidden. + * + * Note that even though the recursive main loop gives the effect of a + * modal dialog (it prevents the user from interacting with other + * windows in the same window group while the dialog is run), callbacks + * such as timeouts, IO channel watches, DND drops, etc, will + * be triggered during a gtk_native_dialog_run() call. + * + * Returns: response ID + * + * Since: 2.24 + **/ +gint +gtk_native_dialog_run (GtkNativeDialog *self) +{ + GtkNativeDialogPrivate *priv; + gboolean was_modal; + gulong response_handler; + + g_return_val_if_fail (GTK_IS_NATIVE_DIALOG (self), -1); + + priv = gtk_native_dialog_get_instance_private (self); + g_return_val_if_fail (!priv->visible, -1); + g_return_val_if_fail (priv->run_loop == NULL, -1); + + if (priv->visible || priv->run_loop != NULL) + return -1; + + g_object_ref (self); + + priv->run_response_id = GTK_RESPONSE_NONE; + priv->run_loop = g_main_loop_new (NULL, FALSE); + + was_modal = priv->modal; + gtk_native_dialog_set_modal (self, TRUE); + + response_handler = + g_signal_connect (self, + "response", + G_CALLBACK (run_response_cb), + NULL); + + gtk_native_dialog_show (self); + + if (priv->visible) + { + GDK_THREADS_LEAVE (); + g_main_loop_run (priv->run_loop); + GDK_THREADS_ENTER (); + } + + g_signal_handler_disconnect (self, response_handler); + + g_main_loop_unref (priv->run_loop); + priv->run_loop = NULL; + + if (!was_modal) + gtk_native_dialog_set_modal (self, FALSE); + + g_object_unref (self); + + return priv->run_response_id; +} + +#define __GTK_NATIVE_DIALOG_C__ +#include "gtkaliasdef.c" diff --git a/gtk/gtknativedialog.h b/gtk/gtknativedialog.h new file mode 100644 index 000000000..11120aa1e --- /dev/null +++ b/gtk/gtknativedialog.h @@ -0,0 +1,86 @@ +/* GTK - The GIMP Toolkit + * gtknativedialog.h: Native dialog + * Copyright (C) 2015, Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef __GTK_NATIVE_DIALOG_H__ +#define __GTK_NATIVE_DIALOG_H__ + +#if defined(GTK_DISABLE_SINGLE_INCLUDES) && !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION) +#error "Only can be included directly." +#endif + +#include + +G_BEGIN_DECLS + +#define GTK_TYPE_NATIVE_DIALOG (gtk_native_dialog_get_type ()) +#define GTK_NATIVE_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_NATIVE_DIALOG, GtkNativeDialog)) +#define GTK_NATIVE_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_NATIVE_DIALOG, GtkNativeDialogClass)) +#define GTK_IS_NATIVE_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_NATIVE_DIALOG)) +#define GTK_IS_NATIVE_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_NATIVE_DIALOG)) +#define GTK_NATIVE_DIALOG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_NATIVE_DIALOG, GtkNativeDialogClass)) + +typedef struct _GtkNativeDialog GtkNativeDialog; +typedef struct _GtkNativeDialogClass GtkNativeDialogClass; + +/* A dialog of the system, or of the desktop portal, with the API of + * GTK+ 3.20; see GtkFileChooserNative */ +struct _GtkNativeDialog +{ + GObject parent_instance; +}; + +struct _GtkNativeDialogClass +{ + GObjectClass parent_class; + + void (* response) (GtkNativeDialog *self, gint response_id); + + /* */ + void (* show) (GtkNativeDialog *self); + void (* hide) (GtkNativeDialog *self); + + /* Padding for future expansion */ + void (*_gtk_reserved1) (void); + void (*_gtk_reserved2) (void); + void (*_gtk_reserved3) (void); + void (*_gtk_reserved4) (void); +}; + +GType gtk_native_dialog_get_type (void); + +void gtk_native_dialog_show (GtkNativeDialog *self); +void gtk_native_dialog_hide (GtkNativeDialog *self); +void gtk_native_dialog_destroy (GtkNativeDialog *self); +gboolean gtk_native_dialog_get_visible (GtkNativeDialog *self); +void gtk_native_dialog_set_modal (GtkNativeDialog *self, + gboolean modal); +gboolean gtk_native_dialog_get_modal (GtkNativeDialog *self); +void gtk_native_dialog_set_title (GtkNativeDialog *self, + const char *title); +const char *gtk_native_dialog_get_title (GtkNativeDialog *self); +void gtk_native_dialog_set_transient_for (GtkNativeDialog *self, + GtkWindow *parent); +GtkWindow * gtk_native_dialog_get_transient_for (GtkNativeDialog *self); + +gint gtk_native_dialog_run (GtkNativeDialog *self); + +G_END_DECLS + +#endif /* __GTK_NATIVE_DIALOG_H__ */ diff --git a/gtk/gtknativedialogprivate.h b/gtk/gtknativedialogprivate.h new file mode 100644 index 000000000..89573eafd --- /dev/null +++ b/gtk/gtknativedialogprivate.h @@ -0,0 +1,33 @@ +/* GTK - The GIMP Toolkit + * gtknativedialogprivate.h: Native dialog + * Copyright (C) 2015, Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef __GTK_NATIVE_DIALOG_PRIVATE_H__ +#define __GTK_NATIVE_DIALOG_PRIVATE_H__ + +#include + +G_BEGIN_DECLS + +void _gtk_native_dialog_emit_response (GtkNativeDialog *self, + int response_id); + +G_END_DECLS + +#endif /* __GTK_NATIVE_DIALOG_PRIVATE_H__ */ diff --git a/gtk/gtknotebook.c b/gtk/gtknotebook.c index 1b514ca5f..809055bf3 100644 --- a/gtk/gtknotebook.c +++ b/gtk/gtknotebook.c @@ -2249,6 +2249,7 @@ gtk_notebook_size_allocate (GtkWidget *widget, for (i = 0; i < N_ACTION_WIDGETS; i++) { GtkAllocation widget_allocation; + GtkRequisition action_requisition; if (!priv->action_widget[i]) continue; @@ -2257,6 +2258,11 @@ gtk_notebook_size_allocate (GtkWidget *widget, widget_allocation.y = widget->allocation.y + border_width; is_rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL; + /* Use the requisition as adjusted by gtk_widget_set_size_request(), + * which is what gtk_notebook_size_request() reserved space for */ + gtk_widget_get_child_requisition (priv->action_widget[i], + &action_requisition); + switch (tab_pos) { case GTK_POS_BOTTOM: @@ -2264,14 +2270,14 @@ gtk_notebook_size_allocate (GtkWidget *widget, widget->allocation.height - 2 * border_width - notebook->cur_page->requisition.height; /* fall through */ case GTK_POS_TOP: - widget_allocation.width = priv->action_widget[i]->requisition.width; + widget_allocation.width = action_requisition.width; widget_allocation.height = notebook->cur_page->requisition.height - widget->style->ythickness; if ((i == ACTION_WIDGET_START && is_rtl) || (i == ACTION_WIDGET_END && !is_rtl)) widget_allocation.x += widget->allocation.width - 2 * border_width - - priv->action_widget[i]->requisition.width; + action_requisition.width; if (tab_pos == GTK_POS_TOP) /* no fall through */ widget_allocation.y += 2 * focus_width; break; @@ -2280,13 +2286,13 @@ gtk_notebook_size_allocate (GtkWidget *widget, widget->allocation.width - 2 * border_width - notebook->cur_page->requisition.width; /* fall through */ case GTK_POS_LEFT: - widget_allocation.height = priv->action_widget[i]->requisition.height; + widget_allocation.height = action_requisition.height; widget_allocation.width = notebook->cur_page->requisition.width - widget->style->xthickness; if (i == ACTION_WIDGET_END) widget_allocation.y += widget->allocation.height - 2 * border_width - - priv->action_widget[i]->requisition.height; + action_requisition.height; if (tab_pos == GTK_POS_LEFT) /* no fall through */ widget_allocation.x += 2 * focus_width; break; @@ -2612,6 +2618,11 @@ gtk_notebook_scroll (GtkWidget *widget, GtkWidget *child, *event_widget; gint i; + /* a pinch on a touchpad (Ctrl with the wheel) is for programs that + * zoom, not for scrolling here */ + if (gdk_event_get_touchpad_emulated ((GdkEvent *) event)) + return FALSE; + if (!notebook->cur_page) return FALSE; @@ -2641,6 +2652,8 @@ gtk_notebook_scroll (GtkWidget *widget, case GDK_SCROLL_UP: gtk_notebook_prev_page (notebook); break; + default: + break; } return TRUE; @@ -3004,17 +3017,16 @@ gtk_notebook_button_release (GtkWidget *widget, { GtkNotebook *notebook; GtkNotebookPrivate *priv; - GtkNotebookPage *page; if (event->type != GDK_BUTTON_RELEASE) return FALSE; notebook = GTK_NOTEBOOK (widget); priv = GTK_NOTEBOOK_GET_PRIVATE (notebook); - page = notebook->cur_page; if (!priv->during_detach && - page->reorderable && + notebook->cur_page && + notebook->cur_page->reorderable && event->button == priv->pressed_button) gtk_notebook_stop_reorder (notebook); @@ -3968,7 +3980,7 @@ focus_tabs_in (GtkNotebook *notebook) if (notebook->show_tabs && notebook->cur_page) { gtk_widget_grab_focus (GTK_WIDGET (notebook)); - + gtk_notebook_set_focus_child (GTK_CONTAINER (notebook), NULL); gtk_notebook_switch_focus_tab (notebook, g_list_find (notebook->children, notebook->cur_page)); @@ -4687,7 +4699,10 @@ gtk_notebook_real_remove (GtkNotebook *notebook, gtk_widget_unparent (page->child); tab_label = page->tab_label; - if (tab_label) + /* Do not unparent the tab label if it's already in another + hierarchy. It means we are in the middle of a DnD and it's + already taken care of. */ + if (tab_label && NOTEBOOK_IS_TAB_LABEL_PARENT (notebook, page)) { g_object_ref (tab_label); gtk_notebook_remove_tab_label (notebook, page); @@ -7383,7 +7398,6 @@ gtk_notebook_set_tab_label_text (GtkNotebook *notebook, if (tab_text) tab_label = gtk_label_new (tab_text); gtk_notebook_set_tab_label (notebook, child, tab_label); - gtk_widget_child_notify (child, "tab-label"); } /** diff --git a/gtk/gtknotebook.h b/gtk/gtknotebook.h index e2e6e01e3..b9b6cd582 100644 --- a/gtk/gtknotebook.h +++ b/gtk/gtknotebook.h @@ -148,7 +148,7 @@ typedef GtkNotebook* (*GtkNotebookWindowCreationFunc) (GtkNotebook *source, * Creation, insertion, deletion * ***********************************************************/ -GType gtk_notebook_get_type (void) G_GNUC_CONST; +GType gtk_notebook_get_type (void); GtkWidget * gtk_notebook_new (void); gint gtk_notebook_append_page (GtkNotebook *notebook, GtkWidget *child, diff --git a/gtk/gtkobject.h b/gtk/gtkobject.h index 97f1efaa5..dbddd20c3 100644 --- a/gtk/gtkobject.h +++ b/gtk/gtkobject.h @@ -143,7 +143,7 @@ struct _GtkObjectClass /* Application-level methods */ -GType gtk_object_get_type (void) G_GNUC_CONST; +GType gtk_object_get_type (void); #ifndef GTK_DISABLE_DEPRECATED void gtk_object_sink (GtkObject *object); diff --git a/gtk/gtkoffscreenwindow.h b/gtk/gtkoffscreenwindow.h index cb1c56e4d..3cab8fd4a 100644 --- a/gtk/gtkoffscreenwindow.h +++ b/gtk/gtkoffscreenwindow.h @@ -49,7 +49,7 @@ struct _GtkOffscreenWindowClass GtkWindowClass parent_class; }; -GType gtk_offscreen_window_get_type (void) G_GNUC_CONST; +GType gtk_offscreen_window_get_type (void); GtkWidget *gtk_offscreen_window_new (void); GdkPixmap *gtk_offscreen_window_get_pixmap (GtkOffscreenWindow *offscreen); diff --git a/gtk/gtkoldeditable.h b/gtk/gtkoldeditable.h index 4b4dccdc3..107bc7e34 100644 --- a/gtk/gtkoldeditable.h +++ b/gtk/gtkoldeditable.h @@ -113,7 +113,7 @@ struct _GtkOldEditableClass gint position); }; -GType gtk_old_editable_get_type (void) G_GNUC_CONST; +GType gtk_old_editable_get_type (void); void gtk_old_editable_claim_selection (GtkOldEditable *old_editable, gboolean claim, guint32 time_); diff --git a/gtk/gtkoptionmenu.c b/gtk/gtkoptionmenu.c index 36f0b6a31..3db2e6546 100644 --- a/gtk/gtkoptionmenu.c +++ b/gtk/gtkoptionmenu.c @@ -994,6 +994,11 @@ gtk_option_menu_scroll_event (GtkWidget *widget, GList *l; GtkMenuItem *item; + /* a pinch on a touchpad (Ctrl with the wheel) is for programs that + * zoom, not for scrolling here */ + if (gdk_event_get_touchpad_emulated ((GdkEvent *) event)) + return FALSE; + index = gtk_option_menu_get_history (option_menu); if (index != -1) diff --git a/gtk/gtkoptionmenu.h b/gtk/gtkoptionmenu.h index 352774163..bd521da87 100644 --- a/gtk/gtkoptionmenu.h +++ b/gtk/gtkoptionmenu.h @@ -70,7 +70,7 @@ struct _GtkOptionMenuClass }; -GType gtk_option_menu_get_type (void) G_GNUC_CONST; +GType gtk_option_menu_get_type (void); GtkWidget* gtk_option_menu_new (void); GtkWidget* gtk_option_menu_get_menu (GtkOptionMenu *option_menu); void gtk_option_menu_set_menu (GtkOptionMenu *option_menu, diff --git a/gtk/gtkorientable.h b/gtk/gtkorientable.h index f9014e72c..41aa8ff72 100644 --- a/gtk/gtkorientable.h +++ b/gtk/gtkorientable.h @@ -49,7 +49,7 @@ struct _GtkOrientableIface }; -GType gtk_orientable_get_type (void) G_GNUC_CONST; +GType gtk_orientable_get_type (void); void gtk_orientable_set_orientation (GtkOrientable *orientable, GtkOrientation orientation); diff --git a/gtk/gtkpagesetup.h b/gtk/gtkpagesetup.h index 34e2e256c..c1fb5028e 100644 --- a/gtk/gtkpagesetup.h +++ b/gtk/gtkpagesetup.h @@ -37,7 +37,7 @@ typedef struct _GtkPageSetup GtkPageSetup; #define GTK_PAGE_SETUP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_PAGE_SETUP, GtkPageSetup)) #define GTK_IS_PAGE_SETUP(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_PAGE_SETUP)) -GType gtk_page_setup_get_type (void) G_GNUC_CONST; +GType gtk_page_setup_get_type (void); GtkPageSetup * gtk_page_setup_new (void); GtkPageSetup * gtk_page_setup_copy (GtkPageSetup *other); GtkPageOrientation gtk_page_setup_get_orientation (GtkPageSetup *setup); diff --git a/gtk/gtkpagesetupunixdialog.h b/gtk/gtkpagesetupunixdialog.h index 4d889fe56..f77e4ccf1 100644 --- a/gtk/gtkpagesetupunixdialog.h +++ b/gtk/gtkpagesetupunixdialog.h @@ -61,7 +61,7 @@ struct _GtkPageSetupUnixDialogClass void (*_gtk_reserved7) (void); }; -GType gtk_page_setup_unix_dialog_get_type (void) G_GNUC_CONST; +GType gtk_page_setup_unix_dialog_get_type (void); GtkWidget * gtk_page_setup_unix_dialog_new (const gchar *title, GtkWindow *parent); void gtk_page_setup_unix_dialog_set_page_setup (GtkPageSetupUnixDialog *dialog, diff --git a/gtk/gtkpaned.c b/gtk/gtkpaned.c index 36e532363..c2c316e3b 100644 --- a/gtk/gtkpaned.c +++ b/gtk/gtkpaned.c @@ -1495,7 +1495,10 @@ gtk_paned_set_position (GtkPaned *paned, g_return_if_fail (GTK_IS_PANED (paned)); - if (paned->child1_size == position) + /* the current position, which may just be the computed one, still + * has to become the set one */ + if (paned->child1_size == position && + (position < 0 || paned->position_set)) return; object = G_OBJECT (paned); diff --git a/gtk/gtkpaned.h b/gtk/gtkpaned.h index 7d361efa6..eb13f7b37 100644 --- a/gtk/gtkpaned.h +++ b/gtk/gtkpaned.h @@ -106,7 +106,7 @@ struct _GtkPanedClass }; -GType gtk_paned_get_type (void) G_GNUC_CONST; +GType gtk_paned_get_type (void); void gtk_paned_add1 (GtkPaned *paned, GtkWidget *child); void gtk_paned_add2 (GtkPaned *paned, diff --git a/gtk/gtkpapersize.h b/gtk/gtkpapersize.h index 6e7a02a85..77a7aa326 100644 --- a/gtk/gtkpapersize.h +++ b/gtk/gtkpapersize.h @@ -44,7 +44,7 @@ typedef struct _GtkPaperSize GtkPaperSize; #define GTK_PAPER_NAME_EXECUTIVE "na_executive" #define GTK_PAPER_NAME_LEGAL "na_legal" -GType gtk_paper_size_get_type (void) G_GNUC_CONST; +GType gtk_paper_size_get_type (void); GtkPaperSize *gtk_paper_size_new (const gchar *name); GtkPaperSize *gtk_paper_size_new_from_ppd (const gchar *ppd_name, diff --git a/gtk/gtkpathbar.c b/gtk/gtkpathbar.c index fc9da8acc..9b6db49a3 100644 --- a/gtk/gtkpathbar.c +++ b/gtk/gtkpathbar.c @@ -688,6 +688,11 @@ static gboolean gtk_path_bar_scroll (GtkWidget *widget, GdkEventScroll *event) { + /* a pinch on a touchpad (Ctrl with the wheel) is for programs that + * zoom, not for scrolling here */ + if (gdk_event_get_touchpad_emulated ((GdkEvent *) event)) + return FALSE; + switch (event->direction) { case GDK_SCROLL_RIGHT: @@ -698,6 +703,8 @@ gtk_path_bar_scroll (GtkWidget *widget, case GDK_SCROLL_UP: gtk_path_bar_scroll_up (GTK_PATH_BAR (widget)); break; + default: + break; } return TRUE; @@ -1644,7 +1651,11 @@ gtk_path_bar_get_info_callback (GCancellable *cancellable, gboolean info_is_hidden = FALSE; gboolean info_is_backup = FALSE; - if (cancellable != file_info->path_bar->get_info_cancellable) + /* A cancelled lookup is no longer the path bar's (it was replaced or + * the path bar was disposed); the path bar may be gone, so do not + * look at it. */ + if (cancelled || + cancellable != file_info->path_bar->get_info_cancellable) { gtk_path_bar_set_file_finish (file_info, FALSE); g_object_unref (cancellable); @@ -1828,5 +1839,51 @@ _gtk_path_bar_down (GtkPathBar *path_bar) } } + +/** + * _gtk_path_bar_get_file_at: + * @path_bar: a #GtkPathBar + * @x: X coordinate, relative to the path bar + * @y: Y coordinate, relative to the path bar + * @button: (out): the button there + * + * For dropping files on the folders of the path bar. + * + * Returns: the folder of the button at @x, @y, or %NULL + **/ +GFile * +_gtk_path_bar_get_file_at (GtkPathBar *path_bar, + gint x, + gint y, + GtkWidget **button) +{ + GtkWidget *widget = GTK_WIDGET (path_bar); + GList *l; + + *button = NULL; + /* the path bar has no window: the buttons are placed in the one of + * its parent, as the coordinates of a drop are not */ + x += widget->allocation.x; + y += widget->allocation.y; + + for (l = path_bar->button_list; l; l = l->next) + { + ButtonData *button_data = l->data; + GtkWidget *b = button_data->button; + + if (!gtk_widget_get_visible (b) || !gtk_widget_get_child_visible (b)) + continue; + + if (x >= b->allocation.x && x < b->allocation.x + b->allocation.width && + y >= b->allocation.y && y < b->allocation.y + b->allocation.height) + { + *button = b; + return button_data->file; + } + } + + return NULL; +} + #define __GTK_PATH_BAR_C__ #include "gtkaliasdef.c" diff --git a/gtk/gtkpathbar.h b/gtk/gtkpathbar.h index 2006411a0..f4cd96f32 100644 --- a/gtk/gtkpathbar.h +++ b/gtk/gtkpathbar.h @@ -81,7 +81,7 @@ struct _GtkPathBarClass gboolean child_is_hidden); }; -GType gtk_path_bar_get_type (void) G_GNUC_CONST; +GType gtk_path_bar_get_type (void); void _gtk_path_bar_set_file_system (GtkPathBar *path_bar, GtkFileSystem *file_system); gboolean _gtk_path_bar_set_file (GtkPathBar *path_bar, @@ -90,6 +90,10 @@ gboolean _gtk_path_bar_set_file (GtkPathBar *path_bar, GError **error); void _gtk_path_bar_up (GtkPathBar *path_bar); void _gtk_path_bar_down (GtkPathBar *path_bar); +GFile *_gtk_path_bar_get_file_at (GtkPathBar *path_bar, + gint x, + gint y, + GtkWidget **button); G_END_DECLS diff --git a/gtk/gtkpixmap.h b/gtk/gtkpixmap.h index 21fa34993..4002033b7 100644 --- a/gtk/gtkpixmap.h +++ b/gtk/gtkpixmap.h @@ -62,7 +62,7 @@ struct _GtkPixmapClass }; -GType gtk_pixmap_get_type (void) G_GNUC_CONST; +GType gtk_pixmap_get_type (void); GtkWidget* gtk_pixmap_new (GdkPixmap *pixmap, GdkBitmap *mask); void gtk_pixmap_set (GtkPixmap *pixmap, diff --git a/gtk/gtkplug.h b/gtk/gtkplug.h index 69f90ba75..d9ff02c1b 100644 --- a/gtk/gtkplug.h +++ b/gtk/gtkplug.h @@ -75,7 +75,7 @@ struct _GtkPlugClass }; -GType gtk_plug_get_type (void) G_GNUC_CONST; +GType gtk_plug_get_type (void); #ifndef GDK_MULTIHEAD_SAFE void gtk_plug_construct (GtkPlug *plug, diff --git a/gtk/gtkpreview.h b/gtk/gtkpreview.h index 5e87c94aa..c4098023d 100644 --- a/gtk/gtkpreview.h +++ b/gtk/gtkpreview.h @@ -86,7 +86,7 @@ struct _GtkPreviewClass }; -GType gtk_preview_get_type (void) G_GNUC_CONST; +GType gtk_preview_get_type (void); void gtk_preview_uninit (void); GtkWidget* gtk_preview_new (GtkPreviewType type); void gtk_preview_size (GtkPreview *preview, diff --git a/gtk/gtkprintbackend.c b/gtk/gtkprintbackend.c index 66f5b41a9..86921174b 100644 --- a/gtk/gtkprintbackend.c +++ b/gtk/gtkprintbackend.c @@ -48,8 +48,18 @@ struct _GtkPrintBackendPrivate GtkPrintBackendStatus status; char **auth_info_required; char **auth_info; + GtkWidget *remember; /* "Remember password", if offered */ }; +/* A backend that can keep passwords in the user's keyring puts these into + * the first two reserved slots of its class: whether it can do so for the + * password asked for now, and set_password() with the user's choice. */ +typedef gboolean (*CanStorePasswordFunc) (GtkPrintBackend *backend); +typedef void (*SetPasswordFullFunc) (GtkPrintBackend *backend, + gchar **auth_info_required, + gchar **auth_info, + gboolean store_auth_info); + enum { PRINTER_LIST_CHANGED, PRINTER_LIST_DONE, @@ -698,10 +708,15 @@ password_dialog_response (GtkWidget *dialog, GtkPrintBackendPrivate *priv = backend->priv; gint i; - if (response_id == GTK_RESPONSE_OK) + if (response_id == GTK_RESPONSE_OK && priv->remember != NULL && + gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->remember))) + ((SetPasswordFullFunc) GTK_PRINT_BACKEND_GET_CLASS (backend)->_gtk_reserved2) + (backend, priv->auth_info_required, priv->auth_info, TRUE); + else if (response_id == GTK_RESPONSE_OK) gtk_print_backend_set_password (backend, priv->auth_info_required, priv->auth_info); else gtk_print_backend_set_password (backend, priv->auth_info_required, NULL); + priv->remember = NULL; for (i = 0; i < g_strv_length (priv->auth_info_required); i++) if (priv->auth_info[i] != NULL) @@ -810,6 +825,15 @@ request_password (GtkPrintBackend *backend, } } + priv->remember = NULL; + if (GTK_PRINT_BACKEND_GET_CLASS (backend)->_gtk_reserved1 != NULL && + GTK_PRINT_BACKEND_GET_CLASS (backend)->_gtk_reserved2 != NULL && + ((CanStorePasswordFunc) GTK_PRINT_BACKEND_GET_CLASS (backend)->_gtk_reserved1) (backend)) + { + priv->remember = gtk_check_button_new_with_mnemonic (_("_Remember password")); + gtk_box_pack_start (GTK_BOX (vbox), priv->remember, FALSE, FALSE, 6); + } + if (focus != NULL) { gtk_widget_grab_focus (focus); diff --git a/gtk/gtkprintbackend.h b/gtk/gtkprintbackend.h index 6847c1f23..ab49b80e8 100644 --- a/gtk/gtkprintbackend.h +++ b/gtk/gtkprintbackend.h @@ -139,7 +139,7 @@ struct _GtkPrintBackendClass void (*_gtk_reserved4) (void); }; -GType gtk_print_backend_get_type (void) G_GNUC_CONST; +GType gtk_print_backend_get_type (void); GList *gtk_print_backend_get_printer_list (GtkPrintBackend *print_backend); gboolean gtk_print_backend_printer_list_is_done (GtkPrintBackend *print_backend); diff --git a/gtk/gtkprintcontext.h b/gtk/gtkprintcontext.h index 7501d05e1..dfc4b40ab 100644 --- a/gtk/gtkprintcontext.h +++ b/gtk/gtkprintcontext.h @@ -38,7 +38,7 @@ typedef struct _GtkPrintContext GtkPrintContext; #define GTK_PRINT_CONTEXT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_PRINT_CONTEXT, GtkPrintContext)) #define GTK_IS_PRINT_CONTEXT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_PRINT_CONTEXT)) -GType gtk_print_context_get_type (void) G_GNUC_CONST; +GType gtk_print_context_get_type (void); /* Rendering */ diff --git a/gtk/gtkprinter.c b/gtk/gtkprinter.c index 8fd4789e2..1ca4cb95a 100644 --- a/gtk/gtkprinter.c +++ b/gtk/gtkprinter.c @@ -1068,8 +1068,19 @@ typedef struct gpointer data; GDestroyNotify destroy; GMainLoop *loop; + guint timeout_id; } PrinterList; +/* A printing system that takes connections and then never answers (a hung + * cupsd, a print server gone away behind a firewall) never says its list + * is complete, and a caller waiting for the list (Firefox and Pale Moon do + * before every print dialog) waited forever. Waiting ends after this many + * seconds without news from any backend; the printers known by then are + * the list. */ +#define ENUMERATE_WAIT_SECONDS 5 + +static void list_progress (PrinterList *printer_list); + static void list_done_cb (GtkPrintBackend *backend, PrinterList *printer_list); @@ -1090,6 +1101,9 @@ stop_enumeration (PrinterList *printer_list) static void free_printer_list (PrinterList *printer_list) { + if (printer_list->timeout_id) + g_source_remove (printer_list->timeout_id); + if (printer_list->destroy) printer_list->destroy (printer_list->data); @@ -1113,9 +1127,34 @@ list_added_cb (GtkPrintBackend *backend, return TRUE; } + list_progress (printer_list); return FALSE; } +static gboolean +list_wait_timeout (gpointer data) +{ + PrinterList *printer_list = data; + + printer_list->timeout_id = 0; + stop_enumeration (printer_list); + + return FALSE; +} + +/* news from a backend: waiting goes on */ +static void +list_progress (PrinterList *printer_list) +{ + if (printer_list->timeout_id) + { + g_source_remove (printer_list->timeout_id); + printer_list->timeout_id = + gdk_threads_add_timeout_seconds (ENUMERATE_WAIT_SECONDS, + list_wait_timeout, printer_list); + } +} + static void backend_status_changed (GObject *object, GParamSpec *pspec, @@ -1131,7 +1170,8 @@ backend_status_changed (GObject *object, list_done_cb (backend, printer_list); } -static void +/* TRUE when it was the last backend and @printer_list is gone */ +static gboolean list_printers_remove_backend (PrinterList *printer_list, GtkPrintBackend *backend) { @@ -1140,7 +1180,12 @@ list_printers_remove_backend (PrinterList *printer_list, g_object_unref (backend); if (printer_list->backends == NULL) - free_printer_list (printer_list); + { + free_printer_list (printer_list); + return TRUE; + } + + return FALSE; } static void @@ -1151,7 +1196,8 @@ list_done_cb (GtkPrintBackend *backend, g_signal_handlers_disconnect_by_func (backend, list_done_cb, printer_list); g_signal_handlers_disconnect_by_func (backend, backend_status_changed, printer_list); - list_printers_remove_backend(printer_list, backend); + if (!list_printers_remove_backend (printer_list, backend)) + list_progress (printer_list); } static gboolean @@ -1178,7 +1224,10 @@ list_printers_init (PrinterList *printer_list, if (status == GTK_PRINT_BACKEND_STATUS_UNAVAILABLE || gtk_print_backend_printer_list_is_done (backend)) - list_printers_remove_backend(printer_list, backend); + { + if (list_printers_remove_backend (printer_list, backend)) + return TRUE; + } else { g_signal_connect (backend, "printer-added", @@ -1244,6 +1293,9 @@ gtk_enumerate_printers (GtkPrinterFunc func, if (wait && printer_list->backends) { printer_list->loop = g_main_loop_new (NULL, FALSE); + printer_list->timeout_id = + gdk_threads_add_timeout_seconds (ENUMERATE_WAIT_SECONDS, + list_wait_timeout, printer_list); GDK_THREADS_LEAVE (); g_main_loop_run (printer_list->loop); diff --git a/gtk/gtkprinter.h b/gtk/gtkprinter.h index 0ef09f82d..f292c17ad 100644 --- a/gtk/gtkprinter.h +++ b/gtk/gtkprinter.h @@ -48,7 +48,7 @@ typedef enum GTK_PRINT_CAPABILITY_NUMBER_UP_LAYOUT = 1 << 9 } GtkPrintCapabilities; -GType gtk_print_capabilities_get_type (void) G_GNUC_CONST; +GType gtk_print_capabilities_get_type (void); #define GTK_TYPE_PRINTER (gtk_printer_get_type ()) #define GTK_PRINTER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_PRINTER, GtkPrinter)) @@ -88,7 +88,7 @@ struct _GtkPrinterClass void (*_gtk_reserved7) (void); }; -GType gtk_printer_get_type (void) G_GNUC_CONST; +GType gtk_printer_get_type (void); GtkPrinter *gtk_printer_new (const gchar *name, GtkPrintBackend *backend, gboolean virtual_); diff --git a/gtk/gtkprinteroption.h b/gtk/gtkprinteroption.h index 7b0763c45..bb9a56a88 100644 --- a/gtk/gtkprinteroption.h +++ b/gtk/gtkprinteroption.h @@ -92,7 +92,7 @@ struct _GtkPrinterOptionClass void (*_gtk_reserved7) (void); }; -GType gtk_printer_option_get_type (void) G_GNUC_CONST; +GType gtk_printer_option_get_type (void); GtkPrinterOption *gtk_printer_option_new (const char *name, const char *display_text, diff --git a/gtk/gtkprinteroptionset.h b/gtk/gtkprinteroptionset.h index 1a2cfca8e..dc3345a88 100644 --- a/gtk/gtkprinteroptionset.h +++ b/gtk/gtkprinteroptionset.h @@ -71,7 +71,7 @@ typedef void (*GtkPrinterOptionSetFunc) (GtkPrinterOption *option, gpointer user_data); -GType gtk_printer_option_set_get_type (void) G_GNUC_CONST; +GType gtk_printer_option_set_get_type (void); GtkPrinterOptionSet *gtk_printer_option_set_new (void); void gtk_printer_option_set_add (GtkPrinterOptionSet *set, diff --git a/gtk/gtkprinteroptionwidget.c b/gtk/gtkprinteroptionwidget.c index 831fb68f5..6cd623a98 100644 --- a/gtk/gtkprinteroptionwidget.c +++ b/gtk/gtkprinteroptionwidget.c @@ -140,6 +140,8 @@ gtk_printer_option_widget_finalize (GObject *object) if (priv->source) { + g_signal_handler_disconnect (priv->source, + priv->source_changed_handler); g_object_unref (priv->source); priv->source = NULL; } @@ -201,6 +203,23 @@ gtk_printer_option_widget_mnemonic_activate (GtkWidget *widget, return gtk_widget_mnemonic_activate (priv->combo, group_cycling); if (priv->entry) return gtk_widget_mnemonic_activate (priv->entry, group_cycling); + if (priv->box) + { + GList *children, *l; + GtkWidget *button = NULL; + + /* Radio buttons: focus the chosen one, don't change the choice */ + children = gtk_container_get_children (GTK_CONTAINER (priv->box)); + for (l = children; l; l = l->next) + if (GTK_IS_TOGGLE_BUTTON (l->data) && + (button == NULL || + gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (l->data)))) + button = l->data; + g_list_free (children); + + if (button) + return gtk_widget_mnemonic_activate (button, TRUE); + } return FALSE; } @@ -932,13 +951,22 @@ update_widgets (GtkPrinterOptionWidget *widget) basename = g_path_get_basename (filename); dirname = g_path_get_dirname (filename); + text = g_filename_to_utf8 (basename, -1, NULL, NULL, NULL); + /* need to update dirname and basename without triggering function to avoid loosing names */ + g_signal_handlers_block_by_func (priv->entry, G_CALLBACK (filesave_changed_cb), widget); + g_signal_handlers_block_by_func (priv->combo, G_CALLBACK (filesave_changed_cb), widget); + if (text != NULL) gtk_entry_set_text (GTK_ENTRY (priv->entry), text); if (g_path_is_absolute (dirname)) - gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (priv->combo), + gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (priv->combo), dirname); + + g_signal_handlers_unblock_by_func (priv->entry, G_CALLBACK (filesave_changed_cb), widget); + g_signal_handlers_unblock_by_func (priv->combo, G_CALLBACK (filesave_changed_cb), widget); + g_free (text); g_free (basename); g_free (dirname); diff --git a/gtk/gtkprinteroptionwidget.h b/gtk/gtkprinteroptionwidget.h index 5037959d4..a9f9ff931 100644 --- a/gtk/gtkprinteroptionwidget.h +++ b/gtk/gtkprinteroptionwidget.h @@ -50,7 +50,7 @@ struct _GtkPrinterOptionWidgetClass void (*changed) (GtkPrinterOptionWidget *widget); }; -GType gtk_printer_option_widget_get_type (void) G_GNUC_CONST; +GType gtk_printer_option_widget_get_type (void); GtkWidget *gtk_printer_option_widget_new (GtkPrinterOption *source); void gtk_printer_option_widget_set_source (GtkPrinterOptionWidget *setting, diff --git a/gtk/gtkprintjob.c b/gtk/gtkprintjob.c index 906aa7e00..9b558199a 100644 --- a/gtk/gtkprintjob.c +++ b/gtk/gtkprintjob.c @@ -419,6 +419,11 @@ gtk_print_job_set_source_file (GtkPrintJob *job, priv = job->priv; + /* Drop the channel of an earlier source file; the channel of the + * surface of gtk_print_job_get_surface() is still written by it. */ + if (priv->spool_io != NULL && priv->surface == NULL) + g_io_channel_unref (priv->spool_io); + priv->spool_io = g_io_channel_new_file (filename, "r", &tmp_error); if (tmp_error == NULL) diff --git a/gtk/gtkprintjob.h b/gtk/gtkprintjob.h index e5505d767..d48eab3b9 100644 --- a/gtk/gtkprintjob.h +++ b/gtk/gtkprintjob.h @@ -86,7 +86,7 @@ struct _GtkPrintJobClass void (*_gtk_reserved7) (void); }; -GType gtk_print_job_get_type (void) G_GNUC_CONST; +GType gtk_print_job_get_type (void); GtkPrintJob *gtk_print_job_new (const gchar *title, GtkPrinter *printer, GtkPrintSettings *settings, diff --git a/gtk/gtkprintoperation-win32.c b/gtk/gtkprintoperation-win32.c index bc5fc93dd..cca829be6 100644 --- a/gtk/gtkprintoperation-win32.c +++ b/gtk/gtkprintoperation-win32.c @@ -673,6 +673,7 @@ devmode_to_settings (GtkPrintSettings *settings, HANDLE hDevMode) { LPDEVMODEW devmode; + char *devmode_name; devmode = GlobalLock (hDevMode); @@ -688,6 +689,11 @@ devmode_to_settings (GtkPrintSettings *settings, g_free (extra); } + /* The driver data is only taken for the device it was made for */ + devmode_name = g_utf16_to_utf8 (devmode->dmDeviceName, CCHDEVICENAME, NULL, NULL, NULL); + gtk_print_settings_set (settings, "win32-devmode-name", devmode_name); + g_free (devmode_name); + if (devmode->dmFields & DM_ORIENTATION) gtk_print_settings_set_orientation (settings, orientation_from_win32 (devmode->dmOrientation)); @@ -935,11 +941,12 @@ devmode_from_settings (GtkPrintSettings *settings, { HANDLE hDevMode; LPDEVMODEW devmode; - char *extras; + guchar *extras; GtkPaperSize *paper_size; const char *extras_base64; - int extras_len; + gsize extras_len; const char *val; + const char *saved_device_name; extras = NULL; extras_len = 0; @@ -957,6 +964,23 @@ devmode_from_settings (GtkPrintSettings *settings, devmode->dmSpecVersion = DM_SPECVERSION; devmode->dmSize = sizeof (DEVMODEW); + /* The driver data (driver preferences) is only taken by the driver + * with the name of the device it was made for */ + saved_device_name = gtk_print_settings_get (settings, "win32-devmode-name"); + if (saved_device_name) + { + gunichar2 *device_name = g_utf8_to_utf16 (saved_device_name, -1, NULL, NULL, NULL); + + if (device_name) + { + int i; + + for (i = 0; i < CCHDEVICENAME - 1 && device_name[i] != 0; i++) + devmode->dmDeviceName[i] = device_name[i]; + g_free (device_name); + } + } + devmode->dmDriverExtra = 0; if (extras && extras_len > 0) { diff --git a/gtk/gtkprintoperation.c b/gtk/gtkprintoperation.c index d6fab4bcd..8fb41875a 100644 --- a/gtk/gtkprintoperation.c +++ b/gtk/gtkprintoperation.c @@ -469,11 +469,19 @@ preview_print_idle_done (gpointer data) op = GTK_PRINT_OPERATION (pop->preview); cairo_surface_finish (pop->surface); - /* Surface is destroyed in launch_preview */ - _gtk_print_operation_platform_backend_launch_preview (op, - pop->surface, - pop->parent, - pop->filename); + + if (op->priv->status == GTK_PRINT_STATUS_FINISHED_ABORTED) + { + cairo_surface_destroy (pop->surface); + } + else + { + /* Surface is destroyed in launch_preview */ + _gtk_print_operation_platform_backend_launch_preview (op, + pop->surface, + pop->parent, + pop->filename); + } g_free (pop->filename); @@ -502,7 +510,12 @@ preview_print_idle (gpointer data) if (priv->page_drawing_state == GTK_PAGE_DRAWING_STATE_READY) { - if (!pop->pages_data->initialized) + if (priv->cancelled) + { + done = TRUE; + _gtk_print_operation_set_status (op, GTK_PRINT_STATUS_FINISHED_ABORTED, NULL); + } + else if (!pop->pages_data->initialized) { pop->pages_data->initialized = TRUE; prepare_data (pop->pages_data); @@ -2412,11 +2425,9 @@ common_render_page (GtkPrintOperation *op, cr = gtk_print_context_get_cairo_context (print_context); cairo_save (cr); - if (priv->manual_scale != 1.0 && priv->manual_number_up <= 1) - cairo_scale (cr, - priv->manual_scale, - priv->manual_scale); + /* rotating and moving into the margins translate by the size of + * the paper and of the margins, so they come before the scale */ if (priv->manual_orientation) _gtk_print_context_rotate_according_to_orientation (print_context); @@ -2601,8 +2612,14 @@ common_render_page (GtkPrintOperation *op, } } else - if (!priv->use_full_page) - _gtk_print_context_translate_into_margin (print_context); + { + if (!priv->use_full_page) + _gtk_print_context_translate_into_margin (print_context); + if (priv->manual_scale != 1.0) + cairo_scale (cr, + priv->manual_scale, + priv->manual_scale); + } priv->page_drawing_state = GTK_PAGE_DRAWING_STATE_DRAWING; diff --git a/gtk/gtkprintoperation.h b/gtk/gtkprintoperation.h index 579335ee2..29dd3906a 100644 --- a/gtk/gtkprintoperation.h +++ b/gtk/gtkprintoperation.h @@ -138,7 +138,7 @@ typedef enum GQuark gtk_print_error_quark (void); -GType gtk_print_operation_get_type (void) G_GNUC_CONST; +GType gtk_print_operation_get_type (void); GtkPrintOperation * gtk_print_operation_new (void); void gtk_print_operation_set_default_page_setup (GtkPrintOperation *op, GtkPageSetup *default_page_setup); diff --git a/gtk/gtkprintoperationpreview.h b/gtk/gtkprintoperationpreview.h index 32b2eadcc..61de3f7c7 100644 --- a/gtk/gtkprintoperationpreview.h +++ b/gtk/gtkprintoperationpreview.h @@ -67,7 +67,7 @@ struct _GtkPrintOperationPreviewIface void (*_gtk_reserved7) (void); }; -GType gtk_print_operation_preview_get_type (void) G_GNUC_CONST; +GType gtk_print_operation_preview_get_type (void); void gtk_print_operation_preview_render_page (GtkPrintOperationPreview *preview, gint page_nr); diff --git a/gtk/gtkprintsettings.h b/gtk/gtkprintsettings.h index 89bdb2ae1..f2de68c04 100644 --- a/gtk/gtkprintsettings.h +++ b/gtk/gtkprintsettings.h @@ -46,7 +46,7 @@ struct _GtkPageRange gint end; }; -GType gtk_print_settings_get_type (void) G_GNUC_CONST; +GType gtk_print_settings_get_type (void); GtkPrintSettings *gtk_print_settings_new (void); GtkPrintSettings *gtk_print_settings_copy (GtkPrintSettings *other); diff --git a/gtk/gtkprintunixdialog.c b/gtk/gtkprintunixdialog.c index af64a5a37..08de92f37 100644 --- a/gtk/gtkprintunixdialog.c +++ b/gtk/gtkprintunixdialog.c @@ -463,10 +463,14 @@ error_dialogs (GtkPrintUnixDialog *print_dialog, if (file != NULL && g_file_query_exists (file, NULL)) { + GFile *parent; + toplevel = get_toplevel (GTK_WIDGET (print_dialog)); basename = g_file_get_basename (file); - dirname = g_file_get_parse_name (g_file_get_parent (file)); + parent = g_file_get_parent (file); + dirname = g_file_get_parse_name (parent); + g_object_unref (parent); dialog = gtk_message_dialog_new (toplevel, GTK_DIALOG_MODAL | @@ -766,13 +770,12 @@ void set_cell_sensitivity_func (GtkTreeViewColumn *tree_column, gtk_tree_model_get (tree_model, iter, PRINTER_LIST_COL_PRINTER_OBJ, &printer, -1); if (printer != NULL && !gtk_printer_is_accepting_jobs (printer)) - g_object_set (cell, - "sensitive", FALSE, - NULL); + g_object_set (cell, "sensitive", FALSE, NULL); else - g_object_set (cell, - "sensitive", TRUE, - NULL); + g_object_set (cell, "sensitive", TRUE, NULL); + + if (printer) + g_object_unref (printer); } static void @@ -1003,10 +1006,8 @@ is_printer_active (GtkTreeModel *model, GtkPrinter *printer; GtkPrintUnixDialogPrivate *priv = dialog->priv; - gtk_tree_model_get (model, - iter, - PRINTER_LIST_COL_PRINTER_OBJ, - &printer, + gtk_tree_model_get (model, iter, + PRINTER_LIST_COL_PRINTER_OBJ, &printer, -1); if (printer == NULL) @@ -1076,8 +1077,10 @@ default_printer_list_sort_func (GtkTreeModel *model, g_free (a_name); g_free (b_name); - g_object_unref (a_printer); - g_object_unref (b_printer); + if (a_printer) + g_object_unref (a_printer); + if (b_printer) + g_object_unref (b_printer); return result; } @@ -1884,7 +1887,7 @@ selected_printer_changed (GtkTreeSelection *selection, priv->printer_capabilities = 0; - if (gtk_printer_is_accepting_jobs (printer)) + if (printer != NULL && gtk_printer_is_accepting_jobs (printer)) gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, TRUE); priv->current_printer = printer; @@ -1915,6 +1918,7 @@ selected_printer_changed (GtkTreeSelection *selection, priv->options_changed_handler = g_signal_connect_swapped (priv->options, "changed", G_CALLBACK (options_changed_cb), dialog); + schedule_idle_mark_conflicts (dialog); } update_dialog_from_settings (dialog); diff --git a/gtk/gtkprintunixdialog.h b/gtk/gtkprintunixdialog.h index dcf6bbf85..e38a58553 100644 --- a/gtk/gtkprintunixdialog.h +++ b/gtk/gtkprintunixdialog.h @@ -64,7 +64,7 @@ struct _GtkPrintUnixDialogClass void (*_gtk_reserved7) (void); }; -GType gtk_print_unix_dialog_get_type (void) G_GNUC_CONST; +GType gtk_print_unix_dialog_get_type (void); GtkWidget * gtk_print_unix_dialog_new (const gchar *title, GtkWindow *parent); diff --git a/gtk/gtkprivate.h b/gtk/gtkprivate.h index cc1b50dfa..46a7a3e2f 100644 --- a/gtk/gtkprivate.h +++ b/gtk/gtkprivate.h @@ -28,6 +28,7 @@ #define __GTK_PRIVATE_H__ #include +#include G_BEGIN_DECLS @@ -74,6 +75,7 @@ gpointer _gtk_memdup2 (gconstpointer mem, typedef enum { PRIVATE_GTK_USER_STYLE = 1 << 0, + PRIVATE_GTK_IN_SIZE_GROUP = 1 << 1, /* If the widget is in a size group */ PRIVATE_GTK_RESIZE_PENDING = 1 << 2, PRIVATE_GTK_HAS_POINTER = 1 << 3, /* If the pointer is above a window belonging to the widget */ PRIVATE_GTK_SHADOWED = 1 << 4, /* If there is a grab in effect shadowing the widget */ @@ -186,6 +188,30 @@ gboolean _gtk_fnmatch (const char *pattern, gboolean _gtk_button_event_triggers_context_menu (GdkEventButton *event); +/* while the pictures of a higher scale are made: none of them get one */ +extern gint _gtk_loading_hires; +gint _gtk_screen_get_hires_scale (GdkScreen *screen); +gboolean _gtk_icon_theme_same_icon_at_sizes (GtkIconTheme *icon_theme, + const gchar *icon_name, + gint size, + gint big_size, + GtkIconLookupFlags flags); +void _gtk_pixbuf_attach_hires (GdkPixbuf *pixbuf, + GdkPixbuf *big, + gint scale); + +gboolean _gtk_scroll_event_get_steps (GdkEventScroll *event, + gdouble *steps_x, + gdouble *steps_y, + gboolean *pixels); +guint _gtk_scrolled_window_takes_scroll (GtkWidget *widget, + GdkEventScroll *event); +void _gtk_scroll_latch (GtkWidget *widget, + guint32 time); +gboolean _gtk_scrolled_window_touch_event (GtkWidget *event_widget, + GtkWidget *grab_widget, + GdkEvent *event); + gboolean _gtk_translate_keyboard_accel_state (GdkKeymap *keymap, guint hardware_keycode, GdkModifierType state, diff --git a/gtk/gtkprogress.h b/gtk/gtkprogress.h index b5f42e851..1f60db69a 100644 --- a/gtk/gtkprogress.h +++ b/gtk/gtkprogress.h @@ -85,7 +85,7 @@ struct _GtkProgressClass #if !defined (GTK_DISABLE_DEPRECATED) || defined (__GTK_PROGRESS_C__) || defined (__GTK_PROGRESS_BAR_C__) -GType gtk_progress_get_type (void) G_GNUC_CONST; +GType gtk_progress_get_type (void); void gtk_progress_set_show_text (GtkProgress *progress, gboolean show_text); void gtk_progress_set_text_alignment (GtkProgress *progress, diff --git a/gtk/gtkprogressbar.h b/gtk/gtkprogressbar.h index 0086aa3f6..c38e1df29 100644 --- a/gtk/gtkprogressbar.h +++ b/gtk/gtkprogressbar.h @@ -95,7 +95,7 @@ struct _GtkProgressBarClass }; -GType gtk_progress_bar_get_type (void) G_GNUC_CONST; +GType gtk_progress_bar_get_type (void); GtkWidget* gtk_progress_bar_new (void); /* diff --git a/gtk/gtkquartz.c b/gtk/gtkquartz.c index caf8404f8..fd6318f4c 100644 --- a/gtk/gtkquartz.c +++ b/gtk/gtkquartz.c @@ -20,8 +20,11 @@ #include "config.h" +#include + #include "gtkquartz.h" #include +#include "gtkintl.h" #include "gtkalias.h" NSImage * @@ -285,8 +288,11 @@ _gtk_quartz_set_selection_data_for_pasteboard (NSPasteboard *pasteboard, result = g_uri_list_extract_uris (list[0]); - url = [NSURL URLWithString:[NSString stringWithUTF8String:result[0]]]; - [url writeToPasteboard:pasteboard]; + if (result[0]) + { + url = [NSURL URLWithString:[NSString stringWithUTF8String:result[0]]]; + [url writeToPasteboard:pasteboard]; + } g_strfreev (result); } @@ -300,6 +306,53 @@ _gtk_quartz_set_selection_data_for_pasteboard (NSPasteboard *pasteboard, forType:type]; } +/* The local files of a URI list, for the Finder, which takes only one + * URL from NSURLPboardType: of a drag, and of the clipboard of files */ +void +_gtk_quartz_set_filenames_for_pasteboard (NSPasteboard *pasteboard, + GtkSelectionData *selection_data) +{ + gchar **uris = gtk_selection_data_get_uris (selection_data); + NSMutableArray *paths = [NSMutableArray array]; + gint i; + + for (i = 0; uris && uris[i]; i++) + { + gchar *path = g_filename_from_uri (uris[i], NULL, NULL); + + if (path) + { + [paths addObject:[[NSFileManager defaultManager] stringWithFileSystemRepresentation:path + length:strlen (path)]]; + g_free (path); + } + } + g_strfreev (uris); + + [pasteboard setPropertyList:paths forType:NSFilenamesPboardType]; +} + +/* Whether a clipboard holds files as file managers put them there + * (the URIs and x-special/gnome-copied-files, as the file chooser does), + * so that the Finder can paste them */ +gboolean +_gtk_quartz_targets_are_files (const GtkTargetEntry *targets, + guint n_targets) +{ + gboolean uris = FALSE, files = FALSE; + guint i; + + for (i = 0; i < n_targets; i++) + { + if (strcmp (targets[i].target, "text/uri-list") == 0) + uris = TRUE; + else if (strcmp (targets[i].target, "x-special/gnome-copied-files") == 0) + files = TRUE; + } + + return uris && files; +} + /* * Bundle-based functions for various directories. These almost work * even when the application isn't in a bundle, becuase mainBundle @@ -381,3 +434,86 @@ _gtk_get_data_prefix (void) { return get_bundle_path (); } + +/* Moves @file to the trash of the Mac, where the Finder shows it: + * NSFileManager from 10.8, NSWorkspace before */ +gboolean +_gtk_quartz_trash_file (GFile *file, + GFile **trashed, + GError **error) +{ + NSAutoreleasePool *pool; + NSString *nspath; + gchar *path = g_file_get_path (file); + gboolean done = FALSE; + NSString *reason = nil; + + if (trashed) + *trashed = NULL; + + if (path == NULL) + { + g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, + _("Only local files can be moved to the Trash")); + return FALSE; + } + + pool = [[NSAutoreleasePool alloc] init]; + nspath = [[NSFileManager defaultManager] stringWithFileSystemRepresentation: path + length: strlen (path)]; + g_free (path); + +#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1080 + if ([NSFileManager instancesRespondToSelector: @selector(trashItemAtURL:resultingItemURL:error:)]) + { + NSError *nserror = nil; + NSURL *result = nil; + + done = [[NSFileManager defaultManager] trashItemAtURL: [NSURL fileURLWithPath: nspath] + resultingItemURL: &result + error: &nserror]; + if (!done && nserror) + reason = [nserror localizedDescription]; + /* where it went, so that Undo can put it back */ + if (done && result && [result isFileURL] && trashed) + *trashed = g_file_new_for_path ([[result path] fileSystemRepresentation]); + } + else +#endif + { +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1080 + NSInteger tag; + + done = [[NSWorkspace sharedWorkspace] performFileOperation: NSWorkspaceRecycleOperation + source: [nspath stringByDeletingLastPathComponent] + destination: @"" + files: [NSArray arrayWithObject: [nspath lastPathComponent]] + tag: &tag]; +#endif + } + + if (!done) + g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, + reason ? [reason UTF8String] : _("The Trash refused the file")); + + [pool release]; + + return done; +} + +/* Connect to Server on the Mac: the Finder connects (smb, afp, ftp, nfs, + * WebDAV), asking for the name and the password, and mounts the server + * into /Volumes */ +gboolean +_gtk_quartz_connect_to_server (const gchar *uri) +{ + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + NSURL *url = [NSURL URLWithString: [NSString stringWithUTF8String: uri]]; + gboolean done = FALSE; + + if (url) + done = [[NSWorkspace sharedWorkspace] openURL: url]; + [pool release]; + return done; +} + diff --git a/gtk/gtkquartz.h b/gtk/gtkquartz.h index d98eb877b..afab6f9ea 100644 --- a/gtk/gtkquartz.h +++ b/gtk/gtkquartz.h @@ -38,6 +38,15 @@ GtkSelectionData *_gtk_quartz_get_selection_data_from_pasteboard (NSPasteboard * void _gtk_quartz_set_selection_data_for_pasteboard (NSPasteboard *pasteboard, GtkSelectionData *selection_data); +void _gtk_quartz_set_filenames_for_pasteboard (NSPasteboard *pasteboard, + GtkSelectionData *selection_data); +gboolean _gtk_quartz_targets_are_files (const GtkTargetEntry *targets, + guint n_targets); + +gboolean _gtk_quartz_trash_file (GFile *file, + GFile **trashed, + GError **error); +gboolean _gtk_quartz_connect_to_server (const gchar *uri); NSImage *_gtk_quartz_create_image_from_pixbuf (GdkPixbuf *pixbuf); diff --git a/gtk/gtkradioaction.h b/gtk/gtkradioaction.h index 03b04a8ad..ffdbdbd69 100644 --- a/gtk/gtkradioaction.h +++ b/gtk/gtkradioaction.h @@ -72,7 +72,7 @@ struct _GtkRadioActionClass void (*_gtk_reserved4) (void); }; -GType gtk_radio_action_get_type (void) G_GNUC_CONST; +GType gtk_radio_action_get_type (void); GtkRadioAction *gtk_radio_action_new (const gchar *name, const gchar *label, const gchar *tooltip, diff --git a/gtk/gtkradiobutton.c b/gtk/gtkradiobutton.c index a0f9c9e72..6422246bb 100644 --- a/gtk/gtkradiobutton.c +++ b/gtk/gtkradiobutton.c @@ -619,7 +619,10 @@ gtk_radio_button_focus (GtkWidget *widget, tmp_slist = radio_button->group; while (tmp_slist) { - if (GTK_TOGGLE_BUTTON (tmp_slist->data)->active) + /* a hidden active button (used for "nothing chosen yet") + * must not keep the group from getting the focus */ + if (GTK_TOGGLE_BUTTON (tmp_slist->data)->active && + gtk_widget_get_visible (tmp_slist->data)) selected_button = tmp_slist->data; tmp_slist = tmp_slist->next; } diff --git a/gtk/gtkradiobutton.h b/gtk/gtkradiobutton.h index 8f91d40f3..08c61a63b 100644 --- a/gtk/gtkradiobutton.h +++ b/gtk/gtkradiobutton.h @@ -69,7 +69,7 @@ struct _GtkRadioButtonClass }; -GType gtk_radio_button_get_type (void) G_GNUC_CONST; +GType gtk_radio_button_get_type (void); GtkWidget* gtk_radio_button_new (GSList *group); GtkWidget* gtk_radio_button_new_from_widget (GtkRadioButton *radio_group_member); diff --git a/gtk/gtkradiomenuitem.c b/gtk/gtkradiomenuitem.c index 456f62a36..6d408ca9f 100644 --- a/gtk/gtkradiomenuitem.c +++ b/gtk/gtkradiomenuitem.c @@ -90,10 +90,9 @@ gtk_radio_menu_item_set_property (GObject *object, GSList *slist; case PROP_GROUP: - if (G_VALUE_HOLDS_OBJECT (value)) + slist = NULL; + if (g_value_get_object (value) != NULL) slist = gtk_radio_menu_item_get_group ((GtkRadioMenuItem*) g_value_get_object (value)); - else - slist = NULL; gtk_radio_menu_item_set_group (radio_menu_item, slist); break; default: @@ -169,6 +168,24 @@ gtk_radio_menu_item_set_group (GtkRadioMenuItem *radio_menu_item, tmp_item->group = radio_menu_item->group; } + + /* a group keeps at most one active item: if the group it joins has + * one already, this item is no longer active. Otherwise it keeps its + * state, so that a GtkBuilder file that sets "active" before "group" + * still works. */ + if (GTK_CHECK_MENU_ITEM (radio_menu_item)->active) + { + for (slist = group; slist; slist = slist->next) + if (GTK_CHECK_MENU_ITEM (slist->data)->active) + break; + + if (slist) + { + GTK_CHECK_MENU_ITEM (radio_menu_item)->active = FALSE; + g_object_notify (G_OBJECT (radio_menu_item), "active"); + gtk_widget_queue_draw (GTK_WIDGET (radio_menu_item)); + } + } } else { @@ -255,7 +272,7 @@ gtk_radio_menu_item_new_with_mnemonic (GSList *group, /** * gtk_radio_menu_item_new_from_widget: - * @group: An existing #GtkRadioMenuItem + * @group: (allow-none): An existing #GtkRadioMenuItem, or %NULL * * Creates a new #GtkRadioMenuItem adding it to the same group as @group. * @@ -268,7 +285,7 @@ gtk_radio_menu_item_new_from_widget (GtkRadioMenuItem *group) { GSList *list = NULL; - g_return_val_if_fail (GTK_IS_RADIO_MENU_ITEM (group), NULL); + g_return_val_if_fail (group == NULL || GTK_IS_RADIO_MENU_ITEM (group), NULL); if (group) list = gtk_radio_menu_item_get_group (group); @@ -278,7 +295,7 @@ gtk_radio_menu_item_new_from_widget (GtkRadioMenuItem *group) /** * gtk_radio_menu_item_new_with_mnemonic_from_widget: - * @group: An existing #GtkRadioMenuItem + * @group: (allow-none): An existing #GtkRadioMenuItem, or %NULL * @label: the text of the button, with an underscore in front of the * mnemonic character * @@ -298,7 +315,7 @@ gtk_radio_menu_item_new_with_mnemonic_from_widget (GtkRadioMenuItem *group, { GSList *list = NULL; - g_return_val_if_fail (GTK_IS_RADIO_MENU_ITEM (group), NULL); + g_return_val_if_fail (group == NULL || GTK_IS_RADIO_MENU_ITEM (group), NULL); if (group) list = gtk_radio_menu_item_get_group (group); @@ -308,7 +325,7 @@ gtk_radio_menu_item_new_with_mnemonic_from_widget (GtkRadioMenuItem *group, /** * gtk_radio_menu_item_new_with_label_from_widget: - * @group: an existing #GtkRadioMenuItem + * @group: (allow-none): an existing #GtkRadioMenuItem, or %NULL * @label: the text for the label * * Creates a new GtkRadioMenuItem whose child is a simple GtkLabel. @@ -324,7 +341,7 @@ gtk_radio_menu_item_new_with_label_from_widget (GtkRadioMenuItem *group, { GSList *list = NULL; - g_return_val_if_fail (GTK_IS_RADIO_MENU_ITEM (group), NULL); + g_return_val_if_fail (group == NULL || GTK_IS_RADIO_MENU_ITEM (group), NULL); if (group) list = gtk_radio_menu_item_get_group (group); diff --git a/gtk/gtkradiomenuitem.h b/gtk/gtkradiomenuitem.h index d08a97c93..8df4bf024 100644 --- a/gtk/gtkradiomenuitem.h +++ b/gtk/gtkradiomenuitem.h @@ -69,7 +69,7 @@ struct _GtkRadioMenuItemClass }; -GType gtk_radio_menu_item_get_type (void) G_GNUC_CONST; +GType gtk_radio_menu_item_get_type (void); GtkWidget* gtk_radio_menu_item_new (GSList *group); GtkWidget* gtk_radio_menu_item_new_with_label (GSList *group, diff --git a/gtk/gtkradiotoolbutton.h b/gtk/gtkradiotoolbutton.h index 6ea4caba5..22720ede9 100644 --- a/gtk/gtkradiotoolbutton.h +++ b/gtk/gtkradiotoolbutton.h @@ -57,7 +57,7 @@ struct _GtkRadioToolButtonClass void (* _gtk_reserved4) (void); }; -GType gtk_radio_tool_button_get_type (void) G_GNUC_CONST; +GType gtk_radio_tool_button_get_type (void); GtkToolItem *gtk_radio_tool_button_new (GSList *group); GtkToolItem *gtk_radio_tool_button_new_from_stock (GSList *group, diff --git a/gtk/gtkrange.c b/gtk/gtkrange.c index a38ea51b8..d7f454e58 100644 --- a/gtk/gtkrange.c +++ b/gtk/gtkrange.c @@ -981,9 +981,12 @@ gtk_range_set_slider_size_fixed (GtkRange *range, { range->slider_size_fixed = size_fixed ? TRUE : FALSE; - range->need_recalc = TRUE; - gtk_range_calc_layout (range, range->adjustment->value); - gtk_widget_queue_draw (GTK_WIDGET (range)); + if (range->adjustment && gtk_widget_get_mapped (GTK_WIDGET (range))) + { + range->need_recalc = TRUE; + gtk_range_calc_layout (range, range->adjustment->value); + gtk_widget_queue_draw (GTK_WIDGET (range)); + } } } @@ -2557,37 +2560,93 @@ gtk_range_button_release (GtkWidget *widget, return FALSE; } +/* The steps of the wheel in a scroll event, to the right and down; + * on Quartz, smooth events of trackpads come in pixels, as GTK+ 3 + * takes them. FALSE for a smooth event without its steps. */ +gboolean +_gtk_scroll_event_get_steps (GdkEventScroll *event, + gdouble *steps_x, + gdouble *steps_y, + gboolean *pixels) +{ + *steps_x = *steps_y = 0; + *pixels = FALSE; + + switch (event->direction) + { + case GDK_SCROLL_UP: + *steps_y = -1; + break; + case GDK_SCROLL_DOWN: + *steps_y = 1; + break; + case GDK_SCROLL_LEFT: + *steps_x = -1; + break; + case GDK_SCROLL_RIGHT: + *steps_x = 1; + break; + default: + if (!gdk_event_get_scroll_deltas ((GdkEvent *) event, steps_x, steps_y)) + return FALSE; +#ifdef GDK_WINDOWING_QUARTZ + *pixels = TRUE; +#endif + break; + } + + return TRUE; +} + +/* How far a step of the wheel, or a pixel of a trackpad, moves @range */ +gdouble +_gtk_range_get_wheel_step (GtkRange *range, + gboolean pixels) +{ + GtkAdjustment *adj = range->adjustment; + gdouble step; + + if (pixels) + step = 1; + else if (GTK_IS_SCROLLBAR (range)) + /* for page sizes below 8, pow() gives more than half a page, + * and for those below 1 even more than a whole one */ + step = MIN (pow (adj->page_size, 2.0 / 3.0), adj->page_size / 2.0); + else + step = adj->step_increment * 2; + + return range->inverted ? - step : step; +} + /** * _gtk_range_get_wheel_delta: * @range: a #GtkRange - * @direction: A #GdkScrollDirection + * @event: the scroll event * - * Returns a good step value for the mouse wheel. + * Returns a good step value for the mouse wheel; a smooth scroll moves + * by its fraction of that, a horizontal range by the steps to the right + * where there are some. * * Return value: A good step value for the mouse wheel. * * Since: 2.4 **/ gdouble -_gtk_range_get_wheel_delta (GtkRange *range, - GdkScrollDirection direction) +_gtk_range_get_wheel_delta (GtkRange *range, + GdkEventScroll *event) { - GtkAdjustment *adj = range->adjustment; - gdouble delta; + gdouble steps_x, steps_y, steps; + gboolean pixels; - if (GTK_IS_SCROLLBAR (range)) - delta = pow (adj->page_size, 2.0 / 3.0); + if (!_gtk_scroll_event_get_steps (event, &steps_x, &steps_y, &pixels)) + return 0; + + if (range->orientation == GTK_ORIENTATION_HORIZONTAL) + steps = steps_x != 0 ? steps_x : steps_y; else - delta = adj->step_increment * 2; + steps = steps_y != 0 ? steps_y : steps_x; - if (direction == GDK_SCROLL_UP || - direction == GDK_SCROLL_LEFT) - delta = - delta; - - if (range->inverted) - delta = - delta; - - return delta; + return steps * _gtk_range_get_wheel_step (range, pixels); } static gboolean @@ -2596,13 +2655,18 @@ gtk_range_scroll_event (GtkWidget *widget, { GtkRange *range = GTK_RANGE (widget); + /* a pinch on a touchpad (Ctrl with the wheel) is for programs that + * zoom, not for scrolling here */ + if (gdk_event_get_touchpad_emulated ((GdkEvent *) event)) + return FALSE; + if (gtk_widget_get_realized (widget)) { GtkAdjustment *adj = GTK_RANGE (range)->adjustment; gdouble delta; gboolean handled; - delta = _gtk_range_get_wheel_delta (range, event->direction); + delta = _gtk_range_get_wheel_delta (range, event); g_signal_emit (range, signals[CHANGE_VALUE], 0, GTK_SCROLL_JUMP, adj->value + delta, diff --git a/gtk/gtkrange.h b/gtk/gtkrange.h index e1e5034f3..8a9d6d17d 100644 --- a/gtk/gtkrange.h +++ b/gtk/gtkrange.h @@ -133,7 +133,7 @@ struct _GtkRangeClass }; -GType gtk_range_get_type (void) G_GNUC_CONST; +GType gtk_range_get_type (void); #ifndef GTK_DISABLE_DEPRECATED void gtk_range_set_update_policy (GtkRange *range, @@ -199,8 +199,10 @@ gint gtk_range_get_round_digits (GtkRange *range /* internal API */ -gdouble _gtk_range_get_wheel_delta (GtkRange *range, - GdkScrollDirection direction); +gdouble _gtk_range_get_wheel_delta (GtkRange *range, + GdkEventScroll *event); +gdouble _gtk_range_get_wheel_step (GtkRange *range, + gboolean pixels); void _gtk_range_set_stop_values (GtkRange *range, gdouble *values, diff --git a/gtk/gtkrc.c b/gtk/gtkrc.c index d316a0d90..94e71aee5 100644 --- a/gtk/gtkrc.c +++ b/gtk/gtkrc.c @@ -55,6 +55,7 @@ #include "gtkprivate.h" #include "gtksettings.h" #include "gtkwindow.h" +#include "gtktimeprivate.h" #include "gtkalias.h" @@ -128,6 +129,10 @@ struct _GtkRcContext GHashTable *color_hash; + /* the sets matched by a widget path, class path or type name (the key + * starts with 'w', 'c' or 't'), for widgets with the same path */ + GHashTable *matches; + guint reloading : 1; }; @@ -700,6 +705,7 @@ gtk_rc_context_get (GtkSettings *settings) context->rc_sets_class = NULL; context->rc_files = NULL; context->default_style = NULL; + context->matches = NULL; context->reloading = FALSE; g_object_get (settings, @@ -786,6 +792,9 @@ _gtk_rc_context_destroy (GtkSettings *settings) if (context->color_hash) g_hash_table_unref (context->color_hash); + if (context->matches) + g_hash_table_destroy (context->matches); + g_signal_handlers_disconnect_by_func (settings, gtk_rc_settings_changed, context); g_signal_handlers_disconnect_by_func (settings, @@ -1001,7 +1010,7 @@ gtk_rc_context_parse_one_file (GtkRcContext *context, gboolean reload) { GtkRcFile *rc_file; - GStatBuf statbuf; + GtkStatBuf statbuf; gint saved_priority; g_return_if_fail (filename != NULL); @@ -1034,11 +1043,11 @@ gtk_rc_context_parse_one_file (GtkRcContext *context, if (g_slist_find (current_files_stack, rc_file)) return; - if (!g_lstat (rc_file->canonical_name, &statbuf)) + if (!_gtk_stat (rc_file->canonical_name, FALSE, &statbuf)) { gint fd; - rc_file->mtime = (gint64) statbuf.st_mtime; + rc_file->mtime = statbuf.mtime; fd = g_open (rc_file->canonical_name, O_RDONLY, 0); if (fd < 0) @@ -1613,11 +1622,21 @@ gtk_rc_free_rc_sets (GSList *slist) } } +/* The sets of @context are new: what paths matched is to be found again */ +static void +gtk_rc_context_sets_changed (GtkRcContext *context) +{ + if (context->matches) + g_hash_table_remove_all (context->matches); +} + static void gtk_rc_clear_styles (GtkRcContext *context) { /* Clear out all old rc_styles */ + gtk_rc_context_sets_changed (context); + if (context->rc_style_ht) { g_hash_table_foreach (context->rc_style_ht, gtk_rc_clear_hash_node, NULL); @@ -1780,7 +1799,7 @@ gtk_rc_reparse_all_for_settings (GtkSettings *settings, GtkRcFile *rc_file; GSList *tmp_list; GtkRcContext *context; - GStatBuf statbuf; + GtkStatBuf statbuf; g_return_val_if_fail (GTK_IS_SETTINGS (settings), FALSE); @@ -1801,8 +1820,8 @@ gtk_rc_reparse_all_for_settings (GtkSettings *settings, if (!rc_file->is_string) { - if (!g_lstat (rc_file->name, &statbuf) && - ((gint64) statbuf.st_mtime != rc_file->mtime)) + if (!_gtk_stat (rc_file->name, FALSE, &statbuf) && + statbuf.mtime != rc_file->mtime) { mtime_modified = TRUE; break; @@ -1913,6 +1932,44 @@ gtk_rc_styles_match (GSList *rc_styles, return rc_styles; } +/* gtk_rc_styles_match() of the sets of @context of @kind, by way of the + * matches of earlier widgets with the same path: many widgets have the + * same class path, and all of a type the same type names */ +#define MAX_MATCHES 2048 + +static GSList * +gtk_rc_context_match (GtkRcContext *context, + GSList *rc_styles, + gchar kind, + GSList *sets, + guint path_length, + gchar *path, + gchar *path_reversed) +{ + gchar *key; + gpointer matches; + + key = g_malloc (path_length + 2); + key[0] = kind; + memcpy (key + 1, path, path_length + 1); + + if (!context->matches) + context->matches = g_hash_table_new_full (g_str_hash, g_str_equal, + g_free, (GDestroyNotify) g_slist_free); + + if (!g_hash_table_lookup_extended (context->matches, key, NULL, &matches)) + { + matches = gtk_rc_styles_match (NULL, sets, path_length, path, path_reversed); + if (g_hash_table_size (context->matches) >= MAX_MATCHES) + g_hash_table_remove_all (context->matches); + g_hash_table_insert (context->matches, key, matches); + } + else + g_free (key); + + return g_slist_concat (rc_styles, g_slist_copy (matches)); +} + static gint rc_set_compare (gconstpointer a, gconstpointer b) { @@ -1995,7 +2052,8 @@ gtk_rc_get_style (GtkWidget *widget) guint path_length; gtk_widget_path (widget, &path_length, &path, &path_reversed); - rc_styles = gtk_rc_styles_match (rc_styles, context->rc_sets_widget, path_length, path, path_reversed); + rc_styles = gtk_rc_context_match (context, rc_styles, 'w', context->rc_sets_widget, + path_length, path, path_reversed); g_free (path); g_free (path_reversed); } @@ -2006,7 +2064,8 @@ gtk_rc_get_style (GtkWidget *widget) guint path_length; gtk_widget_class_path (widget, &path_length, &path, &path_reversed); - rc_styles = gtk_rc_styles_match (rc_styles, context->rc_sets_widget_class, path_length, path, path_reversed); + rc_styles = gtk_rc_context_match (context, rc_styles, 'c', context->rc_sets_widget_class, + path_length, path, path_reversed); g_free (path); g_free (path_reversed); } @@ -2027,7 +2086,8 @@ gtk_rc_get_style (GtkWidget *widget) path_reversed = g_strdup (path); g_strreverse (path_reversed); - rc_styles = gtk_rc_styles_match (rc_styles, context->rc_sets_class, path_length, path, path_reversed); + rc_styles = gtk_rc_context_match (context, rc_styles, 't', context->rc_sets_class, + path_length, path, path_reversed); g_free (path); g_free (path_reversed); @@ -2220,6 +2280,7 @@ gtk_rc_add_widget_name_style (GtkRcStyle *rc_style, context = gtk_rc_context_get (gtk_settings_get_default ()); + gtk_rc_context_sets_changed (context); context->rc_sets_widget = gtk_rc_add_rc_sets (context->rc_sets_widget, rc_style, pattern, GTK_PATH_WIDGET); } @@ -2234,6 +2295,7 @@ gtk_rc_add_widget_class_style (GtkRcStyle *rc_style, context = gtk_rc_context_get (gtk_settings_get_default ()); + gtk_rc_context_sets_changed (context); context->rc_sets_widget_class = gtk_rc_add_rc_sets (context->rc_sets_widget_class, rc_style, pattern, GTK_PATH_WIDGET_CLASS); } @@ -2248,6 +2310,7 @@ gtk_rc_add_class_style (GtkRcStyle *rc_style, context = gtk_rc_context_get (gtk_settings_get_default ()); + gtk_rc_context_sets_changed (context); context->rc_sets_class = gtk_rc_add_rc_sets (context->rc_sets_class, rc_style, pattern, GTK_PATH_CLASS); } @@ -4292,6 +4355,8 @@ gtk_rc_parse_path_pattern (GtkRcContext *context, rc_set->rc_style = rc_style; rc_set->priority = priority; + gtk_rc_context_sets_changed (context); + if (path_type == GTK_PATH_WIDGET) context->rc_sets_widget = g_slist_prepend (context->rc_sets_widget, rc_set); else if (path_type == GTK_PATH_WIDGET_CLASS) @@ -4735,6 +4800,65 @@ gtk_rc_set_free (GtkRcSet *rc_set) g_free (rc_set); } +/* A widget class path is matched against every widget_class pattern + * of the theme, and a pattern like "**" looks up the type + * of each class in the path by its name: the types of the path being + * matched are kept by the place of their name in it, so that each name + * is looked up once for all patterns. */ +#define PATH_TYPES 48 + +static struct +{ + gchar *path; /* a copy, to know the path again */ + const gchar *base; /* the path being matched */ + gsize len; + guint n; + struct { + guint offset; + GType type; + } types[PATH_TYPES]; +} path_types; + +static void +path_types_set_path (gchar *path) +{ + if (!path_types.path || strcmp (path_types.path, path) != 0) + { + g_free (path_types.path); + path_types.path = g_strdup (path); + path_types.len = strlen (path); + path_types.n = 0; + } + path_types.base = path; +} + +static GType +path_type_from_name (gchar *type_name) +{ + guint offset, i; + GType type; + + if (!path_types.base || + type_name < path_types.base || + type_name >= path_types.base + path_types.len) + return g_type_from_name (type_name); + + offset = type_name - path_types.base; + for (i = 0; i < path_types.n; i++) + if (path_types.types[i].offset == offset) + return path_types.types[i].type; + + type = g_type_from_name (type_name); + if (path_types.n < PATH_TYPES) + { + path_types.types[path_types.n].offset = offset; + path_types.types[path_types.n].type = type; + path_types.n++; + } + + return type; +} + static gboolean match_class (PathElt *path_elt, gchar *type_name) @@ -4754,7 +4878,7 @@ match_class (PathElt *path_elt, return g_str_equal (type_name, path_elt->elt.class_name); } - return g_type_is_a (g_type_from_name (type_name), path_elt->elt.class_type); + return g_type_is_a (path_type_from_name (type_name), path_elt->elt.class_type); } static gboolean @@ -4910,7 +5034,13 @@ _gtk_rc_match_widget_class (GSList *list, gchar *path, gchar *path_reversed) { - return match_widget_class_recursive (list, length, path, path_reversed); + gboolean result; + + path_types_set_path (path); + result = match_widget_class_recursive (list, length, path, path_reversed); + path_types.base = NULL; + + return result; } #if defined (G_OS_WIN32) && !defined (_WIN64) diff --git a/gtk/gtkrc.h b/gtk/gtkrc.h index 5a9419912..f3619cb88 100644 --- a/gtk/gtkrc.h +++ b/gtk/gtkrc.h @@ -169,7 +169,7 @@ void gtk_rc_add_class_style (GtkRcStyle *rc_style, #endif /* GTK_DISABLE_DEPRECATED */ -GType gtk_rc_style_get_type (void) G_GNUC_CONST; +GType gtk_rc_style_get_type (void); GtkRcStyle* gtk_rc_style_new (void); GtkRcStyle* gtk_rc_style_copy (GtkRcStyle *orig); diff --git a/gtk/gtkrecentaction.h b/gtk/gtkrecentaction.h index c180e7b3e..f9e9d166a 100644 --- a/gtk/gtkrecentaction.h +++ b/gtk/gtkrecentaction.h @@ -55,7 +55,7 @@ struct _GtkRecentActionClass GtkActionClass parent_class; }; -GType gtk_recent_action_get_type (void) G_GNUC_CONST; +GType gtk_recent_action_get_type (void); GtkAction *gtk_recent_action_new (const gchar *name, const gchar *label, const gchar *tooltip, diff --git a/gtk/gtkrecentchooser.c b/gtk/gtkrecentchooser.c index 5d761781e..04d06f716 100644 --- a/gtk/gtkrecentchooser.c +++ b/gtk/gtkrecentchooser.c @@ -1033,7 +1033,7 @@ gtk_recent_chooser_list_filters (GtkRecentChooser *chooser) /** * gtk_recent_chooser_set_filter: * @chooser: a #GtkRecentChooser - * @filter: a #GtkRecentFilter + * @filter: (allow-none): a #GtkRecentFilter, or %NULL to unset the filter * * Sets @filter as the current #GtkRecentFilter object used by @chooser * to affect the displayed recently used resources. @@ -1045,7 +1045,7 @@ gtk_recent_chooser_set_filter (GtkRecentChooser *chooser, GtkRecentFilter *filter) { g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser)); - g_return_if_fail (GTK_IS_RECENT_FILTER (filter)); + g_return_if_fail (filter == NULL || GTK_IS_RECENT_FILTER (filter)); g_object_set (G_OBJECT (chooser), "filter", filter, NULL); } diff --git a/gtk/gtkrecentchooser.h b/gtk/gtkrecentchooser.h index 77f01aa79..926701d83 100644 --- a/gtk/gtkrecentchooser.h +++ b/gtk/gtkrecentchooser.h @@ -115,7 +115,7 @@ struct _GtkRecentChooserIface void (* selection_changed) (GtkRecentChooser *chooser); }; -GType gtk_recent_chooser_get_type (void) G_GNUC_CONST; +GType gtk_recent_chooser_get_type (void); /* * Configuration diff --git a/gtk/gtkrecentchooserdefault.c b/gtk/gtkrecentchooserdefault.c index d4e1eb3e3..cb29e4498 100644 --- a/gtk/gtkrecentchooserdefault.c +++ b/gtk/gtkrecentchooserdefault.c @@ -1535,22 +1535,17 @@ append_uri_to_urilist (GtkTreeModel *model, gpointer user_data) { DragData *drag_data = (DragData *) user_data; - GtkTreeModel *child_model; - GtkTreeIter child_iter; gchar *uri = NULL; gsize pos; - child_model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model)); - gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), - &child_iter, - iter); - gtk_tree_model_get (child_model, &child_iter, + /* the view's model is the store itself, not a filter on it */ + gtk_tree_model_get (model, iter, RECENT_URI_COLUMN, &uri, -1); g_assert (uri != NULL); pos = drag_data->next_pos; - drag_data->uri_list[pos] = g_strdup (uri); + drag_data->uri_list[pos] = uri; drag_data->next_pos = pos + 1; } diff --git a/gtk/gtkrecentchooserdefault.h b/gtk/gtkrecentchooserdefault.h index 7edc1de38..5bd2487ed 100644 --- a/gtk/gtkrecentchooserdefault.h +++ b/gtk/gtkrecentchooserdefault.h @@ -33,7 +33,7 @@ G_BEGIN_DECLS typedef struct _GtkRecentChooserDefault GtkRecentChooserDefault; -GType _gtk_recent_chooser_default_get_type (void) G_GNUC_CONST; +GType _gtk_recent_chooser_default_get_type (void); GtkWidget *_gtk_recent_chooser_default_new (GtkRecentManager *recent_manager); diff --git a/gtk/gtkrecentchooserdialog.h b/gtk/gtkrecentchooserdialog.h index c48e6b100..e81e3181e 100644 --- a/gtk/gtkrecentchooserdialog.h +++ b/gtk/gtkrecentchooserdialog.h @@ -57,7 +57,7 @@ struct _GtkRecentChooserDialogClass }; -GType gtk_recent_chooser_dialog_get_type (void) G_GNUC_CONST; +GType gtk_recent_chooser_dialog_get_type (void); GtkWidget *gtk_recent_chooser_dialog_new (const gchar *title, GtkWindow *parent, diff --git a/gtk/gtkrecentchoosermenu.c b/gtk/gtkrecentchoosermenu.c index cd5ad6df0..fcbe9fdc7 100644 --- a/gtk/gtkrecentchoosermenu.c +++ b/gtk/gtkrecentchoosermenu.c @@ -1008,6 +1008,7 @@ check_and_return: { g_list_foreach (pdata->items, (GFunc) gtk_recent_info_unref, NULL); g_list_free (pdata->items); + pdata->items = NULL; priv->populate_id = 0; @@ -1031,10 +1032,19 @@ idle_populate_clean_up (gpointer data) */ if (!pdata->displayed_items) gtk_widget_show (pdata->placeholder); - g_object_unref (pdata->placeholder); - - g_slice_free (MenuPopulateData, data); } + + /* The idle may also have been removed before it finished (e.g. on + * dispose or when the items are reloaded); free everything anyway. + */ + if (pdata->items) + { + g_list_foreach (pdata->items, (GFunc) gtk_recent_info_unref, NULL); + g_list_free (pdata->items); + } + + g_object_unref (pdata->placeholder); + g_slice_free (MenuPopulateData, pdata); } static void @@ -1183,6 +1193,9 @@ static void gtk_recent_chooser_sync_action_properties (GtkActivatable *activatable, GtkAction *action) { + if (!action) + return; + gtk_widget_set_sensitive (GTK_WIDGET (activatable), gtk_action_is_sensitive (action)); _gtk_recent_chooser_sync_action_properties (activatable, action); diff --git a/gtk/gtkrecentchoosermenu.h b/gtk/gtkrecentchoosermenu.h index 9fb99cd93..c630e2764 100644 --- a/gtk/gtkrecentchoosermenu.h +++ b/gtk/gtkrecentchoosermenu.h @@ -60,7 +60,7 @@ struct _GtkRecentChooserMenuClass void (* gtk_recent4) (void); }; -GType gtk_recent_chooser_menu_get_type (void) G_GNUC_CONST; +GType gtk_recent_chooser_menu_get_type (void); GtkWidget *gtk_recent_chooser_menu_new (void); GtkWidget *gtk_recent_chooser_menu_new_for_manager (GtkRecentManager *manager); diff --git a/gtk/gtkrecentchooserutils.c b/gtk/gtkrecentchooserutils.c index 12170e320..aca7808ef 100644 --- a/gtk/gtkrecentchooserutils.c +++ b/gtk/gtkrecentchooserutils.c @@ -300,9 +300,16 @@ sort_recent_items_mru (GtkRecentInfo *a, GtkRecentInfo *b, gpointer unused) { + gint64 time_a, time_b; + g_assert (a != NULL && b != NULL); - return gtk_recent_info_get_modified (b) - gtk_recent_info_get_modified (a); + /* compared, not subtracted: the difference of two times does not fit + * into the gint returned when they are more than 68 years apart */ + time_a = gtk_recent_info_get_modified_unix (a); + time_b = gtk_recent_info_get_modified_unix (b); + + return time_b < time_a ? -1 : (time_b > time_a ? 1 : 0); } static gint @@ -312,7 +319,7 @@ sort_recent_items_lru (GtkRecentInfo *a, { g_assert (a != NULL && b != NULL); - return -1 * (gtk_recent_info_get_modified (b) - gtk_recent_info_get_modified (a)); + return -sort_recent_items_mru (a, b, unused); } typedef struct @@ -361,7 +368,7 @@ get_is_recent_filtered (GtkRecentFilter *filter, filter_info.contains |= GTK_RECENT_FILTER_DISPLAY_NAME; } else - filter_info.uri = NULL; + filter_info.display_name = NULL; if (needed & GTK_RECENT_FILTER_APPLICATION) { diff --git a/gtk/gtkrecentchooserutils.h b/gtk/gtkrecentchooserutils.h index 833d9a9c9..916c22091 100644 --- a/gtk/gtkrecentchooserutils.h +++ b/gtk/gtkrecentchooserutils.h @@ -55,7 +55,7 @@ void _gtk_recent_chooser_delegate_iface_init (GtkRecentChooserIface *iface); void _gtk_recent_chooser_set_delegate (GtkRecentChooser *receiver, GtkRecentChooser *delegate); -GQuark _gtk_recent_chooser_delegate_get_quark (void) G_GNUC_CONST; +GQuark _gtk_recent_chooser_delegate_get_quark (void); G_END_DECLS diff --git a/gtk/gtkrecentchooserwidget.h b/gtk/gtkrecentchooserwidget.h index 557f134c0..7c3f068e3 100644 --- a/gtk/gtkrecentchooserwidget.h +++ b/gtk/gtkrecentchooserwidget.h @@ -55,7 +55,7 @@ struct _GtkRecentChooserWidgetClass GtkVBoxClass parent_class; }; -GType gtk_recent_chooser_widget_get_type (void) G_GNUC_CONST; +GType gtk_recent_chooser_widget_get_type (void); GtkWidget *gtk_recent_chooser_widget_new (void); GtkWidget *gtk_recent_chooser_widget_new_for_manager (GtkRecentManager *manager); diff --git a/gtk/gtkrecentfilter.c b/gtk/gtkrecentfilter.c index b5f933b0d..5747a0786 100644 --- a/gtk/gtkrecentfilter.c +++ b/gtk/gtkrecentfilter.c @@ -488,11 +488,12 @@ gtk_recent_filter_filter (GtkRecentFilter *filter, if (filter_info->mime_type != NULL) { gchar *filter_content_type, *rule_content_type; - gboolean match; + gboolean match = FALSE; filter_content_type = g_content_type_from_mime_type (filter_info->mime_type); rule_content_type = g_content_type_from_mime_type (rule->u.mime_type); - match = g_content_type_is_a (filter_content_type, rule_content_type); + if (filter_content_type != NULL && rule_content_type != NULL) + match = g_content_type_is_a (filter_content_type, rule_content_type); g_free (filter_content_type); g_free (rule_content_type); diff --git a/gtk/gtkrecentfilter.h b/gtk/gtkrecentfilter.h index 83cad90bc..2afe44516 100644 --- a/gtk/gtkrecentfilter.h +++ b/gtk/gtkrecentfilter.h @@ -61,7 +61,7 @@ struct _GtkRecentFilterInfo gint age; }; -GType gtk_recent_filter_get_type (void) G_GNUC_CONST; +GType gtk_recent_filter_get_type (void); GtkRecentFilter * gtk_recent_filter_new (void); void gtk_recent_filter_set_name (GtkRecentFilter *filter, diff --git a/gtk/gtkrecentmanager.c b/gtk/gtkrecentmanager.c index a7187f5a1..265b63416 100644 --- a/gtk/gtkrecentmanager.c +++ b/gtk/gtkrecentmanager.c @@ -38,6 +38,7 @@ #include "gtkicontheme.h" #include "gtktypebuiltins.h" #include "gtkprivate.h" +#include "gtktimeprivate.h" #include "gtkmarshalers.h" #include "gtkalias.h" @@ -93,6 +94,14 @@ struct _GtkRecentManagerPrivate gchar *filename; guint is_dirty : 1; + /* the file is read when its items are first needed, not before */ + guint needs_load : 1; + /* what the file looked like after we wrote it: its own change + * notification does not need to read it back */ + guint have_written : 1; + guint64 written_inode; + gint64 written_size; + gint64 written_mtime; gint limit; gint size; @@ -144,6 +153,7 @@ static gboolean recent_time_get_days_elapsed (gint64 now, gint64 then, gint *days_elapsed); static void build_recent_items_list (GtkRecentManager *manager); +static void ensure_items_loaded (GtkRecentManager *manager); static void purge_recent_items_list (GtkRecentManager *manager, GError **error); @@ -382,6 +392,7 @@ gtk_recent_manager_get_property (GObject *object, g_value_set_int (value, recent_manager->priv->limit); break; case PROP_SIZE: + ensure_items_loaded (recent_manager); g_value_set_int (value, recent_manager->priv->size); break; default: @@ -447,6 +458,8 @@ gtk_recent_manager_real_changed (GtkRecentManager *manager) { GError *write_error; + ensure_items_loaded (manager); + /* we are marked as dirty, so we dump the content of our * recently used items list */ @@ -479,6 +492,15 @@ gtk_recent_manager_real_changed (GtkRecentManager *manager) gtk_recent_manager_clamp_to_size (manager, max_size); } + /* the folder may not be there yet: ~/.local/share on Mac OS X + * and on new accounts (Ardour found it) */ + { + gchar *dir = g_path_get_dirname (priv->filename); + + g_mkdir_with_parents (dir, 0700); + g_free (dir); + } + write_error = NULL; g_bookmark_file_to_file (priv->recent_items, priv->filename, &write_error); if (write_error) @@ -498,6 +520,19 @@ gtk_recent_manager_real_changed (GtkRecentManager *manager) g_strerror (errno)); } + { + GStatBuf st; + + priv->have_written = FALSE; + if (!write_error && g_stat (priv->filename, &st) == 0 && st.st_ino != 0) + { + priv->have_written = TRUE; + priv->written_inode = st.st_ino; + priv->written_size = st.st_size; + priv->written_mtime = st.st_mtime; + } + } + /* mark us as clean */ priv->is_dirty = FALSE; } @@ -505,9 +540,11 @@ gtk_recent_manager_real_changed (GtkRecentManager *manager) { /* we are not marked as dirty, so we have been called * because the recently used resources file has been - * changed (and not from us). + * changed (and not from us). Not read yet: it will be read + * when it is needed. */ - build_recent_items_list (manager); + if (!priv->needs_load) + build_recent_items_list (manager); } g_object_thaw_notify (G_OBJECT (manager)); @@ -521,11 +558,24 @@ gtk_recent_manager_monitor_changed (GFileMonitor *monitor, gpointer user_data) { GtkRecentManager *manager = user_data; + GtkRecentManagerPrivate *priv = manager->priv; switch (event_type) { case G_FILE_MONITOR_EVENT_CHANGED: case G_FILE_MONITOR_EVENT_CREATED: + /* the file as we wrote it last (the same inode: it is replaced by + * a rename on every write, ours or another program's) */ + if (priv->have_written && priv->filename) + { + GStatBuf st; + + if (g_stat (priv->filename, &st) == 0 && + st.st_ino == priv->written_inode && + st.st_size == priv->written_size && + st.st_mtime == priv->written_mtime) + break; + } gdk_threads_enter (); gtk_recent_manager_changed (manager); gdk_threads_leave (); @@ -867,7 +917,31 @@ gtk_recent_manager_set_filename (GtkRecentManager *manager, g_object_unref (file); priv->is_dirty = FALSE; - build_recent_items_list (manager); + priv->have_written = FALSE; + if (priv->recent_items) + { + g_bookmark_file_free (priv->recent_items); + priv->recent_items = NULL; + } + priv->size = 0; + /* reading a large file is a pause; many programs ask for the manager + * at start and only use it later, or never */ + priv->needs_load = TRUE; +} + +static void +ensure_items_loaded (GtkRecentManager *manager) +{ + GtkRecentManagerPrivate *priv = manager->priv; + + if (priv->needs_load) + { + gboolean dirty = priv->is_dirty; + + priv->needs_load = FALSE; + build_recent_items_list (manager); + priv->is_dirty = dirty; + } } /* reads the recently used resources file and builds the items list. @@ -1113,7 +1187,19 @@ gtk_recent_manager_add_item_query_info (GObject *source_object, g_object_unref (file_info); } else - recent_data.mime_type = g_strdup (GTK_RECENT_DEFAULT_MIME); /* FIXME: maybe we should make up the MIME type from the filename's extension */ + { + /* the file is not there (yet) or cannot be asked: guess the type + * from the name instead of calling every such item a binary file */ + gchar *basename = g_file_get_basename (file); + gchar *content_type = g_content_type_guess (basename, NULL, 0, NULL); + + recent_data.mime_type = content_type ? g_content_type_get_mime_type (content_type) : NULL; + if (!recent_data.mime_type) + recent_data.mime_type = g_strdup (GTK_RECENT_DEFAULT_MIME); + + g_free (content_type); + g_free (basename); + } recent_data.app_name = g_strdup (g_get_application_name ()); recent_data.app_exec = g_strjoin (" ", g_get_prgname (), "%u", NULL); @@ -1274,6 +1360,7 @@ gtk_recent_manager_add_full (GtkRecentManager *manager, } priv = manager->priv; + ensure_items_loaded (manager); if (!priv->recent_items) { @@ -1344,6 +1431,7 @@ gtk_recent_manager_remove_item (GtkRecentManager *manager, g_return_val_if_fail (error == NULL || *error == NULL, FALSE); priv = manager->priv; + ensure_items_loaded (manager); if (!priv->recent_items) { @@ -1399,6 +1487,7 @@ gtk_recent_manager_has_item (GtkRecentManager *manager, g_return_val_if_fail (uri != NULL, FALSE); priv = manager->priv; + ensure_items_loaded (manager); g_return_val_if_fail (priv->recent_items != NULL, FALSE); return g_bookmark_file_has_item (priv->recent_items, uri); @@ -1495,6 +1584,7 @@ gtk_recent_manager_lookup_item (GtkRecentManager *manager, g_return_val_if_fail (error == NULL || *error == NULL, NULL); priv = manager->priv; + ensure_items_loaded (manager); if (!priv->recent_items) { priv->recent_items = g_bookmark_file_new (); @@ -1559,6 +1649,7 @@ gtk_recent_manager_move_item (GtkRecentManager *recent_manager, g_return_val_if_fail (error == NULL || *error == NULL, FALSE); priv = recent_manager->priv; + ensure_items_loaded (recent_manager); if (!priv->recent_items) { @@ -1623,6 +1714,7 @@ gtk_recent_manager_get_items (GtkRecentManager *manager) g_return_val_if_fail (GTK_IS_RECENT_MANAGER (manager), NULL); priv = manager->priv; + ensure_items_loaded (manager); if (!priv->recent_items) return NULL; @@ -1682,6 +1774,7 @@ gtk_recent_manager_purge_items (GtkRecentManager *manager, g_return_val_if_fail (GTK_IS_RECENT_MANAGER (manager), -1); priv = manager->priv; + ensure_items_loaded (manager); if (!priv->recent_items) return 0; @@ -1742,24 +1835,23 @@ gtk_recent_manager_clamp_to_age (GtkRecentManager *manager, GtkRecentManagerPrivate *priv = manager->priv; gchar **uris; gsize n_uris, i; - time_t now; + gint64 now; if (G_UNLIKELY (!priv->recent_items)) return; - now = time (NULL); - if (now == (time_t) -1) - return; + /* not time (), which a 32-bit time_t cannot give after 2038 */ + now = _gtk_get_real_time () / G_USEC_PER_SEC; uris = g_bookmark_file_get_uris (priv->recent_items, &n_uris); for (i = 0; i < n_uris; i++) { const gchar *uri = uris[i]; - time_t modified; + gint64 modified; gint item_age; - modified = recent_time_to_time_t (gtk_recent_bookmark_file_get_modified_time (priv->recent_items, uri)); + modified = gtk_recent_bookmark_file_get_modified_time (priv->recent_items, uri); if (recent_time_get_days_elapsed (now, modified, &item_age) && item_age > age) @@ -2059,6 +2151,66 @@ gtk_recent_info_get_visited (GtkRecentInfo *info) return recent_time_to_time_t (info->visited); } +/** + * gtk_recent_info_get_added_unix: + * @info: a #GtkRecentInfo + * + * Like gtk_recent_info_get_added(), as 64-bit seconds: a #time_t of 32 + * bits ends in 2038. + * + * Return value: the number of seconds elapsed from 1970-01-01 UTC when + * the resource was added to the list, or -1 on failure. + * + * Since: 2.24 + */ +gint64 +gtk_recent_info_get_added_unix (GtkRecentInfo *info) +{ + g_return_val_if_fail (info != NULL, -1); + + return info->added; +} + +/** + * gtk_recent_info_get_modified_unix: + * @info: a #GtkRecentInfo + * + * Like gtk_recent_info_get_modified(), as 64-bit seconds: a #time_t of + * 32 bits ends in 2038. + * + * Return value: the number of seconds elapsed from 1970-01-01 UTC when + * the resource was last modified, or -1 on failure. + * + * Since: 2.24 + */ +gint64 +gtk_recent_info_get_modified_unix (GtkRecentInfo *info) +{ + g_return_val_if_fail (info != NULL, -1); + + return info->modified; +} + +/** + * gtk_recent_info_get_visited_unix: + * @info: a #GtkRecentInfo + * + * Like gtk_recent_info_get_visited(), as 64-bit seconds: a #time_t of + * 32 bits ends in 2038. + * + * Return value: the number of seconds elapsed from 1970-01-01 UTC when + * the resource was last visited, or -1 on failure. + * + * Since: 2.24 + */ +gint64 +gtk_recent_info_get_visited_unix (GtkRecentInfo *info) +{ + g_return_val_if_fail (info != NULL, -1); + + return info->visited; +} + /** * gtk_recent_info_get_private_hint: * @info: a #GtkRecentInfo @@ -2136,6 +2288,44 @@ gtk_recent_info_get_application_info (GtkRecentInfo *info, const gchar **app_exec, guint *count, time_t *time_) +{ + gint64 stamp; + + if (!gtk_recent_info_get_application_info_unix (info, app_name, app_exec, + count, &stamp)) + return FALSE; + + if (time_) + *time_ = recent_time_to_time_t (stamp); + + return TRUE; +} + +/** + * gtk_recent_info_get_application_info_unix: + * @info: a #GtkRecentInfo + * @app_name: the name of the application that has registered this item + * @app_exec: (transfer none) (out): return location for the string containing the command line + * @count: (out): return location for the number of times this item was registered + * @time_: (out): return location for the timestamp this item was last registered + * for this application, in seconds from 1970-01-01 UTC + * + * Like gtk_recent_info_get_application_info(), with the time as 64-bit + * seconds: a #time_t of 32 bits ends in 2038. + * + * Return value: %TRUE if an application with @app_name has registered this + * resource inside the recently used list, or %FALSE otherwise. The + * @app_exec string is owned by the #GtkRecentInfo and should not be + * modified or freed + * + * Since: 2.24 + */ +gboolean +gtk_recent_info_get_application_info_unix (GtkRecentInfo *info, + const gchar *app_name, + const gchar **app_exec, + guint *count, + gint64 *time_) { RecentAppInfo *ai; @@ -2160,7 +2350,7 @@ gtk_recent_info_get_application_info (GtkRecentInfo *info, *count = ai->count; if (time_) - *time_ = recent_time_to_time_t (ai->stamp); + *time_ = ai->stamp; return TRUE; } @@ -2396,7 +2586,6 @@ gboolean gtk_recent_info_exists (GtkRecentInfo *info) { gchar *filename; - GStatBuf stat_buf; gboolean retval = FALSE; g_return_val_if_fail (info != NULL, FALSE); @@ -2408,8 +2597,9 @@ gtk_recent_info_exists (GtkRecentInfo *info) filename = g_filename_from_uri (info->uri, NULL, NULL); if (filename) { - if (g_stat (filename, &stat_buf) == 0) - retval = TRUE; + /* not g_stat(): it fails for files changed after 2038 where + * time_t has 32 bits, and the times are not needed here */ + retval = g_file_test (filename, G_FILE_TEST_EXISTS); g_free (filename); } @@ -2652,7 +2842,7 @@ gtk_recent_info_get_age (GtkRecentInfo *info) g_return_val_if_fail (info != NULL, -1); - now = (gint64) time (NULL); + now = _gtk_get_real_time () / G_USEC_PER_SEC; if (!recent_time_get_days_elapsed (now, info->modified, &retval)) return -1; @@ -2758,7 +2948,8 @@ gtk_recent_info_has_group (GtkRecentInfo *info, void _gtk_recent_manager_sync (void) { - if (recent_manager_singleton) + /* never read, so nothing of it was changed here */ + if (recent_manager_singleton && !recent_manager_singleton->priv->needs_load) { /* force a dump of the contents of the recent manager singleton */ recent_manager_singleton->priv->is_dirty = TRUE; diff --git a/gtk/gtkrecentmanager.h b/gtk/gtkrecentmanager.h index 10dd2eebb..dc7f43700 100644 --- a/gtk/gtkrecentmanager.h +++ b/gtk/gtkrecentmanager.h @@ -135,7 +135,7 @@ typedef enum GQuark gtk_recent_manager_error_quark (void); -GType gtk_recent_manager_get_type (void) G_GNUC_CONST; +GType gtk_recent_manager_get_type (void); GtkRecentManager *gtk_recent_manager_new (void); GtkRecentManager *gtk_recent_manager_get_default (void); @@ -171,7 +171,7 @@ gint gtk_recent_manager_purge_items (GtkRecentManager *manag GError **error); -GType gtk_recent_info_get_type (void) G_GNUC_CONST; +GType gtk_recent_info_get_type (void); GtkRecentInfo * gtk_recent_info_ref (GtkRecentInfo *info); void gtk_recent_info_unref (GtkRecentInfo *info); @@ -183,12 +183,20 @@ const gchar * gtk_recent_info_get_mime_type (GtkRecentInfo *info time_t gtk_recent_info_get_added (GtkRecentInfo *info); time_t gtk_recent_info_get_modified (GtkRecentInfo *info); time_t gtk_recent_info_get_visited (GtkRecentInfo *info); +gint64 gtk_recent_info_get_added_unix (GtkRecentInfo *info); +gint64 gtk_recent_info_get_modified_unix (GtkRecentInfo *info); +gint64 gtk_recent_info_get_visited_unix (GtkRecentInfo *info); gboolean gtk_recent_info_get_private_hint (GtkRecentInfo *info); gboolean gtk_recent_info_get_application_info (GtkRecentInfo *info, const gchar *app_name, const gchar **app_exec, guint *count, time_t *time_); +gboolean gtk_recent_info_get_application_info_unix (GtkRecentInfo *info, + const gchar *app_name, + const gchar **app_exec, + guint *count, + gint64 *time_); gchar ** gtk_recent_info_get_applications (GtkRecentInfo *info, gsize *length) G_GNUC_MALLOC; gchar * gtk_recent_info_last_application (GtkRecentInfo *info) G_GNUC_MALLOC; diff --git a/gtk/gtkruler.h b/gtk/gtkruler.h index b2260524d..a2ae204e9 100644 --- a/gtk/gtkruler.h +++ b/gtk/gtkruler.h @@ -111,7 +111,7 @@ struct _GtkRulerMetric }; -GType gtk_ruler_get_type (void) G_GNUC_CONST; +GType gtk_ruler_get_type (void); void gtk_ruler_set_metric (GtkRuler *ruler, GtkMetricType metric); GtkMetricType gtk_ruler_get_metric (GtkRuler *ruler); diff --git a/gtk/gtkscale.c b/gtk/gtkscale.c index d89211f97..e3dd07a29 100644 --- a/gtk/gtkscale.c +++ b/gtk/gtkscale.c @@ -29,6 +29,7 @@ #include #include +#include #include "gdk/gdkkeysyms.h" #include "gtkscale.h" @@ -66,6 +67,15 @@ struct _GtkScalePrivate { PangoLayout *layout; GSList *marks; + + /* the size of the value text for the bounds of the adjustment, + * which every change of the value asks for; measured again at each + * size request and whenever the bounds, the digits or the style are + * new */ + guint value_size_valid : 1; + gint value_width, value_height; + gdouble value_lower, value_upper; + gint value_digits; }; enum { @@ -821,12 +831,25 @@ _gtk_scale_get_value_size (GtkScale *scale, if (scale->draw_value) { + GtkScalePrivate *priv = GTK_SCALE_GET_PRIVATE (scale); PangoLayout *layout; PangoRectangle logical_rect; gchar *txt; range = GTK_RANGE (scale); + if (priv->value_size_valid && + priv->value_lower == range->adjustment->lower && + priv->value_upper == range->adjustment->upper && + priv->value_digits == scale->digits) + { + if (width) + *width = priv->value_width; + if (height) + *height = priv->value_height; + return; + } + layout = gtk_widget_create_pango_layout (GTK_WIDGET (scale), NULL); txt = _gtk_scale_format_value (scale, range->adjustment->lower); @@ -852,6 +875,16 @@ _gtk_scale_get_value_size (GtkScale *scale, *height = MAX (*height, logical_rect.height); g_object_unref (layout); + + if (width && height) + { + priv->value_size_valid = TRUE; + priv->value_width = *width; + priv->value_height = *height; + priv->value_lower = range->adjustment->lower; + priv->value_upper = range->adjustment->upper; + priv->value_digits = scale->digits; + } } else { @@ -889,7 +922,7 @@ gtk_scale_get_mark_label_size (GtkScale *scale, { GtkScaleMark *mark = m->data; - if (mark->markup) + if (mark->markup && *mark->markup) { pango_layout_set_markup (layout, mark->markup, -1); pango_layout_get_pixel_extents (layout, NULL, &logical_rect); @@ -955,6 +988,10 @@ gtk_scale_size_request (GtkWidget *widget, gint n1, w1, h1, n2, w2, h2; gint slider_length; + /* a new size is asked for: the text of the value may be new as well, + * from a handler of ::format-value */ + GTK_SCALE_GET_PRIVATE (widget)->value_size_valid = FALSE; + GTK_WIDGET_CLASS (gtk_scale_parent_class)->size_request (widget, requisition); gtk_widget_style_get (widget, "slider-length", &slider_length, NULL); @@ -1270,6 +1307,23 @@ gtk_scale_real_get_layout_offsets (GtkScale *scale, *y += widget->allocation.y; } +/* "%0.*f" gives "-0.0" for small negative values; drop the sign then */ +static gchar * +weed_out_neg_zero (gchar *str, + gint digits) +{ + if (str[0] == '-') + { + gchar *neg_zero = g_strdup_printf ("%0.*f", digits, -0.0); + + if (strcmp (neg_zero, str) == 0) + memmove (str, str + 1, strlen (str)); + g_free (neg_zero); + } + + return str; +} + /** * _gtk_scale_format_value: * @scale: a #GtkScale @@ -1294,8 +1348,16 @@ _gtk_scale_format_value (GtkScale *scale, if (fmt) return fmt; else - /* insert a LRM, to prevent -20 to come out as 20- in RTL locales */ - return g_strdup_printf ("\342\200\216%0.*f", scale->digits, value); + { + gchar *str = weed_out_neg_zero (g_strdup_printf ("%0.*f", scale->digits, value), + scale->digits); + + /* insert a LRM, to prevent -20 to come out as 20- in RTL locales */ + fmt = g_strconcat ("\342\200\216", str, NULL); + g_free (str); + + return fmt; + } } static void @@ -1390,6 +1452,8 @@ _gtk_scale_clear_layout (GtkScale *scale) g_return_if_fail (GTK_IS_SCALE (scale)); + priv->value_size_valid = FALSE; + if (priv->layout) { g_object_unref (priv->layout); @@ -1722,6 +1786,12 @@ gtk_scale_buildable_custom_finished (GtkBuildable *buildable, g_slist_free (marks_data->marks); g_slice_free (MarksSubparserData, marks_data); } + else + { + parent_buildable_iface->custom_finished (buildable, builder, child, + tagname, user_data); + } + } #define __GTK_SCALE_C__ diff --git a/gtk/gtkscale.h b/gtk/gtkscale.h index 01b70e0c9..7c19cfd3a 100644 --- a/gtk/gtkscale.h +++ b/gtk/gtkscale.h @@ -76,7 +76,7 @@ struct _GtkScaleClass void (*_gtk_reserved3) (void); }; -GType gtk_scale_get_type (void) G_GNUC_CONST; +GType gtk_scale_get_type (void); void gtk_scale_set_digits (GtkScale *scale, gint digits); gint gtk_scale_get_digits (GtkScale *scale); diff --git a/gtk/gtkscalebutton.c b/gtk/gtkscalebutton.c index d47459dbc..9526765d8 100644 --- a/gtk/gtkscalebutton.c +++ b/gtk/gtkscalebutton.c @@ -861,6 +861,11 @@ gtk_scale_button_scroll (GtkWidget *widget, GtkAdjustment *adj; gdouble d; + /* a pinch on a touchpad (Ctrl with the wheel) is for programs that + * zoom, not for scrolling here */ + if (gdk_event_get_touchpad_emulated ((GdkEvent *) event)) + return FALSE; + button = GTK_SCALE_BUTTON (widget); priv = button->priv; adj = priv->adjustment; diff --git a/gtk/gtkscalebutton.h b/gtk/gtkscalebutton.h index 29ab8a875..ede1865f7 100644 --- a/gtk/gtkscalebutton.h +++ b/gtk/gtkscalebutton.h @@ -81,7 +81,7 @@ struct _GtkScaleButtonClass void (*_gtk_reserved4) (void); }; -GType gtk_scale_button_get_type (void) G_GNUC_CONST; +GType gtk_scale_button_get_type (void); GtkWidget * gtk_scale_button_new (GtkIconSize size, gdouble min, gdouble max, diff --git a/gtk/gtkscrollbar.h b/gtk/gtkscrollbar.h index 8ce77d3ba..d3155818f 100644 --- a/gtk/gtkscrollbar.h +++ b/gtk/gtkscrollbar.h @@ -65,7 +65,7 @@ struct _GtkScrollbarClass }; -GType gtk_scrollbar_get_type (void) G_GNUC_CONST; +GType gtk_scrollbar_get_type (void); G_END_DECLS diff --git a/gtk/gtkscrolledwindow.c b/gtk/gtkscrolledwindow.c index a836953b3..817fa564c 100644 --- a/gtk/gtkscrolledwindow.c +++ b/gtk/gtkscrolledwindow.c @@ -28,6 +28,8 @@ #include #include #include "gtkbindings.h" +#include "gtkmain.h" +#include "gtkrange.h" #include "gtkmarshalers.h" #include "gtkscrolledwindow.h" #include "gtkwindow.h" @@ -76,6 +78,13 @@ typedef struct { gboolean window_placement_set; GtkCornerType real_window_placement; + + /* dragging with a finger (see gtk_scrolled_window_touch_event()) */ + gboolean no_kinetic_scrolling; + guint fling_source; + gdouble fling_vx, fling_vy; /* pixels a second */ + gdouble fling_x, fling_y; /* where the adjustments are going */ + gint64 fling_tick; } GtkScrolledWindowPrivate; #define GTK_SCROLLED_WINDOW_GET_PRIVATE(obj) ((GtkScrolledWindowPrivate *) gtk_scrolled_window_get_instance_private (GTK_SCROLLED_WINDOW (obj))) @@ -88,7 +97,8 @@ enum { PROP_VSCROLLBAR_POLICY, PROP_WINDOW_PLACEMENT, PROP_WINDOW_PLACEMENT_SET, - PROP_SHADOW_TYPE + PROP_SHADOW_TYPE, + PROP_KINETIC_SCROLLING }; /* Signals */ @@ -109,6 +119,8 @@ static void gtk_scrolled_window_get_property (GObject *objec GValue *value, GParamSpec *pspec); +static void gtk_scrolled_window_realize (GtkWidget *widget); +static void fling_stop (GtkScrolledWindow *scrolled_window); static void gtk_scrolled_window_screen_changed (GtkWidget *widget, GdkScreen *previous_screen); static gboolean gtk_scrolled_window_expose (GtkWidget *widget, @@ -196,6 +208,7 @@ gtk_scrolled_window_class_init (GtkScrolledWindowClass *class) object_class->destroy = gtk_scrolled_window_destroy; + widget_class->realize = gtk_scrolled_window_realize; widget_class->screen_changed = gtk_scrolled_window_screen_changed; widget_class->expose_event = gtk_scrolled_window_expose; widget_class->size_request = gtk_scrolled_window_size_request; @@ -277,6 +290,23 @@ gtk_scrolled_window_class_init (GtkScrolledWindowClass *class) GTK_SHADOW_NONE, GTK_PARAM_READABLE | GTK_PARAM_WRITABLE)); + /** + * GtkScrolledWindow:kinetic-scrolling: + * + * Whether a finger on a touchscreen scrolls by dragging, also with a + * swipe that goes on for a while, as in GTK+ 3. A finger that rests + * a moment first, or taps, is for the widgets inside, as is a mouse. + * + * Since: 2.24 + */ + g_object_class_install_property (gobject_class, + PROP_KINETIC_SCROLLING, + g_param_spec_boolean ("kinetic-scrolling", + P_("Kinetic Scrolling"), + P_("Kinetic scrolling mode."), + TRUE, + GTK_PARAM_READABLE | GTK_PARAM_WRITABLE)); + /** * GtkScrolledWindow:scrollbars-within-bevel: * @@ -845,6 +875,8 @@ gtk_scrolled_window_destroy (GtkObject *object) { GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (object); + fling_stop (scrolled_window); + if (scrolled_window->hscrollbar) { g_signal_handlers_disconnect_by_func (gtk_range_get_adjustment (GTK_RANGE (scrolled_window->hscrollbar)), @@ -910,6 +942,10 @@ gtk_scrolled_window_set_property (GObject *object, gtk_scrolled_window_set_shadow_type (scrolled_window, g_value_get_enum (value)); break; + case PROP_KINETIC_SCROLLING: + gtk_scrolled_window_set_kinetic_scrolling (scrolled_window, + g_value_get_boolean (value)); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -950,6 +986,9 @@ gtk_scrolled_window_get_property (GObject *object, case PROP_SHADOW_TYPE: g_value_set_enum (value, scrolled_window->shadow_type); break; + case PROP_KINETIC_SCROLLING: + g_value_set_boolean (value, !priv->no_kinetic_scrolling); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -1559,37 +1598,779 @@ gtk_scrolled_window_size_allocate (GtkWidget *widget, gtk_widget_hide (scrolled_window->vscrollbar); } +/* Wheel steps glide over a short while, as in GTK+ 3 and browsers, + * unless the setting gtk-enable-animations is off. A record exists + * only while an adjustment glides; a value that someone else sets + * meanwhile, by the keyboard or the slider, ends it. A machine that + * cannot draw the frames in time gets the step at once instead. */ + +#define GLIDE_MIN_TIME 50000 /* microseconds */ +#define GLIDE_MAX_TIME 150000 +#define GLIDE_INTERVAL 16 /* milliseconds */ +#define GLIDE_TOO_SLOW 50000 /* microseconds between frames */ + +typedef struct +{ + GtkAdjustment *adjustment; + gdouble from; + gdouble to; + gdouble last; /* what the adjustment got last */ + gint64 start; + gint64 duration; + gint64 tick; /* when the last frame was */ + guint source; +} Glide; + +static GQuark glide_quark; + +static void +glide_free (gpointer data) +{ + Glide *glide = data; + + if (glide->source) + g_source_remove (glide->source); + g_slice_free (Glide, glide); +} + +static void +glide_stop (GtkAdjustment *adj) +{ + if (glide_quark) + g_object_set_qdata (G_OBJECT (adj), glide_quark, NULL); +} + +/* The highest value @adj takes; never below the lowest */ +static gdouble +adjustment_top (GtkAdjustment *adj) +{ + return MAX (adj->lower, adj->upper - adj->page_size); +} + +static gboolean +glide_tick (gpointer data) +{ + Glide *glide = data; + GtkAdjustment *adj = glide->adjustment; + gboolean more = FALSE; + + /* "value-changed" may drop the adjustment, or end the glide */ + g_object_ref (adj); + + if (adj->value == glide->last) + { + gint64 now = g_get_monotonic_time (); + gdouble t = (now - glide->start) / (gdouble) glide->duration, value; + + if (now - glide->tick > GLIDE_TOO_SLOW) + t = 1; + glide->tick = now; + + if (t < 1) + value = glide->to - (glide->to - glide->from) * (1 - t) * (1 - t) * (1 - t); + else + value = glide->to; + + gtk_adjustment_set_value (adj, CLAMP (value, adj->lower, adjustment_top (adj))); + + if (g_object_get_qdata (G_OBJECT (adj), glide_quark) != glide) + { + g_object_unref (adj); + return FALSE; + } + glide->last = adj->value; + more = t < 1 && adj->value != glide->to; + } + + if (!more) + { + glide->source = 0; + glide_stop (adj); + } + g_object_unref (adj); + + return more; +} + +/* Moves @adj by @delta; returns whether it is going to move */ +static gboolean +scroll_adjustment (GtkAdjustment *adj, + gdouble delta, + gboolean glide) +{ + Glide *running = glide_quark ? g_object_get_qdata (G_OBJECT (adj), glide_quark) : NULL; + gdouble top = adjustment_top (adj); + gdouble target; + + if (running && adj->value != running->last) + { + /* someone else moved it */ + glide_stop (adj); + running = NULL; + } + + if (!glide) + { + target = CLAMP (adj->value + delta, adj->lower, top); + if (running) + { + /* a fine step during a glide moves the whole glide along */ + running->from += target - adj->value; + running->to = CLAMP (running->to + target - adj->value, adj->lower, top); + } + if (target == adj->value) + return FALSE; + gtk_adjustment_set_value (adj, target); + if (running && g_object_get_qdata (G_OBJECT (adj), glide_quark) == running) + running->last = adj->value; + return TRUE; + } + + /* a step while gliding goes on from where it was going */ + target = CLAMP ((running ? running->to : adj->value) + delta, adj->lower, top); + if (target == adj->value) + { + if (running) + glide_stop (adj); + return FALSE; + } + + if (!running) + { + if (!glide_quark) + glide_quark = g_quark_from_static_string ("gtk-scroll-glide"); + running = g_slice_new0 (Glide); + running->adjustment = adj; + running->source = gdk_threads_add_timeout (GLIDE_INTERVAL, glide_tick, running); + g_object_set_qdata_full (G_OBJECT (adj), glide_quark, running, glide_free); + } + + running->from = adj->value; + running->to = target; + running->last = adj->value; + running->start = running->tick = g_get_monotonic_time (); + running->duration = CLAMP (sqrt (fabs (target - adj->value)) / 60 * G_USEC_PER_SEC, + GLIDE_MIN_TIME, GLIDE_MAX_TIME); + + return TRUE; +} + +/* Shift and the wheel go sideways where that is possible, as in GTK+ 3 + * and browsers */ +static void +shift_sideways (GtkScrolledWindow *scrolled_window, + GdkEventScroll *event, + gdouble *steps_x, + gdouble *steps_y) +{ + if ((event->state & GDK_SHIFT_MASK) && *steps_x == 0 && + scrolled_window->hscrollbar && gtk_widget_get_visible (scrolled_window->hscrollbar)) + { + *steps_x = *steps_y; + *steps_y = 0; + } +} + +static gboolean +scroll_bar (GtkWidget *bar, + gdouble steps, + gboolean pixels, + gboolean glide) +{ + GtkRange *range = GTK_RANGE (bar); + + return scroll_adjustment (range->adjustment, + steps * _gtk_range_get_wheel_step (range, pixels), glide); +} + static gboolean gtk_scrolled_window_scroll_event (GtkWidget *widget, GdkEventScroll *event) { - GtkWidget *range; + GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (widget); + GtkWidget *vbar = scrolled_window->vscrollbar, *hbar = scrolled_window->hscrollbar; + gdouble steps_x, steps_y; + gboolean pixels, glide = FALSE, handled = FALSE, moved = FALSE; + + /* a pinch on a touchpad (Ctrl with the wheel) is for programs that + * zoom, not for scrolling here */ + if (gdk_event_get_touchpad_emulated ((GdkEvent *) event)) + return FALSE; g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (widget), FALSE); g_return_val_if_fail (event != NULL, FALSE); - if (event->direction == GDK_SCROLL_UP || event->direction == GDK_SCROLL_DOWN) - range = GTK_SCROLLED_WINDOW (widget)->vscrollbar; - else - range = GTK_SCROLLED_WINDOW (widget)->hscrollbar; + if (!_gtk_scroll_event_get_steps (event, &steps_x, &steps_y, &pixels)) + return FALSE; - if (range && gtk_widget_get_visible (range)) + shift_sideways (scrolled_window, event, &steps_x, &steps_y); + + /* whole steps glide; the fractions of fine wheels and touchpads + * are already smooth */ + if (!pixels && steps_x == floor (steps_x) && steps_y == floor (steps_y)) + g_object_get (gtk_widget_get_settings (widget), "gtk-enable-animations", &glide, NULL); + + if (steps_y != 0 && vbar && gtk_widget_get_visible (vbar)) { - GtkAdjustment *adj = GTK_RANGE (range)->adjustment; - gdouble delta, new_value; - - delta = _gtk_range_get_wheel_delta (GTK_RANGE (range), event->direction); - - new_value = CLAMP (adj->value + delta, adj->lower, adj->upper - adj->page_size); - - gtk_adjustment_set_value (adj, new_value); - - return TRUE; + handled = TRUE; + moved |= scroll_bar (vbar, steps_y, pixels, glide); + } + if (steps_x != 0 && hbar && gtk_widget_get_visible (hbar)) + { + handled = TRUE; + moved |= scroll_bar (hbar, steps_x, pixels, glide); } + if (moved) + _gtk_scroll_latch (widget, event->time); + + return handled; +} + +/* Which steps of a scroll event the scrolled window would use: 1 for + * those to the side, 2 for those up and down */ +guint +_gtk_scrolled_window_takes_scroll (GtkWidget *widget, + GdkEventScroll *event) +{ + GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (widget); + GtkWidget *vbar = scrolled_window->vscrollbar, *hbar = scrolled_window->hscrollbar; + gdouble steps_x, steps_y, sideways_x, sideways_y; + gboolean pixels; + + if (!_gtk_scroll_event_get_steps (event, &steps_x, &steps_y, &pixels)) + return 0; + + sideways_x = steps_x; + sideways_y = steps_y; + shift_sideways (scrolled_window, event, &sideways_x, &sideways_y); + if (sideways_x != steps_x) + return 2; + + return (steps_y != 0 && vbar && gtk_widget_get_visible (vbar) ? 2 : 0) | + (steps_x != 0 && hbar && gtk_widget_get_visible (hbar) ? 1 : 0); +} + +/* Dragging with a finger scrolls, as GTK+ 3's kinetic scrolling, in all + * programs: GDK marks the pointer events that a finger makes + * (gdk_event_get_pointer_emulated()), and gtk_main_do_event() shows + * them here before anyone else. A press of a finger inside a scrolled + * window that can scroll waits: if the finger moves on, the scrolled + * window scrolls with it, and after a swipe goes on, slowing down; if + * it is lifted, or rests for TOUCH_HOLD_TIME, the press goes to the + * widget below after all, so that tapping, selecting and dragging and + * dropping stay as they were. A finger on a scrollbar or slider moves + * that. The mouse is never held back. */ + +#define TOUCH_HOLD_TIME 300 /* milliseconds */ +#define FLING_INTERVAL 16 /* milliseconds */ +#define FLING_DECAY 0.325 /* seconds for the speed to fall to 1/e */ +#define FLING_MIN_SPEED 50.0 /* pixels a second to start a swipe */ +#define FLING_STOP_SPEED 15.0 /* and to end it */ +#define SAMPLE_TIME 100 /* milliseconds of motion that tell the speed */ + +enum +{ + TOUCH_IDLE, + TOUCH_HOLD, /* a press waits */ + TOUCH_DRAG, /* the finger scrolls */ + TOUCH_STOPPED, /* the finger stopped a swipe */ + TOUCH_PASS /* the finger is for the widget below */ +}; + +static struct +{ + gint state; + GtkWidget *inner; /* innermost scrolled window under the finger */ + GtkWidget *scrolling; /* the one that scrolls */ + GList *held; /* the presses held back, newest first */ + gdouble x0, y0; /* root position of the press */ + gdouble h0, v0; /* adjustment values at the press */ + guint timeout; + gboolean replaying; + struct { guint32 time; gdouble x, y; } samples[8]; + guint nsamples; +} touch; + +static GtkAdjustment * +touch_adjustment (GtkScrolledWindow *scrolled_window, + gboolean vertical) +{ + GtkWidget *bar = vertical ? scrolled_window->vscrollbar : scrolled_window->hscrollbar; + + return bar ? gtk_range_get_adjustment (GTK_RANGE (bar)) : NULL; +} + +/* whether the scrolled window has room to scroll that way */ +static gboolean +touch_can_scroll (GtkWidget *widget, + gboolean vertical) +{ + GtkAdjustment *adj = touch_adjustment (GTK_SCROLLED_WINDOW (widget), vertical); + + return adj && adj->upper - adj->page_size > adj->lower + 0.5; +} + +static gboolean +touch_takes (GtkWidget *widget) +{ + return GTK_IS_SCROLLED_WINDOW (widget) && + !GTK_SCROLLED_WINDOW_GET_PRIVATE (widget)->no_kinetic_scrolling && + gtk_widget_is_sensitive (widget); +} + +static void +touch_set_widget (GtkWidget **where, + GtkWidget *widget) +{ + if (*where) + g_object_remove_weak_pointer (G_OBJECT (*where), (gpointer *) where); + *where = widget; + if (widget) + g_object_add_weak_pointer (G_OBJECT (widget), (gpointer *) where); +} + +static void +touch_drop_held (void) +{ + g_list_foreach (touch.held, (GFunc) gdk_event_free, NULL); + g_list_free (touch.held); + touch.held = NULL; + if (touch.timeout) + g_source_remove (touch.timeout); + touch.timeout = 0; +} + +/* the presses go to the widgets after all */ +static void +touch_replay (void) +{ + GList *held = g_list_reverse (touch.held), *l; + + touch.held = NULL; + if (touch.timeout) + g_source_remove (touch.timeout); + touch.timeout = 0; + + touch.replaying = TRUE; + for (l = held; l; l = l->next) + { + gtk_main_do_event (l->data); + gdk_event_free (l->data); + } + touch.replaying = FALSE; + g_list_free (held); +} + +static gboolean +touch_hold_timeout (gpointer data) +{ + touch.timeout = 0; + touch.state = TOUCH_PASS; + touch_replay (); return FALSE; } +static void +fling_stop (GtkScrolledWindow *scrolled_window) +{ + GtkScrolledWindowPrivate *priv = GTK_SCROLLED_WINDOW_GET_PRIVATE (scrolled_window); + + if (priv->fling_source) + g_source_remove (priv->fling_source); + priv->fling_source = 0; +} + +/* stops the swipes of @widget and the scrolled windows around it; + * returns whether there was one */ +static gboolean +fling_stop_around (GtkWidget *widget) +{ + gboolean stopped = FALSE; + + for (; widget; widget = widget->parent) + if (GTK_IS_SCROLLED_WINDOW (widget) && + GTK_SCROLLED_WINDOW_GET_PRIVATE (widget)->fling_source) + { + fling_stop (GTK_SCROLLED_WINDOW (widget)); + stopped = TRUE; + } + + return stopped; +} + +/* moves one adjustment of a swipe; returns whether it goes on */ +static gboolean +fling_axis (GtkAdjustment *adj, + gdouble *speed, + gdouble *last, + gdouble dt, + gdouble decay) +{ + gdouble value, top; + + if (adj == NULL || *speed == 0) + return FALSE; + + /* someone else moved it */ + if (fabs (adj->value - *last) >= 1) + { + *speed = 0; + return FALSE; + } + + top = adjustment_top (adj); + value = CLAMP (*last + *speed * dt, adj->lower, top); + *speed *= decay; + *last = value; + if (floor (value) != floor (adj->value)) + gtk_adjustment_set_value (adj, floor (value)); + + if (value <= adj->lower || value >= top || fabs (*speed) < FLING_STOP_SPEED) + { + *speed = 0; + return FALSE; + } + + return TRUE; +} + +static gboolean +fling_tick (gpointer data) +{ + GtkScrolledWindow *scrolled_window = data; + GtkScrolledWindowPrivate *priv = GTK_SCROLLED_WINDOW_GET_PRIVATE (scrolled_window); + gint64 now = g_get_monotonic_time (); + gdouble dt = MIN (now - priv->fling_tick, 100000) / (gdouble) G_USEC_PER_SEC; + gdouble decay = exp (- dt / FLING_DECAY); + gboolean more; + + priv->fling_tick = now; + g_object_ref (scrolled_window); + more = fling_axis (touch_adjustment (scrolled_window, FALSE), &priv->fling_vx, + &priv->fling_x, dt, decay); + more |= fling_axis (touch_adjustment (scrolled_window, TRUE), &priv->fling_vy, + &priv->fling_y, dt, decay); + if (!more) + priv->fling_source = 0; + g_object_unref (scrolled_window); + + return more; +} + +/* the speed of the finger in pixels a second, from its last motions */ +static void +touch_speed (guint32 time, + gdouble *vx, + gdouble *vy) +{ + guint i, last = touch.nsamples - 1; + + *vx = *vy = 0; + if (touch.nsamples < 2 || time - touch.samples[last % 8].time > SAMPLE_TIME) + return; + + for (i = touch.nsamples > 8 ? touch.nsamples - 8 : 0; i < last; i++) + if (touch.samples[last % 8].time - touch.samples[i % 8].time <= SAMPLE_TIME) + break; + + if (touch.samples[last % 8].time > touch.samples[i % 8].time) + { + gdouble dt = (touch.samples[last % 8].time - touch.samples[i % 8].time) / 1000.0; + + *vx = (touch.samples[last % 8].x - touch.samples[i % 8].x) / dt; + *vy = (touch.samples[last % 8].y - touch.samples[i % 8].y) / dt; + } +} + +static void +touch_fling (guint32 time) +{ + GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (touch.scrolling); + GtkScrolledWindowPrivate *priv = GTK_SCROLLED_WINDOW_GET_PRIVATE (scrolled_window); + GtkAdjustment *hadj = touch_adjustment (scrolled_window, FALSE); + GtkAdjustment *vadj = touch_adjustment (scrolled_window, TRUE); + gboolean animations; + gdouble vx, vy; + + g_object_get (gtk_widget_get_settings (touch.scrolling), "gtk-enable-animations", &animations, NULL); + if (!animations) + return; + + touch_speed (time, &vx, &vy); + priv->fling_vx = touch_can_scroll (touch.scrolling, FALSE) ? -vx : 0; + priv->fling_vy = touch_can_scroll (touch.scrolling, TRUE) ? -vy : 0; + if (hypot (priv->fling_vx, priv->fling_vy) < FLING_MIN_SPEED) + return; + + priv->fling_x = hadj ? hadj->value : 0; + priv->fling_y = vadj ? vadj->value : 0; + priv->fling_tick = g_get_monotonic_time (); + fling_stop (scrolled_window); + priv->fling_source = gdk_threads_add_timeout (FLING_INTERVAL, fling_tick, scrolled_window); +} + +static void +touch_scroll_to (gdouble x_root, + gdouble y_root) +{ + GtkWidget *widget = g_object_ref (touch.scrolling); + GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (widget); + GtkAdjustment *adj; + + if (touch_can_scroll (widget, FALSE) && + (adj = touch_adjustment (scrolled_window, FALSE))) + { + glide_stop (adj); + gtk_adjustment_set_value (adj, CLAMP (floor (touch.h0 - (x_root - touch.x0)), + adj->lower, adjustment_top (adj))); + } + if (touch_can_scroll (widget, TRUE) && + (adj = touch_adjustment (scrolled_window, TRUE))) + { + glide_stop (adj); + gtk_adjustment_set_value (adj, CLAMP (floor (touch.v0 - (y_root - touch.y0)), + adj->lower, adjustment_top (adj))); + } + g_object_unref (widget); +} + +/* The finger went far enough: the scrolled window from the innermost + * one out that can scroll the way it went begins to. Returns FALSE + * where none can. */ +static gboolean +touch_begin_drag (gdouble x_root, + gdouble y_root) +{ + gboolean vertical = fabs (y_root - touch.y0) >= fabs (x_root - touch.x0); + GtkWidget *w; + GtkAdjustment *adj; + + for (w = touch.inner; w; w = w->parent) + if (touch_takes (w) && touch_can_scroll (w, vertical)) + break; + if (w == NULL) + return FALSE; + + touch_set_widget (&touch.scrolling, w); + adj = touch_adjustment (GTK_SCROLLED_WINDOW (w), FALSE); + touch.h0 = adj ? adj->value : 0; + adj = touch_adjustment (GTK_SCROLLED_WINDOW (w), TRUE); + touch.v0 = adj ? adj->value : 0; + touch.state = TOUCH_DRAG; + touch_drop_held (); + + return TRUE; +} + +static void +touch_sample (guint32 time, + gdouble x_root, + gdouble y_root) +{ + guint i = touch.nsamples++ % 8; + + touch.samples[i].time = time; + touch.samples[i].x = x_root; + touch.samples[i].y = y_root; +} + +/* Returns whether the event is taken, from gtk_main_do_event() for the + * pointer events; @grab_widget is the one that would get it */ +gboolean +_gtk_scrolled_window_touch_event (GtkWidget *event_widget, + GtkWidget *grab_widget, + GdkEvent *event) +{ + GtkWidget *w, *inner = NULL; + gboolean finger; + gint threshold; + + if (touch.replaying) + return FALSE; + + finger = gdk_event_get_pointer_emulated (event); + + switch (event->type) + { + case GDK_BUTTON_PRESS: + case GDK_2BUTTON_PRESS: + case GDK_3BUTTON_PRESS: + if (touch.state == TOUCH_HOLD && finger) + { + /* the double click of a second tap waits with its press */ + touch.held = g_list_prepend (touch.held, gdk_event_copy (event)); + return TRUE; + } + if (touch.state == TOUCH_DRAG || touch.state == TOUCH_STOPPED) + return finger; + if (touch.state == TOUCH_PASS && event->type != GDK_BUTTON_PRESS) + return FALSE; + + touch.state = TOUCH_IDLE; + touch_drop_held (); + if (!finger || event->type != GDK_BUTTON_PRESS || event->button.button != 1 || + grab_widget != event_widget) + return FALSE; + + /* where the finger is for a scrollbar or slider, or no scrolled + * window around can scroll, nothing waits */ + for (w = event_widget; w; w = w->parent) + { + if (GTK_IS_RANGE (w)) + return FALSE; + if (touch_takes (w) && + (touch_can_scroll (w, FALSE) || touch_can_scroll (w, TRUE) || + GTK_SCROLLED_WINDOW_GET_PRIVATE (w)->fling_source)) + { + inner = w; + break; + } + } + if (inner == NULL) + return FALSE; + + touch_set_widget (&touch.inner, inner); + touch_set_widget (&touch.scrolling, NULL); + touch.x0 = event->button.x_root; + touch.y0 = event->button.y_root; + touch.nsamples = 0; + touch_sample (event->button.time, touch.x0, touch.y0); + + /* a finger on a swipe stops it, and is not a tap */ + if (fling_stop_around (inner)) + { + touch.state = TOUCH_STOPPED; + return TRUE; + } + + touch.state = TOUCH_HOLD; + touch.held = g_list_prepend (NULL, gdk_event_copy (event)); + touch.timeout = gdk_threads_add_timeout (TOUCH_HOLD_TIME, touch_hold_timeout, NULL); + return TRUE; + + case GDK_MOTION_NOTIFY: + if (touch.state == TOUCH_IDLE || touch.state == TOUCH_PASS || !finger) + return FALSE; + + touch_sample (event->motion.time, event->motion.x_root, event->motion.y_root); + + if (touch.state == TOUCH_HOLD || touch.state == TOUCH_STOPPED) + { + g_object_get (gtk_widget_get_settings (event_widget), + "gtk-dnd-drag-threshold", &threshold, NULL); + if (fabs (event->motion.x_root - touch.x0) <= threshold && + fabs (event->motion.y_root - touch.y0) <= threshold) + return TRUE; + + if (!touch.inner || !touch_begin_drag (event->motion.x_root, event->motion.y_root)) + { + /* nothing can scroll that way: for the widget below */ + if (touch.state == TOUCH_HOLD) + { + touch.state = TOUCH_PASS; + touch_replay (); + return FALSE; + } + return TRUE; + } + } + + if (touch.scrolling) + touch_scroll_to (event->motion.x_root, event->motion.y_root); + return TRUE; + + case GDK_BUTTON_RELEASE: + switch (touch.state) + { + case TOUCH_HOLD: + touch.state = TOUCH_IDLE; + touch_replay (); + return FALSE; + + case TOUCH_DRAG: + touch.state = TOUCH_IDLE; + if (finger && touch.scrolling) + touch_fling (event->button.time); + touch_set_widget (&touch.scrolling, NULL); + return finger; + + case TOUCH_STOPPED: + touch.state = TOUCH_IDLE; + return finger; + + case TOUCH_PASS: + touch.state = TOUCH_IDLE; + return FALSE; + + default: + return FALSE; + } + + default: + return FALSE; + } +} + +static void +gtk_scrolled_window_realize (GtkWidget *widget) +{ + GTK_WIDGET_CLASS (gtk_scrolled_window_parent_class)->realize (widget); + + /* for the marks of the pointer events of fingers */ + if (!GTK_SCROLLED_WINDOW_GET_PRIVATE (widget)->no_kinetic_scrolling) + gdk_window_set_touch_emulation_libgtk_only (widget->window); +} + +/** + * gtk_scrolled_window_set_kinetic_scrolling: + * @scrolled_window: a #GtkScrolledWindow + * @kinetic_scrolling: %TRUE to enable kinetic scrolling + * + * Turns dragging with a finger on a touchscreen on or off, see + * #GtkScrolledWindow:kinetic-scrolling. On by default. + * + * Since: 2.24 + */ +void +gtk_scrolled_window_set_kinetic_scrolling (GtkScrolledWindow *scrolled_window, + gboolean kinetic_scrolling) +{ + GtkScrolledWindowPrivate *priv; + + g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window)); + + priv = GTK_SCROLLED_WINDOW_GET_PRIVATE (scrolled_window); + if (priv->no_kinetic_scrolling == !kinetic_scrolling) + return; + + priv->no_kinetic_scrolling = !kinetic_scrolling; + if (!kinetic_scrolling) + fling_stop (scrolled_window); + else if (gtk_widget_get_realized (GTK_WIDGET (scrolled_window))) + gdk_window_set_touch_emulation_libgtk_only (GTK_WIDGET (scrolled_window)->window); + + g_object_notify (G_OBJECT (scrolled_window), "kinetic-scrolling"); +} + +/** + * gtk_scrolled_window_get_kinetic_scrolling: + * @scrolled_window: a #GtkScrolledWindow + * + * Returns whether a finger scrolls by dragging. + * + * Returns: the kinetic scrolling behavior flags. + * + * Since: 2.24 + */ +gboolean +gtk_scrolled_window_get_kinetic_scrolling (GtkScrolledWindow *scrolled_window) +{ + g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), FALSE); + + return !GTK_SCROLLED_WINDOW_GET_PRIVATE (scrolled_window)->no_kinetic_scrolling; +} + static gboolean gtk_scrolled_window_focus (GtkWidget *widget, GtkDirectionType direction) diff --git a/gtk/gtkscrolledwindow.h b/gtk/gtkscrolledwindow.h index 5407547c1..bd3812000 100644 --- a/gtk/gtkscrolledwindow.h +++ b/gtk/gtkscrolledwindow.h @@ -99,7 +99,7 @@ struct _GtkScrolledWindowClass }; -GType gtk_scrolled_window_get_type (void) G_GNUC_CONST; +GType gtk_scrolled_window_get_type (void); GtkWidget* gtk_scrolled_window_new (GtkAdjustment *hadjustment, GtkAdjustment *vadjustment); void gtk_scrolled_window_set_hadjustment (GtkScrolledWindow *scrolled_window, @@ -126,6 +126,9 @@ void gtk_scrolled_window_set_shadow_type (GtkScrolledWindow *scrolle GtkShadowType gtk_scrolled_window_get_shadow_type (GtkScrolledWindow *scrolled_window); void gtk_scrolled_window_add_with_viewport (GtkScrolledWindow *scrolled_window, GtkWidget *child); +void gtk_scrolled_window_set_kinetic_scrolling (GtkScrolledWindow *scrolled_window, + gboolean kinetic_scrolling); +gboolean gtk_scrolled_window_get_kinetic_scrolling (GtkScrolledWindow *scrolled_window); gint _gtk_scrolled_window_get_scrollbar_spacing (GtkScrolledWindow *scrolled_window); diff --git a/gtk/gtksearchenginequartz.c b/gtk/gtksearchenginequartz.c index 4594619ec..a2ca581bc 100644 --- a/gtk/gtksearchenginequartz.c +++ b/gtk/gtksearchenginequartz.c @@ -86,6 +86,7 @@ G_DEFINE_TYPE_WITH_PRIVATE (GtkSearchEngineQuartz, _gtk_search_engine_quartz, GT } _gtk_search_engine_hits_added (engine, hits); + g_list_foreach (hits, (GFunc) g_free, NULL); g_list_free (hits); submitted_hits = [ns_query resultCount]; diff --git a/gtk/gtksearchenginesimple.c b/gtk/gtksearchenginesimple.c index 9dbb68c76..5e73fbe88 100644 --- a/gtk/gtksearchenginesimple.c +++ b/gtk/gtksearchenginesimple.c @@ -22,22 +22,9 @@ #include "config.h" -/* these must be defined even when HAVE_GNU_FTW is not defined - * because (really) old versions of GNU libc have ftw.h but do - * export ftw() and friends only if _XOPEN_SOURCE and _GNU_SOURCE - * are defined. see bug #444097. - */ -#if !defined(_XOPEN_SOURCE) && (!defined(__sun) || __STDC_VERSION__ - 0 < 199901L) -#define _XOPEN_SOURCE 500 -#endif -#define _GNU_SOURCE - -#ifdef HAVE_FTW_H -#include -#endif - #include "gtksearchenginesimple.h" #include "gtkprivate.h" +#include "gtktimeprivate.h" #include @@ -193,99 +180,82 @@ send_batch (SearchThreadData *data) data->uri_hits = NULL; } -static GPrivate search_thread_data = G_PRIVATE_INIT (NULL); - -#ifdef HAVE_FTW_H -static int -search_visit_func (const char *fpath, - const struct stat *sb, - int typeflag, - struct FTW *ftwbuf) +/* Notes @path as a hit if its name has all the words; a hidden name + * (starting with a dot) is never a hit */ +static void +search_visit (SearchThreadData *data, + const gchar *path, + const gchar *name) { - SearchThreadData *data; - gint i; - const gchar *name; gchar *lower_name; - gchar *uri; - gboolean hit; - gboolean is_hidden; + gboolean hit = TRUE; + gint i; - data = (SearchThreadData*)g_private_get (&search_thread_data); - if (data->cancelled) -#ifdef HAVE_GNU_FTW - return FTW_STOP; -#else - return 1; -#endif /* HAVE_GNU_FTW */ - - name = strrchr (fpath, '/'); - if (name) - name++; + if (*name == '.') + hit = FALSE; else - name = fpath; - - is_hidden = *name == '.'; - - hit = FALSE; - - if (!is_hidden) { lower_name = g_ascii_strdown (name, -1); - - hit = TRUE; for (i = 0; data->words[i] != NULL; i++) - { - if (strstr (lower_name, data->words[i]) == NULL) - { - hit = FALSE; - break; - } - } + if (strstr (lower_name, data->words[i]) == NULL) + { + hit = FALSE; + break; + } g_free (lower_name); } if (hit) - { - uri = g_filename_to_uri (fpath, NULL, NULL); - data->uri_hits = g_list_prepend (data->uri_hits, uri); - } + data->uri_hits = g_list_prepend (data->uri_hits, g_filename_to_uri (path, NULL, NULL)); data->n_processed_files++; if (data->n_processed_files > BATCH_SIZE) send_batch (data); - -#ifdef HAVE_GNU_FTW - if (is_hidden) - return FTW_SKIP_SUBTREE; - else - return FTW_CONTINUE; -#else - return 0; -#endif /* HAVE_GNU_FTW */ } -#endif /* HAVE_FTW_H */ +/* Walks the folders below the search folder, without following links + * and leaving out hidden folders, as nftw() did with FTW_PHYS and + * FTW_ACTIONRETVAL. Its own walk rather than nftw(): that one has no + * Windows, and with a 32-bit time_t its stat() fails for anything + * changed after 2038, whose folders it then did not go into. */ static gpointer search_thread_func (gpointer user_data) { -#ifdef HAVE_FTW_H - SearchThreadData *data; + SearchThreadData *data = user_data; + GPtrArray *todo = g_ptr_array_new (); + gchar *base = g_path_get_basename (data->path); - data = user_data; + search_visit (data, data->path, base); + g_free (base); + g_ptr_array_add (todo, g_strdup (data->path)); - g_private_set (&search_thread_data, data); + while (todo->len > 0) + { + gchar *dir_path = g_ptr_array_remove_index (todo, todo->len - 1); + GDir *dir = data->cancelled ? NULL : g_dir_open (dir_path, 0, NULL); + const gchar *name; - nftw (data->path, search_visit_func, 20, -#ifdef HAVE_GNU_FTW - FTW_ACTIONRETVAL | -#endif - FTW_PHYS); + while (dir != NULL && !data->cancelled && (name = g_dir_read_name (dir)) != NULL) + { + gchar *path = g_build_filename (dir_path, name, NULL); + GtkStatBuf buf; + + search_visit (data, path, name); + if (*name != '.' && _gtk_stat (path, FALSE, &buf) == 0 && S_ISDIR (buf.mode)) + g_ptr_array_add (todo, path); + else + g_free (path); + } + if (dir != NULL) + g_dir_close (dir); + g_free (dir_path); + } + g_ptr_array_free (todo, TRUE); send_batch (data); gdk_threads_add_idle (search_thread_done_idle, data); -#endif /* HAVE_FTW_H */ return NULL; } diff --git a/gtk/gtksearchenginetracker.c b/gtk/gtksearchenginetracker.c index add96d0ff..a8e3a25a7 100644 --- a/gtk/gtksearchenginetracker.c +++ b/gtk/gtksearchenginetracker.c @@ -317,15 +317,19 @@ query_callback (GObject *object, v = g_variant_iter_next_value (&iter); strv = g_variant_get_strv (v, NULL); - result[i] = (gchar*)strv[0]; + result[i] = g_strdup (strv[0]); g_free (strv); + g_variant_unref (v); } /* We iterate result by result, not n at a time. */ hits = string_list_to_gslist (result); _gtk_search_engine_hits_added (GTK_SEARCH_ENGINE (tracker), hits); _gtk_search_engine_finished (GTK_SEARCH_ENGINE (tracker)); + g_list_foreach (hits, (GFunc) g_free, NULL); g_list_free (hits); + for (i = 0; i < n; i++) + g_free (result[i]); g_free (result); g_variant_unref (reply); g_variant_unref (r); diff --git a/gtk/gtkselection.c b/gtk/gtkselection.c index 2888b352b..85325b1cc 100644 --- a/gtk/gtkselection.c +++ b/gtk/gtkselection.c @@ -1070,7 +1070,7 @@ gtk_selection_convert (GtkWidget *widget, { GtkWidget *owner_widget; gpointer owner_widget_ptr; - GtkSelectionData selection_data; + GtkSelectionData selection_data = { 0 }; selection_data.selection = selection; selection_data.target = target; @@ -2295,6 +2295,16 @@ _gtk_selection_request (GtkWidget *widget, info->requestor = NULL; #endif +#if defined GDK_WINDOWING_X11 || defined GDK_WINDOWING_WIN32 + /* the requesting window is already gone: nobody to answer */ + if (info->requestor == NULL) + { + g_object_unref (widget); + g_slice_free (GtkIncrInfo, info); + return FALSE; + } +#endif + /* Determine conversions we need to perform */ if (event->target == gtk_selection_atoms[MULTIPLE]) @@ -2320,6 +2330,7 @@ _gtk_selection_request (GtkWidget *widget, g_free (mult_atoms); g_slice_free (GtkIncrInfo, info); gdk_error_trap_pop (); + g_object_unref (widget); return TRUE; } gdk_error_trap_pop (); @@ -2412,23 +2423,31 @@ _gtk_selection_request (GtkWidget *widget, info->conversions[i].data = data; info->num_incrs++; + /* the requestor may have gone away meanwhile; an X error + * about it must not end the program */ + gdk_error_trap_push (); gdk_property_change (info->requestor, info->conversions[i].property, gtk_selection_atoms[INCR], 32, GDK_PROP_MODE_REPLACE, (guchar *)&items, 1); + gdk_display_sync (display); + gdk_error_trap_pop (); } else { info->conversions[i].offset = -1; + gdk_error_trap_push (); gdk_property_change (info->requestor, info->conversions[i].property, data.type, data.format, GDK_PROP_MODE_REPLACE, data.data, items); + gdk_display_sync (display); + gdk_error_trap_pop (); g_free (data.data); } @@ -2439,16 +2458,16 @@ _gtk_selection_request (GtkWidget *widget, if (info->num_incrs > 0) { - /* FIXME: this could be dangerous if window doesn't still - exist */ - #ifdef DEBUG_SELECTION g_message ("Starting INCR..."); #endif + gdk_error_trap_push (); gdk_window_set_events (info->requestor, gdk_window_get_events (info->requestor) | GDK_PROPERTY_CHANGE_MASK); + gdk_display_sync (display); + gdk_error_trap_pop (); current_incrs = g_list_append (current_incrs, info); gdk_threads_add_timeout (1000, (GSourceFunc) gtk_selection_incr_timeout, info); } @@ -2464,10 +2483,13 @@ _gtk_selection_request (GtkWidget *widget, mult_atoms[2*i+1] = info->conversions[i].property; } + gdk_error_trap_push (); gdk_property_change (info->requestor, event->property, gdk_atom_intern_static_string ("ATOM_PAIR"), 32, GDK_PROP_MODE_REPLACE, (guchar *)mult_atoms, 2*info->num_conversions); + gdk_display_sync (display); + gdk_error_trap_pop (); g_free (mult_atoms); } @@ -2591,12 +2613,17 @@ _gtk_selection_incr_event (GdkWindow *window, #endif bytes_per_item = gtk_selection_bytes_per_item (info->conversions[i].data.format); + /* the requestor may have gone away meanwhile; an X error + * about it must not end the program */ + gdk_error_trap_push (); gdk_property_change (info->requestor, event->atom, info->conversions[i].data.type, info->conversions[i].data.format, GDK_PROP_MODE_REPLACE, buffer, num_bytes / bytes_per_item); + gdk_display_sync (gdk_window_get_display (window)); + gdk_error_trap_pop (); if (info->conversions[i].offset == -2) { @@ -2694,6 +2721,7 @@ gboolean _gtk_selection_notify (GtkWidget *widget, GdkEventSelection *event) { + GdkWindow *window; GList *tmp_list; GtkRetrievalInfo *info = NULL; guchar *buffer = NULL; @@ -2718,6 +2746,8 @@ _gtk_selection_notify (GtkWidget *widget, if (!tmp_list) /* no retrieval in progress */ return FALSE; + window = g_object_ref (widget->window); + if (event->property != GDK_NONE) length = gdk_selection_property_get (widget->window, &buffer, &type, &format); @@ -2731,6 +2761,7 @@ _gtk_selection_notify (GtkWidget *widget, /* structure will be freed in timeout */ gtk_selection_retrieval_report (info, GDK_NONE, 0, NULL, -1, event->time); + g_object_unref (window); return TRUE; } @@ -2759,7 +2790,11 @@ _gtk_selection_notify (GtkWidget *widget, buffer, length, event->time); } - gdk_property_delete (widget->window, event->property); + /* the window held, as the callback may have destroyed the widget (the + * clipboard does so with the widgets of requests that ran at the same + * time as another) */ + gdk_property_delete (window, event->property); + g_object_unref (window); g_free (buffer); diff --git a/gtk/gtkselection.h b/gtk/gtkselection.h index 012e7d4b4..7db23e754 100644 --- a/gtk/gtkselection.h +++ b/gtk/gtkselection.h @@ -210,11 +210,11 @@ gboolean _gtk_selection_notify (GtkWidget *widget, gboolean _gtk_selection_property_notify (GtkWidget *widget, GdkEventProperty *event); -GType gtk_selection_data_get_type (void) G_GNUC_CONST; +GType gtk_selection_data_get_type (void); GtkSelectionData *gtk_selection_data_copy (GtkSelectionData *data); void gtk_selection_data_free (GtkSelectionData *data); -GType gtk_target_list_get_type (void) G_GNUC_CONST; +GType gtk_target_list_get_type (void); G_END_DECLS diff --git a/gtk/gtkseparator.h b/gtk/gtkseparator.h index 98441b667..eea41a039 100644 --- a/gtk/gtkseparator.h +++ b/gtk/gtkseparator.h @@ -59,7 +59,7 @@ struct _GtkSeparatorClass }; -GType gtk_separator_get_type (void) G_GNUC_CONST; +GType gtk_separator_get_type (void); G_END_DECLS diff --git a/gtk/gtkseparatormenuitem.h b/gtk/gtkseparatormenuitem.h index 2c99572d1..c6196481f 100644 --- a/gtk/gtkseparatormenuitem.h +++ b/gtk/gtkseparatormenuitem.h @@ -59,7 +59,7 @@ struct _GtkSeparatorMenuItemClass }; -GType gtk_separator_menu_item_get_type (void) G_GNUC_CONST; +GType gtk_separator_menu_item_get_type (void); GtkWidget* gtk_separator_menu_item_new (void); diff --git a/gtk/gtkseparatortoolitem.h b/gtk/gtkseparatortoolitem.h index 58b04bfde..3d904dcf7 100644 --- a/gtk/gtkseparatortoolitem.h +++ b/gtk/gtkseparatortoolitem.h @@ -60,7 +60,7 @@ struct _GtkSeparatorToolItemClass void (* _gtk_reserved4) (void); }; -GType gtk_separator_tool_item_get_type (void) G_GNUC_CONST; +GType gtk_separator_tool_item_get_type (void); GtkToolItem *gtk_separator_tool_item_new (void); gboolean gtk_separator_tool_item_get_draw (GtkSeparatorToolItem *item); diff --git a/gtk/gtksettings.c b/gtk/gtksettings.c index ed2eb2287..d18629ec6 100644 --- a/gtk/gtksettings.c +++ b/gtk/gtksettings.c @@ -293,7 +293,7 @@ gtk_settings_class_init (GtkSettingsClass *class) g_param_spec_int ("gtk-cursor-blink-timeout", P_("Cursor Blink Timeout"), P_("Time after which the cursor stops blinking, in seconds"), - 1, G_MAXINT, G_MAXINT, + 1, G_MAXINT, 10, GTK_PARAM_READWRITE), NULL); g_assert (result == PROP_CURSOR_BLINK_TIMEOUT); diff --git a/gtk/gtksettings.h b/gtk/gtksettings.h index 91d2be610..ab481efc7 100644 --- a/gtk/gtksettings.h +++ b/gtk/gtksettings.h @@ -75,7 +75,7 @@ struct _GtkSettingsValue /* --- functions --- */ -GType gtk_settings_get_type (void) G_GNUC_CONST; +GType gtk_settings_get_type (void); #ifndef GDK_MULTIHEAD_SAFE GtkSettings* gtk_settings_get_default (void); #endif diff --git a/gtk/gtksizegroup.c b/gtk/gtksizegroup.c index 7362b0f1c..abfde84f0 100644 --- a/gtk/gtksizegroup.c +++ b/gtk/gtksizegroup.c @@ -68,12 +68,16 @@ static void gtk_size_group_buildable_custom_finished (GtkBuildable *buildable, static GQuark size_groups_quark; static const gchar size_groups_tag[] = "gtk-size-groups"; -static GQuark visited_quark; -static const gchar visited_tag[] = "gtk-size-group-visited"; +/* most widgets are in no group: a flag says so, without looking for + * the groups in the data of the widget, for each widget and each of + * its parents at every resize asked for */ static GSList * get_size_groups (GtkWidget *widget) { + if (!(GTK_PRIVATE_FLAGS (widget) & PRIVATE_GTK_IN_SIZE_GROUP)) + return NULL; + return g_object_get_qdata (G_OBJECT (widget), size_groups_quark); } @@ -82,24 +86,38 @@ set_size_groups (GtkWidget *widget, GSList *groups) { g_object_set_qdata (G_OBJECT (widget), size_groups_quark, groups); + + if (groups) + GTK_PRIVATE_SET_FLAG (widget, GTK_IN_SIZE_GROUP); + else + GTK_PRIVATE_UNSET_FLAG (widget, GTK_IN_SIZE_GROUP); } +/* The widgets and groups of a closure being built are marked in a set, + * not with data on each object: setting and reading object data takes + * a lock and a search of all data of the object each time, for every + * widget of a group at every resize asked for by one of them */ +static GHashTable *visited_set; + static void mark_visited (gpointer object) { - g_object_set_qdata (object, visited_quark, "visited"); + if (!visited_set) + visited_set = g_hash_table_new (NULL, NULL); + g_hash_table_insert (visited_set, object, object); } static void mark_unvisited (gpointer object) { - g_object_set_qdata (object, visited_quark, NULL); + if (visited_set) + g_hash_table_remove (visited_set, object); } static gboolean is_visited (gpointer object) { - return g_object_get_qdata (object, visited_quark) != NULL; + return visited_set && g_hash_table_lookup (visited_set, object) != NULL; } static void @@ -176,18 +194,68 @@ reset_group_sizes (GSList *groups) } } +static void queue_resize_on_widget (GtkWidget *widget, + gboolean check_siblings); + +/* Resets the groups of the closure of @parent in @mode and asks for a + * new size of all its widgets; returns whether all groups of all these + * widgets are of both modes, when the closure in the other mode is the + * same and needs no second round */ +static gboolean +queue_resize_on_closure (GtkWidget *widget, + GtkWidget *parent, + GtkSizeGroupMode mode) +{ + GSList *groups = NULL; + GSList *widgets = NULL; + GSList *tmp_list; + gboolean all_both = TRUE; + + add_widget_to_closure (parent, mode, &groups, &widgets); + g_slist_foreach (widgets, (GFunc)mark_unvisited, NULL); + g_slist_foreach (groups, (GFunc)mark_unvisited, NULL); + + reset_group_sizes (groups); + + tmp_list = widgets; + while (tmp_list) + { + GSList *g; + + for (g = get_size_groups (tmp_list->data); g; g = g->next) + if (((GtkSizeGroup *) g->data)->mode != GTK_SIZE_GROUP_BOTH) + all_both = FALSE; + + if (tmp_list->data == parent) + { + if (widget == parent) + real_queue_resize (parent); + } + else if (tmp_list->data == widget) + { + g_warning ("A container and its child are part of this SizeGroup"); + } + else + queue_resize_on_widget (tmp_list->data, FALSE); + + tmp_list = tmp_list->next; + } + + g_slist_free (widgets); + g_slist_free (groups); + + return all_both; +} + static void queue_resize_on_widget (GtkWidget *widget, gboolean check_siblings) { GtkWidget *parent = widget; - GSList *tmp_list; while (parent) { GSList *widget_groups; - GSList *groups; - GSList *widgets; if (widget == parent && !check_siblings) { @@ -206,65 +274,8 @@ queue_resize_on_widget (GtkWidget *widget, continue; } - groups = NULL; - widgets = NULL; - - add_widget_to_closure (parent, GTK_SIZE_GROUP_HORIZONTAL, &groups, &widgets); - g_slist_foreach (widgets, (GFunc)mark_unvisited, NULL); - g_slist_foreach (groups, (GFunc)mark_unvisited, NULL); - - reset_group_sizes (groups); - - tmp_list = widgets; - while (tmp_list) - { - if (tmp_list->data == parent) - { - if (widget == parent) - real_queue_resize (parent); - } - else if (tmp_list->data == widget) - { - g_warning ("A container and its child are part of this SizeGroup"); - } - else - queue_resize_on_widget (tmp_list->data, FALSE); - - tmp_list = tmp_list->next; - } - - g_slist_free (widgets); - g_slist_free (groups); - - groups = NULL; - widgets = NULL; - - add_widget_to_closure (parent, GTK_SIZE_GROUP_VERTICAL, &groups, &widgets); - g_slist_foreach (widgets, (GFunc)mark_unvisited, NULL); - g_slist_foreach (groups, (GFunc)mark_unvisited, NULL); - - reset_group_sizes (groups); - - tmp_list = widgets; - while (tmp_list) - { - if (tmp_list->data == parent) - { - if (widget == parent) - real_queue_resize (parent); - } - else if (tmp_list->data == widget) - { - g_warning ("A container and its child are part of this SizeGroup"); - } - else - queue_resize_on_widget (tmp_list->data, FALSE); - - tmp_list = tmp_list->next; - } - - g_slist_free (widgets); - g_slist_free (groups); + if (!queue_resize_on_closure (widget, parent, GTK_SIZE_GROUP_HORIZONTAL)) + queue_resize_on_closure (widget, parent, GTK_SIZE_GROUP_VERTICAL); parent = parent->parent; } @@ -283,7 +294,6 @@ initialize_size_group_quarks (void) if (!size_groups_quark) { size_groups_quark = g_quark_from_static_string (size_groups_tag); - visited_quark = g_quark_from_static_string (visited_tag); } } diff --git a/gtk/gtksizegroup.h b/gtk/gtksizegroup.h index f1ff8b1f9..f4b580ac8 100644 --- a/gtk/gtksizegroup.h +++ b/gtk/gtksizegroup.h @@ -84,7 +84,7 @@ typedef enum { GTK_SIZE_GROUP_BOTH } GtkSizeGroupMode; -GType gtk_size_group_get_type (void) G_GNUC_CONST; +GType gtk_size_group_get_type (void); GtkSizeGroup * gtk_size_group_new (GtkSizeGroupMode mode); void gtk_size_group_set_mode (GtkSizeGroup *size_group, diff --git a/gtk/gtksocket-win32.c b/gtk/gtksocket-win32.c index c8b49cf77..3242b78a6 100644 --- a/gtk/gtksocket-win32.c +++ b/gtk/gtksocket-win32.c @@ -46,7 +46,7 @@ _gtk_socket_windowing_get_id (GtkSocket *socket) g_return_val_if_fail (GTK_IS_SOCKET (socket), 0); g_return_val_if_fail (GTK_WIDGET_ANCHORED (socket), 0); - if (!gtk_widget_get_realized (socket)) + if (!gtk_widget_get_realized (GTK_WIDGET (socket))) gtk_widget_realize (GTK_WIDGET (socket)); return (GdkNativeWindow) GDK_WINDOW_HWND (GTK_WIDGET (socket)->window); diff --git a/gtk/gtksocket-x11.c b/gtk/gtksocket-x11.c index 3c6f60849..13e60236e 100644 --- a/gtk/gtksocket-x11.c +++ b/gtk/gtksocket-x11.c @@ -106,15 +106,18 @@ _gtk_socket_windowing_size_request (GtkSocket *socket) GDK_WINDOW_XWINDOW (socket->plug_window), &hints, &supplied)) { + /* HiDPI: the hints are in pixels of the X server */ + gint scale = gdk_window_get_scale_factor (socket->plug_window); + if (hints.flags & PMinSize) { - socket->request_width = MAX (hints.min_width, 1); - socket->request_height = MAX (hints.min_height, 1); + socket->request_width = MAX ((hints.min_width + scale - 1) / scale, 1); + socket->request_height = MAX ((hints.min_height + scale - 1) / scale, 1); } else if (hints.flags & PBaseSize) { - socket->request_width = MAX (hints.base_width, 1); - socket->request_height = MAX (hints.base_height, 1); + socket->request_width = MAX ((hints.base_width + scale - 1) / scale, 1); + socket->request_height = MAX ((hints.base_height + scale - 1) / scale, 1); } } socket->have_size = TRUE; @@ -211,6 +214,7 @@ void _gtk_socket_windowing_send_configure_event (GtkSocket *socket) { XConfigureEvent xconfigure; + gint scale; gint x, y; g_return_if_fail (socket->plug_window != NULL); @@ -225,14 +229,26 @@ _gtk_socket_windowing_send_configure_event (GtkSocket *socket) * coordinates. We still aren't really ICCCM compliant, since * we don't send events when the real toplevel is moved. */ + /* in pixels of the X server: the X server's own position (on + * monitors of different scales root coordinates of GDK are not simply + * scaled) */ + x = y = 0; gdk_error_trap_push (); - gdk_window_get_origin (socket->plug_window, &x, &y); + { + Window child; + + XTranslateCoordinates (GDK_WINDOW_XDISPLAY (socket->plug_window), + GDK_WINDOW_XWINDOW (socket->plug_window), + GDK_WINDOW_XWINDOW (gdk_screen_get_root_window (gdk_drawable_get_screen (socket->plug_window))), + 0, 0, &x, &y, &child); + } gdk_error_trap_pop (); + scale = gdk_window_get_scale_factor (socket->plug_window); xconfigure.x = x; xconfigure.y = y; - xconfigure.width = GTK_WIDGET(socket)->allocation.width; - xconfigure.height = GTK_WIDGET(socket)->allocation.height; + xconfigure.width = GTK_WIDGET(socket)->allocation.width * scale; + xconfigure.height = GTK_WIDGET(socket)->allocation.height * scale; xconfigure.border_width = 0; xconfigure.above = None; diff --git a/gtk/gtksocket.h b/gtk/gtksocket.h index c7bf32ddb..ff284e385 100644 --- a/gtk/gtksocket.h +++ b/gtk/gtksocket.h @@ -84,7 +84,7 @@ struct _GtkSocketClass }; -GType gtk_socket_get_type (void) G_GNUC_CONST; +GType gtk_socket_get_type (void); GtkWidget* gtk_socket_new (void); void gtk_socket_add_id (GtkSocket *socket_, diff --git a/gtk/gtkspinbutton.c b/gtk/gtkspinbutton.c index 83cc50f38..45816b4f7 100644 --- a/gtk/gtkspinbutton.c +++ b/gtk/gtkspinbutton.c @@ -496,6 +496,9 @@ gtk_spin_button_init (GtkSpinButton *spin_button) gtk_spin_button_set_adjustment (spin_button, (GtkAdjustment*) gtk_adjustment_new (0, 0, 0, 0, 0, 0)); + + /* for on-screen keyboards, as in GTK+ 3 */ + gtk_entry_set_input_purpose (GTK_ENTRY (spin_button), GTK_INPUT_PURPOSE_NUMBER); } static void @@ -1037,6 +1040,11 @@ gtk_spin_button_scroll (GtkWidget *widget, { GtkSpinButton *spin = GTK_SPIN_BUTTON (widget); + /* a pinch on a touchpad (Ctrl with the wheel) is for programs that + * zoom, not for scrolling here */ + if (gdk_event_get_touchpad_emulated ((GdkEvent *) event)) + return FALSE; + if (event->direction == GDK_SCROLL_UP) { if (!gtk_widget_has_focus (widget)) @@ -1614,18 +1622,70 @@ gtk_spin_button_default_input (GtkSpinButton *spin_button, gdouble *new_val) { gchar *err = NULL; + const gchar *text; - *new_val = g_strtod (gtk_entry_get_text (GTK_ENTRY (spin_button)), &err); + text = gtk_entry_get_text (GTK_ENTRY (spin_button)); + + *new_val = g_strtod (text, &err); if (*err) - return GTK_INPUT_ERROR; - else - return FALSE; + { + /* a whole number in the digits of another script, such as + * Arabic-Indic or Devanagari ones, typed with the keyboard of + * that language */ + gdouble val = 0; + gint sign = 1; + gboolean have_digit = FALSE; + const gchar *p; + + for (p = text; *p; p = g_utf8_next_char (p)) + { + gunichar ch = g_utf8_get_char (p); + + if (p == text && ch == '-') + { + sign = -1; + continue; + } + + if (!g_unichar_isdigit (ch)) + break; + + val = val * 10 + g_unichar_digit_value (ch); + have_digit = TRUE; + } + + if (*p || !have_digit) + return GTK_INPUT_ERROR; + + *new_val = sign * val; + } + + return FALSE; +} + +/* "%0.*f" gives "-0.0" for small negative values; drop the sign then */ +static gchar * +weed_out_neg_zero (gchar *str, + gint digits) +{ + if (str[0] == '-') + { + gchar *neg_zero = g_strdup_printf ("%0.*f", digits, -0.0); + + if (strcmp (neg_zero, str) == 0) + memmove (str, str + 1, strlen (str)); + g_free (neg_zero); + } + + return str; } static gint gtk_spin_button_default_output (GtkSpinButton *spin_button) { - gchar *buf = g_strdup_printf ("%0.*f", spin_button->digits, spin_button->adjustment->value); + gchar *buf = weed_out_neg_zero (g_strdup_printf ("%0.*f", spin_button->digits, + spin_button->adjustment->value), + spin_button->digits); if (strcmp (buf, gtk_entry_get_text (GTK_ENTRY (spin_button)))) gtk_entry_set_text (GTK_ENTRY (spin_button), buf); diff --git a/gtk/gtkspinbutton.h b/gtk/gtkspinbutton.h index 3fc70d7a2..680512b18 100644 --- a/gtk/gtkspinbutton.h +++ b/gtk/gtkspinbutton.h @@ -120,7 +120,7 @@ struct _GtkSpinButtonClass }; -GType gtk_spin_button_get_type (void) G_GNUC_CONST; +GType gtk_spin_button_get_type (void); void gtk_spin_button_configure (GtkSpinButton *spin_button, GtkAdjustment *adjustment, diff --git a/gtk/gtkspinner.c b/gtk/gtkspinner.c index 69de3ad04..a2077f651 100644 --- a/gtk/gtkspinner.c +++ b/gtk/gtkspinner.c @@ -73,8 +73,8 @@ enum { static void gtk_spinner_class_init (GtkSpinnerClass *klass); static void gtk_spinner_init (GtkSpinner *spinner); static void gtk_spinner_dispose (GObject *gobject); -static void gtk_spinner_realize (GtkWidget *widget); -static void gtk_spinner_unrealize (GtkWidget *widget); +static void gtk_spinner_map (GtkWidget *widget); +static void gtk_spinner_unmap (GtkWidget *widget); static gboolean gtk_spinner_expose (GtkWidget *widget, GdkEventExpose *event); static void gtk_spinner_screen_changed (GtkWidget *widget, @@ -107,8 +107,8 @@ gtk_spinner_class_init (GtkSpinnerClass *klass) widget_class = GTK_WIDGET_CLASS(klass); widget_class->expose_event = gtk_spinner_expose; - widget_class->realize = gtk_spinner_realize; - widget_class->unrealize = gtk_spinner_unrealize; + widget_class->map = gtk_spinner_map; + widget_class->unmap = gtk_spinner_unmap; widget_class->screen_changed = gtk_spinner_screen_changed; widget_class->style_set = gtk_spinner_style_set; widget_class->get_accessible = gtk_spinner_get_accessible; @@ -282,21 +282,24 @@ gtk_spinner_remove_timeout (GtkSpinner *spinner) priv->timeout = 0; } +/* The spinner turns only while it can be seen: one that is hidden, + * or on a page of a notebook that is not shown, does not wake the + * program up a dozen times a second. */ static void -gtk_spinner_realize (GtkWidget *widget) +gtk_spinner_map (GtkWidget *widget) { GtkSpinnerPrivate *priv; priv = GTK_SPINNER (widget)->priv; - GTK_WIDGET_CLASS (gtk_spinner_parent_class)->realize (widget); + GTK_WIDGET_CLASS (gtk_spinner_parent_class)->map (widget); - if (priv->active) + if (priv->active && priv->timeout == 0) gtk_spinner_add_timeout (GTK_SPINNER (widget)); } static void -gtk_spinner_unrealize (GtkWidget *widget) +gtk_spinner_unmap (GtkWidget *widget) { GtkSpinnerPrivate *priv; @@ -307,7 +310,7 @@ gtk_spinner_unrealize (GtkWidget *widget) gtk_spinner_remove_timeout (GTK_SPINNER (widget)); } - GTK_WIDGET_CLASS (gtk_spinner_parent_class)->unrealize (widget); + GTK_WIDGET_CLASS (gtk_spinner_parent_class)->unmap (widget); } static void @@ -373,7 +376,7 @@ gtk_spinner_set_active (GtkSpinner *spinner, gboolean active) priv->active = active; g_object_notify (G_OBJECT (spinner), "active"); - if (active && gtk_widget_get_realized (GTK_WIDGET (spinner)) && priv->timeout == 0) + if (active && gtk_widget_get_mapped (GTK_WIDGET (spinner)) && priv->timeout == 0) { gtk_spinner_add_timeout (spinner); } diff --git a/gtk/gtkspinner.h b/gtk/gtkspinner.h index c0715be51..944f75898 100644 --- a/gtk/gtkspinner.h +++ b/gtk/gtkspinner.h @@ -55,7 +55,7 @@ struct _GtkSpinnerClass GtkDrawingAreaClass parent_class; }; -GType gtk_spinner_get_type (void) G_GNUC_CONST; +GType gtk_spinner_get_type (void); GtkWidget *gtk_spinner_new (void); void gtk_spinner_start (GtkSpinner *spinner); void gtk_spinner_stop (GtkSpinner *spinner); diff --git a/gtk/gtkstatusbar.h b/gtk/gtkstatusbar.h index 6a0a2ebf6..ea45832eb 100644 --- a/gtk/gtkstatusbar.h +++ b/gtk/gtkstatusbar.h @@ -86,7 +86,7 @@ struct _GtkStatusbarClass }; -GType gtk_statusbar_get_type (void) G_GNUC_CONST; +GType gtk_statusbar_get_type (void); GtkWidget* gtk_statusbar_new (void); /* If you don't want to use contexts, 0 is a predefined global * context_id you can pass to push/pop/remove diff --git a/gtk/gtkstatusicon.h b/gtk/gtkstatusicon.h index c45caca5a..c581d8722 100644 --- a/gtk/gtkstatusicon.h +++ b/gtk/gtkstatusicon.h @@ -77,7 +77,7 @@ struct _GtkStatusIconClass void *__gtk_reserved2; }; -GType gtk_status_icon_get_type (void) G_GNUC_CONST; +GType gtk_status_icon_get_type (void); GtkStatusIcon *gtk_status_icon_new (void); GtkStatusIcon *gtk_status_icon_new_from_pixbuf (GdkPixbuf *pixbuf); diff --git a/gtk/gtkstock.h b/gtk/gtkstock.h index c67e97538..33af590ef 100644 --- a/gtk/gtkstock.h +++ b/gtk/gtkstock.h @@ -62,7 +62,7 @@ gboolean gtk_stock_lookup (const gchar *stock_id, */ GSList* gtk_stock_list_ids (void); -GType gtk_stock_item_get_type (void) G_GNUC_CONST; +GType gtk_stock_item_get_type (void); GtkStockItem *gtk_stock_item_copy (const GtkStockItem *item); void gtk_stock_item_free (GtkStockItem *item); diff --git a/gtk/gtkstyle.c b/gtk/gtkstyle.c index a5a20fd7c..a02aa6ad1 100644 --- a/gtk/gtkstyle.c +++ b/gtk/gtkstyle.c @@ -42,6 +42,7 @@ #include "gtkiconfactory.h" #include "gtksettings.h" /* _gtk_settings_parse_convert() */ #include "gtkintl.h" +#include "gtkprivate.h" #include "gtkalias.h" #define LIGHTNESS_MULT 1.3 @@ -1907,9 +1908,6 @@ _gtk_style_peek_property_value (GtkStyle *style, guint i; g_return_val_if_fail (GTK_IS_STYLE (style), NULL); - g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), NULL); - g_return_val_if_fail (g_type_is_a (pspec->owner_type, GTK_TYPE_WIDGET), NULL); - g_return_val_if_fail (g_type_is_a (widget_type, pspec->owner_type), NULL); key.widget_type = widget_type; key.pspec = pspec; @@ -1926,6 +1924,11 @@ _gtk_style_peek_property_value (GtkStyle *style, return &pcache->value; } + /* what is in the cache has been checked on the way in */ + g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), NULL); + g_return_val_if_fail (g_type_is_a (pspec->owner_type, GTK_TYPE_WIDGET), NULL); + g_return_val_if_fail (g_type_is_a (widget_type, pspec->owner_type), NULL); + i = 0; while (i < style->property_cache->len && style_property_values_cmp (&key, &g_array_index (style->property_cache, PropertyValue, i)) >= 0) @@ -2199,6 +2202,48 @@ gtk_style_render_icon (GtkStyle *style, g_return_val_if_fail (pixbuf != NULL, NULL); + /* HiDPI: a picture of a higher scale that the source pixbuf carries + * gets the same treatment (insensitive, prelight), where the icon + * keeps its size */ + if (!_gtk_loading_hires && + gtk_icon_source_get_pixbuf (source) && + gdk_pixbuf_get_width (pixbuf) == gdk_pixbuf_get_width (gtk_icon_source_get_pixbuf (source)) && + gdk_pixbuf_get_height (pixbuf) == gdk_pixbuf_get_height (gtk_icon_source_get_pixbuf (source))) + { + gint scale; + + for (scale = 2; scale <= 4; scale++) + { + gchar key[32]; + GdkPixbuf *hires, *rendered; + GtkIconSource *hires_source; + + g_snprintf (key, sizeof key, "gdk-pixbuf-hires-%d", scale); + hires = g_object_get_data (G_OBJECT (gtk_icon_source_get_pixbuf (source)), key); + if (!hires) + continue; + + if (pixbuf == gtk_icon_source_get_pixbuf (source)) + break; /* the same pixbuf, it has it already */ + + hires_source = gtk_icon_source_copy (source); + gtk_icon_source_set_pixbuf (hires_source, hires); + gtk_icon_source_set_size_wildcarded (hires_source, FALSE); + _gtk_loading_hires++; + rendered = GTK_STYLE_GET_CLASS (style)->render_icon (style, hires_source, direction, + state, (GtkIconSize) -1, + widget, detail); + _gtk_loading_hires--; + gtk_icon_source_free (hires_source); + if (rendered) + { + _gtk_pixbuf_attach_hires (pixbuf, rendered, scale); + g_object_unref (rendered); + } + break; + } + } + return pixbuf; } @@ -3157,7 +3202,7 @@ draw_arrow (GdkWindow *window, gint width, gint height) { - cairo_t *cr = gdk_cairo_create (window); + cairo_t *cr = gdk_cairo_create_in_area_libgtk_only (window, area); gdk_cairo_set_source_color (cr, color); if (area) @@ -3857,7 +3902,7 @@ gtk_default_draw_check (GtkStyle *style, gint width, gint height) { - cairo_t *cr = gdk_cairo_create (window); + cairo_t *cr = gdk_cairo_create_in_area_libgtk_only (window, area); enum { BUTTON, MENU, CELL } type = BUTTON; int exterior_size; int interior_size; @@ -3982,7 +4027,7 @@ gtk_default_draw_option (GtkStyle *style, gint width, gint height) { - cairo_t *cr = gdk_cairo_create (window); + cairo_t *cr = gdk_cairo_create_in_area_libgtk_only (window, area); enum { BUTTON, MENU, CELL } type = BUTTON; int exterior_size; @@ -4740,6 +4785,353 @@ gtk_default_draw_extension (GtkStyle *style, } } +/* A dashed frame of whole-pixel width whose dash ends fall on pixel + * edges covers each pixel either fully or not at all. Such a frame + * is drawn as four masked edges and up to four corners instead of + * as a stroke, which cairo splits into one box per dash and sorts: + * the pixels are the same, the work is a small fraction. Patterns + * that would put a dash end on a corner, and frames too small to + * have all four edges, still go through cairo_stroke. + */ + +typedef struct +{ + gchar *dashes; /* the pattern, as the style property */ + cairo_pattern_t *masks[4]; /* rows forward, backward; columns forward, backward */ +} FocusMasks; + +/* Is the frame on at a phase of P half pixels into the pattern? */ +static gboolean +focus_dash_on (const gint8 *dashes, + gint n_dashes, + gint p) +{ + gint i = 0; + gboolean on = TRUE; + + while (p >= 2 * dashes[i]) + { + p -= 2 * dashes[i]; + on = !on; + if (++i == n_dashes) + i = 0; + } + + return on; +} + +/* Does a dash begin or end at a phase of P half pixels? */ +static gboolean +focus_dash_edge (const gint8 *dashes, + gint n_dashes, + gint p) +{ + gint i = 0; + + while (p > 0) + { + p -= 2 * dashes[i]; + if (++i == n_dashes) + i = 0; + } + + return p == 0; +} + +static cairo_pattern_t * +focus_mask_new (cairo_surface_t *target, + const gint8 *dashes, + gint n_dashes, + gint period, + gboolean backward, + gboolean vertical) +{ + cairo_surface_t *surface; + cairo_pattern_t *pattern; + cairo_t *cr; + gint i; + + /* made like the target, so that it is not sent anew at each use */ + surface = cairo_surface_create_similar (target, CAIRO_CONTENT_ALPHA, + vertical ? 1 : period, + vertical ? period : 1); + cr = cairo_create (surface); + for (i = 0; i < period; i++) + { + gint j = backward ? (period - i) % period : i; + + if (focus_dash_on (dashes, n_dashes, 2 * j + 1)) + cairo_rectangle (cr, vertical ? 0 : i, vertical ? i : 0, 1, 1); + } + cairo_fill (cr); + cairo_destroy (cr); + + pattern = cairo_pattern_create_for_surface (surface); + cairo_surface_destroy (surface); + cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT); + cairo_pattern_set_filter (pattern, CAIRO_FILTER_NEAREST); + + return pattern; +} + +static void +focus_masks_free (gpointer data) +{ + FocusMasks *masks = data; + gint i, k; + + for (i = 0; i < 2; i++) + { + g_free (masks[i].dashes); + for (k = 0; k < 4; k++) + if (masks[i].masks[k]) + cairo_pattern_destroy (masks[i].masks[k]); + } + g_free (masks); +} + +/* The masks for DASHES, kept on HOLDER (the screen) for the two + * patterns used last. */ +static FocusMasks * +focus_masks_get (GObject *holder, + cairo_t *cr, + const gint8 *dashes, + gint n_dashes, + gint period) +{ + cairo_surface_t *target = cairo_get_target (cr), *surface; + FocusMasks *masks, tmp; + gint i, k; + + masks = g_object_get_data (holder, "gtk-focus-masks"); + if (!masks) + { + masks = g_new0 (FocusMasks, 2); + g_object_set_data_full (holder, I_("gtk-focus-masks"), masks, focus_masks_free); + } + + for (i = 0; i < 2; i++) + if (masks[i].dashes && strcmp (masks[i].dashes, (const gchar *) dashes) == 0) + { + cairo_pattern_get_surface (masks[i].masks[0], &surface); + if (cairo_surface_get_type (surface) == cairo_surface_get_type (target)) + break; + } + + if (i == 2) + { + /* replace the one used least recently */ + i = 1; + g_free (masks[i].dashes); + masks[i].dashes = g_strdup ((const gchar *) dashes); + for (k = 0; k < 4; k++) + { + if (masks[i].masks[k]) + cairo_pattern_destroy (masks[i].masks[k]); + masks[i].masks[k] = focus_mask_new (target, dashes, n_dashes, period, k & 1, k >> 1); + } + } + + if (i == 1) + { + tmp = masks[0]; + masks[0] = masks[1]; + masks[1] = tmp; + } + + return &masks[0]; +} + +/* Fills the part of [x0,x1)x[y0,y1) inside AREA (if any) through MASK, + * moved so that pattern pixel (tx + x) mod period, or (ty + y) for + * columns, lands on device pixel x. */ +static void +focus_mask_edge (cairo_t *cr, + GdkRectangle *area, + cairo_pattern_t *mask, + gint period, + gint x0, + gint y0, + gint x1, + gint y1, + gint shift, + gboolean vertical) +{ + cairo_matrix_t matrix; + + if (area) + { + x0 = MAX (x0, area->x); + y0 = MAX (y0, area->y); + x1 = MIN (x1, area->x + area->width); + y1 = MIN (y1, area->y + area->height); + } + if (x0 >= x1 || y0 >= y1) + return; + + shift %= period; + if (shift < 0) + shift += period; + if (vertical) + cairo_matrix_init_translate (&matrix, 0, shift); + else + cairo_matrix_init_translate (&matrix, shift, 0); + cairo_pattern_set_matrix (mask, &matrix); + + cairo_save (cr); + cairo_rectangle (cr, x0, y0, x1 - x0, y1 - y0); + cairo_clip (cr); + cairo_mask (cr, mask); + cairo_restore (cr); +} + +/* Adds the covered pixels of the L x L corner square at (X, Y) whose + * centre is the path vertex. IN/OUT are the directions of the edges + * meeting there, S_IN/S_OUT the phases (half pixels, dash offset + * included) of the vertex on them. */ +static gboolean +focus_corner (cairo_t *cr, + GdkRectangle *area, + const gint8 *dashes, + gint n_dashes, + gint period2, + gint lw, + gint X, + gint Y, + gint in_x, + gint in_y, + gint out_x, + gint out_y, + gint s_in, + gint s_out) +{ + gboolean join = focus_dash_on (dashes, n_dashes, s_in % period2) && + focus_dash_on (dashes, n_dashes, s_out % period2); + gboolean any = FALSE; + gint i, j; + + for (j = 0; j < lw; j++) + { + gint run = -1; + + for (i = 0; i <= lw; i++) + { + gboolean on = FALSE; + + if (i < lw) + { + /* pixel centre relative to the vertex, half pixels */ + gint rx = 2 * i + 1 - lw, ry = 2 * j + 1 - lw; + gint along_in = rx * in_x + ry * in_y; + gint along_out = rx * out_x + ry * out_y; + + if (along_in <= 0 && focus_dash_on (dashes, n_dashes, ((s_in + along_in) % period2 + period2) % period2)) + on = TRUE; + else if (along_out >= 0 && focus_dash_on (dashes, n_dashes, (s_out + along_out) % period2)) + on = TRUE; + else if (along_in > 0 && along_out < 0 && join) + on = TRUE; + + if (on && area && + (X + i < area->x || X + i >= area->x + area->width || + Y + j < area->y || Y + j >= area->y + area->height)) + on = FALSE; + } + + if (on && run < 0) + run = i; + else if (!on && run >= 0) + { + cairo_rectangle (cr, X + run, Y + j, i - run, 1); + any = TRUE; + run = -1; + } + } + } + + return any; +} + +static gboolean +focus_draw_aligned (GObject *holder, + cairo_t *cr, + GdkRectangle *area, + const gint8 *dashes, + gint lw, + gint x, + gint y, + gint width, + gint height) +{ + gint n_dashes = strlen ((const gchar *) dashes); + gint total = 0, period, period2, off, a, b, inset, i; + gint v[5]; + FocusMasks *masks; + + if (n_dashes == 0 || (lw != 1 && lw % 2 != 0) || + width < 2 * lw + 1 || height < 2 * lw + 1) + return FALSE; + for (i = 0; i < n_dashes; i++) + { + if (dashes[i] <= 0) + return FALSE; + total += dashes[i]; + } + period = n_dashes % 2 ? 2 * total : total; + period2 = 2 * period; + + /* the dash offset gtk_default_draw_focus gives cairo, in half pixels */ + off = -lw; + while (off < 0) + off += 2 * total; + off %= period2; + + a = width - lw; + b = height - lw; + v[0] = off; + v[1] = off + 2 * a; + v[2] = off + 2 * (a + b); + v[3] = off + 2 * (2 * a + b); + v[4] = off + 4 * (a + b); + for (i = 0; i < 5; i++) + if (focus_dash_edge (dashes, n_dashes, v[i] % period2)) + return FALSE; + /* where the path closes, the frame must be on on both sides or on neither */ + if (focus_dash_on (dashes, n_dashes, v[0] % period2) != + focus_dash_on (dashes, n_dashes, v[4] % period2)) + return FALSE; + + masks = focus_masks_get (holder, cr, dashes, n_dashes, period); + + /* The corners: top left, top right, bottom right, bottom left. With + * lines one pixel wide a corner is on where the path is, so the top + * and bottom edges take them in. */ + inset = lw == 1 ? 0 : lw; + if (inset && + (focus_corner (cr, area, dashes, n_dashes, period2, lw, x, y, 0, -1, 1, 0, v[4], v[0]) | + focus_corner (cr, area, dashes, n_dashes, period2, lw, x + width - lw, y, 1, 0, 0, 1, v[1], v[1]) | + focus_corner (cr, area, dashes, n_dashes, period2, lw, x + width - lw, y + height - lw, 0, 1, -1, 0, v[2], v[2]) | + focus_corner (cr, area, dashes, n_dashes, period2, lw, x, y + height - lw, -1, 0, 0, -1, v[3], v[3]))) + cairo_fill (cr); + + /* The edges. Pixel column c of the top edge has its centre at phase + * off + 2 (c - x) + 1 - lw, which is pattern pixel c + (off - lw) / 2 - x. */ + focus_mask_edge (cr, area, masks->masks[0], period, + x + inset, y, x + width - inset, y + lw, + (off - lw) / 2 - x, FALSE); + focus_mask_edge (cr, area, masks->masks[2], period, + x + width - lw, y + lw, x + width, y + height - lw, + (off + 2 * a - lw) / 2 - y, TRUE); + focus_mask_edge (cr, area, masks->masks[1], period, + x + inset, y + height - lw, x + width - inset, y + height, + -((off + 2 * (a + b) + 2 * (x + width) - lw - 2) / 2), FALSE); + focus_mask_edge (cr, area, masks->masks[3], period, + x, y + lw, x + lw, y + height - lw, + -((off + 2 * (2 * a + b) + 2 * (y + height) - lw - 2) / 2), TRUE); + + return TRUE; +} + static void gtk_default_draw_focus (GtkStyle *style, GdkWindow *window, @@ -4756,6 +5148,7 @@ gtk_default_draw_focus (GtkStyle *style, gboolean free_dash_list = FALSE; gint line_width = 1; gint8 *dash_list = (gint8 *) "\1\1"; + gint depth; if (widget) { @@ -4787,6 +5180,14 @@ gtk_default_draw_focus (GtkStyle *style, else gdk_cairo_set_source_color (cr, &style->fg[state_type]); + /* Deeper channels than 8 bits can come out a step apart + * between masks and strokes, so they are left to the stroke. */ + depth = gdk_drawable_get_depth (window); + if (depth >= 15 && (depth <= 24 || depth == 32) && + focus_draw_aligned (G_OBJECT (gdk_drawable_get_screen (window)), cr, area, + dash_list, line_width, x, y, width, height)) + goto done; + cairo_set_line_width (cr, line_width); if (dash_list[0]) @@ -4828,6 +5229,8 @@ gtk_default_draw_focus (GtkStyle *style, width - line_width, height - line_width); cairo_stroke (cr); + + done: cairo_destroy (cr); if (free_dash_list) @@ -5022,7 +5425,7 @@ gtk_default_draw_expander (GtkStyle *style, double x_double, y_double; gint degrees = 0; - cairo_t *cr = gdk_cairo_create (window); + cairo_t *cr = gdk_cairo_create_in_area_libgtk_only (window, area); if (area) { diff --git a/gtk/gtkstyle.h b/gtk/gtkstyle.h index 77d3ae1af..43d3b53a0 100644 --- a/gtk/gtkstyle.h +++ b/gtk/gtkstyle.h @@ -437,7 +437,7 @@ struct _GtkBorder gint bottom; }; -GType gtk_style_get_type (void) G_GNUC_CONST; +GType gtk_style_get_type (void); GtkStyle* gtk_style_new (void); GtkStyle* gtk_style_copy (GtkStyle *style); GtkStyle* gtk_style_attach (GtkStyle *style, @@ -878,7 +878,7 @@ void gtk_paint_spinner (GtkStyle *style, gint width, gint height); -GType gtk_border_get_type (void) G_GNUC_CONST; +GType gtk_border_get_type (void); GtkBorder *gtk_border_new (void) G_GNUC_MALLOC; GtkBorder *gtk_border_copy (const GtkBorder *border_); void gtk_border_free (GtkBorder *border_); diff --git a/gtk/gtktable.h b/gtk/gtktable.h index 0e2bb874f..5a098be5f 100644 --- a/gtk/gtktable.h +++ b/gtk/gtktable.h @@ -99,7 +99,7 @@ struct _GtkTableRowCol }; -GType gtk_table_get_type (void) G_GNUC_CONST; +GType gtk_table_get_type (void); GtkWidget* gtk_table_new (guint rows, guint columns, gboolean homogeneous); diff --git a/gtk/gtktearoffmenuitem.h b/gtk/gtktearoffmenuitem.h index 3900fd081..8dc03ecd6 100644 --- a/gtk/gtktearoffmenuitem.h +++ b/gtk/gtktearoffmenuitem.h @@ -67,7 +67,7 @@ struct _GtkTearoffMenuItemClass }; -GType gtk_tearoff_menu_item_get_type (void) G_GNUC_CONST; +GType gtk_tearoff_menu_item_get_type (void); GtkWidget* gtk_tearoff_menu_item_new (void); G_END_DECLS diff --git a/gtk/gtktestutils.c b/gtk/gtktestutils.c index 51154fb3e..b598f9308 100644 --- a/gtk/gtktestutils.c +++ b/gtk/gtktestutils.c @@ -229,24 +229,29 @@ GtkWidget* gtk_test_find_label (GtkWidget *widget, const gchar *label_pattern) { + GtkWidget *label = NULL; + if (GTK_IS_LABEL (widget)) { const gchar *text = gtk_label_get_text (GTK_LABEL (widget)); if (g_pattern_match_simple (label_pattern, text)) return widget; } + if (GTK_IS_CONTAINER (widget)) { - GList *node, *list = gtk_container_get_children (GTK_CONTAINER (widget)); + GList *node, *list; + + list = gtk_container_get_children (GTK_CONTAINER (widget)); for (node = list; node; node = node->next) { - GtkWidget *label = gtk_test_find_label (node->data, label_pattern); + label = gtk_test_find_label (node->data, label_pattern); if (label) - return label; + break; } g_list_free (list); } - return NULL; + return label; } static GList* diff --git a/gtk/gtktext.h b/gtk/gtktext.h index 42da9bc53..2a795ab8d 100644 --- a/gtk/gtktext.h +++ b/gtk/gtktext.h @@ -175,7 +175,7 @@ struct _GtkTextClass }; -GType gtk_text_get_type (void) G_GNUC_CONST; +GType gtk_text_get_type (void); GtkWidget* gtk_text_new (GtkAdjustment *hadj, GtkAdjustment *vadj); void gtk_text_set_editable (GtkText *text, diff --git a/gtk/gtktextbtree.c b/gtk/gtktextbtree.c index 2cd097800..f1918f95a 100644 --- a/gtk/gtktextbtree.c +++ b/gtk/gtktextbtree.c @@ -1475,30 +1475,28 @@ _gtk_text_btree_find_line_top (GtkTextBTree *tree, { gint y = 0; BTreeView *view; - GSList *nodes; - GSList *iter; + GtkTextBTreeNode *nodes[64]; /* the path from the root, on the stack */ + int tos = 0; GtkTextBTreeNode *node; view = gtk_text_btree_get_view (tree, view_id); g_return_val_if_fail (view != NULL, 0); - nodes = NULL; node = target_line->parent; - while (node != NULL) + while (node != NULL && tos < (int) G_N_ELEMENTS (nodes)) { - nodes = g_slist_prepend (nodes, node); + nodes[tos++] = node; node = node->parent; } - iter = nodes; - while (iter != NULL) + tos--; + while (tos >= 0) { - node = iter->data; + node = nodes[tos]; if (node->level == 0) { - g_slist_free (nodes); return find_line_top_in_line_list (tree, view, node->children.line, target_line, y); @@ -1508,8 +1506,8 @@ _gtk_text_btree_find_line_top (GtkTextBTree *tree, GtkTextBTreeNode *child; GtkTextBTreeNode *target_node; - g_assert (iter->next != NULL); /* not at level 0 */ - target_node = iter->next->data; + g_assert (tos > 0); /* not at level 0 */ + target_node = nodes[tos - 1]; child = node->children.node; @@ -1532,7 +1530,7 @@ _gtk_text_btree_find_line_top (GtkTextBTree *tree, ran out of nodes */ } - iter = g_slist_next (iter); + tos--; } g_assert_not_reached (); /* we return when we find the target line */ @@ -2439,8 +2437,7 @@ _gtk_text_btree_get_text (const GtkTextIter *start_orig, copy_segment (retval, include_hidden, include_nonchars, &iter, &end); - str = retval->str; - g_string_free (retval, FALSE); + str = g_string_free (retval, FALSE); return str; } @@ -2467,10 +2464,11 @@ _gtk_text_btree_char_is_invisible (const GtkTextIter *iter) { gboolean invisible = FALSE; /* if nobody says otherwise, it's visible */ - int deftagCnts[LOTSA_TAGS] = { 0, }; + int deftagCnts[LOTSA_TAGS]; int *tagCnts = deftagCnts; GtkTextTag *deftags[LOTSA_TAGS]; GtkTextTag **tags = deftags; + GSList *l; int numTags; GtkTextBTreeNode *node; GtkTextLine *siblingline; @@ -2481,8 +2479,17 @@ _gtk_text_btree_char_is_invisible (const GtkTextIter *iter) GtkTextBTree *tree; gint byte_index; - line = _gtk_text_iter_get_text_line (iter); tree = _gtk_text_iter_get_btree (iter); + + /* Only tags applied somewhere in the buffer have infos; when none + * of them sets the invisible property, everything is visible. */ + for (l = tree->tag_infos; l != NULL; l = l->next) + if (((GtkTextTagInfo *) l->data)->tag->invisible_set) + break; + if (l == NULL) + return FALSE; + + line = _gtk_text_iter_get_text_line (iter); byte_index = gtk_text_iter_get_line_index (iter); numTags = gtk_text_tag_table_get_size (tree->table); @@ -2493,6 +2500,8 @@ _gtk_text_btree_char_is_invisible (const GtkTextIter *iter) tagCnts = g_new0 (int, numTags); tags = g_new (GtkTextTag*, numTags); } + else + memset (tagCnts, 0, numTags * sizeof (int)); /* * Record tag toggles within the line of indexPtr but preceding @@ -3267,6 +3276,12 @@ find_toggle_outside_current_line (GtkTextLine *line, int toggles; GtkTextTagInfo *info = NULL; + /* a tag that is applied nowhere has no toggles to look for */ + info = gtk_text_btree_get_existing_tag_info (tree, tag); + + if (info == NULL) + return FALSE; + /* * No toggle in this line. Look for toggles for the tag in lines * that are predecessors of line but under the same @@ -3299,11 +3314,6 @@ find_toggle_outside_current_line (GtkTextLine *line, * siblings that precede that GtkTextBTreeNode. */ - info = gtk_text_btree_get_existing_tag_info (tree, tag); - - if (info == NULL) - return FALSE; - toggles = 0; node = line->parent; while (node->parent != NULL) @@ -3731,7 +3741,8 @@ _gtk_text_line_byte_count (GtkTextLine *line) gint _gtk_text_line_char_index (GtkTextLine *target_line) { - GSList *node_stack = NULL; + GtkTextBTreeNode *node_stack[64]; /* the path from the root */ + int tos = 0; GtkTextBTreeNode *iter; GtkTextLine *line; gint num_chars; @@ -3741,46 +3752,41 @@ _gtk_text_line_char_index (GtkTextLine *target_line) g_assert (iter != NULL); - while (iter != NULL) + while (iter != NULL && tos < (int) G_N_ELEMENTS (node_stack)) { - node_stack = g_slist_prepend (node_stack, iter); - + node_stack[tos++] = iter; iter = iter->parent; } + tos--; + /* Check that we have the root node on top of the stack. */ - g_assert (node_stack != NULL && - node_stack->data != NULL && - ((GtkTextBTreeNode*)node_stack->data)->parent == NULL); + g_assert (node_stack[tos]->parent == NULL); /* Add up chars in all nodes before the nodes in our stack. */ num_chars = 0; - iter = node_stack->data; - while (iter != NULL) + iter = NULL; + while (tos >= 0) { GtkTextBTreeNode *child_iter; - GtkTextBTreeNode *next_node; - next_node = node_stack->next ? - node_stack->next->data : NULL; - node_stack = g_slist_remove (node_stack, node_stack->data); + iter = node_stack[tos]; if (iter->level == 0) { /* stack should be empty when we're on the last node */ - g_assert (node_stack == NULL); + g_assert (tos == 0); break; /* Our children are now lines */ } - g_assert (next_node != NULL); - g_assert (iter != NULL); - g_assert (next_node->parent == iter); + tos--; + g_assert (node_stack[tos]->parent == iter); /* Add up chars before us in the tree */ child_iter = iter->children.node; - while (child_iter != next_node) + while (child_iter != node_stack[tos]) { g_assert (child_iter != NULL); @@ -3788,8 +3794,6 @@ _gtk_text_line_char_index (GtkTextLine *target_line) child_iter = child_iter->next; } - - iter = next_node; } g_assert (iter != NULL); diff --git a/gtk/gtktextbuffer.c b/gtk/gtktextbuffer.c index d73924cdd..4dfd012e0 100644 --- a/gtk/gtktextbuffer.c +++ b/gtk/gtktextbuffer.c @@ -3629,13 +3629,12 @@ update_selection_clipboards (GtkTextBuffer *buffer) /* Even if we already have the selection, we need to update our * timestamp. */ - if (!gtk_clipboard_set_with_owner (clipboard, - priv->copy_target_entries, - priv->n_copy_target_entries, - clipboard_get_selection_cb, - clipboard_clear_selection_cb, - G_OBJECT (buffer))) - clipboard_clear_selection_cb (clipboard, buffer); + gtk_clipboard_set_with_owner (clipboard, + priv->copy_target_entries, + priv->n_copy_target_entries, + clipboard_get_selection_cb, + clipboard_clear_selection_cb, + G_OBJECT (buffer)); } tmp_list = tmp_list->next; diff --git a/gtk/gtktextbuffer.h b/gtk/gtktextbuffer.h index 3d80c3ef7..d989f9fdd 100644 --- a/gtk/gtktextbuffer.h +++ b/gtk/gtktextbuffer.h @@ -154,7 +154,7 @@ struct _GtkTextBufferClass void (*_gtk_reserved5) (void); }; -GType gtk_text_buffer_get_type (void) G_GNUC_CONST; +GType gtk_text_buffer_get_type (void); diff --git a/gtk/gtktextbufferserialize.c b/gtk/gtktextbufferserialize.c index 96d77bfb2..9f9f25af0 100644 --- a/gtk/gtktextbufferserialize.c +++ b/gtk/gtktextbufferserialize.c @@ -575,6 +575,8 @@ serialize_text (GtkTextBuffer *buffer, } while (!gtk_text_iter_equal (&iter, &context->end)); + g_slist_free (tag_list); + /* Close any open tags */ for (tag_list = active_tags; tag_list; tag_list = tag_list->next) g_string_append (context->text_str, ""); @@ -844,7 +846,8 @@ check_id_or_name (GMarkupParseContext *context, { set_error (error, context, G_MARKUP_ERROR, G_MARKUP_ERROR_PARSE, - _("<%s> element has invalid ID \"%s\""), attribute_values[i]); + _("<%s> element has invalid ID \"%s\""), + element_name, attribute_values[i]); return FALSE; } } @@ -1746,7 +1749,9 @@ read_headers (const gchar *start, { section_len = read_int ((const guchar *) start + i + 26); - if (i + 30 + section_len > len) + /* a length below zero would go back, and one past the end + * would overflow the sum */ + if (section_len < 0 || section_len > len - i - 30) goto error; header = g_new0 (Header, 1); diff --git a/gtk/gtktextchild.h b/gtk/gtktextchild.h index 7a814cec3..91bc9ca7b 100644 --- a/gtk/gtktextchild.h +++ b/gtk/gtktextchild.h @@ -70,7 +70,7 @@ struct _GtkTextChildAnchorClass void (*_gtk_reserved4) (void); }; -GType gtk_text_child_anchor_get_type (void) G_GNUC_CONST; +GType gtk_text_child_anchor_get_type (void); GtkTextChildAnchor* gtk_text_child_anchor_new (void); diff --git a/gtk/gtktextdisplay.c b/gtk/gtktextdisplay.c index 0b55382a9..bfed148a5 100644 --- a/gtk/gtktextdisplay.c +++ b/gtk/gtktextdisplay.c @@ -804,6 +804,9 @@ gtk_text_layout_draw (GtkTextLayout *layout, if (line_list == NULL) return; /* nothing on the screen */ + /* keep the displays of all the lines drawn, for the next time */ + _gtk_text_layout_cache_lines (layout, g_slist_length (line_list)); + clip.x = x; clip.y = y; clip.width = width; diff --git a/gtk/gtktextiter.c b/gtk/gtktextiter.c index 6e462e3e0..5b175a5f4 100644 --- a/gtk/gtktextiter.c +++ b/gtk/gtktextiter.c @@ -3003,9 +3003,12 @@ inside_sentence_func (const PangoLogAttr *attrs, gint len) { /* Find next sentence start or end */ - while (offset >= min_offset && - !(attrs[offset].is_sentence_start || attrs[offset].is_sentence_end)) - --offset; + while (!(attrs[offset].is_sentence_start || attrs[offset].is_sentence_end)) + { + --offset; + if (offset < min_offset) + return FALSE; + } return attrs[offset].is_sentence_start; } @@ -4142,6 +4145,9 @@ gtk_text_iter_forward_to_tag_toggle (GtkTextIter *iter, check_invariants (iter); + if (gtk_text_iter_is_end (iter)) + return FALSE; + current_line = real->line; next_line = _gtk_text_line_next_could_contain_tag (current_line, real->tree, tag); @@ -4802,6 +4808,8 @@ lines_window_init (LinesWindow *win, } win->lines[i] = line_text; + win->first_line_start = line_start; + win->first_line_end = line_end; line_end = line_start; gtk_text_iter_backward_line (&line_start); @@ -5307,14 +5315,24 @@ _gtk_text_btree_get_iter_at_last_toggle (GtkTextBTree *tree, GtkTextIter *iter, GtkTextTag *tag) { + gboolean found; + g_return_val_if_fail (iter != NULL, FALSE); g_return_val_if_fail (tree != NULL, FALSE); _gtk_text_btree_get_end_iter (tree, iter); - gtk_text_iter_backward_to_tag_toggle (iter, tag); + + /* a tag reaching the end of the buffer toggles off at the end + * iter itself: moving backward from there would find the + * toggle on instead */ + if (gtk_text_iter_toggles_tag (iter, tag)) + found = TRUE; + else + found = gtk_text_iter_backward_to_tag_toggle (iter, tag); + check_invariants (iter); - return TRUE; + return found; } gboolean diff --git a/gtk/gtktextiter.h b/gtk/gtktextiter.h index 4b0d2e46e..a58c39246 100644 --- a/gtk/gtktextiter.h +++ b/gtk/gtktextiter.h @@ -87,7 +87,7 @@ GtkTextBuffer *gtk_text_iter_get_buffer (const GtkTextIter *iter); GtkTextIter *gtk_text_iter_copy (const GtkTextIter *iter); void gtk_text_iter_free (GtkTextIter *iter); -GType gtk_text_iter_get_type (void) G_GNUC_CONST; +GType gtk_text_iter_get_type (void); /* * Convert to different kinds of index diff --git a/gtk/gtktextlayout.c b/gtk/gtktextlayout.c index 905a4b73d..84dba5186 100644 --- a/gtk/gtktextlayout.c +++ b/gtk/gtktextlayout.c @@ -100,8 +100,25 @@ struct _GtkTextLayoutPrivate direction only influences the direction of the cursor line. */ GtkTextLine *cursor_line; + + /* The displays of the lines laid out last, most recently used first, + * so that drawing the same lines again does not lay them out again. + * layout->one_display_cache is the first of them. */ + GtkTextLineDisplay **displays; + guint n_displays; + guint max_displays; + + /* while validating in the background: displays made for that go to + * the end of the cache, so they do not push out the lines on screen */ + guint validating_in_background : 1; + /* while validating the lines on screen: those are drawn next, so they + * are laid out in full at once, not only for their size */ + guint validating_on_screen : 1; }; +#define MIN_CACHED_DISPLAYS 16 +#define MAX_CACHED_DISPLAYS 128 + static GtkTextLineData *gtk_text_layout_real_wrap (GtkTextLayout *layout, GtkTextLine *line, /* may be NULL */ @@ -251,6 +268,129 @@ free_style_cache (GtkTextLayout *text_layout) } } +static void free_line_display_now (GtkTextLineDisplay *display); + +static gint +display_cache_find (GtkTextLayoutPrivate *priv, + GtkTextLine *line) +{ + guint i; + + for (i = 0; i < priv->n_displays; i++) + if (priv->displays[i]->line == line) + return i; + + return -1; +} + +static gboolean +display_cache_contains (GtkTextLayoutPrivate *priv, + GtkTextLineDisplay *display) +{ + guint i; + + for (i = 0; i < priv->n_displays; i++) + if (priv->displays[i] == display) + return TRUE; + + return FALSE; +} + +static void +display_cache_sync (GtkTextLayout *layout) +{ + GtkTextLayoutPrivate *priv = GTK_TEXT_LAYOUT_GET_PRIVATE (layout); + + layout->one_display_cache = priv->n_displays ? priv->displays[0] : NULL; +} + +/* Takes the display at @i out of the cache, without freeing it */ +static GtkTextLineDisplay * +display_cache_take (GtkTextLayout *layout, + guint i) +{ + GtkTextLayoutPrivate *priv = GTK_TEXT_LAYOUT_GET_PRIVATE (layout); + GtkTextLineDisplay *display = priv->displays[i]; + + memmove (priv->displays + i, priv->displays + i + 1, + (priv->n_displays - i - 1) * sizeof (GtkTextLineDisplay *)); + priv->n_displays--; + display_cache_sync (layout); + + return display; +} + +static void +display_cache_remove (GtkTextLayout *layout, + guint i) +{ + free_line_display_now (display_cache_take (layout, i)); +} + +static void +display_cache_clear (GtkTextLayout *layout) +{ + GtkTextLayoutPrivate *priv = GTK_TEXT_LAYOUT_GET_PRIVATE (layout); + + while (priv->n_displays > 0) + display_cache_remove (layout, priv->n_displays - 1); +} + +/* Most recently used first, or last for displays that are only made + * while validating in the background */ +static void +display_cache_add (GtkTextLayout *layout, + GtkTextLineDisplay *display) +{ + GtkTextLayoutPrivate *priv = GTK_TEXT_LAYOUT_GET_PRIVATE (layout); + guint max = MAX (priv->max_displays, MIN_CACHED_DISPLAYS); + + if (priv->displays == NULL) + priv->displays = g_new (GtkTextLineDisplay *, MAX_CACHED_DISPLAYS); + + while (priv->n_displays >= max) + display_cache_remove (layout, priv->n_displays - 1); + + if (priv->validating_in_background) + priv->displays[priv->n_displays] = display; + else + { + memmove (priv->displays + 1, priv->displays, + priv->n_displays * sizeof (GtkTextLineDisplay *)); + priv->displays[0] = display; + } + priv->n_displays++; + display_cache_sync (layout); +} + +static void +display_cache_move_to_front (GtkTextLayout *layout, + guint i) +{ + GtkTextLayoutPrivate *priv = GTK_TEXT_LAYOUT_GET_PRIVATE (layout); + GtkTextLineDisplay *display; + + if (i == 0 || priv->validating_in_background) + return; + + display = priv->displays[i]; + memmove (priv->displays + 1, priv->displays, i * sizeof (GtkTextLineDisplay *)); + priv->displays[0] = display; + display_cache_sync (layout); +} + +/* Drawing @n_lines lines at once: keep at least that many displays */ +void +_gtk_text_layout_cache_lines (GtkTextLayout *layout, + gint n_lines) +{ + GtkTextLayoutPrivate *priv = GTK_TEXT_LAYOUT_GET_PRIVATE (layout); + guint want = CLAMP (n_lines + 8, MIN_CACHED_DISPLAYS, MAX_CACHED_DISPLAYS); + + if (want > priv->max_displays) + priv->max_displays = want; +} + static void gtk_text_layout_finalize (GObject *object) { @@ -275,12 +415,8 @@ gtk_text_layout_finalize (GObject *object) layout->rtl_context = NULL; } - if (layout->one_display_cache) - { - GtkTextLineDisplay *tmp_display = layout->one_display_cache; - layout->one_display_cache = NULL; - gtk_text_layout_free_line_display (layout, tmp_display); - } + display_cache_clear (layout); + g_free (GTK_TEXT_LAYOUT_GET_PRIVATE (layout)->displays); if (layout->preedit_string) { @@ -313,6 +449,7 @@ gtk_text_layout_set_buffer (GtkTextLayout *layout, return; free_style_cache (layout); + display_cache_clear (layout); if (layout->buffer) { @@ -490,6 +627,34 @@ gtk_text_layout_get_buffer (GtkTextLayout *layout) return layout->buffer; } +static void +tag_may_wrap (GtkTextTag *tag, + gpointer data) +{ + if (tag->wrap_mode_set && tag->values->wrap_mode != GTK_WRAP_NONE) + *(gboolean *) data = TRUE; +} + +/* Whether a line of the buffer may wrap, so that its layout depends on + * the screen width; always for a subclass with its own invalidation */ +static gboolean +gtk_text_layout_may_wrap (GtkTextLayout *layout) +{ + gboolean wraps = FALSE; + + if (GTK_TEXT_LAYOUT_GET_CLASS (layout)->invalidate != gtk_text_layout_real_invalidate || + GTK_TEXT_LAYOUT_GET_CLASS (layout)->wrap != gtk_text_layout_real_wrap || + layout->buffer == NULL || + layout->default_style == NULL || + layout->default_style->wrap_mode != GTK_WRAP_NONE) + return TRUE; + + gtk_text_tag_table_foreach (gtk_text_buffer_get_tag_table (layout->buffer), + tag_may_wrap, &wraps); + + return wraps; +} + void gtk_text_layout_set_screen_width (GtkTextLayout *layout, gint width) { @@ -502,6 +667,22 @@ gtk_text_layout_set_screen_width (GtkTextLayout *layout, gint width) layout->screen_width = width; + /* Where no line wraps, the lines keep their layout and their size + * at any width: only the room beside them changes, which the + * displays hold (with the place of lines aligned right or centered), + * so these are made again, as the lines are drawn. Without this, a + * resize of a window with a text view that does not wrap lays out + * every line of the buffer again. */ + if (!gtk_text_layout_may_wrap (layout)) + { + gint height; + + display_cache_clear (layout); + height = layout->height; + gtk_text_layout_emit_changed (layout, 0, height, height); + return; + } + DV (g_print ("invalidating all due to new screen width (%s)\n", G_STRLOC)); gtk_text_layout_invalidate_all (layout); } @@ -638,15 +819,18 @@ text_layout_changed (GtkTextLayout *layout, gint new_height, gboolean cursors_only) { - /* Check if the range intersects our cached line display, - * and invalidate the cached line if so. + GtkTextLayoutPrivate *priv = GTK_TEXT_LAYOUT_GET_PRIVATE (layout); + gint i; + + /* Check if the range intersects our cached line displays, + * and invalidate the cached lines if so. */ - if (layout->one_display_cache) + for (i = (gint) priv->n_displays - 1; i >= 0; i--) { - GtkTextLine *line = layout->one_display_cache->line; + GtkTextLine *line = priv->displays[i]->line; gint cache_y = _gtk_text_btree_find_line_top (_gtk_text_buffer_get_btree (layout->buffer), line, layout); - gint cache_height = layout->one_display_cache->height; + gint cache_height = priv->displays[i]->height; if (cache_y + cache_height > y && cache_y < y + old_height) gtk_text_layout_invalidate_cache (layout, line, cursors_only); @@ -821,9 +1005,16 @@ gtk_text_layout_invalidate_cache (GtkTextLayout *layout, GtkTextLine *line, gboolean cursors_only) { - if (layout->one_display_cache && line == layout->one_display_cache->line) + GtkTextLayoutPrivate *priv = GTK_TEXT_LAYOUT_GET_PRIVATE (layout); + gint i; + + if (priv->n_displays == 0) + return; + + i = display_cache_find (priv, line); + if (i >= 0) { - GtkTextLineDisplay *display = layout->one_display_cache; + GtkTextLineDisplay *display = priv->displays[i]; if (cursors_only) { @@ -834,10 +1025,7 @@ gtk_text_layout_invalidate_cache (GtkTextLayout *layout, display->has_block_cursor = FALSE; } else - { - layout->one_display_cache = NULL; - gtk_text_layout_free_line_display (layout, display); - } + display_cache_remove (layout, i); } } @@ -874,10 +1062,22 @@ gtk_text_layout_update_cursor_line(GtkTextLayout *layout) GtkTextLayoutPrivate *priv = GTK_TEXT_LAYOUT_GET_PRIVATE (layout); GtkTextIter iter; + GtkTextLine *old_line = priv->cursor_line; + gtk_text_buffer_get_iter_at_mark (layout->buffer, &iter, gtk_text_buffer_get_insert (layout->buffer)); priv->cursor_line = _gtk_text_iter_get_text_line (&iter); + + /* The cursor line is laid out in the direction of the keyboard + * when it has none of its own, and with the preedit string: the + * kept displays of the line the cursor leaves and of the one it + * comes to are out of date. (Only the pointers are compared.) */ + if (old_line != priv->cursor_line) + { + gtk_text_layout_invalidate_cache (layout, old_line, FALSE); + gtk_text_layout_invalidate_cache (layout, priv->cursor_line, FALSE); + } } static void @@ -906,6 +1106,10 @@ gtk_text_layout_real_invalidate (GtkTextLayout *layout, last_line = _gtk_text_iter_get_text_line (end); line = _gtk_text_iter_get_text_line (start); + /* all of the buffer: no need to look for each line in the cache */ + if (gtk_text_iter_is_start (start) && gtk_text_iter_is_end (end)) + display_cache_clear (layout); + while (TRUE) { GtkTextLineData *line_data = _gtk_text_line_get_data (line, layout); @@ -929,13 +1133,23 @@ gtk_text_layout_real_invalidate_cursors (GtkTextLayout *layout, const GtkTextIter *start, const GtkTextIter *end) { - /* Check if the range intersects our cached line display, - * and invalidate the cached line if so. + GtkTextLayoutPrivate *priv = GTK_TEXT_LAYOUT_GET_PRIVATE (layout); + gint i; + + if (gtk_text_iter_compare (start, end) > 0) + { + const GtkTextIter *tmp = start; + start = end; + end = tmp; + } + + /* Check if the range intersects our cached line displays, + * and invalidate the cursors of the cached lines if so. */ - if (layout->one_display_cache) + for (i = (gint) priv->n_displays - 1; i >= 0; i--) { GtkTextIter line_start, line_end; - GtkTextLine *line = layout->one_display_cache->line; + GtkTextLine *line = priv->displays[i]->line; _gtk_text_btree_get_iter_at_line (_gtk_text_buffer_get_btree (layout->buffer), &line_start, line, 0); @@ -943,13 +1157,6 @@ gtk_text_layout_real_invalidate_cursors (GtkTextLayout *layout, if (!gtk_text_iter_ends_line (&line_end)) gtk_text_iter_forward_to_line_end (&line_end); - if (gtk_text_iter_compare (start, end) > 0) - { - const GtkTextIter *tmp = start; - start = end; - end = tmp; - } - if (gtk_text_iter_compare (&line_start, end) <= 0 && gtk_text_iter_compare (start, &line_end) <= 0) { @@ -1024,8 +1231,13 @@ gtk_text_layout_validate_yrange (GtkTextLayout *layout, gint first_line_y = 0; /* Quiet GCC */ gint last_line_y = 0; /* Quiet GCC */ + GtkTextLayoutPrivate *priv; + g_return_if_fail (GTK_IS_TEXT_LAYOUT (layout)); + priv = GTK_TEXT_LAYOUT_GET_PRIVATE (layout); + priv->validating_on_screen = TRUE; + if (y0 > 0) y0 = 0; if (y1 < 0) @@ -1098,6 +1310,8 @@ gtk_text_layout_validate_yrange (GtkTextLayout *layout, line = _gtk_text_line_next_excluding_last (line); } + priv->validating_on_screen = FALSE; + /* If we found and validated any invalid lines, update size and * emit the changed signal */ @@ -1130,15 +1344,25 @@ void gtk_text_layout_validate (GtkTextLayout *layout, gint max_pixels) { + GtkTextLayoutPrivate *priv; gint y, old_height, new_height; + gboolean validated; g_return_if_fail (GTK_IS_TEXT_LAYOUT (layout)); - while (max_pixels > 0 && - _gtk_text_btree_validate (_gtk_text_buffer_get_btree (layout->buffer), - layout, max_pixels, - &y, &old_height, &new_height)) + priv = GTK_TEXT_LAYOUT_GET_PRIVATE (layout); + + while (max_pixels > 0) { + priv->validating_in_background = TRUE; + validated = _gtk_text_btree_validate (_gtk_text_buffer_get_btree (layout->buffer), + layout, max_pixels, + &y, &old_height, &new_height); + priv->validating_in_background = FALSE; + + if (!validated) + break; + max_pixels -= new_height; update_layout_size (layout); @@ -1163,7 +1387,9 @@ gtk_text_layout_real_wrap (GtkTextLayout *layout, _gtk_text_line_add_data (line, line_data); } - display = gtk_text_layout_get_line_display (layout, line, TRUE); + /* a line validated because it is on screen is drawn next */ + display = gtk_text_layout_get_line_display (layout, line, + !GTK_TEXT_LAYOUT_GET_PRIVATE (layout)->validating_on_screen); line_data->width = display->width; line_data->height = display->height; line_data->valid = TRUE; @@ -2147,6 +2373,7 @@ gtk_text_layout_get_line_display (GtkTextLayout *layout, GtkTextIter iter; GtkTextAttributes *style; gchar *text; + gint text_pixel_width; PangoAttrList *attrs; gint text_allocated, layout_byte_offset, buffer_byte_offset; PangoRectangle extents; @@ -2161,22 +2388,26 @@ gtk_text_layout_get_line_display (GtkTextLayout *layout, g_return_val_if_fail (line != NULL, NULL); - if (layout->one_display_cache) - { - if (line == layout->one_display_cache->line && - (size_only || !layout->one_display_cache->size_only)) - { - if (!size_only) - update_text_display_cursors (layout, line, layout->one_display_cache); - return layout->one_display_cache; - } - else - { - GtkTextLineDisplay *tmp_display = layout->one_display_cache; - layout->one_display_cache = NULL; - gtk_text_layout_free_line_display (layout, tmp_display); - } - } + { + GtkTextLayoutPrivate *priv = GTK_TEXT_LAYOUT_GET_PRIVATE (layout); + gint i = display_cache_find (priv, line); + + if (i >= 0) + { + display = priv->displays[i]; + + if (size_only || !display->size_only) + { + display_cache_move_to_front (layout, i); + if (!size_only) + update_text_display_cursors (layout, line, display); + return display; + } + + /* laid out only for its size: lay it out in full */ + display_cache_remove (layout, i); + } + } DV (g_print ("creating one line display cache (%s)\n", G_STRLOC)); @@ -2468,7 +2699,8 @@ gtk_text_layout_get_line_display (GtkTextLayout *layout, pango_layout_get_extents (display->layout, NULL, &extents); - display->width = PIXEL_BOUND (extents.width) + display->left_margin + display->right_margin; + text_pixel_width = PIXEL_BOUND (extents.width); + display->width = text_pixel_width + display->left_margin + display->right_margin; display->height += PANGO_PIXELS (extents.height); /* If we aren't wrapping, we need to do the alignment of each @@ -2476,7 +2708,7 @@ gtk_text_layout_get_line_display (GtkTextLayout *layout, */ if (pango_layout_get_width (display->layout) < 0) { - gint excess = display->total_width - display->width; + gint excess = display->total_width - text_pixel_width; switch (pango_layout_get_alignment (display->layout)) { @@ -2500,7 +2732,7 @@ gtk_text_layout_get_line_display (GtkTextLayout *layout, if (tags != NULL) g_ptr_array_free (tags, TRUE); - layout->one_display_cache = display; + display_cache_add (layout, display); if (saw_widget) allocate_child_widgets (layout, display); @@ -2512,7 +2744,14 @@ void gtk_text_layout_free_line_display (GtkTextLayout *layout, GtkTextLineDisplay *display) { - if (display != layout->one_display_cache) + /* the displays in the cache stay there */ + if (!display_cache_contains (GTK_TEXT_LAYOUT_GET_PRIVATE (layout), display)) + free_line_display_now (display); +} + +static void +free_line_display_now (GtkTextLineDisplay *display) +{ { if (display->layout) g_object_unref (display->layout); @@ -3639,7 +3878,8 @@ gtk_text_layout_move_iter_visually (GtkTextLayout *layout, gtk_text_iter_backward_char (iter); } - gtk_text_layout_free_line_display (layout, display); + if (display) + gtk_text_layout_free_line_display (layout, display); done: diff --git a/gtk/gtktextlayout.h b/gtk/gtktextlayout.h index 2ab3c7e76..aaff2368b 100644 --- a/gtk/gtktextlayout.h +++ b/gtk/gtktextlayout.h @@ -267,7 +267,7 @@ struct _GtkTextLineDisplay extern PangoAttrType gtk_text_attr_appearance_type; -GType gtk_text_layout_get_type (void) G_GNUC_CONST; +GType gtk_text_layout_get_type (void); GtkTextLayout* gtk_text_layout_new (void); void gtk_text_layout_set_buffer (GtkTextLayout *layout, @@ -322,6 +322,10 @@ GtkTextLineDisplay* gtk_text_layout_get_line_display (GtkTextLayout *layou void gtk_text_layout_free_line_display (GtkTextLayout *layout, GtkTextLineDisplay *display); +/* private: keep the displays of that many lines, drawn at once */ +void _gtk_text_layout_cache_lines (GtkTextLayout *layout, + gint n_lines); + void gtk_text_layout_get_line_at_y (GtkTextLayout *layout, GtkTextIter *target_iter, gint y, diff --git a/gtk/gtktextmark.h b/gtk/gtktextmark.h index 4eab44519..5d29405c7 100644 --- a/gtk/gtktextmark.h +++ b/gtk/gtktextmark.h @@ -86,7 +86,7 @@ struct _GtkTextMarkClass void (*_gtk_reserved4) (void); }; -GType gtk_text_mark_get_type (void) G_GNUC_CONST; +GType gtk_text_mark_get_type (void); void gtk_text_mark_set_visible (GtkTextMark *mark, gboolean setting); diff --git a/gtk/gtktexttag.c b/gtk/gtktexttag.c index a4705400d..75d3cf3bf 100644 --- a/gtk/gtktexttag.c +++ b/gtk/gtktexttag.c @@ -1760,6 +1760,7 @@ gtk_text_tag_get_property (GObject *object, case PROP_FOREGROUND: case PROP_PARAGRAPH_BACKGROUND: g_warning ("'foreground', 'background' and 'paragraph_background' properties are not readable, use 'foreground_gdk', 'background_gdk' and 'paragraph_background_gdk'"); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; diff --git a/gtk/gtktexttag.h b/gtk/gtktexttag.h index ea7c20f09..3714ad122 100644 --- a/gtk/gtktexttag.h +++ b/gtk/gtktexttag.h @@ -153,7 +153,7 @@ struct _GtkTextTagClass void (*_gtk_reserved4) (void); }; -GType gtk_text_tag_get_type (void) G_GNUC_CONST; +GType gtk_text_tag_get_type (void); GtkTextTag *gtk_text_tag_new (const gchar *name); gint gtk_text_tag_get_priority (GtkTextTag *tag); void gtk_text_tag_set_priority (GtkTextTag *tag, @@ -280,7 +280,7 @@ void gtk_text_attributes_copy_values (GtkTextAttributes *src, void gtk_text_attributes_unref (GtkTextAttributes *values); GtkTextAttributes *gtk_text_attributes_ref (GtkTextAttributes *values); -GType gtk_text_attributes_get_type (void) G_GNUC_CONST; +GType gtk_text_attributes_get_type (void); G_END_DECLS diff --git a/gtk/gtktexttagtable.h b/gtk/gtktexttagtable.h index aa7d985d9..c1292b033 100644 --- a/gtk/gtktexttagtable.h +++ b/gtk/gtktexttagtable.h @@ -72,7 +72,7 @@ struct _GtkTextTagTableClass void (*_gtk_reserved4) (void); }; -GType gtk_text_tag_table_get_type (void) G_GNUC_CONST; +GType gtk_text_tag_table_get_type (void); GtkTextTagTable *gtk_text_tag_table_new (void); void gtk_text_tag_table_add (GtkTextTagTable *table, diff --git a/gtk/gtktextview.c b/gtk/gtktextview.c index 1769094a4..0886d639d 100644 --- a/gtk/gtktextview.c +++ b/gtk/gtktextview.c @@ -49,6 +49,7 @@ #include "gtkpango.h" #include "gtktextutil.h" #include "gtkwindow.h" +#include "gtkemojichooser.h" #include "gtkalias.h" /* How scrolling, validation, exposes, etc. work. @@ -141,6 +142,7 @@ enum SELECT_ALL, TOGGLE_CURSOR_VISIBLE, PREEDIT_CHANGED, + INSERT_EMOJI, LAST_SIGNAL }; @@ -161,7 +163,9 @@ enum PROP_BUFFER, PROP_OVERWRITE, PROP_ACCEPTS_TAB, - PROP_IM_MODULE + PROP_IM_MODULE, + PROP_INPUT_PURPOSE, + PROP_INPUT_HINTS }; static void gtk_text_view_destroy (GtkObject *object); @@ -212,6 +216,8 @@ static gboolean gtk_text_view_focus (GtkWidget *widget, GtkDirectionType direction); static void gtk_text_view_move_focus (GtkWidget *widget, GtkDirectionType direction_type); +static void gtk_text_view_insert_emoji (GtkTextView *text_view); +static gboolean gtk_text_view_emoji_allowed (GtkTextView *text_view); static void gtk_text_view_select_all (GtkWidget *widget, gboolean select); @@ -687,6 +693,39 @@ gtk_text_view_class_init (GtkTextViewClass *klass) NULL, GTK_PARAM_READWRITE)); + /** + * GtkTextView:input-purpose: + * + * The purpose of this text field, as in GTK+ 3.6. + * + * Since: 2.24 + */ + g_object_class_install_property (gobject_class, + PROP_INPUT_PURPOSE, + g_param_spec_enum ("input-purpose", + P_("Purpose"), + P_("Purpose of the text field"), + GTK_TYPE_INPUT_PURPOSE, + GTK_INPUT_PURPOSE_FREE_FORM, + GTK_PARAM_READWRITE)); + + /** + * GtkTextView:input-hints: + * + * Additional hints (beyond #GtkTextView:input-purpose) that + * allow input methods to fine-tune their behaviour, as in GTK+ 3.6. + * + * Since: 2.24 + */ + g_object_class_install_property (gobject_class, + PROP_INPUT_HINTS, + g_param_spec_flags ("input-hints", + P_("hints"), + P_("Hints for the text field behaviour"), + GTK_TYPE_INPUT_HINTS, + GTK_INPUT_HINT_NONE, + GTK_PARAM_READWRITE)); + /* * Style properties */ @@ -1259,6 +1298,36 @@ gtk_text_view_class_init (GtkTextViewClass *klass) gtk_binding_entry_add_signal (binding_set, GDK_Insert, GDK_SHIFT_MASK, "paste-clipboard", 0); + gtk_binding_entry_add_signal (binding_set, GDK_KP_Delete, GDK_SHIFT_MASK, + "cut-clipboard", 0); + gtk_binding_entry_add_signal (binding_set, GDK_KP_Insert, GDK_CONTROL_MASK, + "copy-clipboard", 0); + gtk_binding_entry_add_signal (binding_set, GDK_KP_Insert, GDK_SHIFT_MASK, + "paste-clipboard", 0); + + /** + * GtkTextView::insert-emoji: + * @text_view: the object which received the signal + * + * A keybinding signal which opens the emoji chooser, as in GTK+ 3.22. + * The default bindings are Ctrl-. and Ctrl-; + * + * Since: 2.24 + */ + signals[INSERT_EMOJI] = + g_signal_new_class_handler (I_("insert-emoji"), + G_OBJECT_CLASS_TYPE (gobject_class), + G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, + G_CALLBACK (gtk_text_view_insert_emoji), + NULL, NULL, + _gtk_marshal_VOID__VOID, + G_TYPE_NONE, 0); + + gtk_binding_entry_add_signal (binding_set, GDK_period, GDK_CONTROL_MASK, + "insert-emoji", 0); + gtk_binding_entry_add_signal (binding_set, GDK_semicolon, GDK_CONTROL_MASK, + "insert-emoji", 0); + /* Overwrite */ gtk_binding_entry_add_signal (binding_set, GDK_Insert, 0, "toggle-overwrite", 0); @@ -2329,7 +2398,7 @@ gtk_text_view_set_wrap_mode (GtkTextView *text_view, { text_view->wrap_mode = wrap_mode; - if (text_view->layout) + if (text_view->layout && text_view->layout->default_style) { text_view->layout->default_style->wrap_mode = wrap_mode; gtk_text_layout_default_style_changed (text_view->layout); @@ -2389,8 +2458,12 @@ gtk_text_view_set_editable (GtkTextView *text_view, { gtk_text_layout_set_overwrite_mode (text_view->layout, text_view->overwrite_mode && text_view->editable); - text_view->layout->default_style->editable = text_view->editable; - gtk_text_layout_default_style_changed (text_view->layout); + /* default_style is still NULL while the layout is being set up */ + if (text_view->layout->default_style) + { + text_view->layout->default_style->editable = text_view->editable; + gtk_text_layout_default_style_changed (text_view->layout); + } } g_object_notify (G_OBJECT (text_view), "editable"); @@ -2432,7 +2505,7 @@ gtk_text_view_set_pixels_above_lines (GtkTextView *text_view, { text_view->pixels_above_lines = pixels_above_lines; - if (text_view->layout) + if (text_view->layout && text_view->layout->default_style) { text_view->layout->default_style->pixels_above_lines = pixels_above_lines; gtk_text_layout_default_style_changed (text_view->layout); @@ -2477,7 +2550,7 @@ gtk_text_view_set_pixels_below_lines (GtkTextView *text_view, { text_view->pixels_below_lines = pixels_below_lines; - if (text_view->layout) + if (text_view->layout && text_view->layout->default_style) { text_view->layout->default_style->pixels_below_lines = pixels_below_lines; gtk_text_layout_default_style_changed (text_view->layout); @@ -2522,7 +2595,7 @@ gtk_text_view_set_pixels_inside_wrap (GtkTextView *text_view, { text_view->pixels_inside_wrap = pixels_inside_wrap; - if (text_view->layout) + if (text_view->layout && text_view->layout->default_style) { text_view->layout->default_style->pixels_inside_wrap = pixels_inside_wrap; gtk_text_layout_default_style_changed (text_view->layout); @@ -2567,7 +2640,7 @@ gtk_text_view_set_justification (GtkTextView *text_view, { text_view->justify = justification; - if (text_view->layout) + if (text_view->layout && text_view->layout->default_style) { text_view->layout->default_style->justification = justification; gtk_text_layout_default_style_changed (text_view->layout); @@ -2612,7 +2685,7 @@ gtk_text_view_set_left_margin (GtkTextView *text_view, { text_view->left_margin = left_margin; - if (text_view->layout) + if (text_view->layout && text_view->layout->default_style) { text_view->layout->default_style->left_margin = left_margin; gtk_text_layout_default_style_changed (text_view->layout); @@ -2657,7 +2730,7 @@ gtk_text_view_set_right_margin (GtkTextView *text_view, { text_view->right_margin = right_margin; - if (text_view->layout) + if (text_view->layout && text_view->layout->default_style) { text_view->layout->default_style->right_margin = right_margin; gtk_text_layout_default_style_changed (text_view->layout); @@ -2702,7 +2775,7 @@ gtk_text_view_set_indent (GtkTextView *text_view, { text_view->indent = indent; - if (text_view->layout) + if (text_view->layout && text_view->layout->default_style) { text_view->layout->default_style->indent = indent; gtk_text_layout_default_style_changed (text_view->layout); @@ -2749,7 +2822,7 @@ gtk_text_view_set_tabs (GtkTextView *text_view, text_view->tabs = tabs ? pango_tab_array_copy (tabs) : NULL; - if (text_view->layout) + if (text_view->layout && text_view->layout->default_style) { /* some unkosher futzing in internal struct details... */ if (text_view->layout->default_style->tabs) @@ -3037,6 +3110,14 @@ gtk_text_view_set_property (GObject *object, gtk_im_multicontext_set_context_id (GTK_IM_MULTICONTEXT (text_view->im_context), priv->im_module); break; + case PROP_INPUT_PURPOSE: + gtk_text_view_set_input_purpose (text_view, g_value_get_enum (value)); + break; + + case PROP_INPUT_HINTS: + gtk_text_view_set_input_hints (text_view, g_value_get_flags (value)); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -3117,6 +3198,14 @@ gtk_text_view_get_property (GObject *object, g_value_set_string (value, priv->im_module); break; + case PROP_INPUT_PURPOSE: + g_value_set_enum (value, gtk_text_view_get_input_purpose (text_view)); + break; + + case PROP_INPUT_HINTS: + g_value_set_flags (value, gtk_text_view_get_input_hints (text_view)); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -4000,7 +4089,7 @@ gtk_text_view_direction_changed (GtkWidget *widget, { GtkTextView *text_view = GTK_TEXT_VIEW (widget); - if (text_view->layout) + if (text_view->layout && text_view->layout->default_style) { text_view->layout->default_style->direction = gtk_widget_get_direction (widget); @@ -4187,6 +4276,11 @@ gtk_text_view_event (GtkWidget *widget, GdkEvent *event) if (event->any.window != text_view->text_window->bin_window) return FALSE; + /* Only tags get these events: without any, a motion of the pointer + * needs no lookup of the character under it. */ + if (gtk_text_tag_table_get_size (gtk_text_buffer_get_tag_table (get_buffer (text_view))) == 0) + return FALSE; + if (get_event_coordinates (event, &x, &y)) { GtkTextIter iter; @@ -6222,17 +6316,20 @@ typedef struct SelectionGranularity granularity; GtkTextMark *orig_start; GtkTextMark *orig_end; + /* keeps the marks alive when the view drops its buffer + * (e.g. is destroyed) during the drag */ + GtkTextBuffer *buffer; } SelectionData; static void selection_data_free (SelectionData *data) { if (data->orig_start != NULL) - gtk_text_buffer_delete_mark (gtk_text_mark_get_buffer (data->orig_start), - data->orig_start); + gtk_text_buffer_delete_mark (data->buffer, data->orig_start); if (data->orig_end != NULL) - gtk_text_buffer_delete_mark (gtk_text_mark_get_buffer (data->orig_end), - data->orig_end); + gtk_text_buffer_delete_mark (data->buffer, data->orig_end); + if (data->buffer != NULL) + g_object_unref (data->buffer); g_free (data); } @@ -6359,6 +6456,7 @@ gtk_text_view_start_selection_drag (GtkTextView *text_view, &orig_start, TRUE); data->orig_end = gtk_text_buffer_create_mark (buffer, NULL, &orig_end, TRUE); + data->buffer = g_object_ref (buffer); gtk_text_view_check_cursor_blink (text_view); @@ -7979,11 +8077,22 @@ popup_targets_received (GtkClipboard *clipboard, gtk_menu_shell_append (GTK_MENU_SHELL (text_view->popup_menu), menuitem); menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_SELECT_ALL, NULL); + gtk_widget_set_sensitive (menuitem, + gtk_text_buffer_get_char_count (get_buffer (text_view)) > 0); g_signal_connect (menuitem, "activate", G_CALLBACK (select_all_cb), text_view); gtk_widget_show (menuitem); gtk_menu_shell_append (GTK_MENU_SHELL (text_view->popup_menu), menuitem); + if (gtk_text_view_emoji_allowed (text_view)) + { + menuitem = gtk_menu_item_new_with_mnemonic (_("Insert _Emoji")); + g_signal_connect_swapped (menuitem, "activate", + G_CALLBACK (gtk_text_view_insert_emoji), text_view); + gtk_widget_show (menuitem); + gtk_menu_shell_append (GTK_MENU_SHELL (text_view->popup_menu), menuitem); + } + g_object_get (gtk_widget_get_settings (GTK_WIDGET (text_view)), "gtk-show-input-method-menu", &show_input_method_menu, "gtk-show-unicode-menu", &show_unicode_menu, @@ -9344,5 +9453,148 @@ gtk_text_view_move_visually (GtkTextView *text_view, return gtk_text_layout_move_iter_visually (text_view->layout, iter, count); } +/* The emoji chooser, as in GTK+ 3.22 */ +static gboolean +gtk_text_view_emoji_allowed (GtkTextView *text_view) +{ + GtkInputPurpose purpose = gtk_text_view_get_input_purpose (text_view); + + return (text_view->editable && + !(gtk_text_view_get_input_hints (text_view) & GTK_INPUT_HINT_NO_EMOJI) && + purpose != GTK_INPUT_PURPOSE_DIGITS && + purpose != GTK_INPUT_PURPOSE_NUMBER && + purpose != GTK_INPUT_PURPOSE_PHONE && + purpose != GTK_INPUT_PURPOSE_PIN && + purpose != GTK_INPUT_PURPOSE_PASSWORD && + _gtk_emoji_chooser_available ()); +} + +static void +gtk_text_view_emoji_chosen (const gchar *text, + gpointer data) +{ + GtkTextView *text_view = data; + GtkTextBuffer *buffer = get_buffer (text_view); + + gtk_text_buffer_begin_user_action (buffer); + gtk_text_buffer_delete_selection (buffer, TRUE, text_view->editable); + gtk_text_buffer_insert_interactive_at_cursor (buffer, text, -1, text_view->editable); + gtk_text_buffer_end_user_action (buffer); + gtk_text_view_scroll_mark_onscreen (text_view, gtk_text_buffer_get_insert (buffer)); +} + +static void +gtk_text_view_insert_emoji (GtkTextView *text_view) +{ + GtkTextBuffer *buffer; + GtkTextIter iter; + GdkRectangle rect; + gint wx, wy, x, y; + + if (!gtk_text_view_emoji_allowed (text_view) || !gtk_widget_get_realized (GTK_WIDGET (text_view))) + return; + + buffer = get_buffer (text_view); + gtk_text_buffer_get_iter_at_mark (buffer, &iter, gtk_text_buffer_get_insert (buffer)); + gtk_text_view_get_iter_location (text_view, &iter, &rect); + gtk_text_view_buffer_to_window_coords (text_view, GTK_TEXT_WINDOW_WIDGET, + rect.x, rect.y, &x, &y); + /* the widget window is GtkWidget::window, which the chooser goes by */ + wx = x; + wy = y; + rect.x = wx; + rect.y = wy; + rect.width = 1; + + _gtk_emoji_chooser_popup (GTK_WIDGET (text_view), &rect, gtk_text_view_emoji_chosen, text_view); +} + +/** + * gtk_text_view_set_input_purpose: + * @text_view: a #GtkTextView + * @purpose: the purpose + * + * Sets the #GtkTextView:input-purpose property which + * can be used by on-screen keyboards and other input + * methods to adjust their behaviour. + * + * Since: 2.24 + */ +void +gtk_text_view_set_input_purpose (GtkTextView *text_view, + GtkInputPurpose purpose) +{ + g_return_if_fail (GTK_IS_TEXT_VIEW (text_view)); + + if (gtk_text_view_get_input_purpose (text_view) != purpose) + { + g_object_set (G_OBJECT (text_view->im_context), "input-purpose", purpose, NULL); + g_object_notify (G_OBJECT (text_view), "input-purpose"); + } +} + +/** + * gtk_text_view_get_input_purpose: + * @text_view: a #GtkTextView + * + * Gets the value of the #GtkTextView:input-purpose property. + * + * Since: 2.24 + */ +GtkInputPurpose +gtk_text_view_get_input_purpose (GtkTextView *text_view) +{ + GtkInputPurpose purpose; + + g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), GTK_INPUT_PURPOSE_FREE_FORM); + + g_object_get (G_OBJECT (text_view->im_context), "input-purpose", &purpose, NULL); + + return purpose; +} + +/** + * gtk_text_view_set_input_hints: + * @text_view: a #GtkTextView + * @hints: the hints + * + * Sets the #GtkTextView:input-hints property, which + * allows input methods to fine-tune their behaviour. + * + * Since: 2.24 + */ +void +gtk_text_view_set_input_hints (GtkTextView *text_view, + GtkInputHints hints) +{ + g_return_if_fail (GTK_IS_TEXT_VIEW (text_view)); + + if (gtk_text_view_get_input_hints (text_view) != hints) + { + g_object_set (G_OBJECT (text_view->im_context), "input-hints", hints, NULL); + g_object_notify (G_OBJECT (text_view), "input-hints"); + } +} + +/** + * gtk_text_view_get_input_hints: + * @text_view: a #GtkTextView + * + * Gets the value of the #GtkTextView:input-hints property. + * + * Since: 2.24 + */ +GtkInputHints +gtk_text_view_get_input_hints (GtkTextView *text_view) +{ + GtkInputHints hints; + + g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), GTK_INPUT_HINT_NONE); + + g_object_get (G_OBJECT (text_view->im_context), "input-hints", &hints, NULL); + + return hints; +} + #define __GTK_TEXT_VIEW_C__ #include "gtkaliasdef.c" diff --git a/gtk/gtktextview.h b/gtk/gtktextview.h index bdd47579f..ed0688287 100644 --- a/gtk/gtktextview.h +++ b/gtk/gtktextview.h @@ -214,7 +214,7 @@ struct _GtkTextViewClass void (*_gtk_reserved7) (void); }; -GType gtk_text_view_get_type (void) G_GNUC_CONST; +GType gtk_text_view_get_type (void); GtkWidget * gtk_text_view_new (void); GtkWidget * gtk_text_view_new_with_buffer (GtkTextBuffer *buffer); void gtk_text_view_set_buffer (GtkTextView *text_view, @@ -371,6 +371,14 @@ PangoTabArray* gtk_text_view_get_tabs (GtkTextView *text_vi /* note that the return value of this changes with the theme */ GtkTextAttributes* gtk_text_view_get_default_attributes (GtkTextView *text_view); +/* as in GTK+ 3.6 */ +void gtk_text_view_set_input_purpose (GtkTextView *text_view, + GtkInputPurpose purpose); +GtkInputPurpose gtk_text_view_get_input_purpose (GtkTextView *text_view); +void gtk_text_view_set_input_hints (GtkTextView *text_view, + GtkInputHints hints); +GtkInputHints gtk_text_view_get_input_hints (GtkTextView *text_view); + G_END_DECLS #endif /* __GTK_TEXT_VIEW_H__ */ diff --git a/gtk/gtkthemes.h b/gtk/gtkthemes.h index 49d3e511d..ec89f7353 100644 --- a/gtk/gtkthemes.h +++ b/gtk/gtkthemes.h @@ -39,7 +39,7 @@ G_BEGIN_DECLS #define GTK_THEME_ENGINE(theme_engine) (G_TYPE_CHECK_INSTANCE_CAST ((theme_engine), GTK_TYPE_THEME_ENGINE, GtkThemeEngine)) #define GTK_IS_THEME_ENGINE(theme_engine) (G_TYPE_CHECK_INSTANCE_TYPE ((theme_engine), GTK_TYPE_THEME_ENGINE)) -GType gtk_theme_engine_get_type (void) G_GNUC_CONST; +GType gtk_theme_engine_get_type (void); GtkThemeEngine *gtk_theme_engine_get (const gchar *name); GtkRcStyle *gtk_theme_engine_create_rc_style (GtkThemeEngine *engine); diff --git a/gtk/gtktimeprivate.h b/gtk/gtktimeprivate.h new file mode 100644 index 000000000..f1f7c3e12 --- /dev/null +++ b/gtk/gtktimeprivate.h @@ -0,0 +1,296 @@ +/* GTK - The GIMP Toolkit + * Copyright (C) 2026 the gtk2-ng authors + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +/* The time of now and the times of files as 64-bit seconds, also where + * time_t has 32 bits and the C library ends on 2038-01-19: + * + * - Linux: the kernel has had 64-bit calls for 32-bit programs since + * 4.11 (statx) and 5.1 (clock_gettime64, utimensat_time64); they are + * called directly where time_t is 32 bits, as Rust's standard + * library does, so a GTK+ built for an old 32-bit system still + * knows the time after 2038 when it runs on a newer kernel + * - Windows: GetFileAttributesEx and SetFileTime take the 64-bit + * FILETIME (since Windows 95/NT 4), where the stat of a 32-bit + * program has a 32-bit time + * - elsewhere, where time_t has 32 bits (Mac OS X on PowerPC and + * i386, FreeBSD on i386), a time past 2038 comes back negative; + * no clock and no file of a desktop goes back to 1901, so it is + * read as the unsigned number it was, which lasts until 2106 (the + * way NTP reads its 32-bit seconds) + * + * Where time_t has 64 bits, all of this is the plain GLib call. + * Header only, for libgtk, gtk-update-icon-cache and the modules. */ + +#ifndef __GTK_TIME_PRIVATE_H__ +#define __GTK_TIME_PRIVATE_H__ + +#include +#include +#include +#include +#include +#include + +#ifdef G_OS_WIN32 +#include +#else +#include +#include +#include +#endif + +#include + +#ifdef __linux__ +#include +#include +/* declared by unistd.h only with _DEFAULT_SOURCE or _GNU_SOURCE */ +extern long syscall (long number, ...); +#endif + +G_BEGIN_DECLS + +typedef struct +{ + guint mode; /* as st_mode */ + guint64 dev; /* as st_dev, 0 on Windows */ + guint64 ino; /* as st_ino, 0 on Windows */ + gint64 size; + gint64 mtime; /* seconds since 1970 */ +} GtkStatBuf; + +/* A time from a 32-bit time_t: see above */ +static inline gint64 +_gtk_time_from_time_t (gint64 t) +{ + if (sizeof (time_t) < 8 && t < 0) + t += G_GINT64_CONSTANT (1) << 32; + return t; +} + +/* g_get_real_time(), past 2038 also where time_t has 32 bits */ +static inline gint64 +_gtk_get_real_time (void) +{ + gint64 t; + +#if defined (__linux__) && defined (SYS_clock_gettime64) + if (sizeof (time_t) < 8) + { + struct { gint64 tv_sec; gint64 tv_nsec; } ts; /* struct __kernel_timespec */ + + if (syscall (SYS_clock_gettime64, CLOCK_REALTIME, &ts) == 0) + return ts.tv_sec * G_USEC_PER_SEC + ts.tv_nsec / 1000; + } +#endif + + t = g_get_real_time (); + if (sizeof (time_t) < 8 && t < 0) + t += (G_GINT64_CONSTANT (1) << 32) * G_USEC_PER_SEC; + return t; +} + +/* g_date_time_new_now_local(), past 2038 also where time_t has 32 bits */ +static inline GDateTime * +_gtk_date_time_new_now_local (void) +{ + return g_date_time_new_from_unix_local (_gtk_get_real_time () / G_USEC_PER_SEC); +} + +#ifdef G_OS_WIN32 +static inline gint64 +_gtk_time_from_filetime (const FILETIME *ft) +{ + guint64 t = ((guint64) ft->dwHighDateTime << 32) | ft->dwLowDateTime; + + /* 100 ns since 1601 */ + return (gint64) (t / 10000000) - G_GINT64_CONSTANT (11644473600); +} + +static inline void +_gtk_set_errno_from_win32 (DWORD error) +{ + switch (error) + { + case ERROR_FILE_NOT_FOUND: + case ERROR_PATH_NOT_FOUND: + case ERROR_INVALID_NAME: + case ERROR_INVALID_DRIVE: + errno = ENOENT; + break; + case ERROR_ACCESS_DENIED: + case ERROR_SHARING_VIOLATION: + errno = EACCES; + break; + default: + errno = EIO; + break; + } +} +#endif + +/* g_stat() or g_lstat() (@follow_links FALSE) for the fields in + * GtkStatBuf: 0 on success, -1 with errno set on failure */ +static inline int +_gtk_stat (const gchar *filename, + gboolean follow_links, + GtkStatBuf *buf) +{ +#ifdef G_OS_WIN32 + WIN32_FILE_ATTRIBUTE_DATA data; + wchar_t *wfilename; + BOOL ok; + + memset (buf, 0, sizeof *buf); + wfilename = g_utf8_to_utf16 (filename, -1, NULL, NULL, NULL); + if (wfilename == NULL) + { + errno = EINVAL; + return -1; + } + ok = GetFileAttributesExW (wfilename, GetFileExInfoStandard, &data); + g_free (wfilename); + if (!ok) + { + _gtk_set_errno_from_win32 (GetLastError ()); + return -1; + } + buf->mode = (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? S_IFDIR | 0755 : S_IFREG | 0644; + buf->dev = 0; + buf->ino = 0; + buf->size = ((gint64) data.nFileSizeHigh << 32) | data.nFileSizeLow; + buf->mtime = _gtk_time_from_filetime (&data.ftLastWriteTime); + return 0; +#else + GStatBuf st; + int res; + + memset (buf, 0, sizeof *buf); + +#if defined (__linux__) && defined (SYS_statx) + static gboolean no_statx = FALSE; + + if (sizeof (time_t) < 8 && !no_statx) + { + guint64 stx[32]; /* struct statx, 256 bytes */ + guint16 mode; + guint32 major, minor; + + memset (stx, 0, sizeof stx); + /* AT_FDCWD, AT_SYMLINK_NOFOLLOW, STATX_BASIC_STATS */ + if (syscall (SYS_statx, -100, filename, follow_links ? 0 : 0x100, 0x7ffU, stx) == 0) + { + guchar *p = (guchar *) stx; + + memcpy (&mode, p + 28, 2); + memcpy (&buf->ino, p + 32, 8); + memcpy (&buf->size, p + 40, 8); + memcpy (&buf->mtime, p + 112, 8); + memcpy (&major, p + 136, 4); + memcpy (&minor, p + 140, 4); + buf->mode = mode; + buf->dev = makedev (major, minor); + return 0; + } + /* a kernel before 4.11, or a sandbox that does not let statx through */ + if (errno != ENOSYS && errno != EPERM) + return -1; + no_statx = TRUE; + } +#endif + + res = follow_links ? g_stat (filename, &st) : g_lstat (filename, &st); + if (res != 0) + return res; + buf->mode = st.st_mode; + buf->dev = st.st_dev; + buf->ino = st.st_ino; + buf->size = st.st_size; + buf->mtime = _gtk_time_from_time_t (st.st_mtime); + return 0; +#endif +} + +/* Sets the modification time of @filename and leaves its access time: + * 0 on success, -1 with errno set on failure */ +static inline int +_gtk_set_mtime (const gchar *filename, + gint64 mtime) +{ +#ifdef G_OS_WIN32 + wchar_t *wfilename = g_utf8_to_utf16 (filename, -1, NULL, NULL, NULL); + HANDLE h; + FILETIME ft; + guint64 t; + BOOL ok; + + if (wfilename == NULL) + { + errno = EINVAL; + return -1; + } + /* FILE_FLAG_BACKUP_SEMANTICS: folders too */ + h = CreateFileW (wfilename, FILE_WRITE_ATTRIBUTES, + FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, + NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); + g_free (wfilename); + if (h == INVALID_HANDLE_VALUE) + { + _gtk_set_errno_from_win32 (GetLastError ()); + return -1; + } + t = (guint64) (mtime + G_GINT64_CONSTANT (11644473600)) * 10000000; + ft.dwLowDateTime = (DWORD) t; + ft.dwHighDateTime = (DWORD) (t >> 32); + ok = SetFileTime (h, NULL, NULL, &ft); + if (!ok) + _gtk_set_errno_from_win32 (GetLastError ()); + CloseHandle (h); + return ok ? 0 : -1; +#else + struct stat st; + struct utimbuf times; + +#if defined (__linux__) && defined (SYS_utimensat_time64) + if (sizeof (time_t) < 8) + { + /* struct __kernel_timespec; the access time is left alone */ + struct { gint64 tv_sec; gint64 tv_nsec; } ts[2] = { + { 0, (1L << 30) - 2L }, /* UTIME_OMIT */ + { mtime, 0 } + }; + + if (syscall (SYS_utimensat_time64, -100, filename, ts, 0) == 0) + return 0; + if (errno != ENOSYS && errno != EPERM) + return -1; + } +#endif + + if (stat (filename, &st) != 0) + return -1; + times.actime = st.st_atime; + times.modtime = (time_t) mtime; + return utime (filename, ×); +#endif +} + +G_END_DECLS + +#endif /* __GTK_TIME_PRIVATE_H__ */ diff --git a/gtk/gtktipsquery.h b/gtk/gtktipsquery.h index b792d8121..8e9d8739b 100644 --- a/gtk/gtktipsquery.h +++ b/gtk/gtktipsquery.h @@ -93,7 +93,7 @@ struct _GtkTipsQueryClass /* --- prototypes --- */ -GType gtk_tips_query_get_type (void) G_GNUC_CONST; +GType gtk_tips_query_get_type (void); GtkWidget* gtk_tips_query_new (void); void gtk_tips_query_start_query (GtkTipsQuery *tips_query); void gtk_tips_query_stop_query (GtkTipsQuery *tips_query); diff --git a/gtk/gtktoggleaction.h b/gtk/gtktoggleaction.h index 34210f588..db448039f 100644 --- a/gtk/gtktoggleaction.h +++ b/gtk/gtktoggleaction.h @@ -72,7 +72,7 @@ struct _GtkToggleActionClass void (*_gtk_reserved4) (void); }; -GType gtk_toggle_action_get_type (void) G_GNUC_CONST; +GType gtk_toggle_action_get_type (void); GtkToggleAction *gtk_toggle_action_new (const gchar *name, const gchar *label, const gchar *tooltip, diff --git a/gtk/gtktogglebutton.h b/gtk/gtktogglebutton.h index 931b013d0..e523b486a 100644 --- a/gtk/gtktogglebutton.h +++ b/gtk/gtktogglebutton.h @@ -71,7 +71,7 @@ struct _GtkToggleButtonClass }; -GType gtk_toggle_button_get_type (void) G_GNUC_CONST; +GType gtk_toggle_button_get_type (void); GtkWidget* gtk_toggle_button_new (void); GtkWidget* gtk_toggle_button_new_with_label (const gchar *label); diff --git a/gtk/gtktoggletoolbutton.h b/gtk/gtktoggletoolbutton.h index d90f6428f..5dbdeb856 100644 --- a/gtk/gtktoggletoolbutton.h +++ b/gtk/gtktoggletoolbutton.h @@ -64,7 +64,7 @@ struct _GtkToggleToolButtonClass void (* _gtk_reserved4) (void); }; -GType gtk_toggle_tool_button_get_type (void) G_GNUC_CONST; +GType gtk_toggle_tool_button_get_type (void); GtkToolItem *gtk_toggle_tool_button_new (void); GtkToolItem *gtk_toggle_tool_button_new_from_stock (const gchar *stock_id); diff --git a/gtk/gtktoolbar.h b/gtk/gtktoolbar.h index 931c20d98..37fd0285e 100644 --- a/gtk/gtktoolbar.h +++ b/gtk/gtktoolbar.h @@ -138,7 +138,7 @@ struct _GtkToolbarClass void (*_gtk_reserved3) (void); }; -GType gtk_toolbar_get_type (void) G_GNUC_CONST; +GType gtk_toolbar_get_type (void); GtkWidget * gtk_toolbar_new (void); void gtk_toolbar_insert (GtkToolbar *toolbar, diff --git a/gtk/gtktoolbutton.c b/gtk/gtktoolbutton.c index 004bd2401..01eed3797 100644 --- a/gtk/gtktoolbutton.c +++ b/gtk/gtktoolbutton.c @@ -374,7 +374,7 @@ gtk_tool_button_construct_contents (GtkToolItem *tool_item) need_label = TRUE; } - if (style == GTK_TOOLBAR_ICONS && button->priv->icon_widget == NULL && + if (style != GTK_TOOLBAR_TEXT && button->priv->icon_widget == NULL && button->priv->stock_id == NULL && button->priv->icon_name == NULL) { need_label = TRUE; diff --git a/gtk/gtktoolbutton.h b/gtk/gtktoolbutton.h index fdb8273db..de582e783 100644 --- a/gtk/gtktoolbutton.h +++ b/gtk/gtktoolbutton.h @@ -66,7 +66,7 @@ struct _GtkToolButtonClass void (* _gtk_reserved4) (void); }; -GType gtk_tool_button_get_type (void) G_GNUC_CONST; +GType gtk_tool_button_get_type (void); GtkToolItem *gtk_tool_button_new (GtkWidget *icon_widget, const gchar *label); GtkToolItem *gtk_tool_button_new_from_stock (const gchar *stock_id); diff --git a/gtk/gtktoolitem.h b/gtk/gtktoolitem.h index 0455ae58a..1febca0b7 100644 --- a/gtk/gtktoolitem.h +++ b/gtk/gtktoolitem.h @@ -76,7 +76,7 @@ struct _GtkToolItemClass void (* _gtk_reserved4) (void); }; -GType gtk_tool_item_get_type (void) G_GNUC_CONST; +GType gtk_tool_item_get_type (void); GtkToolItem *gtk_tool_item_new (void); void gtk_tool_item_set_homogeneous (GtkToolItem *tool_item, diff --git a/gtk/gtktoolitemgroup.c b/gtk/gtktoolitemgroup.c index 76300f4db..8ef2c6c69 100644 --- a/gtk/gtktoolitemgroup.c +++ b/gtk/gtktoolitemgroup.c @@ -501,6 +501,13 @@ gtk_tool_item_group_finalize (GObject *object) group->priv->children = NULL; } + /* Drop the reference taken in init; the header was unparented in dispose */ + if (group->priv->header) + { + g_object_unref (group->priv->header); + group->priv->header = NULL; + } + G_OBJECT_CLASS (gtk_tool_item_group_parent_class)->finalize (object); } @@ -520,6 +527,13 @@ gtk_tool_item_group_dispose (GObject *object) priv->toplevel = NULL; } + /* The header is an internal child, which GtkContainer::destroy does + * not destroy; without unparenting it here it would never be freed. + * It is kept (unparented) until finalize, so that priv->header stays + * valid. */ + if (priv->header && priv->header->parent == GTK_WIDGET (group)) + gtk_widget_unparent (priv->header); + G_OBJECT_CLASS (gtk_tool_item_group_parent_class)->dispose (object); } @@ -1263,7 +1277,7 @@ gtk_tool_item_group_forall (GtkContainer *container, GtkToolItemGroupPrivate* priv = group->priv; GList *children; - if (internals && priv->header) + if (internals && priv->header && priv->header->parent == GTK_WIDGET (group)) callback (priv->header, callback_data); children = priv->children; diff --git a/gtk/gtktoolitemgroup.h b/gtk/gtktoolitemgroup.h index 6b1c936ec..8bdd15127 100644 --- a/gtk/gtktoolitemgroup.h +++ b/gtk/gtktoolitemgroup.h @@ -58,7 +58,7 @@ struct _GtkToolItemGroupClass GtkContainerClass parent_class; }; -GType gtk_tool_item_group_get_type (void) G_GNUC_CONST; +GType gtk_tool_item_group_get_type (void); GtkWidget* gtk_tool_item_group_new (const gchar *label); void gtk_tool_item_group_set_label (GtkToolItemGroup *group, diff --git a/gtk/gtktoolpalette.c b/gtk/gtktoolpalette.c index 70df8f419..503e70e38 100644 --- a/gtk/gtktoolpalette.c +++ b/gtk/gtktoolpalette.c @@ -443,6 +443,8 @@ gtk_tool_palette_size_allocate (GtkWidget *widget, GtkToolItemGroupInfo *group = g_ptr_array_index (palette->priv->groups, i); gint size; + group_sizes[i] = 0; + if (!group->widget) continue; @@ -767,15 +769,21 @@ gtk_tool_palette_forall (GtkContainer *container, gpointer callback_data) { GtkToolPalette *palette = GTK_TOOL_PALETTE (container); - guint i; - + guint i, len; for (i = 0; i < palette->priv->groups->len; ++i) { GtkToolItemGroupInfo *info = g_ptr_array_index (palette->priv->groups, i); + + len = palette->priv->groups->len; + if (info->widget) callback (GTK_WIDGET (info->widget), callback_data); + + /* At destroy time, 'callback' results in removing a widget, + * here we just reset the current index to account for the removed widget. */ + i -= (len - palette->priv->groups->len); } } @@ -1276,8 +1284,9 @@ gint _gtk_tool_palette_compare_groups (gconstpointer a, gconstpointer b) { - const GtkToolItemGroupInfo *group_a = a; - const GtkToolItemGroupInfo *group_b = b; + /* g_ptr_array_sort() passes pointers to the elements */ + const GtkToolItemGroupInfo *group_a = *((GtkToolItemGroupInfo **) a); + const GtkToolItemGroupInfo *group_b = *((GtkToolItemGroupInfo **) b); return group_a->pos - group_b->pos; } @@ -1302,6 +1311,7 @@ gtk_tool_palette_set_group_position (GtkToolPalette *palette, GtkToolItemGroupInfo *group_new; GtkToolItemGroupInfo *group_old; gint old_position; + guint i; g_return_if_fail (GTK_IS_TOOL_PALETTE (palette)); g_return_if_fail (GTK_IS_TOOL_ITEM_GROUP (group)); @@ -1322,11 +1332,27 @@ gtk_tool_palette_set_group_position (GtkToolPalette *palette, group_old = g_ptr_array_index (palette->priv->groups, old_position); - group_new->pos = position; - group_old->pos = old_position; + /* Number the groups in their current order, leaving a gap between + * each two, and put @group into the gap before or after the group + * now at @position, so that sorting moves it there. */ + for (i = 0; i < palette->priv->groups->len; i++) + { + GtkToolItemGroupInfo *info = g_ptr_array_index (palette->priv->groups, i); + + info->pos = 2 * i + 1; + } + + group_old->pos = group_new->pos + (position > old_position ? 1 : -1); g_ptr_array_sort (palette->priv->groups, _gtk_tool_palette_compare_groups); + for (i = 0; i < palette->priv->groups->len; i++) + { + GtkToolItemGroupInfo *info = g_ptr_array_index (palette->priv->groups, i); + + info->pos = i; + } + gtk_widget_queue_resize (GTK_WIDGET (palette)); } diff --git a/gtk/gtktoolpalette.h b/gtk/gtktoolpalette.h index 90aa701e4..2a643d421 100644 --- a/gtk/gtktoolpalette.h +++ b/gtk/gtktoolpalette.h @@ -85,7 +85,7 @@ struct _GtkToolPaletteClass void (*_gtk_reserved6) (void); }; -GType gtk_tool_palette_get_type (void) G_GNUC_CONST; +GType gtk_tool_palette_get_type (void); GtkWidget* gtk_tool_palette_new (void); void gtk_tool_palette_set_group_position (GtkToolPalette *palette, diff --git a/gtk/gtktoolshell.h b/gtk/gtktoolshell.h index 6cf3db5ae..a4dc1699d 100644 --- a/gtk/gtktoolshell.h +++ b/gtk/gtktoolshell.h @@ -74,7 +74,7 @@ struct _GtkToolShellIface GtkSizeGroup * (*get_text_size_group) (GtkToolShell *shell); }; -GType gtk_tool_shell_get_type (void) G_GNUC_CONST; +GType gtk_tool_shell_get_type (void); GtkIconSize gtk_tool_shell_get_icon_size (GtkToolShell *shell); GtkOrientation gtk_tool_shell_get_orientation (GtkToolShell *shell); diff --git a/gtk/gtktooltip.c b/gtk/gtktooltip.c index 2b00ec3d9..98ac488ea 100644 --- a/gtk/gtktooltip.c +++ b/gtk/gtktooltip.c @@ -74,6 +74,9 @@ struct _GtkTooltip guint keyboard_mode_enabled : 1; guint tip_area_set : 1; guint custom_was_reset : 1; + /* whether the query-tooltip handlers gave text and an icon again */ + guint label_was_set : 1; + guint icon_was_set : 1; }; struct _GtkTooltipClass @@ -241,6 +244,8 @@ gtk_tooltip_dispose (GObject *object) gtk_tooltip_display_closed, tooltip); gtk_widget_destroy (tooltip->window); + /* drop the reference taken in gtk_tooltip_init() */ + g_object_unref (tooltip->window); tooltip->window = NULL; } @@ -268,6 +273,7 @@ gtk_tooltip_set_markup (GtkTooltip *tooltip, g_return_if_fail (GTK_IS_TOOLTIP (tooltip)); gtk_label_set_markup (GTK_LABEL (tooltip->label), markup); + tooltip->label_was_set = TRUE; if (markup) gtk_widget_show (tooltip->label); @@ -292,6 +298,7 @@ gtk_tooltip_set_text (GtkTooltip *tooltip, g_return_if_fail (GTK_IS_TOOLTIP (tooltip)); gtk_label_set_text (GTK_LABEL (tooltip->label), text); + tooltip->label_was_set = TRUE; if (text) gtk_widget_show (tooltip->label); @@ -319,6 +326,8 @@ gtk_tooltip_set_icon (GtkTooltip *tooltip, gtk_image_set_from_pixbuf (GTK_IMAGE (tooltip->image), pixbuf); + tooltip->icon_was_set = TRUE; + if (pixbuf) gtk_widget_show (tooltip->image); else @@ -346,6 +355,8 @@ gtk_tooltip_set_icon_from_stock (GtkTooltip *tooltip, gtk_image_set_from_stock (GTK_IMAGE (tooltip->image), stock_id, size); + tooltip->icon_was_set = TRUE; + if (stock_id) gtk_widget_show (tooltip->image); else @@ -373,6 +384,8 @@ gtk_tooltip_set_icon_from_icon_name (GtkTooltip *tooltip, gtk_image_set_from_icon_name (GTK_IMAGE (tooltip->image), icon_name, size); + tooltip->icon_was_set = TRUE; + if (icon_name) gtk_widget_show (tooltip->image); else @@ -400,6 +413,8 @@ gtk_tooltip_set_icon_from_gicon (GtkTooltip *tooltip, gtk_image_set_from_gicon (GTK_IMAGE (tooltip->image), gicon, size); + tooltip->icon_was_set = TRUE; + if (gicon) gtk_widget_show (tooltip->image); else @@ -531,8 +546,11 @@ gtk_tooltip_trigger_tooltip_query (GdkDisplay *display) static void gtk_tooltip_reset (GtkTooltip *tooltip) { - gtk_tooltip_set_markup (tooltip, NULL); - gtk_tooltip_set_icon (tooltip, NULL); + /* The text and icon stay until the query-tooltip handlers had their + * say: moving over a widget sets the same text again and again, and + * emptying the label first would lay it out twice per motion. */ + tooltip->label_was_set = FALSE; + tooltip->icon_was_set = FALSE; gtk_tooltip_set_tip_area (tooltip, NULL); /* See if the custom widget is again set from the query-tooltip @@ -1051,6 +1069,12 @@ gtk_tooltip_run_requery (GtkWidget **widget, if (!tooltip->custom_was_reset) gtk_tooltip_set_custom (tooltip, NULL); + /* the same for the text and the icon */ + if (!tooltip->label_was_set) + gtk_tooltip_set_markup (tooltip, NULL); + if (!tooltip->icon_was_set) + gtk_tooltip_set_icon (tooltip, NULL); + return return_value; } @@ -1067,6 +1091,8 @@ get_bounding_box (GtkWidget *widget, gint x4, y4; window = gtk_widget_get_parent_window (widget); + if (window == NULL) + window = gtk_widget_get_window (widget); x = widget->allocation.x; y = widget->allocation.y; @@ -1570,13 +1596,13 @@ _gtk_tooltip_handle_event (GdkEvent *event) case GDK_KEY_PRESS: case GDK_DRAG_ENTER: case GDK_GRAB_BROKEN: + case GDK_SCROLL: gtk_tooltip_hide_tooltip (current_tooltip); break; case GDK_MOTION_NOTIFY: case GDK_ENTER_NOTIFY: case GDK_LEAVE_NOTIFY: - case GDK_SCROLL: if (current_tooltip) { gboolean tip_area_set; diff --git a/gtk/gtktooltips.h b/gtk/gtktooltips.h index fbafd9939..1b038597d 100644 --- a/gtk/gtktooltips.h +++ b/gtk/gtktooltips.h @@ -92,7 +92,7 @@ struct _GtkTooltipsClass void (*_gtk_reserved4) (void); }; -GType gtk_tooltips_get_type (void) G_GNUC_CONST; +GType gtk_tooltips_get_type (void); GtkTooltips* gtk_tooltips_new (void); void gtk_tooltips_enable (GtkTooltips *tooltips); diff --git a/gtk/gtktrayicon.h b/gtk/gtktrayicon.h index ab4eda2f5..4dd03ea51 100644 --- a/gtk/gtktrayicon.h +++ b/gtk/gtktrayicon.h @@ -54,7 +54,7 @@ struct _GtkTrayIconClass void (*__gtk_reserved6) (void); }; -GType gtk_tray_icon_get_type (void) G_GNUC_CONST; +GType gtk_tray_icon_get_type (void); GtkTrayIcon *_gtk_tray_icon_new_for_screen (GdkScreen *screen, const gchar *name); diff --git a/gtk/gtktree.h b/gtk/gtktree.h index e2fc187a2..2e0ddb811 100644 --- a/gtk/gtktree.h +++ b/gtk/gtktree.h @@ -88,7 +88,7 @@ struct _GtkTreeClass }; -GType gtk_tree_get_type (void) G_GNUC_CONST; +GType gtk_tree_get_type (void); GtkWidget* gtk_tree_new (void); void gtk_tree_append (GtkTree *tree, GtkWidget *tree_item); diff --git a/gtk/gtktreedatalist.c b/gtk/gtktreedatalist.c index f94a87de7..640280a5e 100644 --- a/gtk/gtktreedatalist.c +++ b/gtk/gtktreedatalist.c @@ -449,6 +449,213 @@ _gtk_tree_data_list_compare_func (GtkTreeModel *model, } +/* Sorting a whole list with _gtk_tree_data_list_compare_func() reads + * two values per comparison, copying strings, and collates both + * strings anew each time. _gtk_tree_data_list_sort_rows() reads every + * value once, turns strings into collation keys once, which compare + * with strcmp() as the strings do with g_utf8_collate(), and sorts + * those. */ +typedef enum +{ + SORT_SIGNED, + SORT_UNSIGNED, + SORT_DOUBLE, + SORT_STRING +} SortKind; + +typedef struct +{ + gint pos; + union { + gint64 v_int; + guint64 v_uint; + gdouble v_double; + gchar *v_key; + } v; +} SortRow; + +typedef struct +{ + SortKind kind; + gboolean descending; +} SortRowsData; + +static gint +sort_rows_compare (gconstpointer pa, + gconstpointer pb, + gpointer user_data) +{ + const SortRowsData *data = user_data; + const SortRow *a = pa; + const SortRow *b = pb; + gint retval; + + switch (data->kind) + { + case SORT_SIGNED: + retval = a->v.v_int < b->v.v_int ? -1 : a->v.v_int > b->v.v_int; + break; + case SORT_UNSIGNED: + retval = a->v.v_uint < b->v.v_uint ? -1 : a->v.v_uint > b->v.v_uint; + break; + case SORT_DOUBLE: + retval = a->v.v_double < b->v.v_double ? -1 : a->v.v_double > b->v.v_double; + break; + default: + retval = strcmp (a->v.v_key, b->v.v_key); + break; + } + + if (data->descending) + retval = -retval; + + /* rows that compare equal keep their order, as with the stable + * sorts the comparison function is used with */ + if (retval == 0) + retval = a->pos < b->pos ? -1 : a->pos > b->pos; + + return retval; +} + +/** + * _gtk_tree_data_list_sort_rows: + * @model: the model + * @column: the column to sort by + * @order: the sort order + * @iters: the @n_rows rows to sort + * @n_rows: the number of rows + * @new_order: (out): for every place in the sorted order, the index + * in @iters of the row that goes there + * + * Sorts rows of @model the way _gtk_tree_data_list_compare_func() on + * @column does with a stable sort. + * + * Returns: %FALSE, with nothing sorted, if the type of @column is one + * the comparison does not handle or a float column holds NaN, for + * which the caller sorts with the comparison function + **/ +gboolean +_gtk_tree_data_list_sort_rows (GtkTreeModel *model, + gint column, + GtkSortType order, + GtkTreeIter *iters, + gint n_rows, + gint *new_order) +{ + GType type = gtk_tree_model_get_column_type (model, column); + SortRowsData data; + SortRow *rows; + gint i; + + switch (get_fundamental_type (type)) + { + case G_TYPE_BOOLEAN: + case G_TYPE_CHAR: + case G_TYPE_INT: + case G_TYPE_LONG: + case G_TYPE_INT64: + case G_TYPE_ENUM: + data.kind = SORT_SIGNED; + break; + case G_TYPE_UCHAR: + case G_TYPE_UINT: + case G_TYPE_ULONG: + case G_TYPE_UINT64: + case G_TYPE_FLAGS: + data.kind = SORT_UNSIGNED; + break; + case G_TYPE_FLOAT: + case G_TYPE_DOUBLE: + data.kind = SORT_DOUBLE; + break; + case G_TYPE_STRING: + data.kind = SORT_STRING; + break; + default: + return FALSE; + } + data.descending = order == GTK_SORT_DESCENDING; + + rows = g_new (SortRow, n_rows); + for (i = 0; i < n_rows; i++) + { + GValue value = { 0, }; + const gchar *str; + + gtk_tree_model_get_value (model, &iters[i], column, &value); + rows[i].pos = i; + + switch (get_fundamental_type (type)) + { + case G_TYPE_BOOLEAN: + rows[i].v.v_int = g_value_get_boolean (&value); + break; + case G_TYPE_CHAR: + rows[i].v.v_int = g_value_get_schar (&value); + break; + case G_TYPE_INT: + rows[i].v.v_int = g_value_get_int (&value); + break; + case G_TYPE_LONG: + rows[i].v.v_int = g_value_get_long (&value); + break; + case G_TYPE_INT64: + rows[i].v.v_int = g_value_get_int64 (&value); + break; + case G_TYPE_ENUM: + rows[i].v.v_int = g_value_get_enum (&value); + break; + case G_TYPE_UCHAR: + rows[i].v.v_uint = g_value_get_uchar (&value); + break; + case G_TYPE_UINT: + rows[i].v.v_uint = g_value_get_uint (&value); + break; + case G_TYPE_ULONG: + rows[i].v.v_uint = g_value_get_ulong (&value); + break; + case G_TYPE_UINT64: + rows[i].v.v_uint = g_value_get_uint64 (&value); + break; + case G_TYPE_FLAGS: + rows[i].v.v_uint = g_value_get_flags (&value); + break; + case G_TYPE_FLOAT: + rows[i].v.v_double = g_value_get_float (&value); + break; + case G_TYPE_DOUBLE: + rows[i].v.v_double = g_value_get_double (&value); + break; + default: + str = g_value_get_string (&value); + rows[i].v.v_key = g_utf8_collate_key (str ? str : "", -1); + break; + } + + g_value_unset (&value); + + /* NaN compares neither less nor equal: leave such a column to + * the comparison function, so it sorts exactly as before */ + if (data.kind == SORT_DOUBLE && rows[i].v.v_double != rows[i].v.v_double) + { + g_free (rows); + return FALSE; + } + } + + g_qsort_with_data (rows, n_rows, sizeof (SortRow), sort_rows_compare, &data); + + for (i = 0; i < n_rows; i++) + { + new_order[i] = rows[i].pos; + if (data.kind == SORT_STRING) + g_free (rows[i].v.v_key); + } + g_free (rows); + + return TRUE; +} + GList * _gtk_tree_data_list_header_new (gint n_columns, GType *types) diff --git a/gtk/gtktreedatalist.h b/gtk/gtktreedatalist.h index cfd81b57d..fdaaec44d 100644 --- a/gtk/gtktreedatalist.h +++ b/gtk/gtktreedatalist.h @@ -68,6 +68,12 @@ gint _gtk_tree_data_list_compare_func (GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b, gpointer user_data); +gboolean _gtk_tree_data_list_sort_rows (GtkTreeModel *model, + gint column, + GtkSortType order, + GtkTreeIter *iters, + gint n_rows, + gint *new_order); GList * _gtk_tree_data_list_header_new (gint n_columns, GType *types); void _gtk_tree_data_list_header_free (GList *header_list); diff --git a/gtk/gtktreednd.h b/gtk/gtktreednd.h index aa0684f0b..94fcfd254 100644 --- a/gtk/gtktreednd.h +++ b/gtk/gtktreednd.h @@ -54,7 +54,7 @@ struct _GtkTreeDragSourceIface GtkTreePath *path); }; -GType gtk_tree_drag_source_get_type (void) G_GNUC_CONST; +GType gtk_tree_drag_source_get_type (void); /* Returns whether the given row can be dragged */ gboolean gtk_tree_drag_source_row_draggable (GtkTreeDragSource *drag_source, @@ -94,7 +94,7 @@ struct _GtkTreeDragDestIface GtkSelectionData *selection_data); }; -GType gtk_tree_drag_dest_get_type (void) G_GNUC_CONST; +GType gtk_tree_drag_dest_get_type (void); /* Inserts a row before dest which contains data in selection_data, * or returns FALSE if it can't diff --git a/gtk/gtktreeitem.h b/gtk/gtktreeitem.h index 0e8dbaf1d..c60236136 100644 --- a/gtk/gtktreeitem.h +++ b/gtk/gtktreeitem.h @@ -71,7 +71,7 @@ struct _GtkTreeItemClass }; -GType gtk_tree_item_get_type (void) G_GNUC_CONST; +GType gtk_tree_item_get_type (void); GtkWidget* gtk_tree_item_new (void); GtkWidget* gtk_tree_item_new_with_label (const gchar *label); void gtk_tree_item_set_subtree (GtkTreeItem *tree_item, diff --git a/gtk/gtktreemodel.h b/gtk/gtktreemodel.h index 1faff6468..ba318a9ff 100644 --- a/gtk/gtktreemodel.h +++ b/gtk/gtktreemodel.h @@ -138,7 +138,7 @@ gint *gtk_tree_path_get_indices_with_depth (GtkTreePath *path, gint *depth); void gtk_tree_path_free (GtkTreePath *path); GtkTreePath *gtk_tree_path_copy (const GtkTreePath *path); -GType gtk_tree_path_get_type (void) G_GNUC_CONST; +GType gtk_tree_path_get_type (void); gint gtk_tree_path_compare (const GtkTreePath *a, const GtkTreePath *b); void gtk_tree_path_next (GtkTreePath *path); @@ -160,7 +160,7 @@ gboolean gtk_tree_path_is_descendant (GtkTreePath *path, * want to call gtk_tree_row_reference_new. */ -GType gtk_tree_row_reference_get_type (void) G_GNUC_CONST; +GType gtk_tree_row_reference_get_type (void); GtkTreeRowReference *gtk_tree_row_reference_new (GtkTreeModel *model, GtkTreePath *path); GtkTreeRowReference *gtk_tree_row_reference_new_proxy (GObject *proxy, @@ -185,9 +185,9 @@ void gtk_tree_row_reference_reordered (GObject *proxy, /* GtkTreeIter operations */ GtkTreeIter * gtk_tree_iter_copy (GtkTreeIter *iter); void gtk_tree_iter_free (GtkTreeIter *iter); -GType gtk_tree_iter_get_type (void) G_GNUC_CONST; +GType gtk_tree_iter_get_type (void); -GType gtk_tree_model_get_type (void) G_GNUC_CONST; +GType gtk_tree_model_get_type (void); GtkTreeModelFlags gtk_tree_model_get_flags (GtkTreeModel *tree_model); gint gtk_tree_model_get_n_columns (GtkTreeModel *tree_model); GType gtk_tree_model_get_column_type (GtkTreeModel *tree_model, diff --git a/gtk/gtktreemodelfilter.c b/gtk/gtktreemodelfilter.c index 2da833600..09045569c 100644 --- a/gtk/gtktreemodelfilter.c +++ b/gtk/gtktreemodelfilter.c @@ -2142,17 +2142,20 @@ gtk_tree_model_filter_rows_reordered (GtkTreeModel *c_model, } /* emit rows_reordered */ - if (!gtk_tree_path_get_indices (path)) - gtk_tree_model_rows_reordered (GTK_TREE_MODEL (data), path, NULL, - tmp_array); - else + if (level->visible_nodes > 0) { - /* get a path taking only visible nodes into account */ - gtk_tree_path_free (path); - path = gtk_tree_model_get_path (GTK_TREE_MODEL (data), &iter); + if (!gtk_tree_path_get_indices (path)) + gtk_tree_model_rows_reordered (GTK_TREE_MODEL (data), path, NULL, + tmp_array); + else + { + /* get a path taking only visible nodes into account */ + gtk_tree_path_free (path); + path = gtk_tree_model_get_path (GTK_TREE_MODEL (data), &iter); - gtk_tree_model_rows_reordered (GTK_TREE_MODEL (data), path, &iter, - tmp_array); + gtk_tree_model_rows_reordered (GTK_TREE_MODEL (data), path, &iter, + tmp_array); + } } /* done */ diff --git a/gtk/gtktreemodelfilter.h b/gtk/gtktreemodelfilter.h index d8887584f..f511b1d67 100644 --- a/gtk/gtktreemodelfilter.h +++ b/gtk/gtktreemodelfilter.h @@ -70,7 +70,7 @@ struct _GtkTreeModelFilterClass }; /* base */ -GType gtk_tree_model_filter_get_type (void) G_GNUC_CONST; +GType gtk_tree_model_filter_get_type (void); GtkTreeModel *gtk_tree_model_filter_new (GtkTreeModel *child_model, GtkTreePath *root); void gtk_tree_model_filter_set_visible_func (GtkTreeModelFilter *filter, diff --git a/gtk/gtktreemodelsort.c b/gtk/gtktreemodelsort.c index 8937cecc0..9c179c76a 100644 --- a/gtk/gtktreemodelsort.c +++ b/gtk/gtktreemodelsort.c @@ -756,7 +756,11 @@ gtk_tree_model_sort_row_deleted (GtkTreeModel *s_model, while (elt->ref_count > 0) gtk_tree_model_sort_real_unref_node (GTK_TREE_MODEL (data), &iter, FALSE); - if (level->ref_count == 0) + /* Views that do not ref their rows (as GtkIconView) leave the root + * level unreffed; drop it only with its last row, or the deletion of + * the other rows is no longer passed on */ + if (level->ref_count == 0 && + (level != tree_model_sort->root || level->array->len == 1)) { /* This will prune the level, so I can just emit the signal and * not worry about cleaning this level up. @@ -1341,6 +1345,10 @@ gtk_tree_model_sort_set_sort_column_id (GtkTreeSortable *sortable, { GtkTreeModelSort *tree_model_sort = (GtkTreeModelSort *)sortable; + if (tree_model_sort->sort_column_id == sort_column_id && + tree_model_sort->order == order) + return; + if (sort_column_id != GTK_TREE_SORTABLE_UNSORTED_SORT_COLUMN_ID) { if (sort_column_id != GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID) @@ -1356,17 +1364,6 @@ gtk_tree_model_sort_set_sort_column_id (GtkTreeSortable *sortable, } else g_return_if_fail (tree_model_sort->default_sort_func != NULL); - - if (tree_model_sort->sort_column_id == sort_column_id) - { - if (sort_column_id != GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID) - { - if (tree_model_sort->order == order) - return; - } - else - return; - } } tree_model_sort->sort_column_id = sort_column_id; @@ -1550,6 +1547,60 @@ gtk_tree_model_sort_offset_compare_func (gconstpointer a, return retval; } +/* sorting by a column with its own comparison, where the values can be + * read once (see _gtk_tree_data_list_sort_rows()); returns %FALSE if + * @sort_array is to be sorted with the comparison function */ +static gboolean +gtk_tree_model_sort_sort_by_column (GtkTreeModelSort *tree_model_sort, + SortData *data, + GArray *sort_array) +{ + GtkTreeIter *iters; + SortTuple *sorted; + gint *new_order; + gint n = sort_array->len; + gint i; + + if (data->sort_func != _gtk_tree_data_list_compare_func) + return FALSE; + + iters = g_new (GtkTreeIter, n); + new_order = g_new (gint, n); + for (i = 0; i < n; i++) + { + SortElt *elt = g_array_index (sort_array, SortTuple, i).elt; + + if (GTK_TREE_MODEL_SORT_CACHE_CHILD_ITERS (tree_model_sort)) + iters[i] = elt->iter; + else + { + data->parent_path_indices [data->parent_path_depth-1] = elt->offset; + gtk_tree_model_get_iter (GTK_TREE_MODEL (tree_model_sort->child_model), + &iters[i], data->parent_path); + } + } + + if (!_gtk_tree_data_list_sort_rows (tree_model_sort->child_model, + GPOINTER_TO_INT (data->sort_data), + tree_model_sort->order, + iters, n, new_order)) + { + g_free (iters); + g_free (new_order); + return FALSE; + } + + sorted = g_new (SortTuple, n); + for (i = 0; i < n; i++) + sorted[i] = g_array_index (sort_array, SortTuple, new_order[i]); + memcpy (sort_array->data, sorted, n * sizeof (SortTuple)); + + g_free (sorted); + g_free (iters); + g_free (new_order); + return TRUE; +} + static void gtk_tree_model_sort_sort_level (GtkTreeModelSort *tree_model_sort, SortLevel *level, @@ -1632,7 +1683,7 @@ gtk_tree_model_sort_sort_level (GtkTreeModelSort *tree_model_sort, g_array_sort_with_data (sort_array, gtk_tree_model_sort_offset_compare_func, &data); - else + else if (!gtk_tree_model_sort_sort_by_column (tree_model_sort, &data, sort_array)) g_array_sort_with_data (sort_array, gtk_tree_model_sort_compare_func, &data); diff --git a/gtk/gtktreemodelsort.h b/gtk/gtktreemodelsort.h index ca3dcc94f..942f4c170 100644 --- a/gtk/gtktreemodelsort.h +++ b/gtk/gtktreemodelsort.h @@ -81,7 +81,7 @@ struct _GtkTreeModelSortClass }; -GType gtk_tree_model_sort_get_type (void) G_GNUC_CONST; +GType gtk_tree_model_sort_get_type (void); GtkTreeModel *gtk_tree_model_sort_new_with_model (GtkTreeModel *child_model); GtkTreeModel *gtk_tree_model_sort_get_model (GtkTreeModelSort *tree_model); diff --git a/gtk/gtktreeselection.c b/gtk/gtktreeselection.c index e992a54d1..8dbb6d2bf 100644 --- a/gtk/gtktreeselection.c +++ b/gtk/gtktreeselection.c @@ -1158,8 +1158,9 @@ gtk_tree_selection_real_modify_range (GtkTreeSelection *selection, break; } - g_return_val_if_fail (start_node != NULL, FALSE); - g_return_val_if_fail (end_node != NULL, FALSE); + /* Invalid start or end node? */ + if (start_node == NULL || end_node == NULL) + return dirty; if (anchor_path) { diff --git a/gtk/gtktreeselection.h b/gtk/gtktreeselection.h index 32038dcaf..ecf2cc274 100644 --- a/gtk/gtktreeselection.h +++ b/gtk/gtktreeselection.h @@ -73,7 +73,7 @@ struct _GtkTreeSelectionClass }; -GType gtk_tree_selection_get_type (void) G_GNUC_CONST; +GType gtk_tree_selection_get_type (void); void gtk_tree_selection_set_mode (GtkTreeSelection *selection, GtkSelectionMode type); diff --git a/gtk/gtktreesortable.h b/gtk/gtktreesortable.h index b090f4c0b..39798ace4 100644 --- a/gtk/gtktreesortable.h +++ b/gtk/gtktreesortable.h @@ -78,7 +78,7 @@ struct _GtkTreeSortableIface }; -GType gtk_tree_sortable_get_type (void) G_GNUC_CONST; +GType gtk_tree_sortable_get_type (void); void gtk_tree_sortable_sort_column_changed (GtkTreeSortable *sortable); gboolean gtk_tree_sortable_get_sort_column_id (GtkTreeSortable *sortable, diff --git a/gtk/gtktreestore.c b/gtk/gtktreestore.c index de37cf95d..91f43bfe6 100644 --- a/gtk/gtktreestore.c +++ b/gtk/gtktreestore.c @@ -757,8 +757,7 @@ gtk_tree_store_real_set_value (GtkTreeStore *tree_store, if (! g_type_is_a (G_VALUE_TYPE (value), tree_store->column_headers[column])) { - if (! (g_value_type_compatible (G_VALUE_TYPE (value), tree_store->column_headers[column]) && - g_value_type_compatible (tree_store->column_headers[column], G_VALUE_TYPE (value)))) + if (! (g_value_type_transformable (G_VALUE_TYPE (value), tree_store->column_headers[column]))) { g_warning ("%s: Unable to convert from %s to %s\n", G_STRLOC, @@ -766,6 +765,8 @@ gtk_tree_store_real_set_value (GtkTreeStore *tree_store, g_type_name (tree_store->column_headers[column])); return retval; } + + g_value_init (&real_value, tree_store->column_headers[column]); if (!g_value_transform (value, &real_value)) { g_warning ("%s: Unable to make conversion from %s to %s\n", @@ -947,9 +948,7 @@ gtk_tree_store_set_valist_internal (GtkTreeStore *tree_store, g_warning ("%s: Invalid column number %d added to iter (remember to end your list of columns with a -1)", G_STRLOC, column); break; } - g_value_init (&value, tree_store->column_headers[column]); - - G_VALUE_COLLECT (&value, var_args, 0, &error); + G_VALUE_COLLECT_INIT (&value, tree_store->column_headers[column], var_args, 0, &error); if (error) { g_warning ("%s: %s", G_STRLOC, error); @@ -2174,6 +2173,12 @@ gtk_tree_store_reorder (GtkTreeStore *tree_store, else level = G_NODE (parent->user_data)->children; + if (G_UNLIKELY (!level)) + { + g_warning ("%s: Cannot reorder, parent has no children", G_STRLOC); + return; + } + /* count nodes */ node = level; while (node) @@ -2786,6 +2791,57 @@ gtk_tree_store_compare_func (gconstpointer a, return retval; } +/* sorting by a column with its own comparison, where the values can be + * read once (see _gtk_tree_data_list_sort_rows()); returns %FALSE if + * @sort_array is to be sorted with the comparison function */ +static gboolean +gtk_tree_store_sort_by_column (GtkTreeStore *tree_store, + GArray *sort_array) +{ + GtkTreeDataSortHeader *header; + GtkTreeIter *iters; + SortTuple *sorted; + gint *new_order; + gint n = sort_array->len; + gint i; + + if (tree_store->sort_column_id == GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID) + return FALSE; + + header = _gtk_tree_data_list_get_header (tree_store->sort_list, + tree_store->sort_column_id); + if (!header || header->func != _gtk_tree_data_list_compare_func) + return FALSE; + + iters = g_new (GtkTreeIter, n); + new_order = g_new (gint, n); + for (i = 0; i < n; i++) + { + iters[i].stamp = tree_store->stamp; + iters[i].user_data = g_array_index (sort_array, SortTuple, i).node; + } + + if (!_gtk_tree_data_list_sort_rows (GTK_TREE_MODEL (tree_store), + GPOINTER_TO_INT (header->data), + tree_store->order, + iters, n, new_order)) + { + g_free (iters); + g_free (new_order); + return FALSE; + } + + sorted = g_new (SortTuple, n); + for (i = 0; i < n; i++) + sorted[i] = g_array_index (sort_array, SortTuple, new_order[i]); + memcpy (sort_array->data, sorted, n * sizeof (SortTuple)); + + g_free (sorted); + g_free (iters); + g_free (new_order); + return TRUE; +} + static void gtk_tree_store_sort_helper (GtkTreeStore *tree_store, GNode *parent, @@ -2827,7 +2883,8 @@ gtk_tree_store_sort_helper (GtkTreeStore *tree_store, } /* Sort the array */ - g_array_sort_with_data (sort_array, gtk_tree_store_compare_func, tree_store); + if (!gtk_tree_store_sort_by_column (tree_store, sort_array)) + g_array_sort_with_data (sort_array, gtk_tree_store_compare_func, tree_store); for (i = 0; i < list_length - 1; i++) { diff --git a/gtk/gtktreestore.h b/gtk/gtktreestore.h index 9e4f13dbc..fe4778661 100644 --- a/gtk/gtktreestore.h +++ b/gtk/gtktreestore.h @@ -73,7 +73,7 @@ struct _GtkTreeStoreClass }; -GType gtk_tree_store_get_type (void) G_GNUC_CONST; +GType gtk_tree_store_get_type (void); GtkTreeStore *gtk_tree_store_new (gint n_columns, ...); GtkTreeStore *gtk_tree_store_newv (gint n_columns, diff --git a/gtk/gtktreeview.c b/gtk/gtktreeview.c index fc4d79780..c0b227784 100644 --- a/gtk/gtktreeview.c +++ b/gtk/gtktreeview.c @@ -1604,6 +1604,7 @@ gtk_tree_view_destroy (GtkObject *object) GList *list; gtk_tree_view_stop_editing (tree_view, TRUE); + gtk_tree_view_stop_rubber_band (tree_view); if (tree_view->priv->columns != NULL) { @@ -1676,6 +1677,7 @@ gtk_tree_view_destroy (GtkObject *object) gtk_widget_destroy (tree_view->priv->search_window); tree_view->priv->search_window = NULL; tree_view->priv->search_entry = NULL; + tree_view->priv->search_entry_changed_id = 0; if (tree_view->priv->typeselect_flush_timeout) { g_source_remove (tree_view->priv->typeselect_flush_timeout); @@ -1683,6 +1685,26 @@ gtk_tree_view_destroy (GtkObject *object) } } + /* a search entry of the program's own outlives the tree view: it + * must neither call into it nor be kept by it */ + if (tree_view->priv->search_custom_entry_set) + { + if (tree_view->priv->search_entry_changed_id) + { + g_signal_handler_disconnect (tree_view->priv->search_entry, + tree_view->priv->search_entry_changed_id); + tree_view->priv->search_entry_changed_id = 0; + } + g_signal_handlers_disconnect_by_func (tree_view->priv->search_entry, + G_CALLBACK (gtk_tree_view_search_key_press_event), + tree_view); + + g_object_unref (tree_view->priv->search_entry); + + tree_view->priv->search_entry = NULL; + tree_view->priv->search_custom_entry_set = FALSE; + } + if (tree_view->priv->search_destroy && tree_view->priv->search_user_data) { tree_view->priv->search_destroy (tree_view->priv->search_user_data); @@ -2568,6 +2590,10 @@ gtk_tree_view_button_press (GtkWidget *widget, NULL); + /* Don't handle extra mouse buttons events, let them bubble up */ + if (event->button > 5) + return FALSE; + /* Because grab_focus can cause reentrancy, we delay grab_focus until after * we're done handling the button press. */ @@ -2989,7 +3015,9 @@ gtk_tree_view_button_release_drag_column (GtkWidget *widget, tree_view->priv->cur_reorder->left_column); } tree_view->priv->drag_column = NULL; - gdk_window_hide (tree_view->priv->drag_window); + gdk_window_set_user_data (tree_view->priv->drag_window, NULL); + gdk_window_destroy (tree_view->priv->drag_window); + tree_view->priv->drag_window = NULL; for (l = tree_view->priv->column_drag_info; l != NULL; l = l->next) g_slice_free (GtkTreeViewColumnReorder, l->data); @@ -3568,7 +3596,7 @@ gtk_tree_view_motion_draw_column_motion_arrow (GtkTreeView *tree_view) attributes.y = y; attributes.width = width; attributes.height = height; - tree_view->priv->drag_highlight_window = gdk_window_new (NULL, &attributes, attributes_mask); + tree_view->priv->drag_highlight_window = gdk_window_new (gtk_widget_get_root_window (widget), &attributes, attributes_mask); gdk_window_set_user_data (tree_view->priv->drag_highlight_window, GTK_WIDGET (tree_view)); mask = gdk_pixmap_new (tree_view->priv->drag_highlight_window, width, height, 1); @@ -4279,7 +4307,8 @@ gtk_tree_view_draw_grid_lines (GtkTreeView *tree_view, GdkEventExpose *event, gint n_visible_columns) { - GList *list = tree_view->priv->columns; + GList *list; + gboolean rtl; gint i = 0; gint current_x = 0; @@ -4287,8 +4316,13 @@ gtk_tree_view_draw_grid_lines (GtkTreeView *tree_view, && tree_view->priv->grid_lines != GTK_TREE_VIEW_GRID_LINES_BOTH) return; + /* The columns are laid out from the right in RTL */ + rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL); + /* Only draw the lines for visible rows and columns */ - for (list = tree_view->priv->columns; list; list = list->next) + for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns)); + list; + list = (rtl ? list->prev : list->next)) { GtkTreeViewColumn *column = list->data; @@ -4351,7 +4385,7 @@ gtk_tree_view_bin_expose (GtkWidget *widget, gboolean has_special_cell; gboolean rtl; gint n_visible_columns; - gint pointer_x, pointer_y; + gint pointer_x = 0, pointer_y = 0; gint grid_line_width; gboolean got_pointer = FALSE; gboolean row_ending_details; @@ -4722,7 +4756,9 @@ gtk_tree_view_bin_expose (GtkWidget *widget, if (TREE_VIEW_DRAW_EXPANDERS(tree_view) && (node->flags & GTK_RBNODE_IS_PARENT) == GTK_RBNODE_IS_PARENT) { - if (!got_pointer) + /* the pointer only matters for the arrow being pressed; + * asking for it is a round trip to the server */ + if (!got_pointer && node == tree_view->priv->button_pressed_node) { gdk_window_get_pointer (tree_view->priv->bin_window, &pointer_x, &pointer_y, NULL); @@ -5331,6 +5367,17 @@ gtk_tree_view_get_drop_column (GtkTreeView *tree_view, return (GtkTreeViewColumn *)0x1; } +/* the keys that close the interactive search: no point in opening it + * for them */ +static gboolean +gtk_tree_view_search_key_cancels_search (guint keyval) +{ + return keyval == GDK_Escape + || keyval == GDK_Tab + || keyval == GDK_KP_Tab + || keyval == GDK_ISO_Left_Tab; +} + static gboolean gtk_tree_view_key_press (GtkWidget *widget, GdkEventKey *event) @@ -5504,7 +5551,8 @@ gtk_tree_view_key_press (GtkWidget *widget, * the typeahead find capabilities. */ if (gtk_widget_has_focus (GTK_WIDGET (tree_view)) && tree_view->priv->enable_search - && !tree_view->priv->search_custom_entry_set) + && !tree_view->priv->search_custom_entry_set + && !gtk_tree_view_search_key_cancels_search (event->keyval)) { GdkEvent *new_event; char *old_text; @@ -5628,7 +5676,9 @@ gtk_tree_view_leave_notify (GtkWidget *widget, { GtkTreeView *tree_view; - if (event->mode == GDK_CROSSING_GRAB) + if (event->mode == GDK_CROSSING_GRAB || + event->mode == GDK_CROSSING_GTK_GRAB || + event->mode == GDK_CROSSING_GTK_UNGRAB) return TRUE; tree_view = GTK_TREE_VIEW (widget); @@ -7240,7 +7290,14 @@ gtk_tree_view_drag_begin (GtkWidget *widget, &cell_x, &cell_y); - g_return_if_fail (path != NULL); + /* If path is NULL, there's nothing we can drag. For now, we silently + * bail out. Actually, dragging should not be possible from an empty + * tree view, but there's no way we can cancel that from here. + * Automatically unsetting the tree view as drag source for empty models + * is something that would likely break other people's code ... + */ + if (!path) + return; row_pix = gtk_tree_view_create_row_drag_icon (tree_view, path); @@ -7610,8 +7667,9 @@ gtk_tree_view_drag_data_received (GtkWidget *widget, (gdk_drag_context_get_selected_action (context) == GDK_ACTION_MOVE), time); - if (gtk_tree_path_get_depth (dest_row) == 1 - && gtk_tree_path_get_indices (dest_row)[0] == 0) + if (gtk_tree_path_get_depth (dest_row) == 1 && + gtk_tree_path_get_indices (dest_row)[0] == 0 && + gtk_tree_model_iter_n_children (tree_view->priv->model, NULL) != 0) { /* special special case drag to "0", scroll to first item */ if (!tree_view->priv->scroll_to_path) @@ -8593,7 +8651,7 @@ check_selection_helper (GtkRBTree *tree, { gint *value = (gint *)data; - *value = GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_SELECTED); + *value |= GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_SELECTED); if (node->children && !*value) _gtk_rbtree_traverse (node->children, node->children->root, G_POST_ORDER, check_selection_helper, data); @@ -8874,13 +8932,13 @@ gtk_tree_view_build_tree (GtkTreeView *tree_view, else gtk_tree_path_next (path); - if (gtk_tree_model_iter_children (tree_view->priv->model, &child, iter)) + if (gtk_tree_model_iter_has_child (tree_view->priv->model, iter)) { gboolean expand; g_signal_emit (tree_view, tree_view_signals[TEST_EXPAND_ROW], 0, iter, path, &expand); - if (gtk_tree_model_iter_has_child (tree_view->priv->model, iter) + if (gtk_tree_model_iter_children (tree_view->priv->model, &child, iter) && !expand) { temp->children = _gtk_rbtree_new (); @@ -9186,7 +9244,7 @@ gtk_tree_view_unref_tree_helper (GtkTreeModel *model, if (!gtk_tree_model_iter_children (model, &child, iter)) return FALSE; - retval = retval || gtk_tree_view_unref_tree_helper (model, &child, new_tree, new_node); + retval = gtk_tree_view_unref_tree_helper (model, &child, new_tree, new_node) | retval; } if (GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_SELECTED)) @@ -9344,28 +9402,37 @@ _gtk_tree_view_column_start_drag (GtkTreeView *tree_view, if (tree_view->priv->column_drag_info == NULL) return; - if (tree_view->priv->drag_window == NULL) + /* Create the drag window for every drag, so that it matches the + * position and size of the column header being dragged. + */ + if (tree_view->priv->drag_window != NULL) { - GdkWindowAttr attributes; - guint attributes_mask; - - attributes.window_type = GDK_WINDOW_CHILD; - attributes.wclass = GDK_INPUT_OUTPUT; - attributes.x = column->button->allocation.x; - attributes.y = 0; - attributes.width = column->button->allocation.width; - attributes.height = column->button->allocation.height; - attributes.visual = gtk_widget_get_visual (GTK_WIDGET (tree_view)); - attributes.colormap = gtk_widget_get_colormap (GTK_WIDGET (tree_view)); - attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK; - attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP; - - tree_view->priv->drag_window = gdk_window_new (tree_view->priv->bin_window, - &attributes, - attributes_mask); - gdk_window_set_user_data (tree_view->priv->drag_window, GTK_WIDGET (tree_view)); + gdk_window_set_user_data (tree_view->priv->drag_window, NULL); + gdk_window_destroy (tree_view->priv->drag_window); + tree_view->priv->drag_window = NULL; } + { + GdkWindowAttr attributes; + guint attributes_mask; + + attributes.window_type = GDK_WINDOW_CHILD; + attributes.wclass = GDK_INPUT_OUTPUT; + attributes.x = column->button->allocation.x; + attributes.y = 0; + attributes.width = column->button->allocation.width; + attributes.height = column->button->allocation.height; + attributes.visual = gtk_widget_get_visual (GTK_WIDGET (tree_view)); + attributes.colormap = gtk_widget_get_colormap (GTK_WIDGET (tree_view)); + attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK; + attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP; + + tree_view->priv->drag_window = gdk_window_new (tree_view->priv->bin_window, + &attributes, + attributes_mask); + gdk_window_set_user_data (tree_view->priv->drag_window, GTK_WIDGET (tree_view)); + } + gdk_display_pointer_ungrab (display, GDK_CURRENT_TIME); gdk_display_keyboard_ungrab (display, GDK_CURRENT_TIME); @@ -9416,8 +9483,6 @@ _gtk_tree_view_column_start_drag (GtkTreeView *tree_view, gdk_window_get_origin (tree_view->priv->header_window, &x, &y); gtk_widget_grab_focus (GTK_WIDGET (tree_view)); - while (gtk_events_pending ()) - gtk_main_iteration (); GTK_TREE_VIEW_SET_FLAG (tree_view, GTK_TREE_VIEW_IN_COLUMN_DRAG); gdk_pointer_grab (tree_view->priv->drag_window, @@ -12626,7 +12691,8 @@ gtk_tree_view_real_set_cursor (GtkTreeView *tree_view, } } - g_signal_emit (tree_view, tree_view_signals[CURSOR_CHANGED], 0); + if (!(GTK_OBJECT_FLAGS (tree_view) & GTK_IN_DESTRUCTION)) + g_signal_emit (tree_view, tree_view_signals[CURSOR_CHANGED], 0); } /** @@ -12865,7 +12931,7 @@ gtk_tree_view_get_path_at_pos (GtkTreeView *tree_view, continue; last_column = tmp_column; - if (remaining_x <= tmp_column->width) + if (remaining_x < tmp_column->width) { found = TRUE; @@ -14141,6 +14207,9 @@ gtk_tree_view_set_search_entry (GtkTreeView *tree_view, gtk_widget_destroy (tree_view->priv->search_window); tree_view->priv->search_window = NULL; + /* the handler went with the entry of the window; a new entry + * needs its own */ + tree_view->priv->search_entry_changed_id = 0; } if (entry) @@ -15652,6 +15721,7 @@ gtk_tree_view_set_tooltip_query_cb (GtkWidget *widget, GtkTreePath *path; GtkTreeModel *model; GtkTreeView *tree_view = GTK_TREE_VIEW (widget); + const char *transformed_str = NULL; if (!gtk_tree_view_get_tooltip_context (GTK_TREE_VIEW (widget), &x, &y, @@ -15674,7 +15744,8 @@ gtk_tree_view_set_tooltip_query_cb (GtkWidget *widget, g_value_unset (&value); - if (!g_value_get_string (&transformed)) + transformed_str = g_value_get_string (&transformed); + if (transformed_str == NULL || *transformed_str == '\0') { g_value_unset (&transformed); gtk_tree_path_free (path); @@ -15682,7 +15753,7 @@ gtk_tree_view_set_tooltip_query_cb (GtkWidget *widget, return FALSE; } - gtk_tooltip_set_markup (tooltip, g_value_get_string (&transformed)); + gtk_tooltip_set_markup (tooltip, transformed_str); gtk_tree_view_set_tooltip_row (tree_view, tooltip, path); gtk_tree_path_free (path); diff --git a/gtk/gtktreeview.h b/gtk/gtktreeview.h index 23d8055f4..838f01796 100644 --- a/gtk/gtktreeview.h +++ b/gtk/gtktreeview.h @@ -137,7 +137,7 @@ typedef void (*GtkTreeViewSearchPositionFunc) (GtkTreeView *tree_view, /* Creators */ -GType gtk_tree_view_get_type (void) G_GNUC_CONST; +GType gtk_tree_view_get_type (void); GtkWidget *gtk_tree_view_new (void); GtkWidget *gtk_tree_view_new_with_model (GtkTreeModel *model); diff --git a/gtk/gtktreeviewcolumn.c b/gtk/gtktreeviewcolumn.c index 3b890fc27..6f76fb27b 100644 --- a/gtk/gtktreeviewcolumn.c +++ b/gtk/gtktreeviewcolumn.c @@ -2004,7 +2004,8 @@ gtk_tree_view_column_set_min_width (GtkTreeViewColumn *tree_column, g_object_notify (G_OBJECT (tree_column), "min-width"); g_object_thaw_notify (G_OBJECT (tree_column)); - if (tree_column->column_type == GTK_TREE_VIEW_COLUMN_AUTOSIZE) + if (tree_column->column_type == GTK_TREE_VIEW_COLUMN_AUTOSIZE && + tree_column->tree_view != NULL) _gtk_tree_view_column_autosize (GTK_TREE_VIEW (tree_column->tree_view), tree_column); } @@ -2064,7 +2065,8 @@ gtk_tree_view_column_set_max_width (GtkTreeViewColumn *tree_column, g_object_notify (G_OBJECT (tree_column), "max-width"); g_object_thaw_notify (G_OBJECT (tree_column)); - if (tree_column->column_type == GTK_TREE_VIEW_COLUMN_AUTOSIZE) + if (tree_column->column_type == GTK_TREE_VIEW_COLUMN_AUTOSIZE && + tree_column->tree_view != NULL) _gtk_tree_view_column_autosize (GTK_TREE_VIEW (tree_column->tree_view), tree_column); } diff --git a/gtk/gtktreeviewcolumn.h b/gtk/gtktreeviewcolumn.h index d36f6077f..3ce3dd92b 100644 --- a/gtk/gtktreeviewcolumn.h +++ b/gtk/gtktreeviewcolumn.h @@ -123,7 +123,7 @@ struct _GtkTreeViewColumnClass void (*_gtk_reserved4) (void); }; -GType gtk_tree_view_column_get_type (void) G_GNUC_CONST; +GType gtk_tree_view_column_get_type (void); GtkTreeViewColumn *gtk_tree_view_column_new (void); GtkTreeViewColumn *gtk_tree_view_column_new_with_attributes (const gchar *title, GtkCellRenderer *cell, diff --git a/gtk/gtktypebuiltins.h.template b/gtk/gtktypebuiltins.h.template index 9b2538dc1..f4a0f15ff 100644 --- a/gtk/gtktypebuiltins.h.template +++ b/gtk/gtktypebuiltins.h.template @@ -17,7 +17,7 @@ G_BEGIN_DECLS /*** END file-production ***/ /*** BEGIN value-header ***/ -GType @enum_name@_get_type (void) G_GNUC_CONST; +GType @enum_name@_get_type (void); #define @ENUMPREFIX@_TYPE_@ENUMSHORT@ (@enum_name@_get_type ()) /*** END value-header ***/ diff --git a/gtk/gtktypeutils.h b/gtk/gtktypeutils.h index bd790e424..30d7e5001 100644 --- a/gtk/gtktypeutils.h +++ b/gtk/gtktypeutils.h @@ -39,7 +39,7 @@ G_BEGIN_DECLS /* urg */ #define GTK_TYPE_IDENTIFIER (gtk_identifier_get_type ()) -GType gtk_identifier_get_type (void) G_GNUC_CONST; +GType gtk_identifier_get_type (void); /* --- typedefs --- */ /* here we come with some necessary forward declarations for structures and diff --git a/gtk/gtkuimanager.h b/gtk/gtkuimanager.h index c626ebc38..c298bcd5d 100644 --- a/gtk/gtkuimanager.h +++ b/gtk/gtkuimanager.h @@ -110,7 +110,7 @@ typedef enum { #define gtk_ui_manager_add_ui_from_file gtk_ui_manager_add_ui_from_file_utf8 #endif -GType gtk_ui_manager_get_type (void) G_GNUC_CONST; +GType gtk_ui_manager_get_type (void); GtkUIManager *gtk_ui_manager_new (void); void gtk_ui_manager_set_add_tearoffs (GtkUIManager *self, gboolean add_tearoffs); diff --git a/gtk/gtkvbbox.h b/gtk/gtkvbbox.h index 26f699093..0c6a3e195 100644 --- a/gtk/gtkvbbox.h +++ b/gtk/gtkvbbox.h @@ -60,7 +60,7 @@ struct _GtkVButtonBoxClass }; -GType gtk_vbutton_box_get_type (void) G_GNUC_CONST; +GType gtk_vbutton_box_get_type (void); GtkWidget *gtk_vbutton_box_new (void); /* buttons can be added by gtk_container_add() */ diff --git a/gtk/gtkvbox.h b/gtk/gtkvbox.h index 7b6af6dbc..4ccf03fca 100644 --- a/gtk/gtkvbox.h +++ b/gtk/gtkvbox.h @@ -59,7 +59,7 @@ struct _GtkVBoxClass }; -GType gtk_vbox_get_type (void) G_GNUC_CONST; +GType gtk_vbox_get_type (void); GtkWidget * gtk_vbox_new (gboolean homogeneous, gint spacing); diff --git a/gtk/gtkviewport.h b/gtk/gtkviewport.h index ee74e34a9..8a7c93dc4 100644 --- a/gtk/gtkviewport.h +++ b/gtk/gtkviewport.h @@ -71,7 +71,7 @@ struct _GtkViewportClass }; -GType gtk_viewport_get_type (void) G_GNUC_CONST; +GType gtk_viewport_get_type (void); GtkWidget* gtk_viewport_new (GtkAdjustment *hadjustment, GtkAdjustment *vadjustment); GtkAdjustment* gtk_viewport_get_hadjustment (GtkViewport *viewport); diff --git a/gtk/gtkvolumebutton.h b/gtk/gtkvolumebutton.h index d8a3c72cb..40e3d4448 100644 --- a/gtk/gtkvolumebutton.h +++ b/gtk/gtkvolumebutton.h @@ -64,7 +64,7 @@ struct _GtkVolumeButtonClass void (*_gtk_reserved4) (void); }; -GType gtk_volume_button_get_type (void) G_GNUC_CONST; +GType gtk_volume_button_get_type (void); GtkWidget* gtk_volume_button_new (void); G_END_DECLS diff --git a/gtk/gtkvpaned.h b/gtk/gtkvpaned.h index 9f210f714..b8ce3bf72 100644 --- a/gtk/gtkvpaned.h +++ b/gtk/gtkvpaned.h @@ -57,7 +57,7 @@ struct _GtkVPanedClass }; -GType gtk_vpaned_get_type (void) G_GNUC_CONST; +GType gtk_vpaned_get_type (void); GtkWidget * gtk_vpaned_new (void); G_END_DECLS diff --git a/gtk/gtkvruler.h b/gtk/gtkvruler.h index 9bff47c15..667944f7e 100644 --- a/gtk/gtkvruler.h +++ b/gtk/gtkvruler.h @@ -72,7 +72,7 @@ struct _GtkVRulerClass }; -GType gtk_vruler_get_type (void) G_GNUC_CONST; +GType gtk_vruler_get_type (void); GtkWidget* gtk_vruler_new (void); diff --git a/gtk/gtkvscale.h b/gtk/gtkvscale.h index b5d5d85d6..1a1659450 100644 --- a/gtk/gtkvscale.h +++ b/gtk/gtkvscale.h @@ -66,7 +66,7 @@ struct _GtkVScaleClass }; -GType gtk_vscale_get_type (void) G_GNUC_CONST; +GType gtk_vscale_get_type (void); GtkWidget* gtk_vscale_new (GtkAdjustment *adjustment); GtkWidget* gtk_vscale_new_with_range (gdouble min, gdouble max, diff --git a/gtk/gtkvscrollbar.h b/gtk/gtkvscrollbar.h index e7692af09..5df16a129 100644 --- a/gtk/gtkvscrollbar.h +++ b/gtk/gtkvscrollbar.h @@ -66,7 +66,7 @@ struct _GtkVScrollbarClass }; -GType gtk_vscrollbar_get_type (void) G_GNUC_CONST; +GType gtk_vscrollbar_get_type (void); GtkWidget* gtk_vscrollbar_new (GtkAdjustment *adjustment); diff --git a/gtk/gtkvseparator.h b/gtk/gtkvseparator.h index f41d491cc..2a0e5d033 100644 --- a/gtk/gtkvseparator.h +++ b/gtk/gtkvseparator.h @@ -66,7 +66,7 @@ struct _GtkVSeparatorClass }; -GType gtk_vseparator_get_type (void) G_GNUC_CONST; +GType gtk_vseparator_get_type (void); GtkWidget* gtk_vseparator_new (void); diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c index 447303dfd..36a4c8c54 100644 --- a/gtk/gtkwidget.c +++ b/gtk/gtkwidget.c @@ -215,6 +215,7 @@ enum { KEYNAV_FAILED, DRAG_FAILED, DAMAGE_EVENT, + TOUCH_EVENT, LAST_SIGNAL }; @@ -367,6 +368,7 @@ static void gtk_widget_queue_tooltip_query (GtkWidget *widg static void gtk_widget_set_usize_internal (GtkWidget *widget, gint width, gint height); +static void draw_rects_changed (void); static void gtk_widget_get_draw_rectangle (GtkWidget *widget, GdkRectangle *rect); @@ -380,6 +382,23 @@ static guint composite_child_stack = 0; static GtkTextDirection gtk_default_direction = GTK_TEXT_DIR_LTR; static GParamSpecPool *style_property_spec_pool = NULL; +/* Widgets ask for the same few style properties of the same few types + * at every size request and expose, and a lookup by name walks the + * class tree with a hash lookup per level. The answers are kept here, + * by type and name pointer, until a style property is added or removed. */ +#define STYLE_PROPERTY_CACHE_SIZE 128 +typedef struct +{ + GType type; + const gchar *name; + GParamSpec *pspec; + GtkRcPropertyParser parser; +} StylePropertyCacheEntry; +static StylePropertyCacheEntry style_property_cache[STYLE_PROPERTY_CACHE_SIZE]; +static GParamSpec *style_property_lookup (GType type, + const gchar *name, + GtkRcPropertyParser *parser); + static GQuark quark_property_parser = 0; static GQuark quark_aux_info = 0; static GQuark quark_accel_path = 0; @@ -2260,6 +2279,33 @@ gtk_widget_class_init (GtkWidgetClass *klass) _gtk_marshal_BOOLEAN__BOXED, G_TYPE_BOOLEAN, 1, GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE); + + /** + * GtkWidget::touch-event: + * @widget: the object which received the signal + * @event: (type Gdk.EventTouch): the #GdkEventTouch + * + * A touch of a finger begins, moves, ends or is cancelled, as in + * GTK+ 3. Only the widgets whose #GdkWindow has %GDK_TOUCH_MASK + * (gtk_widget_add_events()) get touches; for all others GDK moves the + * pointer with the first finger, so that they work as with a mouse. + * The events of each finger have their own + * gdk_event_get_event_sequence(). + * + * Returns: %TRUE to stop other handlers from being invoked for the event. + * %FALSE to propagate the event further. + * + * Since: 2.24 + */ + widget_signals[TOUCH_EVENT] = + g_signal_new (I_("touch-event"), + G_TYPE_FROM_CLASS (gobject_class), + G_SIGNAL_RUN_LAST, + 0, + _gtk_boolean_handled_accumulator, NULL, + _gtk_marshal_BOOLEAN__BOXED, + G_TYPE_BOOLEAN, 1, + GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE); /** * GtkWidget::grab-broken-event: * @widget: the object which received the signal @@ -2638,6 +2684,8 @@ gtk_widget_base_class_finalize (GtkWidgetClass *klass) GList *list, *node; list = g_param_spec_pool_list_owned (style_property_spec_pool, G_OBJECT_CLASS_TYPE (klass)); + if (list) + memset (style_property_cache, 0, sizeof (style_property_cache)); for (node = list; node; node = node->next) { GParamSpec *pspec = node->data; @@ -3171,6 +3219,7 @@ gtk_widget_unparent (GtkWidget *widget) g_object_notify_queue_clear (G_OBJECT (widget), nqueue); g_object_notify_queue_thaw (G_OBJECT (widget), nqueue); g_object_unref (widget); + draw_rects_changed (); } /** @@ -3450,6 +3499,7 @@ gtk_widget_map (GtkWidget *widget) if (!gtk_widget_get_has_window (widget)) gdk_window_invalidate_rect (widget->window, &widget->allocation, FALSE); } + draw_rects_changed (); } /** @@ -3471,6 +3521,7 @@ gtk_widget_unmap (GtkWidget *widget) _gtk_tooltip_hide (widget); g_signal_emit (widget, widget_signals[UNMAP], 0); } + draw_rects_changed (); } static void @@ -3595,6 +3646,7 @@ gtk_widget_realize (GtkWidget *widget) if (mode != GDK_EXTENSION_EVENTS_NONE) gtk_widget_set_extension_events_internal (widget, mode, NULL); } + draw_rects_changed (); } /** @@ -3625,6 +3677,7 @@ gtk_widget_unrealize (GtkWidget *widget) gtk_widget_set_mapped (widget, FALSE); g_object_unref (widget); } + draw_rects_changed (); } /***************************************** @@ -3738,28 +3791,61 @@ widget_add_child_draw_rectangle (GtkWidget *widget, gdk_rectangle_union (rect, &child_rect, rect); } +/* Where widgets without a window draw, with their children, is kept for + * the containers among them, as long as nothing happened that may change + * it: a new allocation, size or drawing asked for, a widget mapped, + * realized, parented, styled or the like anywhere. An expose otherwise + * walks through all children of each container away from the exposed + * area, to find whether some of them draw in it after all, and through + * the children of each one it passes on the expose to again. */ +typedef struct +{ + guint serial; + GdkRectangle rect; +} DrawRectCache; + +static guint draw_rects_serial = 1; +static GQuark quark_draw_rect; + +static void +draw_rects_changed (void) +{ + draw_rects_serial++; +} + +/* The allocation of a widget without a window, with its draw border */ +static void +gtk_widget_get_own_draw_rectangle (GtkWidget *widget, + GdkRectangle *rect) +{ + const GtkBorder *draw_border; + GtkRcPropertyParser parser; + GParamSpec *pspec; + + *rect = widget->allocation; + + /* this runs for every child at every expose: look at the + * value instead of asking for a copy of it */ + pspec = style_property_lookup (G_OBJECT_TYPE (widget), "draw-border", &parser); + draw_border = g_value_get_boxed (_gtk_style_peek_property_value (widget->style, + G_OBJECT_TYPE (widget), + pspec, parser)); + if (draw_border) + { + rect->x -= draw_border->left; + rect->y -= draw_border->top; + rect->width += draw_border->left + draw_border->right; + rect->height += draw_border->top + draw_border->bottom; + } +} + static void gtk_widget_get_draw_rectangle (GtkWidget *widget, GdkRectangle *rect) { if (!gtk_widget_get_has_window (widget)) { - GtkBorder *draw_border = NULL; - - *rect = widget->allocation; - - gtk_widget_style_get (widget, - "draw-border", &draw_border, - NULL); - if (draw_border) - { - rect->x -= draw_border->left; - rect->y -= draw_border->top; - rect->width += draw_border->left + draw_border->right; - rect->height += draw_border->top + draw_border->bottom; - - gtk_border_free (draw_border); - } + gtk_widget_get_own_draw_rectangle (widget, rect); if (GTK_IS_CONTAINER (widget)) gtk_container_forall (GTK_CONTAINER (widget), @@ -3775,6 +3861,46 @@ gtk_widget_get_draw_rectangle (GtkWidget *widget, } } +/* for gtk_container_propagate_expose(): whether @widget, a widget + * without a window, draws anywhere in @area of its window. The walk + * through its children is only needed where its own allocation with + * draw border misses @area. */ +gboolean +_gtk_widget_draws_in_area (GtkWidget *widget, + const GdkRectangle *area) +{ + GdkRectangle rect; + + DrawRectCache *cache; + + gtk_widget_get_own_draw_rectangle (widget, &rect); + if (gdk_rectangle_intersect (area, &rect, NULL)) + return TRUE; + if (!GTK_IS_CONTAINER (widget)) + return FALSE; + + /* only here, to leave out children: a stale rectangle (after a + * change outside GTK's own calls) costs a needless expose at most + * where the children stay within the container */ + if (!quark_draw_rect) + quark_draw_rect = g_quark_from_static_string ("gtk-widget-draw-rectangle"); + cache = g_object_get_qdata (G_OBJECT (widget), quark_draw_rect); + if (cache && cache->serial == draw_rects_serial) + return gdk_rectangle_intersect (area, &cache->rect, NULL); + + gtk_widget_get_draw_rectangle (widget, &rect); + + if (!cache) + { + cache = g_new (DrawRectCache, 1); + g_object_set_qdata_full (G_OBJECT (widget), quark_draw_rect, cache, g_free); + } + cache->serial = draw_rects_serial; + cache->rect = rect; + + return gdk_rectangle_intersect (area, &rect, NULL); +} + /** * gtk_widget_queue_draw: * @widget: a #GtkWidget @@ -4130,6 +4256,8 @@ gtk_widget_size_allocate (GtkWidget *widget, if (!alloc_needed && !size_changed && !position_changed) return; + draw_rects_changed (); + g_signal_emit (widget, widget_signals[SIZE_ALLOCATE], 0, &real_allocation); if (gtk_widget_get_mapped (widget)) @@ -4167,6 +4295,7 @@ gtk_widget_size_allocate (GtkWidget *widget, gtk_widget_invalidate_widget_windows (widget->parent, invalidate); gdk_region_destroy (invalidate); } + draw_rects_changed (); } /** @@ -4883,6 +5012,7 @@ event_window_is_still_viewable (GdkEvent *event) case GDK_ENTER_NOTIFY: case GDK_PROXIMITY_IN: case GDK_SCROLL: + case GDK_TOUCH_BEGIN: return event->any.window && gdk_window_is_viewable (event->any.window); #if 0 @@ -5019,6 +5149,12 @@ gtk_widget_event_internal (GtkWidget *widget, case GDK_DAMAGE: signal_num = DAMAGE_EVENT; break; + case GDK_TOUCH_BEGIN: + case GDK_TOUCH_UPDATE: + case GDK_TOUCH_END: + case GDK_TOUCH_CANCEL: + signal_num = TOUCH_EVENT; + break; default: g_warning ("gtk_widget_event(): unhandled event type: %d", event->type); signal_num = -1; @@ -5299,6 +5435,22 @@ gtk_widget_region_intersect (GtkWidget *widget, g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL); g_return_val_if_fail (region != NULL, NULL); + /* The children of a widget without a window draw within its draw + * rectangle too, which takes a walk through all of them to find. + * Where the widget itself already covers the region that is not + * needed: every container on the way to an exposed widget does. */ + if (!gtk_widget_get_has_window (widget)) + { + GdkRectangle clip; + + gtk_widget_get_own_draw_rectangle (widget, &rect); + gdk_region_get_clipbox (region, &clip); + if (clip.x >= rect.x && clip.y >= rect.y && + clip.x + clip.width <= rect.x + rect.width && + clip.y + clip.height <= rect.y + rect.height) + return gdk_region_copy (region); + } + gtk_widget_get_draw_rectangle (widget, &rect); dest = gdk_region_rectangle (&rect); @@ -6111,6 +6263,7 @@ gtk_widget_set_realized (GtkWidget *widget, GTK_OBJECT_FLAGS (widget) |= GTK_REALIZED; else GTK_OBJECT_FLAGS (widget) &= ~(GTK_REALIZED); + draw_rects_changed (); } /** @@ -6153,6 +6306,7 @@ gtk_widget_set_mapped (GtkWidget *widget, GTK_OBJECT_FLAGS (widget) |= GTK_MAPPED; else GTK_OBJECT_FLAGS (widget) &= ~(GTK_MAPPED); + draw_rects_changed (); } /** @@ -6478,6 +6632,7 @@ gtk_widget_set_parent (GtkWidget *widget, gtk_widget_queue_resize (widget); } + draw_rects_changed (); } /** @@ -7029,6 +7184,7 @@ gtk_widget_set_style_internal (GtkWidget *widget, g_object_notify (G_OBJECT (widget), "style"); g_object_thaw_notify (G_OBJECT (widget)); g_object_unref (widget); + draw_rects_changed (); } typedef struct { @@ -7574,6 +7730,7 @@ gtk_widget_set_child_visible (GtkWidget *widget, } g_object_unref (widget); + draw_rects_changed (); } /** @@ -9842,6 +9999,7 @@ gtk_widget_class_install_style_property_parser (GtkWidgetClass *klass, g_param_spec_ref_sink (pspec); g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser); g_param_spec_pool_insert (style_property_spec_pool, pspec, G_OBJECT_CLASS_TYPE (klass)); + memset (style_property_cache, 0, sizeof (style_property_cache)); } /** @@ -9917,6 +10075,39 @@ gtk_widget_class_list_style_properties (GtkWidgetClass *klass, return pspecs; } +static GParamSpec * +style_property_lookup (GType type, + const gchar *name, + GtkRcPropertyParser *parser) +{ + StylePropertyCacheEntry *entry; + GParamSpec *pspec; + + entry = &style_property_cache[(((gsize) name >> 3) ^ ((gsize) type >> 2)) % STYLE_PROPERTY_CACHE_SIZE]; + if (entry->type == type && entry->name == name && + strcmp (name, entry->pspec->name) == 0) + { + *parser = entry->parser; + return entry->pspec; + } + + pspec = g_param_spec_pool_lookup (style_property_spec_pool, name, type, TRUE); + if (!pspec) + return NULL; + + *parser = (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser); + /* names in another spelling or with a type prefix are looked up again */ + if (strcmp (name, pspec->name) == 0) + { + entry->type = type; + entry->name = name; + entry->pspec = pspec; + entry->parser = *parser; + } + + return pspec; +} + /** * gtk_widget_style_get_property: * @widget: a #GtkWidget @@ -9931,16 +10122,13 @@ gtk_widget_style_get_property (GtkWidget *widget, GValue *value) { GParamSpec *pspec; + GtkRcPropertyParser parser; g_return_if_fail (GTK_IS_WIDGET (widget)); g_return_if_fail (property_name != NULL); g_return_if_fail (G_IS_VALUE (value)); - g_object_ref (widget); - pspec = g_param_spec_pool_lookup (style_property_spec_pool, - property_name, - G_OBJECT_TYPE (widget), - TRUE); + pspec = style_property_lookup (G_OBJECT_TYPE (widget), property_name, &parser); if (!pspec) g_warning ("%s: widget class `%s' has no property named `%s'", G_STRLOC, @@ -9953,7 +10141,7 @@ gtk_widget_style_get_property (GtkWidget *widget, peek_value = _gtk_style_peek_property_value (widget->style, G_OBJECT_TYPE (widget), pspec, - (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser)); + parser); /* auto-conversion of the caller's value type */ @@ -9967,7 +10155,6 @@ gtk_widget_style_get_property (GtkWidget *widget, g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)), G_VALUE_TYPE_NAME (value)); } - g_object_unref (widget); } /** @@ -9990,19 +10177,15 @@ gtk_widget_style_get_valist (GtkWidget *widget, g_return_if_fail (GTK_IS_WIDGET (widget)); - g_object_ref (widget); - name = first_property_name; while (name) { const GValue *peek_value; GParamSpec *pspec; + GtkRcPropertyParser parser; gchar *error; - pspec = g_param_spec_pool_lookup (style_property_spec_pool, - name, - G_OBJECT_TYPE (widget), - TRUE); + pspec = style_property_lookup (G_OBJECT_TYPE (widget), name, &parser); if (!pspec) { g_warning ("%s: widget class `%s' has no property named `%s'", @@ -10016,7 +10199,7 @@ gtk_widget_style_get_valist (GtkWidget *widget, peek_value = _gtk_style_peek_property_value (widget->style, G_OBJECT_TYPE (widget), pspec, - (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser)); + parser); G_VALUE_LCOPY (peek_value, var_args, 0, &error); if (error) { @@ -10027,8 +10210,6 @@ gtk_widget_style_get_valist (GtkWidget *widget, name = va_arg (var_args, gchar*); } - - g_object_unref (widget); } /** @@ -11324,6 +11505,7 @@ gtk_widget_set_allocation (GtkWidget *widget, g_return_if_fail (allocation != NULL); widget->allocation = *allocation; + draw_rects_changed (); } /** @@ -11381,6 +11563,7 @@ gtk_widget_set_window (GtkWidget *widget, widget->window = window; g_object_notify (G_OBJECT (widget), "window"); } + draw_rects_changed (); } /** diff --git a/gtk/gtkwidget.h b/gtk/gtkwidget.h index 5d0543db1..297e08399 100644 --- a/gtk/gtkwidget.h +++ b/gtk/gtkwidget.h @@ -830,7 +830,7 @@ struct _GtkWidgetShapeInfo GdkBitmap *shape_mask; }; -GType gtk_widget_get_type (void) G_GNUC_CONST; +GType gtk_widget_get_type (void); GtkWidget* gtk_widget_new (GType type, const gchar *first_property_name, ...); @@ -1305,7 +1305,7 @@ void gtk_widget_set_has_tooltip (GtkWidget *widget, gboolean has_tooltip); gboolean gtk_widget_get_has_tooltip (GtkWidget *widget); -GType gtk_requisition_get_type (void) G_GNUC_CONST; +GType gtk_requisition_get_type (void); GtkRequisition *gtk_requisition_copy (const GtkRequisition *requisition); void gtk_requisition_free (GtkRequisition *requisition); @@ -1314,6 +1314,8 @@ void gtk_requisition_free (GtkRequisition *requisition); # define gtk_widget_unref g_object_unref #endif /* GTK_TRACE_OBJECTS && __GNUC__ */ +gboolean _gtk_widget_draws_in_area (GtkWidget *widget, + const GdkRectangle *area); void _gtk_widget_set_has_default (GtkWidget *widget, gboolean has_default); void _gtk_widget_set_has_grab (GtkWidget *widget, diff --git a/gtk/gtkwin32embedwidget.h b/gtk/gtkwin32embedwidget.h index 92515cfb8..21fdb54aa 100644 --- a/gtk/gtkwin32embedwidget.h +++ b/gtk/gtkwin32embedwidget.h @@ -65,7 +65,7 @@ struct _GtkWin32EmbedWidgetClass }; -GType gtk_win32_embed_widget_get_type (void) G_GNUC_CONST; +GType gtk_win32_embed_widget_get_type (void); GtkWidget* _gtk_win32_embed_widget_new (GdkNativeWindow parent_id); BOOL _gtk_win32_embed_widget_dialog_procedure (GtkWin32EmbedWidget *embed_widget, HWND wnd, UINT message, WPARAM wparam, LPARAM lparam); diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c index 26944b03e..74b9bcc4d 100644 --- a/gtk/gtkwindow.c +++ b/gtk/gtkwindow.c @@ -37,6 +37,7 @@ #include "gtkprivate.h" #include "gtkrc.h" #include "gtkwindow.h" +#include "gtkoffscreenwindow.h" #include "gtkwindow-decorate.h" #include "gtkbindings.h" #include "gtkkeyhash.h" @@ -196,6 +197,8 @@ struct _GtkWindowPrivate gdouble opacity; gchar *startup_id; + + guint32 initial_timestamp; }; static void gtk_window_dispose (GObject *object); @@ -955,6 +958,7 @@ gtk_window_init (GtkWindow *window) priv->type_hint = GDK_WINDOW_TYPE_HINT_NORMAL; priv->opacity = 1.0; priv->startup_id = NULL; + priv->initial_timestamp = GDK_CURRENT_TIME; priv->mnemonics_visible = TRUE; colormap = _gtk_widget_peek_colormap (); @@ -1409,9 +1413,11 @@ gtk_window_set_title (GtkWindow *window, if (gtk_widget_get_realized (GTK_WIDGET (window))) { - gdk_window_set_title (GTK_WIDGET (window)->window, window->title); + /* A NULL title is allowed, but GDK wants a string */ + gdk_window_set_title (GTK_WIDGET (window)->window, + window->title ? window->title : ""); - gtk_decorated_window_set_title (window, title); + gtk_decorated_window_set_title (window, window->title ? window->title : ""); } g_object_notify (G_OBJECT (window), "title"); @@ -4635,7 +4641,9 @@ gtk_window_map (GtkWidget *widget) if (window->frame) gdk_window_show (window->frame); - if (!disable_startup_notification) + if (!disable_startup_notification && + !GTK_IS_OFFSCREEN_WINDOW (window) && + window->type != GTK_WINDOW_POPUP) { /* Do we have a custom startup-notification id? */ if (priv->startup_id != NULL) @@ -4899,6 +4907,12 @@ gtk_window_realize (GtkWidget *widget) gdk_window_set_startup_id (widget->window, priv->startup_id); } +#ifdef GDK_WINDOWING_X11 + /* Timestamp passed to gtk_window_present_with_time() while hidden */ + if (priv->initial_timestamp != GDK_CURRENT_TIME) + gdk_x11_window_set_user_time (widget->window, priv->initial_timestamp); +#endif + /* Icons */ gtk_window_realize_icon (window); } @@ -6813,6 +6827,9 @@ gtk_window_present_with_time (GtkWindow *window, } else { + GtkWindowPrivate *priv = GTK_WINDOW_GET_PRIVATE (window); + + priv->initial_timestamp = timestamp; gtk_widget_show (widget); } } @@ -7730,6 +7747,8 @@ gtk_window_group_list_windows (GtkWindowGroup *window_group) group_windows = g_list_prepend (group_windows, window); } + g_list_free (toplevels); + return g_list_reverse (group_windows); } diff --git a/gtk/gtkwindow.h b/gtk/gtkwindow.h index 39202dc2a..30e83cc57 100644 --- a/gtk/gtkwindow.h +++ b/gtk/gtkwindow.h @@ -175,7 +175,7 @@ struct _GtkWindowGroupClass #define gtk_window_set_default_icon_from_file gtk_window_set_default_icon_from_file_utf8 #endif -GType gtk_window_get_type (void) G_GNUC_CONST; +GType gtk_window_get_type (void); GtkWidget* gtk_window_new (GtkWindowType type); void gtk_window_set_title (GtkWindow *window, const gchar *title); @@ -394,7 +394,7 @@ GtkWindowType gtk_window_get_window_type (GtkWindow *window); /* Window groups */ -GType gtk_window_group_get_type (void) G_GNUC_CONST; +GType gtk_window_group_get_type (void); GtkWindowGroup * gtk_window_group_new (void); void gtk_window_group_add_window (GtkWindowGroup *window_group, diff --git a/gtk/makefile.msc.in b/gtk/makefile.msc.in index 97db1b787..de938fbbb 100644 --- a/gtk/makefile.msc.in +++ b/gtk/makefile.msc.in @@ -120,10 +120,12 @@ gtk_OBJECTS_file = \ gtkfilechooserentry.obj \ gtkfilechoosersettings.obj \ gtkfilechooserutils.obj \ + gtkfileoperation.obj \ gtkfilechooserwidget.obj \ gtkfilefilter.obj \ gtkfilesystem.obj \ gtkfilesystemmodel.obj \ + gtkfilethumbnail.obj \ gtk_OBJECTS_print = \ gtkprint-win32.obj \ @@ -643,7 +645,7 @@ libgtk-win32-$(GTK_VER)-0.dll : $(gtk_SUBLIBS) gtk.def gtk-win32.res $(CC) $(CFLAGS) -LD -Fm -Fe$@ $(gtk_SUBLIBS) gtk-win32.res \ $(GDK_LIBS) $(GDK_PIXBUF_LIBS) $(PANGO_LIBS) $(INTL_LIBS) $(GLIB_LIBS) $(GMODULE_LIBS) \ $(CAIRO_LIBS) $(PANGOCAIRO_LIBS) \ - gdi32.lib user32.lib advapi32.lib wsock32.lib shell32.lib ole32.lib comdlg32.lib winspool.lib comctl32.lib \ + gdi32.lib user32.lib advapi32.lib wsock32.lib shell32.lib ole32.lib comdlg32.lib winspool.lib comctl32.lib mpr.lib \ $(LDFLAGS) /implib:gtk-win32-$(GTK_VER).lib /def:gtk.def gtk-win32-$(GTK_VER)s.lib : $(gtk_OBJECTS) diff --git a/gtk/makegtkalias.pl b/gtk/makegtkalias.pl index 67ec7c973..fb35544fb 100755 --- a/gtk/makegtkalias.pl +++ b/gtk/makegtkalias.pl @@ -14,7 +14,7 @@ print < -#if defined(G_HAVE_GNUC_VISIBILITY) && !defined(__APPLE__) +#if defined(G_HAVE_GNUC_VISIBILITY) && !defined(__APPLE__) && !defined(G_OS_WIN32) EOF diff --git a/gtk/stock-icons/16/audio-volume-high.png b/gtk/stock-icons/16/audio-volume-high.png new file mode 100644 index 000000000..85f455268 Binary files /dev/null and b/gtk/stock-icons/16/audio-volume-high.png differ diff --git a/gtk/stock-icons/16/audio-volume-low.png b/gtk/stock-icons/16/audio-volume-low.png new file mode 100644 index 000000000..de1ef303a Binary files /dev/null and b/gtk/stock-icons/16/audio-volume-low.png differ diff --git a/gtk/stock-icons/16/audio-volume-medium.png b/gtk/stock-icons/16/audio-volume-medium.png new file mode 100644 index 000000000..593a39407 Binary files /dev/null and b/gtk/stock-icons/16/audio-volume-medium.png differ diff --git a/gtk/stock-icons/16/audio-volume-muted.png b/gtk/stock-icons/16/audio-volume-muted.png new file mode 100644 index 000000000..ed7cf1b6b Binary files /dev/null and b/gtk/stock-icons/16/audio-volume-muted.png differ diff --git a/gtk/stock-icons/16/dialog-error.png b/gtk/stock-icons/16/dialog-error.png new file mode 100644 index 000000000..b74281e3b Binary files /dev/null and b/gtk/stock-icons/16/dialog-error.png differ diff --git a/gtk/stock-icons/16/dialog-password.png b/gtk/stock-icons/16/dialog-password.png new file mode 100644 index 000000000..b04f31503 Binary files /dev/null and b/gtk/stock-icons/16/dialog-password.png differ diff --git a/gtk/stock-icons/16/dialog-question.png b/gtk/stock-icons/16/dialog-question.png new file mode 100644 index 000000000..1d6466667 Binary files /dev/null and b/gtk/stock-icons/16/dialog-question.png differ diff --git a/gtk/stock-icons/16/dialog-warning.png b/gtk/stock-icons/16/dialog-warning.png new file mode 100644 index 000000000..d8c71f447 Binary files /dev/null and b/gtk/stock-icons/16/dialog-warning.png differ diff --git a/gtk/stock-icons/16/gtk-apply.png b/gtk/stock-icons/16/gtk-apply.png new file mode 100644 index 000000000..c59a2e75c Binary files /dev/null and b/gtk/stock-icons/16/gtk-apply.png differ diff --git a/gtk/stock-icons/16/gtk-cancel.png b/gtk/stock-icons/16/gtk-cancel.png new file mode 100644 index 000000000..51b66d24c Binary files /dev/null and b/gtk/stock-icons/16/gtk-cancel.png differ diff --git a/gtk/stock-icons/16/gtk-dnd-multiple.png b/gtk/stock-icons/16/gtk-dnd-multiple.png new file mode 100644 index 000000000..1d20a5ef3 Binary files /dev/null and b/gtk/stock-icons/16/gtk-dnd-multiple.png differ diff --git a/gtk/stock-icons/16/gtk-dnd.png b/gtk/stock-icons/16/gtk-dnd.png new file mode 100644 index 000000000..9f629796d Binary files /dev/null and b/gtk/stock-icons/16/gtk-dnd.png differ diff --git a/gtk/stock-icons/16/gtk-no.png b/gtk/stock-icons/16/gtk-no.png new file mode 100644 index 000000000..98d447f43 Binary files /dev/null and b/gtk/stock-icons/16/gtk-no.png differ diff --git a/gtk/stock-icons/16/gtk-ok.png b/gtk/stock-icons/16/gtk-ok.png new file mode 100644 index 000000000..c3527ab91 Binary files /dev/null and b/gtk/stock-icons/16/gtk-ok.png differ diff --git a/gtk/stock-icons/16/gtk-yes.png b/gtk/stock-icons/16/gtk-yes.png new file mode 100644 index 000000000..de22e1037 Binary files /dev/null and b/gtk/stock-icons/16/gtk-yes.png differ diff --git a/gtk/stock-icons/18/application-exit.png b/gtk/stock-icons/18/application-exit.png new file mode 100644 index 000000000..9126272c7 Binary files /dev/null and b/gtk/stock-icons/18/application-exit.png differ diff --git a/gtk/stock-icons/18/audio-volume-high.png b/gtk/stock-icons/18/audio-volume-high.png new file mode 100644 index 000000000..e0861cb6a Binary files /dev/null and b/gtk/stock-icons/18/audio-volume-high.png differ diff --git a/gtk/stock-icons/18/audio-volume-low.png b/gtk/stock-icons/18/audio-volume-low.png new file mode 100644 index 000000000..fca7e2ae1 Binary files /dev/null and b/gtk/stock-icons/18/audio-volume-low.png differ diff --git a/gtk/stock-icons/18/audio-volume-medium.png b/gtk/stock-icons/18/audio-volume-medium.png new file mode 100644 index 000000000..f4a97dadc Binary files /dev/null and b/gtk/stock-icons/18/audio-volume-medium.png differ diff --git a/gtk/stock-icons/18/audio-volume-muted.png b/gtk/stock-icons/18/audio-volume-muted.png new file mode 100644 index 000000000..e0cc82256 Binary files /dev/null and b/gtk/stock-icons/18/audio-volume-muted.png differ diff --git a/gtk/stock-icons/18/dialog-error.png b/gtk/stock-icons/18/dialog-error.png new file mode 100644 index 000000000..411dff404 Binary files /dev/null and b/gtk/stock-icons/18/dialog-error.png differ diff --git a/gtk/stock-icons/18/dialog-information.png b/gtk/stock-icons/18/dialog-information.png new file mode 100644 index 000000000..f2f717a30 Binary files /dev/null and b/gtk/stock-icons/18/dialog-information.png differ diff --git a/gtk/stock-icons/18/dialog-password.png b/gtk/stock-icons/18/dialog-password.png new file mode 100644 index 000000000..655680ce7 Binary files /dev/null and b/gtk/stock-icons/18/dialog-password.png differ diff --git a/gtk/stock-icons/18/dialog-question.png b/gtk/stock-icons/18/dialog-question.png new file mode 100644 index 000000000..43756fc0f Binary files /dev/null and b/gtk/stock-icons/18/dialog-question.png differ diff --git a/gtk/stock-icons/18/dialog-warning.png b/gtk/stock-icons/18/dialog-warning.png new file mode 100644 index 000000000..8e3672726 Binary files /dev/null and b/gtk/stock-icons/18/dialog-warning.png differ diff --git a/gtk/stock-icons/18/document-new.png b/gtk/stock-icons/18/document-new.png new file mode 100644 index 000000000..4910645dc Binary files /dev/null and b/gtk/stock-icons/18/document-new.png differ diff --git a/gtk/stock-icons/18/document-open-recent.png b/gtk/stock-icons/18/document-open-recent.png new file mode 100644 index 000000000..55b16be0e Binary files /dev/null and b/gtk/stock-icons/18/document-open-recent.png differ diff --git a/gtk/stock-icons/18/document-open.png b/gtk/stock-icons/18/document-open.png new file mode 100644 index 000000000..84f9abb8a Binary files /dev/null and b/gtk/stock-icons/18/document-open.png differ diff --git a/gtk/stock-icons/18/document-print-preview.png b/gtk/stock-icons/18/document-print-preview.png new file mode 100644 index 000000000..502cf328a Binary files /dev/null and b/gtk/stock-icons/18/document-print-preview.png differ diff --git a/gtk/stock-icons/18/document-print.png b/gtk/stock-icons/18/document-print.png new file mode 100644 index 000000000..1bf87b05d Binary files /dev/null and b/gtk/stock-icons/18/document-print.png differ diff --git a/gtk/stock-icons/18/document-properties.png b/gtk/stock-icons/18/document-properties.png new file mode 100644 index 000000000..c5f77ff44 Binary files /dev/null and b/gtk/stock-icons/18/document-properties.png differ diff --git a/gtk/stock-icons/18/document-revert-ltr.png b/gtk/stock-icons/18/document-revert-ltr.png new file mode 100644 index 000000000..249f9d761 Binary files /dev/null and b/gtk/stock-icons/18/document-revert-ltr.png differ diff --git a/gtk/stock-icons/18/document-revert-rtl.png b/gtk/stock-icons/18/document-revert-rtl.png new file mode 100644 index 000000000..a3c962227 Binary files /dev/null and b/gtk/stock-icons/18/document-revert-rtl.png differ diff --git a/gtk/stock-icons/18/document-save-as.png b/gtk/stock-icons/18/document-save-as.png new file mode 100644 index 000000000..d6745fe4a Binary files /dev/null and b/gtk/stock-icons/18/document-save-as.png differ diff --git a/gtk/stock-icons/18/drive-harddisk.png b/gtk/stock-icons/18/drive-harddisk.png new file mode 100644 index 000000000..6b8b0f1fb Binary files /dev/null and b/gtk/stock-icons/18/drive-harddisk.png differ diff --git a/gtk/stock-icons/18/edit-clear.png b/gtk/stock-icons/18/edit-clear.png new file mode 100644 index 000000000..8c5ac6ec4 Binary files /dev/null and b/gtk/stock-icons/18/edit-clear.png differ diff --git a/gtk/stock-icons/18/edit-copy.png b/gtk/stock-icons/18/edit-copy.png new file mode 100644 index 000000000..6e58c33a9 Binary files /dev/null and b/gtk/stock-icons/18/edit-copy.png differ diff --git a/gtk/stock-icons/18/edit-cut.png b/gtk/stock-icons/18/edit-cut.png new file mode 100644 index 000000000..a17970dc3 Binary files /dev/null and b/gtk/stock-icons/18/edit-cut.png differ diff --git a/gtk/stock-icons/18/edit-delete.png b/gtk/stock-icons/18/edit-delete.png new file mode 100644 index 000000000..5e92954c3 Binary files /dev/null and b/gtk/stock-icons/18/edit-delete.png differ diff --git a/gtk/stock-icons/18/edit-find-replace.png b/gtk/stock-icons/18/edit-find-replace.png new file mode 100644 index 000000000..35037d394 Binary files /dev/null and b/gtk/stock-icons/18/edit-find-replace.png differ diff --git a/gtk/stock-icons/18/edit-find.png b/gtk/stock-icons/18/edit-find.png new file mode 100644 index 000000000..496add1f0 Binary files /dev/null and b/gtk/stock-icons/18/edit-find.png differ diff --git a/gtk/stock-icons/18/edit-paste.png b/gtk/stock-icons/18/edit-paste.png new file mode 100644 index 000000000..8a70bafb3 Binary files /dev/null and b/gtk/stock-icons/18/edit-paste.png differ diff --git a/gtk/stock-icons/18/edit-redo-ltr.png b/gtk/stock-icons/18/edit-redo-ltr.png new file mode 100644 index 000000000..fb5deabb7 Binary files /dev/null and b/gtk/stock-icons/18/edit-redo-ltr.png differ diff --git a/gtk/stock-icons/18/edit-redo-rtl.png b/gtk/stock-icons/18/edit-redo-rtl.png new file mode 100644 index 000000000..aceb27c4d Binary files /dev/null and b/gtk/stock-icons/18/edit-redo-rtl.png differ diff --git a/gtk/stock-icons/18/edit-select-all.png b/gtk/stock-icons/18/edit-select-all.png new file mode 100644 index 000000000..9da60196f Binary files /dev/null and b/gtk/stock-icons/18/edit-select-all.png differ diff --git a/gtk/stock-icons/18/edit-undo-ltr.png b/gtk/stock-icons/18/edit-undo-ltr.png new file mode 100644 index 000000000..58049c975 Binary files /dev/null and b/gtk/stock-icons/18/edit-undo-ltr.png differ diff --git a/gtk/stock-icons/18/edit-undo-rtl.png b/gtk/stock-icons/18/edit-undo-rtl.png new file mode 100644 index 000000000..3f12f5381 Binary files /dev/null and b/gtk/stock-icons/18/edit-undo-rtl.png differ diff --git a/gtk/stock-icons/18/folder.png b/gtk/stock-icons/18/folder.png new file mode 100644 index 000000000..0fa176449 Binary files /dev/null and b/gtk/stock-icons/18/folder.png differ diff --git a/gtk/stock-icons/18/format-indent-less-ltr.png b/gtk/stock-icons/18/format-indent-less-ltr.png new file mode 100644 index 000000000..f1c4b2490 Binary files /dev/null and b/gtk/stock-icons/18/format-indent-less-ltr.png differ diff --git a/gtk/stock-icons/18/format-indent-less-rtl.png b/gtk/stock-icons/18/format-indent-less-rtl.png new file mode 100644 index 000000000..b33dcf55a Binary files /dev/null and b/gtk/stock-icons/18/format-indent-less-rtl.png differ diff --git a/gtk/stock-icons/18/format-indent-more-ltr.png b/gtk/stock-icons/18/format-indent-more-ltr.png new file mode 100644 index 000000000..e6da4b4af Binary files /dev/null and b/gtk/stock-icons/18/format-indent-more-ltr.png differ diff --git a/gtk/stock-icons/18/format-indent-more-rtl.png b/gtk/stock-icons/18/format-indent-more-rtl.png new file mode 100644 index 000000000..3252419f8 Binary files /dev/null and b/gtk/stock-icons/18/format-indent-more-rtl.png differ diff --git a/gtk/stock-icons/18/format-justify-center.png b/gtk/stock-icons/18/format-justify-center.png new file mode 100644 index 000000000..f238805db Binary files /dev/null and b/gtk/stock-icons/18/format-justify-center.png differ diff --git a/gtk/stock-icons/18/format-justify-fill.png b/gtk/stock-icons/18/format-justify-fill.png new file mode 100644 index 000000000..ebfb31b47 Binary files /dev/null and b/gtk/stock-icons/18/format-justify-fill.png differ diff --git a/gtk/stock-icons/18/format-justify-left.png b/gtk/stock-icons/18/format-justify-left.png new file mode 100644 index 000000000..3bd449d1a Binary files /dev/null and b/gtk/stock-icons/18/format-justify-left.png differ diff --git a/gtk/stock-icons/18/format-justify-right.png b/gtk/stock-icons/18/format-justify-right.png new file mode 100644 index 000000000..ff7bf3589 Binary files /dev/null and b/gtk/stock-icons/18/format-justify-right.png differ diff --git a/gtk/stock-icons/18/format-text-bold.png b/gtk/stock-icons/18/format-text-bold.png new file mode 100644 index 000000000..a58c68d9d Binary files /dev/null and b/gtk/stock-icons/18/format-text-bold.png differ diff --git a/gtk/stock-icons/18/format-text-italic.png b/gtk/stock-icons/18/format-text-italic.png new file mode 100644 index 000000000..a6eff7cff Binary files /dev/null and b/gtk/stock-icons/18/format-text-italic.png differ diff --git a/gtk/stock-icons/18/format-text-strikethrough.png b/gtk/stock-icons/18/format-text-strikethrough.png new file mode 100644 index 000000000..efa070f09 Binary files /dev/null and b/gtk/stock-icons/18/format-text-strikethrough.png differ diff --git a/gtk/stock-icons/18/format-text-underline.png b/gtk/stock-icons/18/format-text-underline.png new file mode 100644 index 000000000..29794ec08 Binary files /dev/null and b/gtk/stock-icons/18/format-text-underline.png differ diff --git a/gtk/stock-icons/18/go-bottom.png b/gtk/stock-icons/18/go-bottom.png new file mode 100644 index 000000000..9dde3bce0 Binary files /dev/null and b/gtk/stock-icons/18/go-bottom.png differ diff --git a/gtk/stock-icons/18/go-down.png b/gtk/stock-icons/18/go-down.png new file mode 100644 index 000000000..38a5a731a Binary files /dev/null and b/gtk/stock-icons/18/go-down.png differ diff --git a/gtk/stock-icons/18/go-first-ltr.png b/gtk/stock-icons/18/go-first-ltr.png new file mode 100644 index 000000000..42951107e Binary files /dev/null and b/gtk/stock-icons/18/go-first-ltr.png differ diff --git a/gtk/stock-icons/18/go-home.png b/gtk/stock-icons/18/go-home.png new file mode 100644 index 000000000..f4c08e243 Binary files /dev/null and b/gtk/stock-icons/18/go-home.png differ diff --git a/gtk/stock-icons/18/go-jump-ltr.png b/gtk/stock-icons/18/go-jump-ltr.png new file mode 100644 index 000000000..b90d8ba5d Binary files /dev/null and b/gtk/stock-icons/18/go-jump-ltr.png differ diff --git a/gtk/stock-icons/18/go-jump-rtl.png b/gtk/stock-icons/18/go-jump-rtl.png new file mode 100644 index 000000000..04f7a82fb Binary files /dev/null and b/gtk/stock-icons/18/go-jump-rtl.png differ diff --git a/gtk/stock-icons/18/go-last-ltr.png b/gtk/stock-icons/18/go-last-ltr.png new file mode 100644 index 000000000..938d61628 Binary files /dev/null and b/gtk/stock-icons/18/go-last-ltr.png differ diff --git a/gtk/stock-icons/18/go-next-ltr.png b/gtk/stock-icons/18/go-next-ltr.png new file mode 100644 index 000000000..776c32f0c Binary files /dev/null and b/gtk/stock-icons/18/go-next-ltr.png differ diff --git a/gtk/stock-icons/18/go-previous-ltr.png b/gtk/stock-icons/18/go-previous-ltr.png new file mode 100644 index 000000000..211adfa3a Binary files /dev/null and b/gtk/stock-icons/18/go-previous-ltr.png differ diff --git a/gtk/stock-icons/18/go-top.png b/gtk/stock-icons/18/go-top.png new file mode 100644 index 000000000..4909f7c2a Binary files /dev/null and b/gtk/stock-icons/18/go-top.png differ diff --git a/gtk/stock-icons/18/go-up.png b/gtk/stock-icons/18/go-up.png new file mode 100644 index 000000000..590667263 Binary files /dev/null and b/gtk/stock-icons/18/go-up.png differ diff --git a/gtk/stock-icons/18/gtk-apply.png b/gtk/stock-icons/18/gtk-apply.png new file mode 100644 index 000000000..4821125ad Binary files /dev/null and b/gtk/stock-icons/18/gtk-apply.png differ diff --git a/gtk/stock-icons/18/gtk-cancel.png b/gtk/stock-icons/18/gtk-cancel.png new file mode 100644 index 000000000..d26fc8c03 Binary files /dev/null and b/gtk/stock-icons/18/gtk-cancel.png differ diff --git a/gtk/stock-icons/18/gtk-caps-lock-warning.png b/gtk/stock-icons/18/gtk-caps-lock-warning.png new file mode 100644 index 000000000..5818dc0e2 Binary files /dev/null and b/gtk/stock-icons/18/gtk-caps-lock-warning.png differ diff --git a/gtk/stock-icons/18/gtk-color-picker.png b/gtk/stock-icons/18/gtk-color-picker.png new file mode 100644 index 000000000..024b584ec Binary files /dev/null and b/gtk/stock-icons/18/gtk-color-picker.png differ diff --git a/gtk/stock-icons/18/gtk-connect.png b/gtk/stock-icons/18/gtk-connect.png new file mode 100644 index 000000000..86597db70 Binary files /dev/null and b/gtk/stock-icons/18/gtk-connect.png differ diff --git a/gtk/stock-icons/18/gtk-convert.png b/gtk/stock-icons/18/gtk-convert.png new file mode 100644 index 000000000..6249db836 Binary files /dev/null and b/gtk/stock-icons/18/gtk-convert.png differ diff --git a/gtk/stock-icons/18/gtk-disconnect.png b/gtk/stock-icons/18/gtk-disconnect.png new file mode 100644 index 000000000..e5b2e853a Binary files /dev/null and b/gtk/stock-icons/18/gtk-disconnect.png differ diff --git a/gtk/stock-icons/18/gtk-dnd-multiple.png b/gtk/stock-icons/18/gtk-dnd-multiple.png new file mode 100644 index 000000000..e7510ece6 Binary files /dev/null and b/gtk/stock-icons/18/gtk-dnd-multiple.png differ diff --git a/gtk/stock-icons/18/gtk-dnd.png b/gtk/stock-icons/18/gtk-dnd.png new file mode 100644 index 000000000..ae009d614 Binary files /dev/null and b/gtk/stock-icons/18/gtk-dnd.png differ diff --git a/gtk/stock-icons/18/gtk-edit.png b/gtk/stock-icons/18/gtk-edit.png new file mode 100644 index 000000000..23edf2df9 Binary files /dev/null and b/gtk/stock-icons/18/gtk-edit.png differ diff --git a/gtk/stock-icons/18/gtk-font.png b/gtk/stock-icons/18/gtk-font.png new file mode 100644 index 000000000..6aa12ca7c Binary files /dev/null and b/gtk/stock-icons/18/gtk-font.png differ diff --git a/gtk/stock-icons/18/gtk-index.png b/gtk/stock-icons/18/gtk-index.png new file mode 100644 index 000000000..2effbb28e Binary files /dev/null and b/gtk/stock-icons/18/gtk-index.png differ diff --git a/gtk/stock-icons/18/gtk-no.png b/gtk/stock-icons/18/gtk-no.png new file mode 100644 index 000000000..f69476bd9 Binary files /dev/null and b/gtk/stock-icons/18/gtk-no.png differ diff --git a/gtk/stock-icons/18/gtk-ok.png b/gtk/stock-icons/18/gtk-ok.png new file mode 100644 index 000000000..f6ede74a8 Binary files /dev/null and b/gtk/stock-icons/18/gtk-ok.png differ diff --git a/gtk/stock-icons/18/gtk-orientation-landscape.png b/gtk/stock-icons/18/gtk-orientation-landscape.png new file mode 100644 index 000000000..53814499c Binary files /dev/null and b/gtk/stock-icons/18/gtk-orientation-landscape.png differ diff --git a/gtk/stock-icons/18/gtk-orientation-portrait.png b/gtk/stock-icons/18/gtk-orientation-portrait.png new file mode 100644 index 000000000..6a6c18f54 Binary files /dev/null and b/gtk/stock-icons/18/gtk-orientation-portrait.png differ diff --git a/gtk/stock-icons/18/gtk-orientation-reverse-landscape.png b/gtk/stock-icons/18/gtk-orientation-reverse-landscape.png new file mode 100644 index 000000000..57992e7c6 Binary files /dev/null and b/gtk/stock-icons/18/gtk-orientation-reverse-landscape.png differ diff --git a/gtk/stock-icons/18/gtk-orientation-reverse-portrait.png b/gtk/stock-icons/18/gtk-orientation-reverse-portrait.png new file mode 100644 index 000000000..5ee56cfd8 Binary files /dev/null and b/gtk/stock-icons/18/gtk-orientation-reverse-portrait.png differ diff --git a/gtk/stock-icons/18/gtk-page-setup.png b/gtk/stock-icons/18/gtk-page-setup.png new file mode 100644 index 000000000..7771b581e Binary files /dev/null and b/gtk/stock-icons/18/gtk-page-setup.png differ diff --git a/gtk/stock-icons/18/gtk-preferences.png b/gtk/stock-icons/18/gtk-preferences.png new file mode 100644 index 000000000..f69e940a1 Binary files /dev/null and b/gtk/stock-icons/18/gtk-preferences.png differ diff --git a/gtk/stock-icons/18/gtk-select-color.png b/gtk/stock-icons/18/gtk-select-color.png new file mode 100644 index 000000000..b71cbc732 Binary files /dev/null and b/gtk/stock-icons/18/gtk-select-color.png differ diff --git a/gtk/stock-icons/18/gtk-select-font.png b/gtk/stock-icons/18/gtk-select-font.png new file mode 100644 index 000000000..265f14330 Binary files /dev/null and b/gtk/stock-icons/18/gtk-select-font.png differ diff --git a/gtk/stock-icons/18/gtk-undelete-ltr.png b/gtk/stock-icons/18/gtk-undelete-ltr.png new file mode 100644 index 000000000..38d38be07 Binary files /dev/null and b/gtk/stock-icons/18/gtk-undelete-ltr.png differ diff --git a/gtk/stock-icons/18/gtk-undelete-rtl.png b/gtk/stock-icons/18/gtk-undelete-rtl.png new file mode 100644 index 000000000..d70a34062 Binary files /dev/null and b/gtk/stock-icons/18/gtk-undelete-rtl.png differ diff --git a/gtk/stock-icons/18/gtk-yes.png b/gtk/stock-icons/18/gtk-yes.png new file mode 100644 index 000000000..8c7182566 Binary files /dev/null and b/gtk/stock-icons/18/gtk-yes.png differ diff --git a/gtk/stock-icons/18/help-about.png b/gtk/stock-icons/18/help-about.png new file mode 100644 index 000000000..53ec35deb Binary files /dev/null and b/gtk/stock-icons/18/help-about.png differ diff --git a/gtk/stock-icons/18/help-contents.png b/gtk/stock-icons/18/help-contents.png new file mode 100644 index 000000000..7d5c5a2cb Binary files /dev/null and b/gtk/stock-icons/18/help-contents.png differ diff --git a/gtk/stock-icons/18/image-missing.png b/gtk/stock-icons/18/image-missing.png new file mode 100644 index 000000000..c3bad94ea Binary files /dev/null and b/gtk/stock-icons/18/image-missing.png differ diff --git a/gtk/stock-icons/18/list-add.png b/gtk/stock-icons/18/list-add.png new file mode 100644 index 000000000..e99866d55 Binary files /dev/null and b/gtk/stock-icons/18/list-add.png differ diff --git a/gtk/stock-icons/18/list-remove.png b/gtk/stock-icons/18/list-remove.png new file mode 100644 index 000000000..b886a4d99 Binary files /dev/null and b/gtk/stock-icons/18/list-remove.png differ diff --git a/gtk/stock-icons/18/media-floppy.png b/gtk/stock-icons/18/media-floppy.png new file mode 100644 index 000000000..62d25e984 Binary files /dev/null and b/gtk/stock-icons/18/media-floppy.png differ diff --git a/gtk/stock-icons/18/media-optical.png b/gtk/stock-icons/18/media-optical.png new file mode 100644 index 000000000..aba244232 Binary files /dev/null and b/gtk/stock-icons/18/media-optical.png differ diff --git a/gtk/stock-icons/18/media-playback-pause.png b/gtk/stock-icons/18/media-playback-pause.png new file mode 100644 index 000000000..fd7253c97 Binary files /dev/null and b/gtk/stock-icons/18/media-playback-pause.png differ diff --git a/gtk/stock-icons/18/media-playback-start-ltr.png b/gtk/stock-icons/18/media-playback-start-ltr.png new file mode 100644 index 000000000..cdc52c2a1 Binary files /dev/null and b/gtk/stock-icons/18/media-playback-start-ltr.png differ diff --git a/gtk/stock-icons/18/media-playback-start-rtl.png b/gtk/stock-icons/18/media-playback-start-rtl.png new file mode 100644 index 000000000..531b450de Binary files /dev/null and b/gtk/stock-icons/18/media-playback-start-rtl.png differ diff --git a/gtk/stock-icons/18/media-playback-stop.png b/gtk/stock-icons/18/media-playback-stop.png new file mode 100644 index 000000000..c41a2ae7b Binary files /dev/null and b/gtk/stock-icons/18/media-playback-stop.png differ diff --git a/gtk/stock-icons/18/media-record.png b/gtk/stock-icons/18/media-record.png new file mode 100644 index 000000000..f4db6fecd Binary files /dev/null and b/gtk/stock-icons/18/media-record.png differ diff --git a/gtk/stock-icons/18/media-seek-backward-ltr.png b/gtk/stock-icons/18/media-seek-backward-ltr.png new file mode 100644 index 000000000..88eb9ae3a Binary files /dev/null and b/gtk/stock-icons/18/media-seek-backward-ltr.png differ diff --git a/gtk/stock-icons/18/media-seek-forward-ltr.png b/gtk/stock-icons/18/media-seek-forward-ltr.png new file mode 100644 index 000000000..432cf51bc Binary files /dev/null and b/gtk/stock-icons/18/media-seek-forward-ltr.png differ diff --git a/gtk/stock-icons/18/media-skip-backward-ltr.png b/gtk/stock-icons/18/media-skip-backward-ltr.png new file mode 100644 index 000000000..97119d6d7 Binary files /dev/null and b/gtk/stock-icons/18/media-skip-backward-ltr.png differ diff --git a/gtk/stock-icons/18/media-skip-forward-ltr.png b/gtk/stock-icons/18/media-skip-forward-ltr.png new file mode 100644 index 000000000..e93ff5062 Binary files /dev/null and b/gtk/stock-icons/18/media-skip-forward-ltr.png differ diff --git a/gtk/stock-icons/18/network-idle.png b/gtk/stock-icons/18/network-idle.png new file mode 100644 index 000000000..284d914f0 Binary files /dev/null and b/gtk/stock-icons/18/network-idle.png differ diff --git a/gtk/stock-icons/18/printer-error.png b/gtk/stock-icons/18/printer-error.png new file mode 100644 index 000000000..921bf4ace Binary files /dev/null and b/gtk/stock-icons/18/printer-error.png differ diff --git a/gtk/stock-icons/18/printer-info.png b/gtk/stock-icons/18/printer-info.png new file mode 100644 index 000000000..3e02b1c2a Binary files /dev/null and b/gtk/stock-icons/18/printer-info.png differ diff --git a/gtk/stock-icons/18/printer-paused.png b/gtk/stock-icons/18/printer-paused.png new file mode 100644 index 000000000..fe5e2e414 Binary files /dev/null and b/gtk/stock-icons/18/printer-paused.png differ diff --git a/gtk/stock-icons/18/printer-warning.png b/gtk/stock-icons/18/printer-warning.png new file mode 100644 index 000000000..393a5cae3 Binary files /dev/null and b/gtk/stock-icons/18/printer-warning.png differ diff --git a/gtk/stock-icons/18/process-stop.png b/gtk/stock-icons/18/process-stop.png new file mode 100644 index 000000000..0694b4b8d Binary files /dev/null and b/gtk/stock-icons/18/process-stop.png differ diff --git a/gtk/stock-icons/18/system-run.png b/gtk/stock-icons/18/system-run.png new file mode 100644 index 000000000..1f17f7f69 Binary files /dev/null and b/gtk/stock-icons/18/system-run.png differ diff --git a/gtk/stock-icons/18/text-x-generic.png b/gtk/stock-icons/18/text-x-generic.png new file mode 100644 index 000000000..4910645dc Binary files /dev/null and b/gtk/stock-icons/18/text-x-generic.png differ diff --git a/gtk/stock-icons/18/tools-check-spelling.png b/gtk/stock-icons/18/tools-check-spelling.png new file mode 100644 index 000000000..db5d578c2 Binary files /dev/null and b/gtk/stock-icons/18/tools-check-spelling.png differ diff --git a/gtk/stock-icons/18/view-fullscreen.png b/gtk/stock-icons/18/view-fullscreen.png new file mode 100644 index 000000000..e2466d3f3 Binary files /dev/null and b/gtk/stock-icons/18/view-fullscreen.png differ diff --git a/gtk/stock-icons/18/view-refresh.png b/gtk/stock-icons/18/view-refresh.png new file mode 100644 index 000000000..4a93c0259 Binary files /dev/null and b/gtk/stock-icons/18/view-refresh.png differ diff --git a/gtk/stock-icons/18/view-restore.png b/gtk/stock-icons/18/view-restore.png new file mode 100644 index 000000000..e2ab564aa Binary files /dev/null and b/gtk/stock-icons/18/view-restore.png differ diff --git a/gtk/stock-icons/18/view-sort-ascending.png b/gtk/stock-icons/18/view-sort-ascending.png new file mode 100644 index 000000000..a4f368938 Binary files /dev/null and b/gtk/stock-icons/18/view-sort-ascending.png differ diff --git a/gtk/stock-icons/18/view-sort-descending.png b/gtk/stock-icons/18/view-sort-descending.png new file mode 100644 index 000000000..af4dd59b4 Binary files /dev/null and b/gtk/stock-icons/18/view-sort-descending.png differ diff --git a/gtk/stock-icons/18/window-close.png b/gtk/stock-icons/18/window-close.png new file mode 100644 index 000000000..fe617218d Binary files /dev/null and b/gtk/stock-icons/18/window-close.png differ diff --git a/gtk/stock-icons/18/zoom-fit-best.png b/gtk/stock-icons/18/zoom-fit-best.png new file mode 100644 index 000000000..795e8f060 Binary files /dev/null and b/gtk/stock-icons/18/zoom-fit-best.png differ diff --git a/gtk/stock-icons/18/zoom-in.png b/gtk/stock-icons/18/zoom-in.png new file mode 100644 index 000000000..c4ecb3f10 Binary files /dev/null and b/gtk/stock-icons/18/zoom-in.png differ diff --git a/gtk/stock-icons/18/zoom-original.png b/gtk/stock-icons/18/zoom-original.png new file mode 100644 index 000000000..5c859a170 Binary files /dev/null and b/gtk/stock-icons/18/zoom-original.png differ diff --git a/gtk/stock-icons/18/zoom-out.png b/gtk/stock-icons/18/zoom-out.png new file mode 100644 index 000000000..ad239b6e3 Binary files /dev/null and b/gtk/stock-icons/18/zoom-out.png differ diff --git a/gtk/stock-icons/20/application-exit.png b/gtk/stock-icons/20/application-exit.png new file mode 100644 index 000000000..5b2526e92 Binary files /dev/null and b/gtk/stock-icons/20/application-exit.png differ diff --git a/gtk/stock-icons/20/audio-volume-high.png b/gtk/stock-icons/20/audio-volume-high.png new file mode 100644 index 000000000..bfda8401d Binary files /dev/null and b/gtk/stock-icons/20/audio-volume-high.png differ diff --git a/gtk/stock-icons/20/audio-volume-low.png b/gtk/stock-icons/20/audio-volume-low.png new file mode 100644 index 000000000..9482ffbc5 Binary files /dev/null and b/gtk/stock-icons/20/audio-volume-low.png differ diff --git a/gtk/stock-icons/20/audio-volume-medium.png b/gtk/stock-icons/20/audio-volume-medium.png new file mode 100644 index 000000000..afb5e213a Binary files /dev/null and b/gtk/stock-icons/20/audio-volume-medium.png differ diff --git a/gtk/stock-icons/20/audio-volume-muted.png b/gtk/stock-icons/20/audio-volume-muted.png new file mode 100644 index 000000000..956698941 Binary files /dev/null and b/gtk/stock-icons/20/audio-volume-muted.png differ diff --git a/gtk/stock-icons/20/dialog-error.png b/gtk/stock-icons/20/dialog-error.png new file mode 100644 index 000000000..ab27b1bd4 Binary files /dev/null and b/gtk/stock-icons/20/dialog-error.png differ diff --git a/gtk/stock-icons/20/dialog-information.png b/gtk/stock-icons/20/dialog-information.png new file mode 100644 index 000000000..4a356972d Binary files /dev/null and b/gtk/stock-icons/20/dialog-information.png differ diff --git a/gtk/stock-icons/20/dialog-password.png b/gtk/stock-icons/20/dialog-password.png new file mode 100644 index 000000000..66c9fa83a Binary files /dev/null and b/gtk/stock-icons/20/dialog-password.png differ diff --git a/gtk/stock-icons/20/dialog-question.png b/gtk/stock-icons/20/dialog-question.png new file mode 100644 index 000000000..4701ccf03 Binary files /dev/null and b/gtk/stock-icons/20/dialog-question.png differ diff --git a/gtk/stock-icons/20/dialog-warning.png b/gtk/stock-icons/20/dialog-warning.png new file mode 100644 index 000000000..1b45d8bc4 Binary files /dev/null and b/gtk/stock-icons/20/dialog-warning.png differ diff --git a/gtk/stock-icons/20/document-new.png b/gtk/stock-icons/20/document-new.png new file mode 100644 index 000000000..de7fa5dcb Binary files /dev/null and b/gtk/stock-icons/20/document-new.png differ diff --git a/gtk/stock-icons/20/document-open-recent.png b/gtk/stock-icons/20/document-open-recent.png new file mode 100644 index 000000000..b997f7277 Binary files /dev/null and b/gtk/stock-icons/20/document-open-recent.png differ diff --git a/gtk/stock-icons/20/document-open.png b/gtk/stock-icons/20/document-open.png new file mode 100644 index 000000000..74ceaec09 Binary files /dev/null and b/gtk/stock-icons/20/document-open.png differ diff --git a/gtk/stock-icons/20/document-print-preview.png b/gtk/stock-icons/20/document-print-preview.png new file mode 100644 index 000000000..4f9e9e2dc Binary files /dev/null and b/gtk/stock-icons/20/document-print-preview.png differ diff --git a/gtk/stock-icons/20/document-print.png b/gtk/stock-icons/20/document-print.png new file mode 100644 index 000000000..cc7766718 Binary files /dev/null and b/gtk/stock-icons/20/document-print.png differ diff --git a/gtk/stock-icons/20/document-properties.png b/gtk/stock-icons/20/document-properties.png new file mode 100644 index 000000000..e485bb032 Binary files /dev/null and b/gtk/stock-icons/20/document-properties.png differ diff --git a/gtk/stock-icons/20/document-revert-ltr.png b/gtk/stock-icons/20/document-revert-ltr.png new file mode 100644 index 000000000..e5fd61b98 Binary files /dev/null and b/gtk/stock-icons/20/document-revert-ltr.png differ diff --git a/gtk/stock-icons/20/document-revert-rtl.png b/gtk/stock-icons/20/document-revert-rtl.png new file mode 100644 index 000000000..a5709e360 Binary files /dev/null and b/gtk/stock-icons/20/document-revert-rtl.png differ diff --git a/gtk/stock-icons/20/document-save-as.png b/gtk/stock-icons/20/document-save-as.png new file mode 100644 index 000000000..d71fce095 Binary files /dev/null and b/gtk/stock-icons/20/document-save-as.png differ diff --git a/gtk/stock-icons/20/drive-harddisk.png b/gtk/stock-icons/20/drive-harddisk.png new file mode 100644 index 000000000..a85279fdd Binary files /dev/null and b/gtk/stock-icons/20/drive-harddisk.png differ diff --git a/gtk/stock-icons/20/edit-clear.png b/gtk/stock-icons/20/edit-clear.png new file mode 100644 index 000000000..922ac3727 Binary files /dev/null and b/gtk/stock-icons/20/edit-clear.png differ diff --git a/gtk/stock-icons/20/edit-copy.png b/gtk/stock-icons/20/edit-copy.png new file mode 100644 index 000000000..ab4361bcc Binary files /dev/null and b/gtk/stock-icons/20/edit-copy.png differ diff --git a/gtk/stock-icons/20/edit-cut.png b/gtk/stock-icons/20/edit-cut.png new file mode 100644 index 000000000..bc47b18bc Binary files /dev/null and b/gtk/stock-icons/20/edit-cut.png differ diff --git a/gtk/stock-icons/20/edit-delete.png b/gtk/stock-icons/20/edit-delete.png new file mode 100644 index 000000000..6e6f770a1 Binary files /dev/null and b/gtk/stock-icons/20/edit-delete.png differ diff --git a/gtk/stock-icons/20/edit-find-replace.png b/gtk/stock-icons/20/edit-find-replace.png new file mode 100644 index 000000000..fa3b1adfe Binary files /dev/null and b/gtk/stock-icons/20/edit-find-replace.png differ diff --git a/gtk/stock-icons/20/edit-find.png b/gtk/stock-icons/20/edit-find.png new file mode 100644 index 000000000..c61861047 Binary files /dev/null and b/gtk/stock-icons/20/edit-find.png differ diff --git a/gtk/stock-icons/20/edit-paste.png b/gtk/stock-icons/20/edit-paste.png new file mode 100644 index 000000000..8cef4d21e Binary files /dev/null and b/gtk/stock-icons/20/edit-paste.png differ diff --git a/gtk/stock-icons/20/edit-redo-ltr.png b/gtk/stock-icons/20/edit-redo-ltr.png new file mode 100644 index 000000000..767e27bc0 Binary files /dev/null and b/gtk/stock-icons/20/edit-redo-ltr.png differ diff --git a/gtk/stock-icons/20/edit-redo-rtl.png b/gtk/stock-icons/20/edit-redo-rtl.png new file mode 100644 index 000000000..6c68470ce Binary files /dev/null and b/gtk/stock-icons/20/edit-redo-rtl.png differ diff --git a/gtk/stock-icons/20/edit-select-all.png b/gtk/stock-icons/20/edit-select-all.png new file mode 100644 index 000000000..cc00c1abb Binary files /dev/null and b/gtk/stock-icons/20/edit-select-all.png differ diff --git a/gtk/stock-icons/20/edit-undo-ltr.png b/gtk/stock-icons/20/edit-undo-ltr.png new file mode 100644 index 000000000..0b96bf90f Binary files /dev/null and b/gtk/stock-icons/20/edit-undo-ltr.png differ diff --git a/gtk/stock-icons/20/edit-undo-rtl.png b/gtk/stock-icons/20/edit-undo-rtl.png new file mode 100644 index 000000000..119e0185c Binary files /dev/null and b/gtk/stock-icons/20/edit-undo-rtl.png differ diff --git a/gtk/stock-icons/20/folder.png b/gtk/stock-icons/20/folder.png new file mode 100644 index 000000000..4946ab5dd Binary files /dev/null and b/gtk/stock-icons/20/folder.png differ diff --git a/gtk/stock-icons/20/format-indent-less-ltr.png b/gtk/stock-icons/20/format-indent-less-ltr.png new file mode 100644 index 000000000..b01abfaf0 Binary files /dev/null and b/gtk/stock-icons/20/format-indent-less-ltr.png differ diff --git a/gtk/stock-icons/20/format-indent-less-rtl.png b/gtk/stock-icons/20/format-indent-less-rtl.png new file mode 100644 index 000000000..e282f0e9b Binary files /dev/null and b/gtk/stock-icons/20/format-indent-less-rtl.png differ diff --git a/gtk/stock-icons/20/format-indent-more-ltr.png b/gtk/stock-icons/20/format-indent-more-ltr.png new file mode 100644 index 000000000..e885a1a3b Binary files /dev/null and b/gtk/stock-icons/20/format-indent-more-ltr.png differ diff --git a/gtk/stock-icons/20/format-indent-more-rtl.png b/gtk/stock-icons/20/format-indent-more-rtl.png new file mode 100644 index 000000000..8313529b4 Binary files /dev/null and b/gtk/stock-icons/20/format-indent-more-rtl.png differ diff --git a/gtk/stock-icons/20/format-justify-center.png b/gtk/stock-icons/20/format-justify-center.png new file mode 100644 index 000000000..e5d3bb90a Binary files /dev/null and b/gtk/stock-icons/20/format-justify-center.png differ diff --git a/gtk/stock-icons/20/format-justify-fill.png b/gtk/stock-icons/20/format-justify-fill.png new file mode 100644 index 000000000..e9fee1b7b Binary files /dev/null and b/gtk/stock-icons/20/format-justify-fill.png differ diff --git a/gtk/stock-icons/20/format-justify-left.png b/gtk/stock-icons/20/format-justify-left.png new file mode 100644 index 000000000..6e7685023 Binary files /dev/null and b/gtk/stock-icons/20/format-justify-left.png differ diff --git a/gtk/stock-icons/20/format-justify-right.png b/gtk/stock-icons/20/format-justify-right.png new file mode 100644 index 000000000..58112ad5a Binary files /dev/null and b/gtk/stock-icons/20/format-justify-right.png differ diff --git a/gtk/stock-icons/20/format-text-bold.png b/gtk/stock-icons/20/format-text-bold.png new file mode 100644 index 000000000..50b6e5279 Binary files /dev/null and b/gtk/stock-icons/20/format-text-bold.png differ diff --git a/gtk/stock-icons/20/format-text-italic.png b/gtk/stock-icons/20/format-text-italic.png new file mode 100644 index 000000000..d6b91f969 Binary files /dev/null and b/gtk/stock-icons/20/format-text-italic.png differ diff --git a/gtk/stock-icons/20/format-text-strikethrough.png b/gtk/stock-icons/20/format-text-strikethrough.png new file mode 100644 index 000000000..b880b23e7 Binary files /dev/null and b/gtk/stock-icons/20/format-text-strikethrough.png differ diff --git a/gtk/stock-icons/20/format-text-underline.png b/gtk/stock-icons/20/format-text-underline.png new file mode 100644 index 000000000..a09dcda4a Binary files /dev/null and b/gtk/stock-icons/20/format-text-underline.png differ diff --git a/gtk/stock-icons/20/go-bottom.png b/gtk/stock-icons/20/go-bottom.png new file mode 100644 index 000000000..0ae41b1c1 Binary files /dev/null and b/gtk/stock-icons/20/go-bottom.png differ diff --git a/gtk/stock-icons/20/go-down.png b/gtk/stock-icons/20/go-down.png new file mode 100644 index 000000000..d3cc06506 Binary files /dev/null and b/gtk/stock-icons/20/go-down.png differ diff --git a/gtk/stock-icons/20/go-first-ltr.png b/gtk/stock-icons/20/go-first-ltr.png new file mode 100644 index 000000000..c9ae15c91 Binary files /dev/null and b/gtk/stock-icons/20/go-first-ltr.png differ diff --git a/gtk/stock-icons/20/go-home.png b/gtk/stock-icons/20/go-home.png new file mode 100644 index 000000000..80dcff07a Binary files /dev/null and b/gtk/stock-icons/20/go-home.png differ diff --git a/gtk/stock-icons/20/go-jump-ltr.png b/gtk/stock-icons/20/go-jump-ltr.png new file mode 100644 index 000000000..96ee5cc9a Binary files /dev/null and b/gtk/stock-icons/20/go-jump-ltr.png differ diff --git a/gtk/stock-icons/20/go-jump-rtl.png b/gtk/stock-icons/20/go-jump-rtl.png new file mode 100644 index 000000000..37c692768 Binary files /dev/null and b/gtk/stock-icons/20/go-jump-rtl.png differ diff --git a/gtk/stock-icons/20/go-last-ltr.png b/gtk/stock-icons/20/go-last-ltr.png new file mode 100644 index 000000000..118c423e5 Binary files /dev/null and b/gtk/stock-icons/20/go-last-ltr.png differ diff --git a/gtk/stock-icons/20/go-next-ltr.png b/gtk/stock-icons/20/go-next-ltr.png new file mode 100644 index 000000000..29242042d Binary files /dev/null and b/gtk/stock-icons/20/go-next-ltr.png differ diff --git a/gtk/stock-icons/20/go-previous-ltr.png b/gtk/stock-icons/20/go-previous-ltr.png new file mode 100644 index 000000000..ac72c4ee0 Binary files /dev/null and b/gtk/stock-icons/20/go-previous-ltr.png differ diff --git a/gtk/stock-icons/20/go-top.png b/gtk/stock-icons/20/go-top.png new file mode 100644 index 000000000..795e56b55 Binary files /dev/null and b/gtk/stock-icons/20/go-top.png differ diff --git a/gtk/stock-icons/20/go-up.png b/gtk/stock-icons/20/go-up.png new file mode 100644 index 000000000..c30e6dde2 Binary files /dev/null and b/gtk/stock-icons/20/go-up.png differ diff --git a/gtk/stock-icons/20/gtk-caps-lock-warning.png b/gtk/stock-icons/20/gtk-caps-lock-warning.png new file mode 100644 index 000000000..d8bed3421 Binary files /dev/null and b/gtk/stock-icons/20/gtk-caps-lock-warning.png differ diff --git a/gtk/stock-icons/20/gtk-color-picker.png b/gtk/stock-icons/20/gtk-color-picker.png new file mode 100644 index 000000000..5fab3320d Binary files /dev/null and b/gtk/stock-icons/20/gtk-color-picker.png differ diff --git a/gtk/stock-icons/20/gtk-connect.png b/gtk/stock-icons/20/gtk-connect.png new file mode 100644 index 000000000..f3e41a27a Binary files /dev/null and b/gtk/stock-icons/20/gtk-connect.png differ diff --git a/gtk/stock-icons/20/gtk-convert.png b/gtk/stock-icons/20/gtk-convert.png new file mode 100644 index 000000000..324a5bf57 Binary files /dev/null and b/gtk/stock-icons/20/gtk-convert.png differ diff --git a/gtk/stock-icons/20/gtk-disconnect.png b/gtk/stock-icons/20/gtk-disconnect.png new file mode 100644 index 000000000..8ee838abc Binary files /dev/null and b/gtk/stock-icons/20/gtk-disconnect.png differ diff --git a/gtk/stock-icons/20/gtk-dnd-multiple.png b/gtk/stock-icons/20/gtk-dnd-multiple.png new file mode 100644 index 000000000..a322c91f9 Binary files /dev/null and b/gtk/stock-icons/20/gtk-dnd-multiple.png differ diff --git a/gtk/stock-icons/20/gtk-dnd.png b/gtk/stock-icons/20/gtk-dnd.png new file mode 100644 index 000000000..9c417e573 Binary files /dev/null and b/gtk/stock-icons/20/gtk-dnd.png differ diff --git a/gtk/stock-icons/20/gtk-edit.png b/gtk/stock-icons/20/gtk-edit.png new file mode 100644 index 000000000..4ea97afae Binary files /dev/null and b/gtk/stock-icons/20/gtk-edit.png differ diff --git a/gtk/stock-icons/20/gtk-font.png b/gtk/stock-icons/20/gtk-font.png new file mode 100644 index 000000000..ba9fd9096 Binary files /dev/null and b/gtk/stock-icons/20/gtk-font.png differ diff --git a/gtk/stock-icons/20/gtk-index.png b/gtk/stock-icons/20/gtk-index.png new file mode 100644 index 000000000..408ae96f8 Binary files /dev/null and b/gtk/stock-icons/20/gtk-index.png differ diff --git a/gtk/stock-icons/20/gtk-orientation-landscape.png b/gtk/stock-icons/20/gtk-orientation-landscape.png new file mode 100644 index 000000000..f1f836655 Binary files /dev/null and b/gtk/stock-icons/20/gtk-orientation-landscape.png differ diff --git a/gtk/stock-icons/20/gtk-orientation-portrait.png b/gtk/stock-icons/20/gtk-orientation-portrait.png new file mode 100644 index 000000000..42bf2265c Binary files /dev/null and b/gtk/stock-icons/20/gtk-orientation-portrait.png differ diff --git a/gtk/stock-icons/20/gtk-orientation-reverse-landscape.png b/gtk/stock-icons/20/gtk-orientation-reverse-landscape.png new file mode 100644 index 000000000..b0405222e Binary files /dev/null and b/gtk/stock-icons/20/gtk-orientation-reverse-landscape.png differ diff --git a/gtk/stock-icons/20/gtk-orientation-reverse-portrait.png b/gtk/stock-icons/20/gtk-orientation-reverse-portrait.png new file mode 100644 index 000000000..3c02a8d28 Binary files /dev/null and b/gtk/stock-icons/20/gtk-orientation-reverse-portrait.png differ diff --git a/gtk/stock-icons/20/gtk-page-setup.png b/gtk/stock-icons/20/gtk-page-setup.png new file mode 100644 index 000000000..eb29a5219 Binary files /dev/null and b/gtk/stock-icons/20/gtk-page-setup.png differ diff --git a/gtk/stock-icons/20/gtk-preferences.png b/gtk/stock-icons/20/gtk-preferences.png new file mode 100644 index 000000000..c4e9493d1 Binary files /dev/null and b/gtk/stock-icons/20/gtk-preferences.png differ diff --git a/gtk/stock-icons/20/gtk-select-color.png b/gtk/stock-icons/20/gtk-select-color.png new file mode 100644 index 000000000..af99760d0 Binary files /dev/null and b/gtk/stock-icons/20/gtk-select-color.png differ diff --git a/gtk/stock-icons/20/gtk-select-font.png b/gtk/stock-icons/20/gtk-select-font.png new file mode 100644 index 000000000..9c64f9677 Binary files /dev/null and b/gtk/stock-icons/20/gtk-select-font.png differ diff --git a/gtk/stock-icons/20/gtk-undelete-ltr.png b/gtk/stock-icons/20/gtk-undelete-ltr.png new file mode 100644 index 000000000..103877e82 Binary files /dev/null and b/gtk/stock-icons/20/gtk-undelete-ltr.png differ diff --git a/gtk/stock-icons/20/gtk-undelete-rtl.png b/gtk/stock-icons/20/gtk-undelete-rtl.png new file mode 100644 index 000000000..8ef12f8c4 Binary files /dev/null and b/gtk/stock-icons/20/gtk-undelete-rtl.png differ diff --git a/gtk/stock-icons/20/help-about.png b/gtk/stock-icons/20/help-about.png new file mode 100644 index 000000000..3e467cdba Binary files /dev/null and b/gtk/stock-icons/20/help-about.png differ diff --git a/gtk/stock-icons/20/help-contents.png b/gtk/stock-icons/20/help-contents.png new file mode 100644 index 000000000..79219e7b7 Binary files /dev/null and b/gtk/stock-icons/20/help-contents.png differ diff --git a/gtk/stock-icons/20/image-missing.png b/gtk/stock-icons/20/image-missing.png new file mode 100644 index 000000000..14b45f6c0 Binary files /dev/null and b/gtk/stock-icons/20/image-missing.png differ diff --git a/gtk/stock-icons/20/list-add.png b/gtk/stock-icons/20/list-add.png new file mode 100644 index 000000000..a06d38e65 Binary files /dev/null and b/gtk/stock-icons/20/list-add.png differ diff --git a/gtk/stock-icons/20/list-remove.png b/gtk/stock-icons/20/list-remove.png new file mode 100644 index 000000000..da178913d Binary files /dev/null and b/gtk/stock-icons/20/list-remove.png differ diff --git a/gtk/stock-icons/20/media-floppy.png b/gtk/stock-icons/20/media-floppy.png new file mode 100644 index 000000000..de127101d Binary files /dev/null and b/gtk/stock-icons/20/media-floppy.png differ diff --git a/gtk/stock-icons/20/media-optical.png b/gtk/stock-icons/20/media-optical.png new file mode 100644 index 000000000..cd3fcff89 Binary files /dev/null and b/gtk/stock-icons/20/media-optical.png differ diff --git a/gtk/stock-icons/20/media-playback-pause.png b/gtk/stock-icons/20/media-playback-pause.png new file mode 100644 index 000000000..0ec02b7eb Binary files /dev/null and b/gtk/stock-icons/20/media-playback-pause.png differ diff --git a/gtk/stock-icons/20/media-playback-start-ltr.png b/gtk/stock-icons/20/media-playback-start-ltr.png new file mode 100644 index 000000000..22d1d5ff6 Binary files /dev/null and b/gtk/stock-icons/20/media-playback-start-ltr.png differ diff --git a/gtk/stock-icons/20/media-playback-start-rtl.png b/gtk/stock-icons/20/media-playback-start-rtl.png new file mode 100644 index 000000000..92b6ad1c0 Binary files /dev/null and b/gtk/stock-icons/20/media-playback-start-rtl.png differ diff --git a/gtk/stock-icons/20/media-playback-stop.png b/gtk/stock-icons/20/media-playback-stop.png new file mode 100644 index 000000000..31df68de7 Binary files /dev/null and b/gtk/stock-icons/20/media-playback-stop.png differ diff --git a/gtk/stock-icons/20/media-record.png b/gtk/stock-icons/20/media-record.png new file mode 100644 index 000000000..34de581eb Binary files /dev/null and b/gtk/stock-icons/20/media-record.png differ diff --git a/gtk/stock-icons/20/media-seek-backward-ltr.png b/gtk/stock-icons/20/media-seek-backward-ltr.png new file mode 100644 index 000000000..271397dd2 Binary files /dev/null and b/gtk/stock-icons/20/media-seek-backward-ltr.png differ diff --git a/gtk/stock-icons/20/media-seek-forward-ltr.png b/gtk/stock-icons/20/media-seek-forward-ltr.png new file mode 100644 index 000000000..5b4205174 Binary files /dev/null and b/gtk/stock-icons/20/media-seek-forward-ltr.png differ diff --git a/gtk/stock-icons/20/media-skip-backward-ltr.png b/gtk/stock-icons/20/media-skip-backward-ltr.png new file mode 100644 index 000000000..4b3f60a11 Binary files /dev/null and b/gtk/stock-icons/20/media-skip-backward-ltr.png differ diff --git a/gtk/stock-icons/20/media-skip-forward-ltr.png b/gtk/stock-icons/20/media-skip-forward-ltr.png new file mode 100644 index 000000000..1811f1e3f Binary files /dev/null and b/gtk/stock-icons/20/media-skip-forward-ltr.png differ diff --git a/gtk/stock-icons/20/network-idle.png b/gtk/stock-icons/20/network-idle.png new file mode 100644 index 000000000..f2a792f09 Binary files /dev/null and b/gtk/stock-icons/20/network-idle.png differ diff --git a/gtk/stock-icons/20/printer-error.png b/gtk/stock-icons/20/printer-error.png new file mode 100644 index 000000000..21abed855 Binary files /dev/null and b/gtk/stock-icons/20/printer-error.png differ diff --git a/gtk/stock-icons/20/printer-info.png b/gtk/stock-icons/20/printer-info.png new file mode 100644 index 000000000..07214dd08 Binary files /dev/null and b/gtk/stock-icons/20/printer-info.png differ diff --git a/gtk/stock-icons/20/printer-paused.png b/gtk/stock-icons/20/printer-paused.png new file mode 100644 index 000000000..7a7de7c8b Binary files /dev/null and b/gtk/stock-icons/20/printer-paused.png differ diff --git a/gtk/stock-icons/20/printer-warning.png b/gtk/stock-icons/20/printer-warning.png new file mode 100644 index 000000000..79b4a08f5 Binary files /dev/null and b/gtk/stock-icons/20/printer-warning.png differ diff --git a/gtk/stock-icons/20/process-stop.png b/gtk/stock-icons/20/process-stop.png new file mode 100644 index 000000000..f2527fc63 Binary files /dev/null and b/gtk/stock-icons/20/process-stop.png differ diff --git a/gtk/stock-icons/20/system-run.png b/gtk/stock-icons/20/system-run.png new file mode 100644 index 000000000..8340db45d Binary files /dev/null and b/gtk/stock-icons/20/system-run.png differ diff --git a/gtk/stock-icons/20/text-x-generic.png b/gtk/stock-icons/20/text-x-generic.png new file mode 100644 index 000000000..de7fa5dcb Binary files /dev/null and b/gtk/stock-icons/20/text-x-generic.png differ diff --git a/gtk/stock-icons/20/tools-check-spelling.png b/gtk/stock-icons/20/tools-check-spelling.png new file mode 100644 index 000000000..68591e622 Binary files /dev/null and b/gtk/stock-icons/20/tools-check-spelling.png differ diff --git a/gtk/stock-icons/20/view-fullscreen.png b/gtk/stock-icons/20/view-fullscreen.png new file mode 100644 index 000000000..096e3eaee Binary files /dev/null and b/gtk/stock-icons/20/view-fullscreen.png differ diff --git a/gtk/stock-icons/20/view-refresh.png b/gtk/stock-icons/20/view-refresh.png new file mode 100644 index 000000000..85281e2ec Binary files /dev/null and b/gtk/stock-icons/20/view-refresh.png differ diff --git a/gtk/stock-icons/20/view-restore.png b/gtk/stock-icons/20/view-restore.png new file mode 100644 index 000000000..5b3badefa Binary files /dev/null and b/gtk/stock-icons/20/view-restore.png differ diff --git a/gtk/stock-icons/20/view-sort-ascending.png b/gtk/stock-icons/20/view-sort-ascending.png new file mode 100644 index 000000000..15a3338db Binary files /dev/null and b/gtk/stock-icons/20/view-sort-ascending.png differ diff --git a/gtk/stock-icons/20/view-sort-descending.png b/gtk/stock-icons/20/view-sort-descending.png new file mode 100644 index 000000000..0bd1edc78 Binary files /dev/null and b/gtk/stock-icons/20/view-sort-descending.png differ diff --git a/gtk/stock-icons/20/zoom-fit-best.png b/gtk/stock-icons/20/zoom-fit-best.png new file mode 100644 index 000000000..e22432c2a Binary files /dev/null and b/gtk/stock-icons/20/zoom-fit-best.png differ diff --git a/gtk/stock-icons/20/zoom-in.png b/gtk/stock-icons/20/zoom-in.png new file mode 100644 index 000000000..6ba22de96 Binary files /dev/null and b/gtk/stock-icons/20/zoom-in.png differ diff --git a/gtk/stock-icons/20/zoom-original.png b/gtk/stock-icons/20/zoom-original.png new file mode 100644 index 000000000..c98169a8e Binary files /dev/null and b/gtk/stock-icons/20/zoom-original.png differ diff --git a/gtk/stock-icons/20/zoom-out.png b/gtk/stock-icons/20/zoom-out.png new file mode 100644 index 000000000..262c6197b Binary files /dev/null and b/gtk/stock-icons/20/zoom-out.png differ diff --git a/gtk/stock-icons/24/dialog-error.png b/gtk/stock-icons/24/dialog-error.png new file mode 100644 index 000000000..d02063d96 Binary files /dev/null and b/gtk/stock-icons/24/dialog-error.png differ diff --git a/gtk/stock-icons/24/dialog-password.png b/gtk/stock-icons/24/dialog-password.png new file mode 100644 index 000000000..eeacae9d7 Binary files /dev/null and b/gtk/stock-icons/24/dialog-password.png differ diff --git a/gtk/stock-icons/24/dialog-question.png b/gtk/stock-icons/24/dialog-question.png new file mode 100644 index 000000000..129792750 Binary files /dev/null and b/gtk/stock-icons/24/dialog-question.png differ diff --git a/gtk/stock-icons/24/dialog-warning.png b/gtk/stock-icons/24/dialog-warning.png new file mode 100644 index 000000000..bac18bd2b Binary files /dev/null and b/gtk/stock-icons/24/dialog-warning.png differ diff --git a/gtk/stock-icons/24/gtk-apply.png b/gtk/stock-icons/24/gtk-apply.png new file mode 100644 index 000000000..fb7528ae6 Binary files /dev/null and b/gtk/stock-icons/24/gtk-apply.png differ diff --git a/gtk/stock-icons/24/gtk-cancel.png b/gtk/stock-icons/24/gtk-cancel.png new file mode 100644 index 000000000..48a5389dc Binary files /dev/null and b/gtk/stock-icons/24/gtk-cancel.png differ diff --git a/gtk/stock-icons/24/gtk-dnd-multiple.png b/gtk/stock-icons/24/gtk-dnd-multiple.png new file mode 100644 index 000000000..b43e4bd95 Binary files /dev/null and b/gtk/stock-icons/24/gtk-dnd-multiple.png differ diff --git a/gtk/stock-icons/24/gtk-dnd.png b/gtk/stock-icons/24/gtk-dnd.png new file mode 100644 index 000000000..7c8a6ddb6 Binary files /dev/null and b/gtk/stock-icons/24/gtk-dnd.png differ diff --git a/gtk/stock-icons/24/gtk-no.png b/gtk/stock-icons/24/gtk-no.png new file mode 100644 index 000000000..a8d8fad18 Binary files /dev/null and b/gtk/stock-icons/24/gtk-no.png differ diff --git a/gtk/stock-icons/24/gtk-ok.png b/gtk/stock-icons/24/gtk-ok.png new file mode 100644 index 000000000..3fd5a0b62 Binary files /dev/null and b/gtk/stock-icons/24/gtk-ok.png differ diff --git a/gtk/stock-icons/24/gtk-yes.png b/gtk/stock-icons/24/gtk-yes.png new file mode 100644 index 000000000..aa8dd94bf Binary files /dev/null and b/gtk/stock-icons/24/gtk-yes.png differ diff --git a/gtk/stock-icons/32/application-exit.png b/gtk/stock-icons/32/application-exit.png new file mode 100644 index 000000000..73a39f8ff Binary files /dev/null and b/gtk/stock-icons/32/application-exit.png differ diff --git a/gtk/stock-icons/32/audio-volume-high.png b/gtk/stock-icons/32/audio-volume-high.png new file mode 100644 index 000000000..13c6010ea Binary files /dev/null and b/gtk/stock-icons/32/audio-volume-high.png differ diff --git a/gtk/stock-icons/32/audio-volume-low.png b/gtk/stock-icons/32/audio-volume-low.png new file mode 100644 index 000000000..52b9ed7a5 Binary files /dev/null and b/gtk/stock-icons/32/audio-volume-low.png differ diff --git a/gtk/stock-icons/32/audio-volume-medium.png b/gtk/stock-icons/32/audio-volume-medium.png new file mode 100644 index 000000000..c9c62ada1 Binary files /dev/null and b/gtk/stock-icons/32/audio-volume-medium.png differ diff --git a/gtk/stock-icons/32/audio-volume-muted.png b/gtk/stock-icons/32/audio-volume-muted.png new file mode 100644 index 000000000..bca2aced6 Binary files /dev/null and b/gtk/stock-icons/32/audio-volume-muted.png differ diff --git a/gtk/stock-icons/32/dialog-error.png b/gtk/stock-icons/32/dialog-error.png new file mode 100644 index 000000000..8b0c6d882 Binary files /dev/null and b/gtk/stock-icons/32/dialog-error.png differ diff --git a/gtk/stock-icons/32/dialog-information.png b/gtk/stock-icons/32/dialog-information.png new file mode 100644 index 000000000..14d7063a9 Binary files /dev/null and b/gtk/stock-icons/32/dialog-information.png differ diff --git a/gtk/stock-icons/32/dialog-password.png b/gtk/stock-icons/32/dialog-password.png new file mode 100644 index 000000000..781bf4f4a Binary files /dev/null and b/gtk/stock-icons/32/dialog-password.png differ diff --git a/gtk/stock-icons/32/dialog-question.png b/gtk/stock-icons/32/dialog-question.png new file mode 100644 index 000000000..0045111b1 Binary files /dev/null and b/gtk/stock-icons/32/dialog-question.png differ diff --git a/gtk/stock-icons/32/dialog-warning.png b/gtk/stock-icons/32/dialog-warning.png new file mode 100644 index 000000000..a24371f7d Binary files /dev/null and b/gtk/stock-icons/32/dialog-warning.png differ diff --git a/gtk/stock-icons/32/document-new.png b/gtk/stock-icons/32/document-new.png new file mode 100644 index 000000000..9db523d7a Binary files /dev/null and b/gtk/stock-icons/32/document-new.png differ diff --git a/gtk/stock-icons/32/document-open-recent.png b/gtk/stock-icons/32/document-open-recent.png new file mode 100644 index 000000000..3db076bb4 Binary files /dev/null and b/gtk/stock-icons/32/document-open-recent.png differ diff --git a/gtk/stock-icons/32/document-open.png b/gtk/stock-icons/32/document-open.png new file mode 100644 index 000000000..4cfb248da Binary files /dev/null and b/gtk/stock-icons/32/document-open.png differ diff --git a/gtk/stock-icons/32/document-print-preview.png b/gtk/stock-icons/32/document-print-preview.png new file mode 100644 index 000000000..bb36e2dfb Binary files /dev/null and b/gtk/stock-icons/32/document-print-preview.png differ diff --git a/gtk/stock-icons/32/document-print.png b/gtk/stock-icons/32/document-print.png new file mode 100644 index 000000000..7e50f1ac0 Binary files /dev/null and b/gtk/stock-icons/32/document-print.png differ diff --git a/gtk/stock-icons/32/document-properties.png b/gtk/stock-icons/32/document-properties.png new file mode 100644 index 000000000..ba9dfdd42 Binary files /dev/null and b/gtk/stock-icons/32/document-properties.png differ diff --git a/gtk/stock-icons/32/document-revert-ltr.png b/gtk/stock-icons/32/document-revert-ltr.png new file mode 100644 index 000000000..1f45f1dec Binary files /dev/null and b/gtk/stock-icons/32/document-revert-ltr.png differ diff --git a/gtk/stock-icons/32/document-revert-rtl.png b/gtk/stock-icons/32/document-revert-rtl.png new file mode 100644 index 000000000..85edc54e6 Binary files /dev/null and b/gtk/stock-icons/32/document-revert-rtl.png differ diff --git a/gtk/stock-icons/32/document-save-as.png b/gtk/stock-icons/32/document-save-as.png new file mode 100644 index 000000000..1de9ce84d Binary files /dev/null and b/gtk/stock-icons/32/document-save-as.png differ diff --git a/gtk/stock-icons/32/drive-harddisk.png b/gtk/stock-icons/32/drive-harddisk.png new file mode 100644 index 000000000..b3552eb6f Binary files /dev/null and b/gtk/stock-icons/32/drive-harddisk.png differ diff --git a/gtk/stock-icons/32/edit-clear.png b/gtk/stock-icons/32/edit-clear.png new file mode 100644 index 000000000..c63bc7d9d Binary files /dev/null and b/gtk/stock-icons/32/edit-clear.png differ diff --git a/gtk/stock-icons/32/edit-copy.png b/gtk/stock-icons/32/edit-copy.png new file mode 100644 index 000000000..6962311e6 Binary files /dev/null and b/gtk/stock-icons/32/edit-copy.png differ diff --git a/gtk/stock-icons/32/edit-cut.png b/gtk/stock-icons/32/edit-cut.png new file mode 100644 index 000000000..17c05a917 Binary files /dev/null and b/gtk/stock-icons/32/edit-cut.png differ diff --git a/gtk/stock-icons/32/edit-delete.png b/gtk/stock-icons/32/edit-delete.png new file mode 100644 index 000000000..45a188198 Binary files /dev/null and b/gtk/stock-icons/32/edit-delete.png differ diff --git a/gtk/stock-icons/32/edit-find-replace.png b/gtk/stock-icons/32/edit-find-replace.png new file mode 100644 index 000000000..505254b45 Binary files /dev/null and b/gtk/stock-icons/32/edit-find-replace.png differ diff --git a/gtk/stock-icons/32/edit-find.png b/gtk/stock-icons/32/edit-find.png new file mode 100644 index 000000000..d4229ee48 Binary files /dev/null and b/gtk/stock-icons/32/edit-find.png differ diff --git a/gtk/stock-icons/32/edit-paste.png b/gtk/stock-icons/32/edit-paste.png new file mode 100644 index 000000000..8703601fc Binary files /dev/null and b/gtk/stock-icons/32/edit-paste.png differ diff --git a/gtk/stock-icons/32/edit-redo-ltr.png b/gtk/stock-icons/32/edit-redo-ltr.png new file mode 100644 index 000000000..ee886fe85 Binary files /dev/null and b/gtk/stock-icons/32/edit-redo-ltr.png differ diff --git a/gtk/stock-icons/32/edit-redo-rtl.png b/gtk/stock-icons/32/edit-redo-rtl.png new file mode 100644 index 000000000..06a41be8e Binary files /dev/null and b/gtk/stock-icons/32/edit-redo-rtl.png differ diff --git a/gtk/stock-icons/32/edit-select-all.png b/gtk/stock-icons/32/edit-select-all.png new file mode 100644 index 000000000..1ebed9d8a Binary files /dev/null and b/gtk/stock-icons/32/edit-select-all.png differ diff --git a/gtk/stock-icons/32/edit-undo-ltr.png b/gtk/stock-icons/32/edit-undo-ltr.png new file mode 100644 index 000000000..5a4e88ae3 Binary files /dev/null and b/gtk/stock-icons/32/edit-undo-ltr.png differ diff --git a/gtk/stock-icons/32/edit-undo-rtl.png b/gtk/stock-icons/32/edit-undo-rtl.png new file mode 100644 index 000000000..5bad58ccb Binary files /dev/null and b/gtk/stock-icons/32/edit-undo-rtl.png differ diff --git a/gtk/stock-icons/32/folder.png b/gtk/stock-icons/32/folder.png new file mode 100644 index 000000000..c5d829b50 Binary files /dev/null and b/gtk/stock-icons/32/folder.png differ diff --git a/gtk/stock-icons/32/format-indent-less-ltr.png b/gtk/stock-icons/32/format-indent-less-ltr.png new file mode 100644 index 000000000..6f610a4c4 Binary files /dev/null and b/gtk/stock-icons/32/format-indent-less-ltr.png differ diff --git a/gtk/stock-icons/32/format-indent-less-rtl.png b/gtk/stock-icons/32/format-indent-less-rtl.png new file mode 100644 index 000000000..bc70c6055 Binary files /dev/null and b/gtk/stock-icons/32/format-indent-less-rtl.png differ diff --git a/gtk/stock-icons/32/format-indent-more-ltr.png b/gtk/stock-icons/32/format-indent-more-ltr.png new file mode 100644 index 000000000..fc62977a0 Binary files /dev/null and b/gtk/stock-icons/32/format-indent-more-ltr.png differ diff --git a/gtk/stock-icons/32/format-indent-more-rtl.png b/gtk/stock-icons/32/format-indent-more-rtl.png new file mode 100644 index 000000000..8fd556598 Binary files /dev/null and b/gtk/stock-icons/32/format-indent-more-rtl.png differ diff --git a/gtk/stock-icons/32/format-justify-center.png b/gtk/stock-icons/32/format-justify-center.png new file mode 100644 index 000000000..b087687dd Binary files /dev/null and b/gtk/stock-icons/32/format-justify-center.png differ diff --git a/gtk/stock-icons/32/format-justify-fill.png b/gtk/stock-icons/32/format-justify-fill.png new file mode 100644 index 000000000..166482fe1 Binary files /dev/null and b/gtk/stock-icons/32/format-justify-fill.png differ diff --git a/gtk/stock-icons/32/format-justify-left.png b/gtk/stock-icons/32/format-justify-left.png new file mode 100644 index 000000000..22e18eadd Binary files /dev/null and b/gtk/stock-icons/32/format-justify-left.png differ diff --git a/gtk/stock-icons/32/format-justify-right.png b/gtk/stock-icons/32/format-justify-right.png new file mode 100644 index 000000000..f7183cbea Binary files /dev/null and b/gtk/stock-icons/32/format-justify-right.png differ diff --git a/gtk/stock-icons/32/format-text-bold.png b/gtk/stock-icons/32/format-text-bold.png new file mode 100644 index 000000000..094fb15b8 Binary files /dev/null and b/gtk/stock-icons/32/format-text-bold.png differ diff --git a/gtk/stock-icons/32/format-text-italic.png b/gtk/stock-icons/32/format-text-italic.png new file mode 100644 index 000000000..21c7ebbf7 Binary files /dev/null and b/gtk/stock-icons/32/format-text-italic.png differ diff --git a/gtk/stock-icons/32/format-text-strikethrough.png b/gtk/stock-icons/32/format-text-strikethrough.png new file mode 100644 index 000000000..b8272f86c Binary files /dev/null and b/gtk/stock-icons/32/format-text-strikethrough.png differ diff --git a/gtk/stock-icons/32/format-text-underline.png b/gtk/stock-icons/32/format-text-underline.png new file mode 100644 index 000000000..2ee3f4ca9 Binary files /dev/null and b/gtk/stock-icons/32/format-text-underline.png differ diff --git a/gtk/stock-icons/32/go-bottom.png b/gtk/stock-icons/32/go-bottom.png new file mode 100644 index 000000000..9264ee4ac Binary files /dev/null and b/gtk/stock-icons/32/go-bottom.png differ diff --git a/gtk/stock-icons/32/go-down.png b/gtk/stock-icons/32/go-down.png new file mode 100644 index 000000000..fd330c08e Binary files /dev/null and b/gtk/stock-icons/32/go-down.png differ diff --git a/gtk/stock-icons/32/go-first-ltr.png b/gtk/stock-icons/32/go-first-ltr.png new file mode 100644 index 000000000..3ec1e5258 Binary files /dev/null and b/gtk/stock-icons/32/go-first-ltr.png differ diff --git a/gtk/stock-icons/32/go-home.png b/gtk/stock-icons/32/go-home.png new file mode 100644 index 000000000..05d84d4bc Binary files /dev/null and b/gtk/stock-icons/32/go-home.png differ diff --git a/gtk/stock-icons/32/go-jump-ltr.png b/gtk/stock-icons/32/go-jump-ltr.png new file mode 100644 index 000000000..366c58def Binary files /dev/null and b/gtk/stock-icons/32/go-jump-ltr.png differ diff --git a/gtk/stock-icons/32/go-jump-rtl.png b/gtk/stock-icons/32/go-jump-rtl.png new file mode 100644 index 000000000..75d20813d Binary files /dev/null and b/gtk/stock-icons/32/go-jump-rtl.png differ diff --git a/gtk/stock-icons/32/go-last-ltr.png b/gtk/stock-icons/32/go-last-ltr.png new file mode 100644 index 000000000..464701109 Binary files /dev/null and b/gtk/stock-icons/32/go-last-ltr.png differ diff --git a/gtk/stock-icons/32/go-next-ltr.png b/gtk/stock-icons/32/go-next-ltr.png new file mode 100644 index 000000000..fe3d2924a Binary files /dev/null and b/gtk/stock-icons/32/go-next-ltr.png differ diff --git a/gtk/stock-icons/32/go-previous-ltr.png b/gtk/stock-icons/32/go-previous-ltr.png new file mode 100644 index 000000000..7d1d1e8f6 Binary files /dev/null and b/gtk/stock-icons/32/go-previous-ltr.png differ diff --git a/gtk/stock-icons/32/go-top.png b/gtk/stock-icons/32/go-top.png new file mode 100644 index 000000000..e8cc25f78 Binary files /dev/null and b/gtk/stock-icons/32/go-top.png differ diff --git a/gtk/stock-icons/32/go-up.png b/gtk/stock-icons/32/go-up.png new file mode 100644 index 000000000..6a83aa497 Binary files /dev/null and b/gtk/stock-icons/32/go-up.png differ diff --git a/gtk/stock-icons/32/gtk-apply.png b/gtk/stock-icons/32/gtk-apply.png new file mode 100644 index 000000000..3b28e6794 Binary files /dev/null and b/gtk/stock-icons/32/gtk-apply.png differ diff --git a/gtk/stock-icons/32/gtk-cancel.png b/gtk/stock-icons/32/gtk-cancel.png new file mode 100644 index 000000000..d2a86ae25 Binary files /dev/null and b/gtk/stock-icons/32/gtk-cancel.png differ diff --git a/gtk/stock-icons/32/gtk-caps-lock-warning.png b/gtk/stock-icons/32/gtk-caps-lock-warning.png new file mode 100644 index 000000000..dc108d355 Binary files /dev/null and b/gtk/stock-icons/32/gtk-caps-lock-warning.png differ diff --git a/gtk/stock-icons/32/gtk-color-picker.png b/gtk/stock-icons/32/gtk-color-picker.png new file mode 100644 index 000000000..b6c1b90eb Binary files /dev/null and b/gtk/stock-icons/32/gtk-color-picker.png differ diff --git a/gtk/stock-icons/32/gtk-connect.png b/gtk/stock-icons/32/gtk-connect.png new file mode 100644 index 000000000..4d3425415 Binary files /dev/null and b/gtk/stock-icons/32/gtk-connect.png differ diff --git a/gtk/stock-icons/32/gtk-convert.png b/gtk/stock-icons/32/gtk-convert.png new file mode 100644 index 000000000..cb09f0507 Binary files /dev/null and b/gtk/stock-icons/32/gtk-convert.png differ diff --git a/gtk/stock-icons/32/gtk-disconnect.png b/gtk/stock-icons/32/gtk-disconnect.png new file mode 100644 index 000000000..4aeabc2ec Binary files /dev/null and b/gtk/stock-icons/32/gtk-disconnect.png differ diff --git a/gtk/stock-icons/32/gtk-edit.png b/gtk/stock-icons/32/gtk-edit.png new file mode 100644 index 000000000..7f362a908 Binary files /dev/null and b/gtk/stock-icons/32/gtk-edit.png differ diff --git a/gtk/stock-icons/32/gtk-font.png b/gtk/stock-icons/32/gtk-font.png new file mode 100644 index 000000000..ade309086 Binary files /dev/null and b/gtk/stock-icons/32/gtk-font.png differ diff --git a/gtk/stock-icons/32/gtk-index.png b/gtk/stock-icons/32/gtk-index.png new file mode 100644 index 000000000..213b3aee4 Binary files /dev/null and b/gtk/stock-icons/32/gtk-index.png differ diff --git a/gtk/stock-icons/32/gtk-no.png b/gtk/stock-icons/32/gtk-no.png new file mode 100644 index 000000000..ef717c87f Binary files /dev/null and b/gtk/stock-icons/32/gtk-no.png differ diff --git a/gtk/stock-icons/32/gtk-ok.png b/gtk/stock-icons/32/gtk-ok.png new file mode 100644 index 000000000..c7a9cc1b5 Binary files /dev/null and b/gtk/stock-icons/32/gtk-ok.png differ diff --git a/gtk/stock-icons/32/gtk-orientation-landscape.png b/gtk/stock-icons/32/gtk-orientation-landscape.png new file mode 100644 index 000000000..201c5cd46 Binary files /dev/null and b/gtk/stock-icons/32/gtk-orientation-landscape.png differ diff --git a/gtk/stock-icons/32/gtk-orientation-portrait.png b/gtk/stock-icons/32/gtk-orientation-portrait.png new file mode 100644 index 000000000..900eb7617 Binary files /dev/null and b/gtk/stock-icons/32/gtk-orientation-portrait.png differ diff --git a/gtk/stock-icons/32/gtk-orientation-reverse-landscape.png b/gtk/stock-icons/32/gtk-orientation-reverse-landscape.png new file mode 100644 index 000000000..2dc5aa91c Binary files /dev/null and b/gtk/stock-icons/32/gtk-orientation-reverse-landscape.png differ diff --git a/gtk/stock-icons/32/gtk-orientation-reverse-portrait.png b/gtk/stock-icons/32/gtk-orientation-reverse-portrait.png new file mode 100644 index 000000000..fdc96a1ba Binary files /dev/null and b/gtk/stock-icons/32/gtk-orientation-reverse-portrait.png differ diff --git a/gtk/stock-icons/32/gtk-page-setup.png b/gtk/stock-icons/32/gtk-page-setup.png new file mode 100644 index 000000000..5c8cc8f46 Binary files /dev/null and b/gtk/stock-icons/32/gtk-page-setup.png differ diff --git a/gtk/stock-icons/32/gtk-preferences.png b/gtk/stock-icons/32/gtk-preferences.png new file mode 100644 index 000000000..a9644f975 Binary files /dev/null and b/gtk/stock-icons/32/gtk-preferences.png differ diff --git a/gtk/stock-icons/32/gtk-select-color.png b/gtk/stock-icons/32/gtk-select-color.png new file mode 100644 index 000000000..753527245 Binary files /dev/null and b/gtk/stock-icons/32/gtk-select-color.png differ diff --git a/gtk/stock-icons/32/gtk-select-font.png b/gtk/stock-icons/32/gtk-select-font.png new file mode 100644 index 000000000..9c9d9624b Binary files /dev/null and b/gtk/stock-icons/32/gtk-select-font.png differ diff --git a/gtk/stock-icons/32/gtk-undelete-ltr.png b/gtk/stock-icons/32/gtk-undelete-ltr.png new file mode 100644 index 000000000..9ba3ed2b1 Binary files /dev/null and b/gtk/stock-icons/32/gtk-undelete-ltr.png differ diff --git a/gtk/stock-icons/32/gtk-undelete-rtl.png b/gtk/stock-icons/32/gtk-undelete-rtl.png new file mode 100644 index 000000000..619a5d53c Binary files /dev/null and b/gtk/stock-icons/32/gtk-undelete-rtl.png differ diff --git a/gtk/stock-icons/32/gtk-yes.png b/gtk/stock-icons/32/gtk-yes.png new file mode 100644 index 000000000..bbf234dac Binary files /dev/null and b/gtk/stock-icons/32/gtk-yes.png differ diff --git a/gtk/stock-icons/32/help-about.png b/gtk/stock-icons/32/help-about.png new file mode 100644 index 000000000..53a9a7a7b Binary files /dev/null and b/gtk/stock-icons/32/help-about.png differ diff --git a/gtk/stock-icons/32/help-contents.png b/gtk/stock-icons/32/help-contents.png new file mode 100644 index 000000000..2be6a5492 Binary files /dev/null and b/gtk/stock-icons/32/help-contents.png differ diff --git a/gtk/stock-icons/32/image-missing.png b/gtk/stock-icons/32/image-missing.png new file mode 100644 index 000000000..e461278ec Binary files /dev/null and b/gtk/stock-icons/32/image-missing.png differ diff --git a/gtk/stock-icons/32/list-add.png b/gtk/stock-icons/32/list-add.png new file mode 100644 index 000000000..2761584e3 Binary files /dev/null and b/gtk/stock-icons/32/list-add.png differ diff --git a/gtk/stock-icons/32/list-remove.png b/gtk/stock-icons/32/list-remove.png new file mode 100644 index 000000000..c020d79c1 Binary files /dev/null and b/gtk/stock-icons/32/list-remove.png differ diff --git a/gtk/stock-icons/32/media-floppy.png b/gtk/stock-icons/32/media-floppy.png new file mode 100644 index 000000000..c9fb75683 Binary files /dev/null and b/gtk/stock-icons/32/media-floppy.png differ diff --git a/gtk/stock-icons/32/media-optical.png b/gtk/stock-icons/32/media-optical.png new file mode 100644 index 000000000..132e4ba57 Binary files /dev/null and b/gtk/stock-icons/32/media-optical.png differ diff --git a/gtk/stock-icons/32/media-playback-pause.png b/gtk/stock-icons/32/media-playback-pause.png new file mode 100644 index 000000000..3d7c2a5d8 Binary files /dev/null and b/gtk/stock-icons/32/media-playback-pause.png differ diff --git a/gtk/stock-icons/32/media-playback-start-ltr.png b/gtk/stock-icons/32/media-playback-start-ltr.png new file mode 100644 index 000000000..c03fd1bce Binary files /dev/null and b/gtk/stock-icons/32/media-playback-start-ltr.png differ diff --git a/gtk/stock-icons/32/media-playback-start-rtl.png b/gtk/stock-icons/32/media-playback-start-rtl.png new file mode 100644 index 000000000..575aeed8c Binary files /dev/null and b/gtk/stock-icons/32/media-playback-start-rtl.png differ diff --git a/gtk/stock-icons/32/media-playback-stop.png b/gtk/stock-icons/32/media-playback-stop.png new file mode 100644 index 000000000..6168a9a19 Binary files /dev/null and b/gtk/stock-icons/32/media-playback-stop.png differ diff --git a/gtk/stock-icons/32/media-record.png b/gtk/stock-icons/32/media-record.png new file mode 100644 index 000000000..864acf185 Binary files /dev/null and b/gtk/stock-icons/32/media-record.png differ diff --git a/gtk/stock-icons/32/media-seek-backward-ltr.png b/gtk/stock-icons/32/media-seek-backward-ltr.png new file mode 100644 index 000000000..41f4338d1 Binary files /dev/null and b/gtk/stock-icons/32/media-seek-backward-ltr.png differ diff --git a/gtk/stock-icons/32/media-seek-forward-ltr.png b/gtk/stock-icons/32/media-seek-forward-ltr.png new file mode 100644 index 000000000..fdca6f031 Binary files /dev/null and b/gtk/stock-icons/32/media-seek-forward-ltr.png differ diff --git a/gtk/stock-icons/32/media-skip-backward-ltr.png b/gtk/stock-icons/32/media-skip-backward-ltr.png new file mode 100644 index 000000000..d49f015c7 Binary files /dev/null and b/gtk/stock-icons/32/media-skip-backward-ltr.png differ diff --git a/gtk/stock-icons/32/media-skip-forward-ltr.png b/gtk/stock-icons/32/media-skip-forward-ltr.png new file mode 100644 index 000000000..b51c4f0fa Binary files /dev/null and b/gtk/stock-icons/32/media-skip-forward-ltr.png differ diff --git a/gtk/stock-icons/32/network-idle.png b/gtk/stock-icons/32/network-idle.png new file mode 100644 index 000000000..e4abce667 Binary files /dev/null and b/gtk/stock-icons/32/network-idle.png differ diff --git a/gtk/stock-icons/32/printer-error.png b/gtk/stock-icons/32/printer-error.png new file mode 100644 index 000000000..f75dacb78 Binary files /dev/null and b/gtk/stock-icons/32/printer-error.png differ diff --git a/gtk/stock-icons/32/printer-info.png b/gtk/stock-icons/32/printer-info.png new file mode 100644 index 000000000..64d05bb37 Binary files /dev/null and b/gtk/stock-icons/32/printer-info.png differ diff --git a/gtk/stock-icons/32/printer-paused.png b/gtk/stock-icons/32/printer-paused.png new file mode 100644 index 000000000..d77b0dd71 Binary files /dev/null and b/gtk/stock-icons/32/printer-paused.png differ diff --git a/gtk/stock-icons/32/printer-warning.png b/gtk/stock-icons/32/printer-warning.png new file mode 100644 index 000000000..0eed9bfef Binary files /dev/null and b/gtk/stock-icons/32/printer-warning.png differ diff --git a/gtk/stock-icons/32/process-stop.png b/gtk/stock-icons/32/process-stop.png new file mode 100644 index 000000000..3354da988 Binary files /dev/null and b/gtk/stock-icons/32/process-stop.png differ diff --git a/gtk/stock-icons/32/system-run.png b/gtk/stock-icons/32/system-run.png new file mode 100644 index 000000000..d5581a623 Binary files /dev/null and b/gtk/stock-icons/32/system-run.png differ diff --git a/gtk/stock-icons/32/text-x-generic.png b/gtk/stock-icons/32/text-x-generic.png new file mode 100644 index 000000000..9db523d7a Binary files /dev/null and b/gtk/stock-icons/32/text-x-generic.png differ diff --git a/gtk/stock-icons/32/tools-check-spelling.png b/gtk/stock-icons/32/tools-check-spelling.png new file mode 100644 index 000000000..4e2b56e6b Binary files /dev/null and b/gtk/stock-icons/32/tools-check-spelling.png differ diff --git a/gtk/stock-icons/32/view-fullscreen.png b/gtk/stock-icons/32/view-fullscreen.png new file mode 100644 index 000000000..982309b0c Binary files /dev/null and b/gtk/stock-icons/32/view-fullscreen.png differ diff --git a/gtk/stock-icons/32/view-refresh.png b/gtk/stock-icons/32/view-refresh.png new file mode 100644 index 000000000..b610e244c Binary files /dev/null and b/gtk/stock-icons/32/view-refresh.png differ diff --git a/gtk/stock-icons/32/view-restore.png b/gtk/stock-icons/32/view-restore.png new file mode 100644 index 000000000..17fa7d7f2 Binary files /dev/null and b/gtk/stock-icons/32/view-restore.png differ diff --git a/gtk/stock-icons/32/view-sort-ascending.png b/gtk/stock-icons/32/view-sort-ascending.png new file mode 100644 index 000000000..b83192d90 Binary files /dev/null and b/gtk/stock-icons/32/view-sort-ascending.png differ diff --git a/gtk/stock-icons/32/view-sort-descending.png b/gtk/stock-icons/32/view-sort-descending.png new file mode 100644 index 000000000..7522120cd Binary files /dev/null and b/gtk/stock-icons/32/view-sort-descending.png differ diff --git a/gtk/stock-icons/32/window-close.png b/gtk/stock-icons/32/window-close.png new file mode 100644 index 000000000..e343dedc9 Binary files /dev/null and b/gtk/stock-icons/32/window-close.png differ diff --git a/gtk/stock-icons/32/zoom-fit-best.png b/gtk/stock-icons/32/zoom-fit-best.png new file mode 100644 index 000000000..6a3dd2a8a Binary files /dev/null and b/gtk/stock-icons/32/zoom-fit-best.png differ diff --git a/gtk/stock-icons/32/zoom-in.png b/gtk/stock-icons/32/zoom-in.png new file mode 100644 index 000000000..14f32ae68 Binary files /dev/null and b/gtk/stock-icons/32/zoom-in.png differ diff --git a/gtk/stock-icons/32/zoom-original.png b/gtk/stock-icons/32/zoom-original.png new file mode 100644 index 000000000..1c37cdd70 Binary files /dev/null and b/gtk/stock-icons/32/zoom-original.png differ diff --git a/gtk/stock-icons/32/zoom-out.png b/gtk/stock-icons/32/zoom-out.png new file mode 100644 index 000000000..da057396d Binary files /dev/null and b/gtk/stock-icons/32/zoom-out.png differ diff --git a/gtk/stock-icons/48/application-exit.png b/gtk/stock-icons/48/application-exit.png new file mode 100644 index 000000000..238f53167 Binary files /dev/null and b/gtk/stock-icons/48/application-exit.png differ diff --git a/gtk/stock-icons/48/audio-volume-high.png b/gtk/stock-icons/48/audio-volume-high.png new file mode 100644 index 000000000..6461f1a99 Binary files /dev/null and b/gtk/stock-icons/48/audio-volume-high.png differ diff --git a/gtk/stock-icons/48/audio-volume-low.png b/gtk/stock-icons/48/audio-volume-low.png new file mode 100644 index 000000000..c12eea6dd Binary files /dev/null and b/gtk/stock-icons/48/audio-volume-low.png differ diff --git a/gtk/stock-icons/48/audio-volume-medium.png b/gtk/stock-icons/48/audio-volume-medium.png new file mode 100644 index 000000000..3b4cde98c Binary files /dev/null and b/gtk/stock-icons/48/audio-volume-medium.png differ diff --git a/gtk/stock-icons/48/audio-volume-muted.png b/gtk/stock-icons/48/audio-volume-muted.png new file mode 100644 index 000000000..8814651ec Binary files /dev/null and b/gtk/stock-icons/48/audio-volume-muted.png differ diff --git a/gtk/stock-icons/48/document-new.png b/gtk/stock-icons/48/document-new.png new file mode 100644 index 000000000..ff58d5923 Binary files /dev/null and b/gtk/stock-icons/48/document-new.png differ diff --git a/gtk/stock-icons/48/document-open-recent.png b/gtk/stock-icons/48/document-open-recent.png new file mode 100644 index 000000000..2bd0b2c87 Binary files /dev/null and b/gtk/stock-icons/48/document-open-recent.png differ diff --git a/gtk/stock-icons/48/document-open.png b/gtk/stock-icons/48/document-open.png new file mode 100644 index 000000000..cc5b9b4d0 Binary files /dev/null and b/gtk/stock-icons/48/document-open.png differ diff --git a/gtk/stock-icons/48/document-print-preview.png b/gtk/stock-icons/48/document-print-preview.png new file mode 100644 index 000000000..f34161f57 Binary files /dev/null and b/gtk/stock-icons/48/document-print-preview.png differ diff --git a/gtk/stock-icons/48/document-print.png b/gtk/stock-icons/48/document-print.png new file mode 100644 index 000000000..07f2cf6d5 Binary files /dev/null and b/gtk/stock-icons/48/document-print.png differ diff --git a/gtk/stock-icons/48/document-properties.png b/gtk/stock-icons/48/document-properties.png new file mode 100644 index 000000000..aa2b571e6 Binary files /dev/null and b/gtk/stock-icons/48/document-properties.png differ diff --git a/gtk/stock-icons/48/document-revert-ltr.png b/gtk/stock-icons/48/document-revert-ltr.png new file mode 100644 index 000000000..b39a94349 Binary files /dev/null and b/gtk/stock-icons/48/document-revert-ltr.png differ diff --git a/gtk/stock-icons/48/document-revert-rtl.png b/gtk/stock-icons/48/document-revert-rtl.png new file mode 100644 index 000000000..f5ed0b842 Binary files /dev/null and b/gtk/stock-icons/48/document-revert-rtl.png differ diff --git a/gtk/stock-icons/48/document-save-as.png b/gtk/stock-icons/48/document-save-as.png new file mode 100644 index 000000000..8f85c362c Binary files /dev/null and b/gtk/stock-icons/48/document-save-as.png differ diff --git a/gtk/stock-icons/48/drive-harddisk.png b/gtk/stock-icons/48/drive-harddisk.png new file mode 100644 index 000000000..6f58b99b3 Binary files /dev/null and b/gtk/stock-icons/48/drive-harddisk.png differ diff --git a/gtk/stock-icons/48/edit-clear.png b/gtk/stock-icons/48/edit-clear.png new file mode 100644 index 000000000..b1e05d079 Binary files /dev/null and b/gtk/stock-icons/48/edit-clear.png differ diff --git a/gtk/stock-icons/48/edit-copy.png b/gtk/stock-icons/48/edit-copy.png new file mode 100644 index 000000000..9e1810af0 Binary files /dev/null and b/gtk/stock-icons/48/edit-copy.png differ diff --git a/gtk/stock-icons/48/edit-cut.png b/gtk/stock-icons/48/edit-cut.png new file mode 100644 index 000000000..3a549af50 Binary files /dev/null and b/gtk/stock-icons/48/edit-cut.png differ diff --git a/gtk/stock-icons/48/edit-delete.png b/gtk/stock-icons/48/edit-delete.png new file mode 100644 index 000000000..4adf4db87 Binary files /dev/null and b/gtk/stock-icons/48/edit-delete.png differ diff --git a/gtk/stock-icons/48/edit-find-replace.png b/gtk/stock-icons/48/edit-find-replace.png new file mode 100644 index 000000000..0a2478fab Binary files /dev/null and b/gtk/stock-icons/48/edit-find-replace.png differ diff --git a/gtk/stock-icons/48/edit-find.png b/gtk/stock-icons/48/edit-find.png new file mode 100644 index 000000000..39a2f71f5 Binary files /dev/null and b/gtk/stock-icons/48/edit-find.png differ diff --git a/gtk/stock-icons/48/edit-paste.png b/gtk/stock-icons/48/edit-paste.png new file mode 100644 index 000000000..36f047500 Binary files /dev/null and b/gtk/stock-icons/48/edit-paste.png differ diff --git a/gtk/stock-icons/48/edit-redo-ltr.png b/gtk/stock-icons/48/edit-redo-ltr.png new file mode 100644 index 000000000..56cec8ed2 Binary files /dev/null and b/gtk/stock-icons/48/edit-redo-ltr.png differ diff --git a/gtk/stock-icons/48/edit-redo-rtl.png b/gtk/stock-icons/48/edit-redo-rtl.png new file mode 100644 index 000000000..e4d0d1b21 Binary files /dev/null and b/gtk/stock-icons/48/edit-redo-rtl.png differ diff --git a/gtk/stock-icons/48/edit-select-all.png b/gtk/stock-icons/48/edit-select-all.png new file mode 100644 index 000000000..9bd2c6ad4 Binary files /dev/null and b/gtk/stock-icons/48/edit-select-all.png differ diff --git a/gtk/stock-icons/48/edit-undo-ltr.png b/gtk/stock-icons/48/edit-undo-ltr.png new file mode 100644 index 000000000..c6a8e5979 Binary files /dev/null and b/gtk/stock-icons/48/edit-undo-ltr.png differ diff --git a/gtk/stock-icons/48/edit-undo-rtl.png b/gtk/stock-icons/48/edit-undo-rtl.png new file mode 100644 index 000000000..cfb529ba0 Binary files /dev/null and b/gtk/stock-icons/48/edit-undo-rtl.png differ diff --git a/gtk/stock-icons/48/folder.png b/gtk/stock-icons/48/folder.png new file mode 100644 index 000000000..5fcef613d Binary files /dev/null and b/gtk/stock-icons/48/folder.png differ diff --git a/gtk/stock-icons/48/format-indent-less-ltr.png b/gtk/stock-icons/48/format-indent-less-ltr.png new file mode 100644 index 000000000..681f9ff90 Binary files /dev/null and b/gtk/stock-icons/48/format-indent-less-ltr.png differ diff --git a/gtk/stock-icons/48/format-indent-less-rtl.png b/gtk/stock-icons/48/format-indent-less-rtl.png new file mode 100644 index 000000000..da3c94adb Binary files /dev/null and b/gtk/stock-icons/48/format-indent-less-rtl.png differ diff --git a/gtk/stock-icons/48/format-indent-more-ltr.png b/gtk/stock-icons/48/format-indent-more-ltr.png new file mode 100644 index 000000000..96666248f Binary files /dev/null and b/gtk/stock-icons/48/format-indent-more-ltr.png differ diff --git a/gtk/stock-icons/48/format-indent-more-rtl.png b/gtk/stock-icons/48/format-indent-more-rtl.png new file mode 100644 index 000000000..52f054fb2 Binary files /dev/null and b/gtk/stock-icons/48/format-indent-more-rtl.png differ diff --git a/gtk/stock-icons/48/format-justify-center.png b/gtk/stock-icons/48/format-justify-center.png new file mode 100644 index 000000000..435e13f60 Binary files /dev/null and b/gtk/stock-icons/48/format-justify-center.png differ diff --git a/gtk/stock-icons/48/format-justify-fill.png b/gtk/stock-icons/48/format-justify-fill.png new file mode 100644 index 000000000..0901e50a9 Binary files /dev/null and b/gtk/stock-icons/48/format-justify-fill.png differ diff --git a/gtk/stock-icons/48/format-justify-left.png b/gtk/stock-icons/48/format-justify-left.png new file mode 100644 index 000000000..441aba1c1 Binary files /dev/null and b/gtk/stock-icons/48/format-justify-left.png differ diff --git a/gtk/stock-icons/48/format-justify-right.png b/gtk/stock-icons/48/format-justify-right.png new file mode 100644 index 000000000..fe6997751 Binary files /dev/null and b/gtk/stock-icons/48/format-justify-right.png differ diff --git a/gtk/stock-icons/48/format-text-bold.png b/gtk/stock-icons/48/format-text-bold.png new file mode 100644 index 000000000..491923fda Binary files /dev/null and b/gtk/stock-icons/48/format-text-bold.png differ diff --git a/gtk/stock-icons/48/format-text-italic.png b/gtk/stock-icons/48/format-text-italic.png new file mode 100644 index 000000000..17192f3e0 Binary files /dev/null and b/gtk/stock-icons/48/format-text-italic.png differ diff --git a/gtk/stock-icons/48/format-text-strikethrough.png b/gtk/stock-icons/48/format-text-strikethrough.png new file mode 100644 index 000000000..d470a4833 Binary files /dev/null and b/gtk/stock-icons/48/format-text-strikethrough.png differ diff --git a/gtk/stock-icons/48/format-text-underline.png b/gtk/stock-icons/48/format-text-underline.png new file mode 100644 index 000000000..7f4a6f666 Binary files /dev/null and b/gtk/stock-icons/48/format-text-underline.png differ diff --git a/gtk/stock-icons/48/go-bottom.png b/gtk/stock-icons/48/go-bottom.png new file mode 100644 index 000000000..a944ea5fe Binary files /dev/null and b/gtk/stock-icons/48/go-bottom.png differ diff --git a/gtk/stock-icons/48/go-down.png b/gtk/stock-icons/48/go-down.png new file mode 100644 index 000000000..0cf0cb7bc Binary files /dev/null and b/gtk/stock-icons/48/go-down.png differ diff --git a/gtk/stock-icons/48/go-first-ltr.png b/gtk/stock-icons/48/go-first-ltr.png new file mode 100644 index 000000000..7fd9bd35b Binary files /dev/null and b/gtk/stock-icons/48/go-first-ltr.png differ diff --git a/gtk/stock-icons/48/go-home.png b/gtk/stock-icons/48/go-home.png new file mode 100644 index 000000000..42d7c674d Binary files /dev/null and b/gtk/stock-icons/48/go-home.png differ diff --git a/gtk/stock-icons/48/go-jump-ltr.png b/gtk/stock-icons/48/go-jump-ltr.png new file mode 100644 index 000000000..ddee52624 Binary files /dev/null and b/gtk/stock-icons/48/go-jump-ltr.png differ diff --git a/gtk/stock-icons/48/go-jump-rtl.png b/gtk/stock-icons/48/go-jump-rtl.png new file mode 100644 index 000000000..f8a319f6b Binary files /dev/null and b/gtk/stock-icons/48/go-jump-rtl.png differ diff --git a/gtk/stock-icons/48/go-last-ltr.png b/gtk/stock-icons/48/go-last-ltr.png new file mode 100644 index 000000000..166b8d964 Binary files /dev/null and b/gtk/stock-icons/48/go-last-ltr.png differ diff --git a/gtk/stock-icons/48/go-next-ltr.png b/gtk/stock-icons/48/go-next-ltr.png new file mode 100644 index 000000000..614db4f61 Binary files /dev/null and b/gtk/stock-icons/48/go-next-ltr.png differ diff --git a/gtk/stock-icons/48/go-previous-ltr.png b/gtk/stock-icons/48/go-previous-ltr.png new file mode 100644 index 000000000..e6b823ad5 Binary files /dev/null and b/gtk/stock-icons/48/go-previous-ltr.png differ diff --git a/gtk/stock-icons/48/go-top.png b/gtk/stock-icons/48/go-top.png new file mode 100644 index 000000000..8837b21a6 Binary files /dev/null and b/gtk/stock-icons/48/go-top.png differ diff --git a/gtk/stock-icons/48/go-up.png b/gtk/stock-icons/48/go-up.png new file mode 100644 index 000000000..d924dda2f Binary files /dev/null and b/gtk/stock-icons/48/go-up.png differ diff --git a/gtk/stock-icons/48/gtk-apply.png b/gtk/stock-icons/48/gtk-apply.png new file mode 100644 index 000000000..fa6b9b070 Binary files /dev/null and b/gtk/stock-icons/48/gtk-apply.png differ diff --git a/gtk/stock-icons/48/gtk-cancel.png b/gtk/stock-icons/48/gtk-cancel.png new file mode 100644 index 000000000..ca0b15fea Binary files /dev/null and b/gtk/stock-icons/48/gtk-cancel.png differ diff --git a/gtk/stock-icons/48/gtk-caps-lock-warning.png b/gtk/stock-icons/48/gtk-caps-lock-warning.png new file mode 100644 index 000000000..dbac6b9ac Binary files /dev/null and b/gtk/stock-icons/48/gtk-caps-lock-warning.png differ diff --git a/gtk/stock-icons/48/gtk-color-picker.png b/gtk/stock-icons/48/gtk-color-picker.png new file mode 100644 index 000000000..d29cc6732 Binary files /dev/null and b/gtk/stock-icons/48/gtk-color-picker.png differ diff --git a/gtk/stock-icons/48/gtk-connect.png b/gtk/stock-icons/48/gtk-connect.png new file mode 100644 index 000000000..dc5118a01 Binary files /dev/null and b/gtk/stock-icons/48/gtk-connect.png differ diff --git a/gtk/stock-icons/48/gtk-convert.png b/gtk/stock-icons/48/gtk-convert.png new file mode 100644 index 000000000..a62a56964 Binary files /dev/null and b/gtk/stock-icons/48/gtk-convert.png differ diff --git a/gtk/stock-icons/48/gtk-disconnect.png b/gtk/stock-icons/48/gtk-disconnect.png new file mode 100644 index 000000000..12c86ec1c Binary files /dev/null and b/gtk/stock-icons/48/gtk-disconnect.png differ diff --git a/gtk/stock-icons/48/gtk-dnd-multiple.png b/gtk/stock-icons/48/gtk-dnd-multiple.png new file mode 100644 index 000000000..f0ac5ca02 Binary files /dev/null and b/gtk/stock-icons/48/gtk-dnd-multiple.png differ diff --git a/gtk/stock-icons/48/gtk-dnd.png b/gtk/stock-icons/48/gtk-dnd.png new file mode 100644 index 000000000..ed5007db2 Binary files /dev/null and b/gtk/stock-icons/48/gtk-dnd.png differ diff --git a/gtk/stock-icons/48/gtk-edit.png b/gtk/stock-icons/48/gtk-edit.png new file mode 100644 index 000000000..aa965d038 Binary files /dev/null and b/gtk/stock-icons/48/gtk-edit.png differ diff --git a/gtk/stock-icons/48/gtk-font.png b/gtk/stock-icons/48/gtk-font.png new file mode 100644 index 000000000..b7ccbbe33 Binary files /dev/null and b/gtk/stock-icons/48/gtk-font.png differ diff --git a/gtk/stock-icons/48/gtk-index.png b/gtk/stock-icons/48/gtk-index.png new file mode 100644 index 000000000..95319923b Binary files /dev/null and b/gtk/stock-icons/48/gtk-index.png differ diff --git a/gtk/stock-icons/48/gtk-no.png b/gtk/stock-icons/48/gtk-no.png new file mode 100644 index 000000000..2edd0d21b Binary files /dev/null and b/gtk/stock-icons/48/gtk-no.png differ diff --git a/gtk/stock-icons/48/gtk-ok.png b/gtk/stock-icons/48/gtk-ok.png new file mode 100644 index 000000000..c8ece5add Binary files /dev/null and b/gtk/stock-icons/48/gtk-ok.png differ diff --git a/gtk/stock-icons/48/gtk-orientation-landscape.png b/gtk/stock-icons/48/gtk-orientation-landscape.png new file mode 100644 index 000000000..eb225d854 Binary files /dev/null and b/gtk/stock-icons/48/gtk-orientation-landscape.png differ diff --git a/gtk/stock-icons/48/gtk-orientation-portrait.png b/gtk/stock-icons/48/gtk-orientation-portrait.png new file mode 100644 index 000000000..17589ede1 Binary files /dev/null and b/gtk/stock-icons/48/gtk-orientation-portrait.png differ diff --git a/gtk/stock-icons/48/gtk-orientation-reverse-landscape.png b/gtk/stock-icons/48/gtk-orientation-reverse-landscape.png new file mode 100644 index 000000000..ab4549182 Binary files /dev/null and b/gtk/stock-icons/48/gtk-orientation-reverse-landscape.png differ diff --git a/gtk/stock-icons/48/gtk-orientation-reverse-portrait.png b/gtk/stock-icons/48/gtk-orientation-reverse-portrait.png new file mode 100644 index 000000000..b358d4211 Binary files /dev/null and b/gtk/stock-icons/48/gtk-orientation-reverse-portrait.png differ diff --git a/gtk/stock-icons/48/gtk-page-setup.png b/gtk/stock-icons/48/gtk-page-setup.png new file mode 100644 index 000000000..a34b06771 Binary files /dev/null and b/gtk/stock-icons/48/gtk-page-setup.png differ diff --git a/gtk/stock-icons/48/gtk-preferences.png b/gtk/stock-icons/48/gtk-preferences.png new file mode 100644 index 000000000..c01cd1c71 Binary files /dev/null and b/gtk/stock-icons/48/gtk-preferences.png differ diff --git a/gtk/stock-icons/48/gtk-select-color.png b/gtk/stock-icons/48/gtk-select-color.png new file mode 100644 index 000000000..451d3eced Binary files /dev/null and b/gtk/stock-icons/48/gtk-select-color.png differ diff --git a/gtk/stock-icons/48/gtk-select-font.png b/gtk/stock-icons/48/gtk-select-font.png new file mode 100644 index 000000000..41395f767 Binary files /dev/null and b/gtk/stock-icons/48/gtk-select-font.png differ diff --git a/gtk/stock-icons/48/gtk-undelete-ltr.png b/gtk/stock-icons/48/gtk-undelete-ltr.png new file mode 100644 index 000000000..681368b60 Binary files /dev/null and b/gtk/stock-icons/48/gtk-undelete-ltr.png differ diff --git a/gtk/stock-icons/48/gtk-undelete-rtl.png b/gtk/stock-icons/48/gtk-undelete-rtl.png new file mode 100644 index 000000000..ec3ba3b7c Binary files /dev/null and b/gtk/stock-icons/48/gtk-undelete-rtl.png differ diff --git a/gtk/stock-icons/48/gtk-yes.png b/gtk/stock-icons/48/gtk-yes.png new file mode 100644 index 000000000..31d31b1f9 Binary files /dev/null and b/gtk/stock-icons/48/gtk-yes.png differ diff --git a/gtk/stock-icons/48/help-about.png b/gtk/stock-icons/48/help-about.png new file mode 100644 index 000000000..d27628e2a Binary files /dev/null and b/gtk/stock-icons/48/help-about.png differ diff --git a/gtk/stock-icons/48/help-contents.png b/gtk/stock-icons/48/help-contents.png new file mode 100644 index 000000000..e1a3fe44a Binary files /dev/null and b/gtk/stock-icons/48/help-contents.png differ diff --git a/gtk/stock-icons/48/image-missing.png b/gtk/stock-icons/48/image-missing.png new file mode 100644 index 000000000..69f2b3b0a Binary files /dev/null and b/gtk/stock-icons/48/image-missing.png differ diff --git a/gtk/stock-icons/48/list-add.png b/gtk/stock-icons/48/list-add.png new file mode 100644 index 000000000..6807badb5 Binary files /dev/null and b/gtk/stock-icons/48/list-add.png differ diff --git a/gtk/stock-icons/48/list-remove.png b/gtk/stock-icons/48/list-remove.png new file mode 100644 index 000000000..6fda73146 Binary files /dev/null and b/gtk/stock-icons/48/list-remove.png differ diff --git a/gtk/stock-icons/48/media-floppy.png b/gtk/stock-icons/48/media-floppy.png new file mode 100644 index 000000000..901bb6020 Binary files /dev/null and b/gtk/stock-icons/48/media-floppy.png differ diff --git a/gtk/stock-icons/48/media-optical.png b/gtk/stock-icons/48/media-optical.png new file mode 100644 index 000000000..4ade3087e Binary files /dev/null and b/gtk/stock-icons/48/media-optical.png differ diff --git a/gtk/stock-icons/48/media-playback-pause.png b/gtk/stock-icons/48/media-playback-pause.png new file mode 100644 index 000000000..a0072f23d Binary files /dev/null and b/gtk/stock-icons/48/media-playback-pause.png differ diff --git a/gtk/stock-icons/48/media-playback-start-ltr.png b/gtk/stock-icons/48/media-playback-start-ltr.png new file mode 100644 index 000000000..f8751b9f2 Binary files /dev/null and b/gtk/stock-icons/48/media-playback-start-ltr.png differ diff --git a/gtk/stock-icons/48/media-playback-start-rtl.png b/gtk/stock-icons/48/media-playback-start-rtl.png new file mode 100644 index 000000000..e3b1b8384 Binary files /dev/null and b/gtk/stock-icons/48/media-playback-start-rtl.png differ diff --git a/gtk/stock-icons/48/media-playback-stop.png b/gtk/stock-icons/48/media-playback-stop.png new file mode 100644 index 000000000..703126cbe Binary files /dev/null and b/gtk/stock-icons/48/media-playback-stop.png differ diff --git a/gtk/stock-icons/48/media-record.png b/gtk/stock-icons/48/media-record.png new file mode 100644 index 000000000..ab5b02d4f Binary files /dev/null and b/gtk/stock-icons/48/media-record.png differ diff --git a/gtk/stock-icons/48/media-seek-backward-ltr.png b/gtk/stock-icons/48/media-seek-backward-ltr.png new file mode 100644 index 000000000..82d4dd03c Binary files /dev/null and b/gtk/stock-icons/48/media-seek-backward-ltr.png differ diff --git a/gtk/stock-icons/48/media-seek-forward-ltr.png b/gtk/stock-icons/48/media-seek-forward-ltr.png new file mode 100644 index 000000000..4c1e2a51b Binary files /dev/null and b/gtk/stock-icons/48/media-seek-forward-ltr.png differ diff --git a/gtk/stock-icons/48/media-skip-backward-ltr.png b/gtk/stock-icons/48/media-skip-backward-ltr.png new file mode 100644 index 000000000..55f0a3752 Binary files /dev/null and b/gtk/stock-icons/48/media-skip-backward-ltr.png differ diff --git a/gtk/stock-icons/48/media-skip-forward-ltr.png b/gtk/stock-icons/48/media-skip-forward-ltr.png new file mode 100644 index 000000000..771be762a Binary files /dev/null and b/gtk/stock-icons/48/media-skip-forward-ltr.png differ diff --git a/gtk/stock-icons/48/network-idle.png b/gtk/stock-icons/48/network-idle.png new file mode 100644 index 000000000..c79efbcf5 Binary files /dev/null and b/gtk/stock-icons/48/network-idle.png differ diff --git a/gtk/stock-icons/48/printer-error.png b/gtk/stock-icons/48/printer-error.png new file mode 100644 index 000000000..62c2cb7f6 Binary files /dev/null and b/gtk/stock-icons/48/printer-error.png differ diff --git a/gtk/stock-icons/48/printer-info.png b/gtk/stock-icons/48/printer-info.png new file mode 100644 index 000000000..414887b65 Binary files /dev/null and b/gtk/stock-icons/48/printer-info.png differ diff --git a/gtk/stock-icons/48/printer-paused.png b/gtk/stock-icons/48/printer-paused.png new file mode 100644 index 000000000..145cd3a16 Binary files /dev/null and b/gtk/stock-icons/48/printer-paused.png differ diff --git a/gtk/stock-icons/48/printer-warning.png b/gtk/stock-icons/48/printer-warning.png new file mode 100644 index 000000000..b7a08eb06 Binary files /dev/null and b/gtk/stock-icons/48/printer-warning.png differ diff --git a/gtk/stock-icons/48/process-stop.png b/gtk/stock-icons/48/process-stop.png new file mode 100644 index 000000000..541d40308 Binary files /dev/null and b/gtk/stock-icons/48/process-stop.png differ diff --git a/gtk/stock-icons/48/system-run.png b/gtk/stock-icons/48/system-run.png new file mode 100644 index 000000000..2feadaa63 Binary files /dev/null and b/gtk/stock-icons/48/system-run.png differ diff --git a/gtk/stock-icons/48/text-x-generic.png b/gtk/stock-icons/48/text-x-generic.png new file mode 100644 index 000000000..ff58d5923 Binary files /dev/null and b/gtk/stock-icons/48/text-x-generic.png differ diff --git a/gtk/stock-icons/48/tools-check-spelling.png b/gtk/stock-icons/48/tools-check-spelling.png new file mode 100644 index 000000000..3b95d2e03 Binary files /dev/null and b/gtk/stock-icons/48/tools-check-spelling.png differ diff --git a/gtk/stock-icons/48/view-fullscreen.png b/gtk/stock-icons/48/view-fullscreen.png new file mode 100644 index 000000000..b47d1838a Binary files /dev/null and b/gtk/stock-icons/48/view-fullscreen.png differ diff --git a/gtk/stock-icons/48/view-refresh.png b/gtk/stock-icons/48/view-refresh.png new file mode 100644 index 000000000..db0eeb66f Binary files /dev/null and b/gtk/stock-icons/48/view-refresh.png differ diff --git a/gtk/stock-icons/48/view-restore.png b/gtk/stock-icons/48/view-restore.png new file mode 100644 index 000000000..e7c7b6ce7 Binary files /dev/null and b/gtk/stock-icons/48/view-restore.png differ diff --git a/gtk/stock-icons/48/view-sort-ascending.png b/gtk/stock-icons/48/view-sort-ascending.png new file mode 100644 index 000000000..af6bb165c Binary files /dev/null and b/gtk/stock-icons/48/view-sort-ascending.png differ diff --git a/gtk/stock-icons/48/view-sort-descending.png b/gtk/stock-icons/48/view-sort-descending.png new file mode 100644 index 000000000..e461fd3a0 Binary files /dev/null and b/gtk/stock-icons/48/view-sort-descending.png differ diff --git a/gtk/stock-icons/48/window-close.png b/gtk/stock-icons/48/window-close.png new file mode 100644 index 000000000..65711cfda Binary files /dev/null and b/gtk/stock-icons/48/window-close.png differ diff --git a/gtk/stock-icons/48/zoom-fit-best.png b/gtk/stock-icons/48/zoom-fit-best.png new file mode 100644 index 000000000..25dc631b2 Binary files /dev/null and b/gtk/stock-icons/48/zoom-fit-best.png differ diff --git a/gtk/stock-icons/48/zoom-in.png b/gtk/stock-icons/48/zoom-in.png new file mode 100644 index 000000000..48875562a Binary files /dev/null and b/gtk/stock-icons/48/zoom-in.png differ diff --git a/gtk/stock-icons/48/zoom-original.png b/gtk/stock-icons/48/zoom-original.png new file mode 100644 index 000000000..e85133637 Binary files /dev/null and b/gtk/stock-icons/48/zoom-original.png differ diff --git a/gtk/stock-icons/48/zoom-out.png b/gtk/stock-icons/48/zoom-out.png new file mode 100644 index 000000000..4b94622e5 Binary files /dev/null and b/gtk/stock-icons/48/zoom-out.png differ diff --git a/gtk/stock-icons/render-sizes.py b/gtk/stock-icons/render-sizes.py new file mode 100755 index 000000000..2245fda6d --- /dev/null +++ b/gtk/stock-icons/render-sizes.py @@ -0,0 +1,65 @@ +#!/usr/bin/env python3 +# render-sizes.py - makes the stock icons of the sizes GTK+ 2 asks for +# (16, 18, 20, 24, 32, 48) where there is no PNG of that size yet. +# +# As Mac OS X does for sizes it has no picture for: the drawing (the SVG +# made for the largest size not above the one wanted, or the smallest) +# is rendered at twice the size, then made smaller with a Lanczos filter. +# Icons without an SVG are made from the next larger PNG the same way, +# or, without one, enlarged from the largest. +# +# Needs rsvg-convert (librsvg) and Python with PIL; run it in this folder +# when an SVG changes. The PNGs it writes are part of the sources, so +# building GTK+ needs neither. +import os, subprocess, sys, tempfile +from PIL import Image + +SIZES = (16, 18, 20, 24, 32, 48) +here = os.path.dirname (os.path.abspath (__file__)) +os.chdir (here) + +def files (ext): + found = {} + for d in os.listdir ('.'): + if not d.isdigit (): + continue + for f in os.listdir (d): + p = os.path.join (d, f) + if f.endswith (ext) and not os.path.islink (p): + found.setdefault (f[:-len (ext)], {})[int (d)] = p + return found + +def render (svg, n): + with tempfile.NamedTemporaryFile (suffix='.png') as t: + subprocess.run (['rsvg-convert', '-w', str (n), '-h', str (n), '-o', t.name, svg], check=True) + return Image.open (t.name).convert ('RGBA').copy () + +def reduce (im, n): + # in premultiplied colour, so the edges of transparent parts stay clean + return im.convert ('RGBa').resize ((n, n), Image.LANCZOS).convert ('RGBA') + +pngs, svgs = files ('.png'), files ('.svg') +made = 0 +for name, have in sorted (pngs.items ()): + for size in SIZES: + if size in have: + continue + designs = svgs.get (name, {}) + if designs: + below = [d for d in designs if d <= size] + design = max (below) if below else min (designs) + im = reduce (render (designs[design], 2 * size), size) + else: + larger = [d for d in have if d > size] + if larger: + im = reduce (Image.open (have[min (larger)]).convert ('RGBA'), size) + else: + src = Image.open (have[max (have)]).convert ('RGBA') + k = size // src.width + if k >= 2: + src = src.resize ((src.width * k, src.height * k), Image.NEAREST) + im = src.resize ((size, size), Image.BILINEAR) + os.makedirs (str (size), exist_ok=True) + im.save (os.path.join (str (size), name + '.png'), optimize=True) + made += 1 +print (made, 'icons made', file=sys.stderr) diff --git a/gtk/updateiconcache.c b/gtk/updateiconcache.c index 4a3158e12..6bac69b6f 100644 --- a/gtk/updateiconcache.c +++ b/gtk/updateiconcache.c @@ -33,6 +33,12 @@ #ifdef _MSC_VER #include #include +#ifndef S_ISDIR +#define S_ISDIR(mode) (((mode) & _S_IFMT) == _S_IFDIR) +#endif +#ifndef S_ISREG +#define S_ISREG(mode) (((mode) & _S_IFMT) == _S_IFREG) +#endif #else #include #endif @@ -43,6 +49,7 @@ #include "gtkpixdatautils.h" #include #include "gtkiconcachevalidator.h" +#include "gtktimeprivate.h" static gboolean force_update = FALSE; static gboolean ignore_theme_index = FALSE; @@ -70,19 +77,36 @@ static gchar *var_name = "-"; #define ALIGN_VALUE(this, boundary) \ (( ((unsigned long)(this)) + (((unsigned long)(boundary)) -1)) & (~(((unsigned long)(boundary))-1))) +/* The times are 64-bit seconds (gtktimeprivate.h): with the stat of a + * 32-bit time_t or of 32-bit Windows, a theme changed after 2038 could + * not be checked or got no cache at all */ #ifdef HAVE_FTW_H #include -static struct stat cache_stat; +static gint64 cache_mtime; static gboolean cache_up_to_date; static int check_dir_mtime (const char *dir, const struct stat *sb, int tf) { - if (tf != FTW_NS && - (gint64) sb->st_mtime > (gint64) cache_stat.st_mtime) + gint64 mtime; + + if (tf == FTW_NS) + { + /* the stat of ftw() failed, as it does for a time it cannot give + * in a 32-bit time_t */ + GtkStatBuf buf; + + if (_gtk_stat (dir, TRUE, &buf) != 0) + return 0; + mtime = buf.mtime; + } + else + mtime = _gtk_time_from_time_t (sb->st_mtime); + + if (mtime > cache_mtime) { cache_up_to_date = FALSE; /* stop tree walk */ @@ -97,9 +121,10 @@ static int check_dir_mtime (const char *dir, { gchar *cache_path; gint retval; + GtkStatBuf cache_stat; cache_path = g_build_filename (path, CACHE_NAME, NULL); - retval = g_stat (cache_path, &cache_stat); + retval = _gtk_stat (cache_path, TRUE, &cache_stat); g_free (cache_path); if (retval < 0) @@ -108,6 +133,7 @@ static int check_dir_mtime (const char *dir, return FALSE; } + cache_mtime = cache_stat.mtime; cache_up_to_date = TRUE; ftw (path, check_dir_mtime, 20); @@ -120,11 +146,11 @@ static int check_dir_mtime (const char *dir, gboolean is_cache_up_to_date (const gchar *path) { - GStatBuf path_stat, cache_stat; + GtkStatBuf path_stat, cache_stat; gchar *cache_path; int retval; - retval = g_stat (path, &path_stat); + retval = _gtk_stat (path, TRUE, &path_stat); if (retval < 0) { @@ -134,7 +160,7 @@ is_cache_up_to_date (const gchar *path) } cache_path = g_build_filename (path, CACHE_NAME, NULL); - retval = g_stat (cache_path, &cache_stat); + retval = _gtk_stat (cache_path, TRUE, &cache_stat); g_free (cache_path); if (retval < 0) @@ -144,7 +170,7 @@ is_cache_up_to_date (const gchar *path) } /* Check mtime */ - return (gint64) cache_stat.st_mtime >= (gint64) path_stat.st_mtime; + return cache_stat.mtime >= path_stat.mtime; } #endif /* !HAVE_FTW_H */ @@ -288,8 +314,7 @@ load_icon_data (const char *path) data->n_attach_points = g_strv_length (split); data->attach_points = g_new (int, 2 * data->n_attach_points); - i = 0; - while (split[i] != NULL && i < data->n_attach_points) + for (i = 0; i < data->n_attach_points; ++i) { split_point = strchr (split[i], ','); if (split_point) @@ -299,7 +324,6 @@ load_icon_data (const char *path) data->attach_points[2 * i] = atoi (split[i]); data->attach_points[2 * i + 1] = atoi (split_point); } - i++; } g_strfreev (split); @@ -608,6 +632,13 @@ replace_backslashes_with_slashes (gchar *path) path[i] = '/'; } +static gint +compare_names (gconstpointer a, + gconstpointer b) +{ + return strcmp (*(const gchar * const *) a, *(const gchar * const *) b); +} + static GList * scan_directory (const gchar *base_path, const gchar *subdir, @@ -617,10 +648,12 @@ scan_directory (const gchar *base_path, { GHashTable *dir_hash; GDir *dir; + GPtrArray *names; const gchar *name; gchar *dir_path; gboolean dir_added = FALSE; guint dir_index = 0xffff; + guint i; dir_path = g_build_path ("/", base_path, subdir, NULL); @@ -628,22 +661,40 @@ scan_directory (const gchar *base_path, dir = g_dir_open (dir_path, 0, NULL); if (!dir) - return directories; + { + g_free (dir_path); + return directories; + } + + /* In name order, so the cache does not depend on the file system */ + names = g_ptr_array_new_with_free_func (g_free); + while ((name = g_dir_read_name (dir))) + g_ptr_array_add (names, g_strdup (name)); + g_dir_close (dir); + g_ptr_array_sort (names, compare_names); dir_hash = g_hash_table_new (g_str_hash, g_str_equal); - while ((name = g_dir_read_name (dir))) + for (i = 0; i < names->len; i++) { gchar *path; - gboolean retval; + GtkStatBuf st; int flags = 0; Image *image; gchar *basename, *dot; + name = g_ptr_array_index (names, i); path = g_build_filename (dir_path, name, NULL); - retval = g_file_test (path, G_FILE_TEST_IS_DIR); - if (retval) + /* not g_stat(): with a 32-bit time_t it fails for files changed + * after 2038, which then were left out of the cache */ + if (_gtk_stat (path, TRUE, &st) != 0) + { + g_free (path); + continue; + } + + if (S_ISDIR (st.mode)) { gchar *subsubdir; @@ -654,16 +705,9 @@ scan_directory (const gchar *base_path, directories = scan_directory (base_path, subsubdir, files, directories, depth + 1); g_free (subsubdir); - - continue; } - /* ignore images in the toplevel directory */ - if (subdir == NULL) - continue; - - retval = g_file_test (path, G_FILE_TEST_IS_REGULAR); - if (retval) + else if (subdir != NULL && S_ISREG (st.mode)) { if (g_str_has_suffix (name, ".png")) flags |= HAS_SUFFIX_PNG; @@ -675,7 +719,10 @@ scan_directory (const gchar *base_path, flags |= HAS_ICON_FILE; if (flags == 0) - continue; + { + g_free (path); + continue; + } basename = g_strdup (name); dot = strrchr (basename, '.'); @@ -712,7 +759,8 @@ scan_directory (const gchar *base_path, g_free (path); } - g_dir_close (dir); + g_ptr_array_free (names, TRUE); + g_free (dir_path); /* Move dir into the big file hash */ g_hash_table_foreach_remove (dir_hash, foreach_remove_func, files); @@ -1482,8 +1530,7 @@ build_cache (const gchar *path) #endif GHashTable *files; FILE *cache; - GStatBuf path_stat, cache_stat; - struct utimbuf utime_buf; + GtkStatBuf cache_stat; GList *directories = NULL; int fd; int retry_count = 0; @@ -1502,7 +1549,9 @@ build_cache (const gchar *path) opentmp: if ((fd = g_open (tmp_cache_path, O_WRONLY | O_CREAT | O_EXCL | O_TRUNC | _O_BINARY, mode)) == -1) { - if (force_update && retry_count == 0) + /* a temporary file left by a run that did not finish would + * otherwise keep the cache from ever being updated again */ + if (retry_count == 0) { retry_count++; g_remove (tmp_cache_path); @@ -1607,19 +1656,13 @@ opentmp: g_unlink (bak_cache_path); #endif - /* Update time */ + /* Update time: the folder gets the time of the cache, which renaming + * the cache into it made older */ /* FIXME: What do do if an error occurs here? */ - if (g_stat (path, &path_stat) < 0 || - g_stat (cache_path, &cache_stat)) + if (_gtk_stat (cache_path, TRUE, &cache_stat) != 0) exit (1); - utime_buf.actime = path_stat.st_atime; - utime_buf.modtime = cache_stat.st_mtime; -#if GLIB_CHECK_VERSION (2, 17, 1) - g_utime (path, &utime_buf); -#else - utime (path, &utime_buf); -#endif + _gtk_set_mtime (path, cache_stat.mtime); if (!quiet) g_printerr (_("Cache file created successfully.\n")); @@ -1686,11 +1729,9 @@ printerr_handler (const gchar *string) result = g_convert_with_fallback (string, -1, charset, "UTF-8", "?", NULL, NULL, NULL); - if (result) - { - fputs (result, stderr); - g_free (result); - } + /* a message that does not convert is still better as it is */ + fputs (result ? result : string, stderr); + g_free (result); fflush (stderr); } @@ -1702,6 +1743,7 @@ main (int argc, char **argv) { gchar *path; GOptionContext *context; + GError *error = NULL; if (argc < 2) return 0; @@ -1720,7 +1762,17 @@ main (int argc, char **argv) context = g_option_context_new ("ICONPATH"); g_option_context_add_main_entries (context, args, GETTEXT_PACKAGE); - g_option_context_parse (context, &argc, &argv, NULL); + if (!g_option_context_parse (context, &argc, &argv, &error)) + { + g_printerr ("%s\n", error->message); + exit (1); + } + + if (argc < 2) + { + g_printerr ("%s\n", _("No icon folder given")); + exit (1); + } path = argv[1]; #ifdef G_OS_WIN32 diff --git a/modules/engines/ms-windows/msw_style.c b/modules/engines/ms-windows/msw_style.c index 6f1525920..e50d5267f 100755 --- a/modules/engines/ms-windows/msw_style.c +++ b/modules/engines/ms-windows/msw_style.c @@ -461,11 +461,11 @@ msw_style_setup_system_settings (void) } g_object_set (settings, "gtk-double-click-distance", - GetSystemMetrics (SM_CXDOUBLECLK), NULL); + MAX (xp_theme_unscale (GetSystemMetrics (SM_CXDOUBLECLK)), 1), NULL); g_object_set (settings, "gtk-double-click-time", GetDoubleClickTime (), NULL); g_object_set (settings, "gtk-dnd-drag-threshold", - GetSystemMetrics (SM_CXDRAG), NULL); + MAX (xp_theme_unscale (GetSystemMetrics (SM_CXDRAG)), 1), NULL); setup_menu_settings (settings); @@ -516,7 +516,8 @@ get_system_metric (XpThemeClass klazz, int id) if (!xp_theme_get_system_metric (klazz, id, &rval)) rval = GetSystemMetrics (id); - return rval; + /* in pixels of GTK+ (HiDPI) */ + return xp_theme_unscale (rval); } static void @@ -710,7 +711,7 @@ setup_msw_rc_style (void) "GtkScrollbar::min-slider-length = 8\n" "}widget_class \"*VScrollbar*\" style \"msw-vscrollbar\"\n" "widget_class \"*VScale*\" style \"msw-vscrollbar\"\n", - GetSystemMetrics (SM_CYVTHUMB), + xp_theme_unscale (GetSystemMetrics (SM_CYVTHUMB)), get_system_metric (XP_THEME_CLASS_SCROLLBAR, SM_CXVSCROLL), 11); gtk_rc_parse_string (buf); @@ -724,7 +725,7 @@ setup_msw_rc_style (void) "GtkScrollbar::min-slider-length = 8\n" "}widget_class \"*HScrollbar*\" style \"msw-hscrollbar\"\n" "widget_class \"*HScale*\" style \"msw-hscrollbar\"\n", - GetSystemMetrics (SM_CXHTHUMB), + xp_theme_unscale (GetSystemMetrics (SM_CXHTHUMB)), get_system_metric (XP_THEME_CLASS_SCROLLBAR, SM_CYHSCROLL), 11); gtk_rc_parse_string (buf); @@ -764,8 +765,8 @@ setup_msw_rc_style (void) "ythickness = %d\n" "}\n" "class \"GtkComboBox\" style \"msw-combobox\"\n", - xp_theme_is_active()? 1 : GetSystemMetrics (SM_CXEDGE), - xp_theme_is_active()? 1 : GetSystemMetrics (SM_CYEDGE)); + xp_theme_is_active()? 1 : xp_theme_unscale (GetSystemMetrics (SM_CXEDGE)), + xp_theme_is_active()? 1 : xp_theme_unscale (GetSystemMetrics (SM_CYEDGE))); gtk_rc_parse_string (buf); /* size of tree view header */ @@ -878,6 +879,22 @@ setup_system_styles (GtkStyle *style) } } +/* the size of a window or pixmap, without the deprecated + * gdk_drawable_get_size() this engine is built without */ +static void +drawable_get_size (GdkDrawable *drawable, gint *width, gint *height) +{ + if (GDK_IS_WINDOW (drawable)) + { + if (width) + *width = gdk_window_get_width (GDK_WINDOW (drawable)); + if (height) + *height = gdk_window_get_height (GDK_WINDOW (drawable)); + } + else + gdk_pixmap_get_size (GDK_PIXMAP (drawable), width, height); +} + static gboolean sanitize_size (GdkWindow *window, gint *width, gint *height) { @@ -886,15 +903,15 @@ sanitize_size (GdkWindow *window, gint *width, gint *height) if ((*width == -1) && (*height == -1)) { set_bg = GDK_IS_WINDOW (window); - gdk_drawable_get_size (window, width, height); + drawable_get_size (window, width, height); } else if (*width == -1) { - gdk_drawable_get_size (window, width, NULL); + drawable_get_size (window, width, NULL); } else if (*height == -1) { - gdk_drawable_get_size (window, NULL, height); + drawable_get_size (window, NULL, height); } return set_bg; @@ -1828,7 +1845,7 @@ draw_box (GtkStyle *style, && xp_theme_draw (window, XP_THEME_ELEMENT_COMBOBUTTON, style, x, y, width, height, state_type, area)) { - cx = GetSystemMetrics(SM_CXVSCROLL); + cx = xp_theme_unscale (GetSystemMetrics (SM_CXVSCROLL)); x += width - cx; width = cx; diff --git a/modules/engines/ms-windows/xp_theme.c b/modules/engines/ms-windows/xp_theme.c index 284bff9c5..74c2ca59b 100755 --- a/modules/engines/ms-windows/xp_theme.c +++ b/modules/engines/ms-windows/xp_theme.c @@ -892,6 +892,20 @@ xp_theme_map_gtk_state (XpThemeElement element, GtkStateType state) return ret; } +gint +xp_theme_scale (void) +{ + return MAX (gdk_screen_get_monitor_scale_factor (gdk_screen_get_default (), 0), 1); +} + +gint +xp_theme_unscale (gint size) +{ + gint s = xp_theme_scale (); + + return size > 0 ? (size + s - 1) / s : size; +} + HDC get_window_dc (GtkStyle *style, GdkWindow *window, @@ -977,6 +991,27 @@ xp_theme_draw (GdkWindow *win, XpThemeElement element, GtkStyle *style, pClip = NULL; } + /* HiDPI: the theme draws in pixels of Windows, with its pictures for + * the resolution, sharp, rather than with GDK's enlarged; the DC gets + * its mapping back in release_window_dc () */ + if (xp_theme_scale () > 1) + { + gint s = xp_theme_scale (); + + SetMapMode (dc, MM_TEXT); + rect.left *= s; + rect.top *= s; + rect.right *= s; + rect.bottom *= s; + if (pClip) + { + clip.left *= s; + clip.top *= s; + clip.right *= s; + clip.bottom *= s; + } + } + part_state = xp_theme_map_gtk_state (element, state_type); /* Support transparency */ @@ -1052,6 +1087,10 @@ xp_theme_get_element_dimensions (XpThemeElement element, *cy += gutter_size.cy * 2; } + /* in pixels of GTK+ (HiDPI) */ + *cx = xp_theme_unscale (*cx); + *cy = xp_theme_unscale (*cy); + return TRUE; } diff --git a/modules/engines/ms-windows/xp_theme.h b/modules/engines/ms-windows/xp_theme.h index f6becaf2f..de45e0a61 100755 --- a/modules/engines/ms-windows/xp_theme.h +++ b/modules/engines/ms-windows/xp_theme.h @@ -134,6 +134,11 @@ HDC get_window_dc (GtkStyle *style, RECT *rect_out); void release_window_dc (XpDCInfo *dc_info); +/* HiDPI: pixels of Windows for one of GTK+, and sizes of Windows in + * those of GTK+ */ +gint xp_theme_scale (void); +gint xp_theme_unscale (gint size); + void xp_theme_init (void); void xp_theme_reset (void); void xp_theme_exit (void); diff --git a/modules/engines/pixbuf/pixbuf-render.c b/modules/engines/pixbuf/pixbuf-render.c index 1ca6c0f03..2a2dea94c 100644 --- a/modules/engines/pixbuf/pixbuf-render.c +++ b/modules/engines/pixbuf/pixbuf-render.c @@ -24,6 +24,9 @@ #include "pixbuf.h" #include +#ifdef GDK_WINDOWING_X11 +#include +#endif typedef struct _PixbufCacheEntry PixbufCacheEntry; @@ -364,6 +367,311 @@ replicate_cols (GdkPixbuf *src, * onto the rectangle (dest_x, dest_y, dest_width, dest_height) * of the destination, clip by clip_rect and render */ +/* The part @rect of the component @src_* stretched to @dest_*, as a + * pixbuf whose pixel (0, 0) is at (*x_offset, *y_offset) of @rect */ +static GdkPixbuf * +render_component (GdkPixbuf *src, + guint hints, + GdkRectangle *rect, + gint src_x, + gint src_y, + gint src_width, + gint src_height, + gint dest_x, + gint dest_y, + gint dest_width, + gint dest_height, + gint *x_offset, + gint *y_offset) +{ + GdkPixbuf *tmp_pixbuf = NULL; + gboolean has_alpha = gdk_pixbuf_get_has_alpha (src); + gint src_rowstride = gdk_pixbuf_get_rowstride (src); + gint src_n_channels = gdk_pixbuf_get_n_channels (src); + + if (dest_width == src_width && dest_height == src_height) + { + tmp_pixbuf = g_object_ref (src); + + *x_offset = src_x + rect->x - dest_x; + *y_offset = src_y + rect->y - dest_y; + } + else if (src_width == 0 && src_height == 0) + { + tmp_pixbuf = bilinear_gradient (src, src_x, src_y, dest_width, dest_height); + + *x_offset = rect->x - dest_x; + *y_offset = rect->y - dest_y; + } + else if (src_width == 0 && dest_height == src_height) + { + tmp_pixbuf = horizontal_gradient (src, src_x, src_y, dest_width, dest_height); + + *x_offset = rect->x - dest_x; + *y_offset = rect->y - dest_y; + } + else if (src_height == 0 && dest_width == src_width) + { + tmp_pixbuf = vertical_gradient (src, src_x, src_y, dest_width, dest_height); + + *x_offset = rect->x - dest_x; + *y_offset = rect->y - dest_y; + } + else if ((hints & THEME_CONSTANT_COLS) && (hints & THEME_CONSTANT_ROWS)) + { + tmp_pixbuf = replicate_single (src, src_x, src_y, dest_width, dest_height); + + *x_offset = rect->x - dest_x; + *y_offset = rect->y - dest_y; + } + else if (dest_width == src_width && (hints & THEME_CONSTANT_COLS)) + { + tmp_pixbuf = replicate_rows (src, src_x, src_y, dest_width, dest_height); + + *x_offset = rect->x - dest_x; + *y_offset = rect->y - dest_y; + } + else if (dest_height == src_height && (hints & THEME_CONSTANT_ROWS)) + { + tmp_pixbuf = replicate_cols (src, src_x, src_y, dest_width, dest_height); + + *x_offset = rect->x - dest_x; + *y_offset = rect->y - dest_y; + } + else if (src_width > 0 && src_height > 0) + { + double x_scale = (double)dest_width / src_width; + double y_scale = (double)dest_height / src_height; + guchar *pixels; + GdkPixbuf *partial_src; + + pixels = (gdk_pixbuf_get_pixels (src) + + src_y * src_rowstride + + src_x * src_n_channels); + + partial_src = gdk_pixbuf_new_from_data (pixels, GDK_COLORSPACE_RGB, + has_alpha, + 8, src_width, src_height, + src_rowstride, + NULL, NULL); + + tmp_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, + has_alpha, 8, + rect->width, rect->height); + + gdk_pixbuf_scale (partial_src, tmp_pixbuf, + 0, 0, rect->width, rect->height, + dest_x - rect->x, dest_y - rect->y, + x_scale, y_scale, + GDK_INTERP_BILINEAR); + + g_object_unref (partial_src); + + *x_offset = 0; + *y_offset = 0; + } + + return tmp_pixbuf; +} + +/* Stretched components as the cairo surfaces they are drawn from, kept + * for the next widget of the same size: buttons, entries and tabs are + * drawn again and again with the same sizes, and scaling and converting + * the image each time is most of the work of a pixmap theme. Only + * components up to MAX_COMPONENT_PIXELS, and CACHE_BUDGET pixels in + * all, so large backgrounds do not stay in memory. */ +#define MAX_COMPONENT_PIXELS (256 * 256) +#define CACHE_BUDGET (512 * 512) +#define MAX_COMPONENTS 64 + +typedef struct +{ + GdkPixbuf *src; + guint hints; + gint src_x, src_y, src_width, src_height; + gint dest_width, dest_height; + cairo_surface_t *surface; + /* the same in the X server, for the screen and scale it was made for */ + cairo_surface_t *server; + gpointer server_screen; + double server_scale; +} Component; + +static Component components[MAX_COMPONENTS]; +static guint n_components; +static gint components_pixels; + +static void +component_drop_last (void) +{ + Component *c = &components[--n_components]; + + components_pixels -= c->dest_width * c->dest_height; + cairo_surface_destroy (c->surface); + if (c->server) + cairo_surface_destroy (c->server); + g_object_unref (c->src); +} + +/* cairo uploads an image surface to the X server again for every fill + * (a pixmap, PutImage and a picture each time); a copy made there once + * is composited directly. Only for X targets: elsewhere the image is + * the right source already. */ +static cairo_surface_t * +component_server_surface (Component *c, + cairo_t *cr) +{ +#ifdef GDK_WINDOWING_X11 + cairo_surface_t *target = cairo_get_target (cr); + double scale_x = 1.0, scale_y = 1.0; + cairo_surface_t *server; + gpointer screen; + cairo_t *scr; + + if (cairo_surface_get_type (target) != CAIRO_SURFACE_TYPE_XLIB) + return NULL; + + screen = cairo_xlib_surface_get_screen (target); + cairo_surface_get_device_scale (target, &scale_x, &scale_y); + if (scale_x != scale_y) + return NULL; + if (c->server && c->server_screen == screen && c->server_scale == scale_x) + return c->server; + + server = cairo_surface_create_similar (target, + cairo_surface_get_content (c->surface), + c->dest_width, c->dest_height); + if (cairo_surface_status (server) != CAIRO_STATUS_SUCCESS || + cairo_surface_get_type (server) != CAIRO_SURFACE_TYPE_XLIB) + { + cairo_surface_destroy (server); + return NULL; + } + scr = cairo_create (server); + cairo_set_operator (scr, CAIRO_OPERATOR_SOURCE); + cairo_set_source_surface (scr, c->surface, 0, 0); + /* at a scale above 1 the edges of the piece must not fade into the + * transparency around it */ + cairo_pattern_set_extend (cairo_get_source (scr), CAIRO_EXTEND_PAD); + cairo_paint (scr); + cairo_destroy (scr); + + if (c->server) + cairo_surface_destroy (c->server); + c->server = server; + c->server_screen = screen; + c->server_scale = scale_x; + return server; +#else + return NULL; +#endif +} + +static cairo_surface_t * +component_surface (GdkPixbuf *src, + guint hints, + gint src_x, + gint src_y, + gint src_width, + gint src_height, + gint dest_width, + gint dest_height, + Component **cached) +{ + GdkRectangle full = { 0, 0, dest_width, dest_height }; + GdkPixbuf *tmp_pixbuf; + cairo_surface_t *surface; + cairo_t *cr; + gint x_offset, y_offset; + guint i; + + for (i = 0; i < n_components; i++) + { + Component *c = &components[i]; + + if (c->src == src && c->hints == hints && + c->src_x == src_x && c->src_y == src_y && + c->src_width == src_width && c->src_height == src_height && + c->dest_width == dest_width && c->dest_height == dest_height) + { + if (i > 0) + { + Component hit = *c; + + memmove (components + 1, components, i * sizeof (Component)); + components[0] = hit; + } + *cached = &components[0]; + return cairo_surface_reference (components[0].surface); + } + } + + *cached = NULL; + tmp_pixbuf = render_component (src, hints, &full, src_x, src_y, src_width, src_height, + 0, 0, dest_width, dest_height, &x_offset, &y_offset); + if (!tmp_pixbuf) + return NULL; + + surface = cairo_image_surface_create (gdk_pixbuf_get_has_alpha (tmp_pixbuf) ? + CAIRO_FORMAT_ARGB32 : CAIRO_FORMAT_RGB24, + dest_width, dest_height); + cr = cairo_create (surface); + cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE); + gdk_cairo_set_source_pixbuf (cr, tmp_pixbuf, -x_offset, -y_offset); + cairo_paint (cr); + cairo_destroy (cr); + g_object_unref (tmp_pixbuf); + + if (dest_width * dest_height <= MAX_COMPONENT_PIXELS) + { + while (n_components > 0 && + (n_components == MAX_COMPONENTS || + components_pixels + dest_width * dest_height > CACHE_BUDGET)) + component_drop_last (); + + memmove (components + 1, components, n_components * sizeof (Component)); + components[0].src = g_object_ref (src); + components[0].hints = hints; + components[0].src_x = src_x; + components[0].src_y = src_y; + components[0].src_width = src_width; + components[0].src_height = src_height; + components[0].dest_width = dest_width; + components[0].dest_height = dest_height; + components[0].surface = cairo_surface_reference (surface); + components[0].server = NULL; + components[0].server_screen = NULL; + components[0].server_scale = 0; + components_pixels += dest_width * dest_height; + n_components++; + *cached = &components[0]; + } + + return surface; +} + +/* An image of the theme is going away: forget what was made from it */ +static void +components_forget (GdkPixbuf *src) +{ + guint i = 0; + + while (i < n_components) + { + if (components[i].src == src) + { + Component c = components[i]; + + memmove (components + i, components + i + 1, + (n_components - i - 1) * sizeof (Component)); + components[n_components - 1] = c; + component_drop_last (); + } + else + i++; + } +} + static void pixbuf_render (GdkPixbuf *src, guint hints, @@ -382,9 +690,6 @@ pixbuf_render (GdkPixbuf *src, GdkPixbuf *tmp_pixbuf = NULL; GdkRectangle rect; int x_offset, y_offset; - gboolean has_alpha = gdk_pixbuf_get_has_alpha (src); - gint src_rowstride = gdk_pixbuf_get_rowstride (src); - gint src_n_channels = gdk_pixbuf_get_n_channels (src); if (dest_width <= 0 || dest_height <= 0) return; @@ -408,87 +713,36 @@ pixbuf_render (GdkPixbuf *src, return; } - if (dest_width == src_width && dest_height == src_height) + /* Without a mask, the whole component is made once and kept, unless + * it is large and only a little of it is drawn. */ + if (!mask && + (dest_width * dest_height <= MAX_COMPONENT_PIXELS || + (rect.width == dest_width && rect.height == dest_height))) { - tmp_pixbuf = g_object_ref (src); + cairo_surface_t *surface, *server = NULL; + Component *cached; + cairo_t *cr; - x_offset = src_x + rect.x - dest_x; - y_offset = src_y + rect.y - dest_y; + surface = component_surface (src, hints, src_x, src_y, src_width, src_height, + dest_width, dest_height, &cached); + if (!surface) + return; + + /* only rect is filled: the clip of the window around it is enough */ + cr = gdk_cairo_create_in_area_libgtk_only (window, &rect); + if (cached) + server = component_server_surface (cached, cr); + cairo_set_source_surface (cr, server ? server : surface, dest_x, dest_y); + gdk_cairo_rectangle (cr, &rect); + cairo_fill (cr); + cairo_destroy (cr); + cairo_surface_destroy (surface); + return; } - else if (src_width == 0 && src_height == 0) - { - tmp_pixbuf = bilinear_gradient (src, src_x, src_y, dest_width, dest_height); - x_offset = rect.x - dest_x; - y_offset = rect.y - dest_y; - } - else if (src_width == 0 && dest_height == src_height) - { - tmp_pixbuf = horizontal_gradient (src, src_x, src_y, dest_width, dest_height); - - x_offset = rect.x - dest_x; - y_offset = rect.y - dest_y; - } - else if (src_height == 0 && dest_width == src_width) - { - tmp_pixbuf = vertical_gradient (src, src_x, src_y, dest_width, dest_height); - - x_offset = rect.x - dest_x; - y_offset = rect.y - dest_y; - } - else if ((hints & THEME_CONSTANT_COLS) && (hints & THEME_CONSTANT_ROWS)) - { - tmp_pixbuf = replicate_single (src, src_x, src_y, dest_width, dest_height); - - x_offset = rect.x - dest_x; - y_offset = rect.y - dest_y; - } - else if (dest_width == src_width && (hints & THEME_CONSTANT_COLS)) - { - tmp_pixbuf = replicate_rows (src, src_x, src_y, dest_width, dest_height); - - x_offset = rect.x - dest_x; - y_offset = rect.y - dest_y; - } - else if (dest_height == src_height && (hints & THEME_CONSTANT_ROWS)) - { - tmp_pixbuf = replicate_cols (src, src_x, src_y, dest_width, dest_height); - - x_offset = rect.x - dest_x; - y_offset = rect.y - dest_y; - } - else if (src_width > 0 && src_height > 0) - { - double x_scale = (double)dest_width / src_width; - double y_scale = (double)dest_height / src_height; - guchar *pixels; - GdkPixbuf *partial_src; - - pixels = (gdk_pixbuf_get_pixels (src) - + src_y * src_rowstride - + src_x * src_n_channels); - - partial_src = gdk_pixbuf_new_from_data (pixels, GDK_COLORSPACE_RGB, - has_alpha, - 8, src_width, src_height, - src_rowstride, - NULL, NULL); - - tmp_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, - has_alpha, 8, - rect.width, rect.height); - - gdk_pixbuf_scale (partial_src, tmp_pixbuf, - 0, 0, rect.width, rect.height, - dest_x - rect.x, dest_y - rect.y, - x_scale, y_scale, - GDK_INTERP_BILINEAR); - - g_object_unref (partial_src); - - x_offset = 0; - y_offset = 0; - } + tmp_pixbuf = render_component (src, hints, &rect, src_x, src_y, src_width, src_height, + dest_x, dest_y, dest_width, dest_height, + &x_offset, &y_offset); if (tmp_pixbuf) { @@ -507,7 +761,7 @@ pixbuf_render (GdkPixbuf *src, cairo_destroy (cr); } - cr = gdk_cairo_create (window); + cr = gdk_cairo_create_in_area_libgtk_only (window, &rect); gdk_cairo_set_source_pixbuf (cr, tmp_pixbuf, -x_offset + rect.x, @@ -549,15 +803,7 @@ theme_pixbuf_destroy (ThemePixbuf *theme_pb) void theme_clear_pixbuf (ThemePixbuf **theme_pb) { -#if GLIB_CHECK_VERSION (2, 34, 0) g_clear_pointer (theme_pb, theme_pixbuf_destroy); -#else - if (*theme_pb) - { - theme_pixbuf_destroy (*theme_pb); - *theme_pb = NULL; - } -#endif } void @@ -575,6 +821,7 @@ theme_pixbuf_set_filename (ThemePixbuf *theme_pb, if (entry->ref_count == 0) { + components_forget (entry->pixbuf); g_hash_table_remove (pixbuf_filename_ht, entry->filename); g_hash_table_remove (pixbuf_pixbuf_ht, entry->pixbuf); @@ -951,15 +1198,17 @@ theme_pixbuf_render (ThemePixbuf *theme_pb, } else { - cairo_t *cr = gdk_cairo_create (window); + GdkRectangle fill = { x, y, width, height }; + cairo_t *cr; + + if (clip_rect) + fill = *clip_rect; + cr = gdk_cairo_create_in_area_libgtk_only (window, &fill); gdk_cairo_set_source_pixbuf (cr, pixbuf, 0, 0); cairo_pattern_set_extend (cairo_get_source (cr), CAIRO_EXTEND_REPEAT); - if (clip_rect) - gdk_cairo_rectangle (cr, clip_rect); - else - cairo_rectangle (cr, x, y, width, height); + gdk_cairo_rectangle (cr, &fill); cairo_fill (cr); diff --git a/modules/input/gtkimcontextime.c b/modules/input/gtkimcontextime.c index 2b3f2dd1b..9287577b3 100644 --- a/modules/input/gtkimcontextime.c +++ b/modules/input/gtkimcontextime.c @@ -825,6 +825,7 @@ gtk_im_context_ime_set_cursor_location (GtkIMContext *context, COMPOSITIONFORM cf; HWND hwnd; HIMC himc; + guint scale; g_return_if_fail (GTK_IS_IM_CONTEXT_IME (context)); @@ -840,10 +841,11 @@ gtk_im_context_ime_set_cursor_location (GtkIMContext *context, if (!himc) return; + scale = gdk_window_get_scale_factor (context_ime->client_window); get_window_position (context_ime->client_window, &wx, &wy); cf.dwStyle = CFS_POINT; - cf.ptCurrentPos.x = wx + context_ime->cursor_location.x; - cf.ptCurrentPos.y = wy + context_ime->cursor_location.y; + cf.ptCurrentPos.x = (wx + context_ime->cursor_location.x) * scale; + cf.ptCurrentPos.y = (wy + context_ime->cursor_location.y) * scale; ImmSetCompositionWindow (himc, &cf); ImmReleaseContext (hwnd, himc); @@ -1019,6 +1021,7 @@ gtk_im_context_ime_message_filter (GdkXEvent *xevent, { gint wx = 0, wy = 0; CANDIDATEFORM cf; + guint scale = gdk_window_get_scale_factor (context_ime->client_window); get_window_position (context_ime->client_window, &wx, &wy); /* FIXME! */ @@ -1031,17 +1034,17 @@ gtk_im_context_ime_message_filter (GdkXEvent *xevent, gdk_win32_window_get_impl_hwnd (gdk_window_get_toplevel (context_ime->client_window)); GetWindowRect (hwnd_top, &rc); - pt.x = wx; - pt.y = wy; + pt.x = wx * scale; + pt.y = wy * scale; ClientToScreen (hwnd_top, &pt); - wx = pt.x - rc.left; - wy = pt.y - rc.top; + wx = (pt.x - rc.left) / scale; + wy = (pt.y - rc.top) / scale; } cf.dwIndex = 0; cf.dwStyle = CFS_CANDIDATEPOS; - cf.ptCurrentPos.x = wx + context_ime->cursor_location.x; - cf.ptCurrentPos.y = wy + context_ime->cursor_location.y - + context_ime->cursor_location.height; + cf.ptCurrentPos.x = (wx + context_ime->cursor_location.x) * scale; + cf.ptCurrentPos.y = (wy + context_ime->cursor_location.y + + context_ime->cursor_location.height) * scale; ImmSetCandidateWindow (himc, &cf); if ((msg->lParam & GCS_COMPSTR)) diff --git a/modules/input/gtkimcontextthai.c b/modules/input/gtkimcontextthai.c index f3295e035..0e456e3f2 100644 --- a/modules/input/gtkimcontextthai.c +++ b/modules/input/gtkimcontextthai.c @@ -197,7 +197,7 @@ get_previous_char (GtkIMContextThai *context_thai, gint offset) if (offset == 0) { prev_char = g_utf8_get_char_validated (q, p - q); - if (prev_char < 0) + if (prev_char == (gunichar)-1 || prev_char == (gunichar)-2) prev_char = 0; } g_free (surrounding); diff --git a/modules/input/imquartz.c b/modules/input/imquartz.c index 033b0dd74..45c869257 100644 --- a/modules/input/imquartz.c +++ b/modules/input/imquartz.c @@ -132,7 +132,10 @@ output_result (GtkIMContext *context, GtkIMContextQuartz *qc = GTK_IM_CONTEXT_QUARTZ (context); gboolean retval = FALSE; gchar *fixed_str, *marked_str; + gint replace_len; + replace_len = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (win), + TIC_INSERT_TEXT_REPLACE_LEN)); fixed_str = g_object_get_data (G_OBJECT (win), TIC_INSERT_TEXT); marked_str = g_object_get_data (G_OBJECT (win), TIC_MARKED_TEXT); if (fixed_str) @@ -141,6 +144,16 @@ output_result (GtkIMContext *context, g_free (qc->preedit_str); qc->preedit_str = NULL; g_object_set_data (G_OBJECT (win), TIC_INSERT_TEXT, NULL); + if (replace_len > 0) + { + /* an accented character from the window of a held key + * replaces the character before the cursor */ + gboolean deleted; + + g_object_set_data (G_OBJECT (win), TIC_INSERT_TEXT_REPLACE_LEN, NULL); + g_signal_emit_by_name (context, "delete-surrounding", + -replace_len, replace_len, &deleted); + } g_signal_emit_by_name (context, "commit", fixed_str); g_signal_emit_by_name (context, "preedit_changed"); @@ -170,6 +183,10 @@ output_result (GtkIMContext *context, } if (!fixed_str && !marked_str) { + /* a key the input method took without text: the repeats of a + * key held down for the window of accented characters */ + if (GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (win), GIC_FILTER_KEY))) + retval = TRUE; if (qc->preedit_str && strlen (qc->preedit_str) > 0) retval = TRUE; } @@ -219,6 +236,9 @@ quartz_filter_keypress (GtkIMContext *context, if (event->hardware_keycode == 55) /* Command */ return FALSE; + if (event->hardware_keycode == 53) /* Escape */ + return FALSE; + NSEventType etype = [nsevent type]; if (etype == NSKeyDown) { diff --git a/modules/other/gail/gailbutton.c b/modules/other/gail/gailbutton.c index 6ecf9cd74..495efce1b 100644 --- a/modules/other/gail/gailbutton.c +++ b/modules/other/gail/gailbutton.c @@ -1021,7 +1021,7 @@ gail_button_get_image_position (AtkImage *image, if (button_image != NULL) { obj = gtk_widget_get_accessible (GTK_WIDGET (button_image)); - atk_component_get_position (ATK_COMPONENT (obj), x, y, coord_type); + atk_component_get_extents (ATK_COMPONENT (obj), x, y, NULL, NULL, coord_type); } else { diff --git a/modules/other/gail/gailimage.c b/modules/other/gail/gailimage.c index 0a33cd1ec..968b1d464 100644 --- a/modules/other/gail/gailimage.c +++ b/modules/other/gail/gailimage.c @@ -179,7 +179,7 @@ gail_image_get_image_position (AtkImage *image, gint *y, AtkCoordType coord_type) { - atk_component_get_position (ATK_COMPONENT (image), x, y, coord_type); + atk_component_get_extents (ATK_COMPONENT (image), x, y, NULL, NULL, coord_type); } static void diff --git a/modules/other/gail/gailimagecell.c b/modules/other/gail/gailimagecell.c index efcded036..5860b723f 100644 --- a/modules/other/gail/gailimagecell.c +++ b/modules/other/gail/gailimagecell.c @@ -150,7 +150,7 @@ gail_image_cell_get_image_position (AtkImage *image, gint *y, AtkCoordType coord_type) { - atk_component_get_position (ATK_COMPONENT (image), x, y, coord_type); + atk_component_get_extents (ATK_COMPONENT (image), x, y, NULL, NULL, coord_type); } static void diff --git a/modules/other/gail/gailnotebookpage.c b/modules/other/gail/gailnotebookpage.c index 444ddac0e..cd4e18d7d 100644 --- a/modules/other/gail/gailnotebookpage.c +++ b/modules/other/gail/gailnotebookpage.c @@ -467,7 +467,7 @@ gail_notebook_page_get_extents (AtkComponent *component, child = atk_object_ref_accessible_child (ATK_OBJECT (component), 0); gail_return_if_fail (child); - atk_component_get_position (ATK_COMPONENT (child), x, y, coord_type); + atk_component_get_extents (ATK_COMPONENT (child), x, y, NULL, NULL, coord_type); g_object_unref (child); } else diff --git a/modules/other/gail/gailpixmap.c b/modules/other/gail/gailpixmap.c index b8ab4b3da..4f44f93be 100644 --- a/modules/other/gail/gailpixmap.c +++ b/modules/other/gail/gailpixmap.c @@ -103,7 +103,7 @@ gail_pixmap_get_image_position (AtkImage *obj, gint *y, AtkCoordType coord_type) { - atk_component_get_position (ATK_COMPONENT (obj), x, y, coord_type); + atk_component_get_extents (ATK_COMPONENT (obj), x, y, NULL, NULL, coord_type); } static void diff --git a/modules/other/gail/libgail-util/gailmisc.c b/modules/other/gail/libgail-util/gailmisc.c index 9dc143d07..8213c716a 100644 --- a/modules/other/gail/libgail-util/gailmisc.c +++ b/modules/other/gail/libgail-util/gailmisc.c @@ -251,7 +251,7 @@ gail_misc_layout_get_run_attributes (AtkAttributeSet *attrib_set, if ((pango_string = (PangoAttrString*) pango_attr_iterator_get (iter, PANGO_ATTR_FAMILY)) != NULL) { - value = g_strdup_printf("%s", pango_string->value); + value = g_strdup (pango_string->value); attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_FAMILY_NAME, value); diff --git a/modules/other/gail/tests/Makefile.am b/modules/other/gail/tests/Makefile.am index 0f0e02317..87a3f9ffe 100644 --- a/modules/other/gail/tests/Makefile.am +++ b/modules/other/gail/tests/Makefile.am @@ -7,8 +7,10 @@ endif moduledir = $(libdir)/gtk-2.0/modules +# ferret, the accessibility explorer, is built on demand only: +# make -C modules/other/gail/tests libferret.la if !OS_WIN32 -module_LTLIBRARIES = \ +EXTRA_LTLIBRARIES = \ libferret.la endif diff --git a/modules/other/gail/tests/ferret.c b/modules/other/gail/tests/ferret.c index 39eaef441..d3c9170d0 100644 --- a/modules/other/gail/tests/ferret.c +++ b/modules/other/gail/tests/ferret.c @@ -1514,9 +1514,9 @@ _button_watcher (GSignalInvocationHint *ihint, event = (GdkEventButton *) gp; aobject = gtk_widget_get_accessible (widget); aobject_x = aobject_y = 0; - atk_component_get_position (ATK_COMPONENT (aobject), - &aobject_x, &aobject_y, - ATK_XY_WINDOW); + atk_component_get_extents (ATK_COMPONENT (aobject), + &aobject_x, &aobject_y, NULL, NULL, + ATK_XY_WINDOW); x = aobject_x + (gint) event->x; y = aobject_y + (gint) event->y; child = atk_component_ref_accessible_at_point (ATK_COMPONENT (aobject), diff --git a/modules/other/gail/tests/testcomponent.c b/modules/other/gail/tests/testcomponent.c index a28eccebd..5efbb2c87 100644 --- a/modules/other/gail/tests/testcomponent.c +++ b/modules/other/gail/tests/testcomponent.c @@ -16,8 +16,11 @@ static void _check_position (AtkObject *obj) return; atk_component_get_extents (ATK_COMPONENT(obj), &x, &y, &width, &height, ATK_XY_SCREEN); + /* compares the deprecated calls with get_extents on purpose */ + G_GNUC_BEGIN_IGNORE_DEPRECATIONS atk_component_get_position (ATK_COMPONENT(obj), &x1, &y1, ATK_XY_SCREEN ); atk_component_get_size (ATK_COMPONENT(obj), &width1, &height1); + G_GNUC_END_IGNORE_DEPRECATIONS if ((x1 != x) || (y1 != y)) { g_print ("atk_component_get_extents and atk_get_position give different" @@ -29,7 +32,7 @@ static void _check_position (AtkObject *obj) " values: %d,%d %d,%d\n", width, height, width1, height1); } - atk_component_get_position (ATK_COMPONENT(obj), &x1, &y1, ATK_XY_SCREEN); + atk_component_get_extents (ATK_COMPONENT(obj), &x1, &y1, NULL, NULL, ATK_XY_SCREEN); g_print ("Object Type: %s\n", g_type_name (G_OBJECT_TYPE (obj))); g_print ("Object at %d, %d on screen\n", x1, y1); g_print ("Object at %d, %d, size: %d, %d\n", x, y, width, height); diff --git a/modules/other/gail/tests/testpaned.c b/modules/other/gail/tests/testpaned.c index 7e1f27f1c..d680689ee 100644 --- a/modules/other/gail/tests/testpaned.c +++ b/modules/other/gail/tests/testpaned.c @@ -69,7 +69,7 @@ static gint _test_paned (gpointer data) last_position = position; position *= 2; g_value_set_int (value, position); - gail_test_value_set_current_value (ATK_VALUE (obj), value); + (void) gail_test_value_set_current_value (ATK_VALUE (obj), value); times++; } if (times < 4) diff --git a/modules/printbackends/cups/gtkcupsutils.c b/modules/printbackends/cups/gtkcupsutils.c index f96b7a5b5..ef6c858ee 100644 --- a/modules/printbackends/cups/gtkcupsutils.c +++ b/modules/printbackends/cups/gtkcupsutils.c @@ -745,6 +745,8 @@ _post_send (GtkCupsRequest *request) { gchar length[255]; struct stat data_info; + gint fd; + off_t size; GTK_NOTE (PRINTING, g_print ("CUPS Backend: %s\n", G_STRFUNC)); @@ -753,8 +755,19 @@ _post_send (GtkCupsRequest *request) if (request->data_io != NULL) { - fstat (g_io_channel_unix_get_fd (request->data_io), &data_info); - sprintf (length, "%lu", (unsigned long) (ippLength (request->ipp_request) + data_info.st_size)); + /* fstat() fails for a file written after 2038 where time_t has + * 32 bits; the end of the file tells its size as well */ + fd = g_io_channel_unix_get_fd (request->data_io); + if (fstat (fd, &data_info) == 0) + size = data_info.st_size; + else + { + off_t here = lseek (fd, 0, SEEK_CUR); + + size = lseek (fd, 0, SEEK_END); + lseek (fd, here, SEEK_SET); + } + sprintf (length, "%lu", (unsigned long) (ippLength (request->ipp_request) + size)); } else sprintf (length, "%lu", (unsigned long) ippLength (request->ipp_request)); @@ -1169,7 +1182,10 @@ _post_check (GtkCupsRequest *request) httpFlush (request->http); request->last_status = HTTP_CONTINUE; - httpClose (request->http); + /* Only close connections we created ourselves; the owner of a + * connection passed in to the request closes it as well. */ + if (request->own_http) + httpClose (request->http); request->http = NULL; return; } @@ -1434,7 +1450,8 @@ _get_check (GtkCupsRequest *request) request->poll_state = GTK_CUPS_HTTP_IDLE; httpFlush (request->http); - httpClose (request->http); + if (request->own_http) + httpClose (request->http); request->last_status = HTTP_CONTINUE; request->http = NULL; return; diff --git a/modules/printbackends/cups/gtkprintbackendcups.c b/modules/printbackends/cups/gtkprintbackendcups.c index d07d1bc7a..12b5cc7a5 100644 --- a/modules/printbackends/cups/gtkprintbackendcups.c +++ b/modules/printbackends/cups/gtkprintbackendcups.c @@ -55,6 +55,7 @@ #include #include #include +#include #include "gtkprintbackendcups.h" #include "gtkprintercups.h" @@ -144,6 +145,8 @@ struct _GtkPrintBackendCups GHashTable *auth; gchar *username; gboolean authentication_lock; + guint secrets_available : 1; /* a keyring answered */ + guint secrets_unavailable : 1; /* there is none */ #ifdef HAVE_CUPS_API_1_6 GDBusConnection *dbus_connection; gchar *avahi_default_printer; @@ -213,6 +216,14 @@ static cairo_surface_t * cups_printer_create_cairo_surface (GtkPrinter static void gtk_print_backend_cups_set_password (GtkPrintBackend *backend, gchar **auth_info_required, gchar **auth_info); +static void gtk_print_backend_cups_set_password_full (GtkPrintBackend *backend, + gchar **auth_info_required, + gchar **auth_info, + gboolean store_auth_info); +static gboolean gtk_print_backend_cups_can_store_password (GtkPrintBackend *backend); +static void cups_secret_store (gchar **auth_info_required, + gchar **auth_info, + const gchar *printer_uri); void overwrite_and_free (gpointer data); static gboolean is_address_local (const gchar *address); @@ -341,6 +352,9 @@ gtk_print_backend_cups_class_init (GtkPrintBackendCupsClass *class) backend_class->printer_get_hard_margins = cups_printer_get_hard_margins; backend_class->printer_get_capabilities = cups_printer_get_capabilities; backend_class->set_password = gtk_print_backend_cups_set_password; + /* see gtk/gtkprintbackend.c */ + backend_class->_gtk_reserved1 = (void (*) (void)) gtk_print_backend_cups_can_store_password; + backend_class->_gtk_reserved2 = (void (*) (void)) gtk_print_backend_cups_set_password_full; } static cairo_status_t @@ -349,7 +363,7 @@ _cairo_write_to_cups (void *closure, unsigned int length) { GIOChannel *io = (GIOChannel *)closure; - gsize written; + gsize written = 0; GError *error; error = NULL; @@ -359,15 +373,21 @@ _cairo_write_to_cups (void *closure, while (length > 0) { - g_io_channel_write_chars (io, (gchar *)data, length, &written, &error); + GIOStatus status; - if (error != NULL) - { - GTK_NOTE (PRINTING, - g_print ("CUPS Backend: Error writing to temp file, %s\n", - error->message)); + status = g_io_channel_write_chars (io, (gchar *)data, length, &written, &error); + + if (status == G_IO_STATUS_ERROR) + { + if (error != NULL) + { + GTK_NOTE (PRINTING, + g_print ("CUPS Backend: Error writing to temp file, %s\n", + error->message)); + + g_error_free (error); + } - g_error_free (error); return CAIRO_STATUS_WRITE_ERROR; } @@ -577,9 +597,14 @@ cups_print_cb (GtkPrintBackendCups *print_backend, typedef struct { GtkCupsRequest *request; + GtkPageSetup *page_setup; GtkPrinterCups *printer; } CupsOptionsData; +#define UNSIGNED_FLOAT_REGEX "([0-9]+([.,][0-9]*)?|[.,][0-9]+)([e][+-]?[0-9]+)?" +#define SIGNED_FLOAT_REGEX "[+-]?"UNSIGNED_FLOAT_REGEX +#define SIGNED_INTEGER_REGEX "[+-]?([0-9]+)" + static void add_cups_options (const gchar *key, const gchar *value, @@ -603,7 +628,7 @@ add_cups_options (const gchar *key, key = key + strlen ("cups-"); - if (printer && printer->ppd_file) + if (printer && printer->ppd_file && !g_str_has_prefix (value, "Custom.")) { ppd_coption_t *coption; gboolean found = FALSE; @@ -624,14 +649,74 @@ add_cups_options (const gchar *key, } if (custom_values_enabled && !found) - custom_value = TRUE; + { + /* Check syntax of the invalid choice to see whether + it could be a custom value */ + if (g_str_equal (key, "PageSize") || + g_str_equal (key, "PageRegion")) + { + /* Handle custom page sizes... */ + if (g_regex_match_simple ("^" UNSIGNED_FLOAT_REGEX "x" UNSIGNED_FLOAT_REGEX "(cm|mm|m|in|ft|pt)?$", value, G_REGEX_CASELESS, 0)) + custom_value = TRUE; + else + { + if (data->page_setup != NULL) + { + custom_value = TRUE; + new_value = + g_strdup_printf ("Custom.%.2fx%.2fmm", + gtk_paper_size_get_width (gtk_page_setup_get_paper_size (data->page_setup), GTK_UNIT_MM), + gtk_paper_size_get_height (gtk_page_setup_get_paper_size (data->page_setup), GTK_UNIT_MM)); + } + } + } + else + { + /* Handle other custom options... */ + ppd_cparam_t *cparam; + + cparam = (ppd_cparam_t *) cupsArrayFirst (coption->params); + if (cparam != NULL) + { + switch (cparam->type) + { + case PPD_CUSTOM_CURVE : + case PPD_CUSTOM_INVCURVE : + case PPD_CUSTOM_REAL : + if (g_regex_match_simple ("^" SIGNED_FLOAT_REGEX "$", value, G_REGEX_CASELESS, 0)) + custom_value = TRUE; + break; + + case PPD_CUSTOM_POINTS : + if (g_regex_match_simple ("^" SIGNED_FLOAT_REGEX "(cm|mm|m|in|ft|pt)?$", value, G_REGEX_CASELESS, 0)) + custom_value = TRUE; + break; + + case PPD_CUSTOM_INT : + if (g_regex_match_simple ("^" SIGNED_INTEGER_REGEX "$", value, G_REGEX_CASELESS, 0)) + custom_value = TRUE; + break; + + case PPD_CUSTOM_PASSCODE : + case PPD_CUSTOM_PASSWORD : + case PPD_CUSTOM_STRING : + custom_value = TRUE; + break; + + default : + custom_value = FALSE; + } + } + } + } } } /* Add "Custom." prefix to custom values if not already added. */ - if (custom_value && !g_str_has_prefix (value, "Custom.")) + if (custom_value) { - new_value = g_strdup_printf ("Custom.%s", value); + if (new_value == NULL) + new_value = g_strdup_printf ("Custom.%s", value); gtk_cups_request_encode_option (request, key, new_value); g_free (new_value); } @@ -650,6 +735,7 @@ gtk_print_backend_cups_print_stream (GtkPrintBackend *print_backend, GtkPrinterCups *cups_printer; CupsPrintStreamData *ps; CupsOptionsData *options_data; + GtkPageSetup *page_setup; GtkCupsRequest *request = NULL; GtkPrintSettings *settings; const gchar *title; @@ -661,14 +747,6 @@ gtk_print_backend_cups_print_stream (GtkPrintBackend *print_backend, cups_printer = GTK_PRINTER_CUPS (gtk_print_job_get_printer (job)); settings = gtk_print_job_get_settings (job); - request = gtk_cups_request_new_with_username (NULL, - GTK_CUPS_POST, - IPP_PRINT_JOB, - data_io, - NULL, - cups_printer->device_uri, - GTK_PRINT_BACKEND_CUPS (print_backend)->username); - #ifdef HAVE_CUPS_API_1_6 if (cups_printer->avahi_browsed) { @@ -686,6 +764,8 @@ gtk_print_backend_cups_print_stream (GtkPrintBackend *print_backend, cups_printer->hostname, cups_printer->device_uri, GTK_PRINT_BACKEND_CUPS (print_backend)->username); + /* Hand the connection over: the request closes it when it is freed */ + request->own_http = TRUE; g_snprintf (printer_absolute_uri, HTTP_MAX_URI, "%s", cups_printer->printer_uri); } else @@ -754,14 +834,36 @@ gtk_print_backend_cups_print_stream (GtkPrintBackend *print_backend, title = gtk_print_job_get_title (job); if (title) - gtk_cups_request_ipp_add_string (request, IPP_TAG_OPERATION, - IPP_TAG_NAME, "job-name", - NULL, title); + { + gchar *title_truncated = NULL; + + /* CUPS refuses jobs whose name is longer than an IPP name + * (255 bytes); cut the title at a character boundary */ + if (strlen (title) >= IPP_MAX_NAME) + { + const gchar *end; + + end = g_utf8_find_prev_char (title, title + IPP_MAX_NAME - 1); + title_truncated = g_strndup (title, end - title); + } + + gtk_cups_request_ipp_add_string (request, IPP_TAG_OPERATION, + IPP_TAG_NAME, "job-name", + NULL, + title_truncated ? title_truncated : title); + g_free (title_truncated); + } + + g_object_get (job, + "page-setup", &page_setup, + NULL); options_data = g_new0 (CupsOptionsData, 1); options_data->request = request; options_data->printer = cups_printer; + options_data->page_setup = page_setup; gtk_print_settings_foreach (settings, add_cups_options, options_data); + g_clear_object (&page_setup); g_free (options_data); ps = g_new0 (CupsPrintStreamData, 1); @@ -770,8 +872,24 @@ gtk_print_backend_cups_print_stream (GtkPrintBackend *print_backend, ps->dnotify = dnotify; ps->job = g_object_ref (job); - request->need_auth_info = cups_printer->auth_info_required != NULL; - request->auth_info_required = g_strdupv (cups_printer->auth_info_required); + request->need_auth_info = FALSE; + request->auth_info_required = NULL; + + /* Check if auth_info_required is set and if it should be handled. + * The cups libraries handle the ticket exchange for "negotiate". */ + if (cups_printer->auth_info_required != NULL && + g_strv_length (cups_printer->auth_info_required) == 1 && + g_strcmp0 (cups_printer->auth_info_required[0], "negotiate") == 0) + { + GTK_NOTE (PRINTING, + g_print ("CUPS Backend: Ignoring auth-info-required \"%s\"\n", + cups_printer->auth_info_required[0])); + } + else if (cups_printer->auth_info_required != NULL) + { + request->need_auth_info = TRUE; + request->auth_info_required = g_strdupv (cups_printer->auth_info_required); + } cups_request_execute (GTK_PRINT_BACKEND_CUPS (print_backend), request, @@ -973,17 +1091,18 @@ httpGetHostname(http_t *http, #endif static void -gtk_print_backend_cups_set_password (GtkPrintBackend *backend, - gchar **auth_info_required, - gchar **auth_info) +gtk_print_backend_cups_set_password_full (GtkPrintBackend *backend, + gchar **auth_info_required, + gchar **auth_info, + gboolean store_auth_info) { GtkPrintBackendCups *cups_backend = GTK_PRINT_BACKEND_CUPS (backend); GList *l; char dispatch_hostname[HTTP_MAX_URI]; gchar *key; - gchar *username = NULL; - gchar *hostname = NULL; - gchar *password = NULL; + const gchar *username = NULL; + const gchar *hostname = NULL; + const gchar *password = NULL; gint length; gint i; @@ -993,25 +1112,24 @@ gtk_print_backend_cups_set_password (GtkPrintBackend *backend, for (i = 0; i < length; i++) { if (g_strcmp0 (auth_info_required[i], "username") == 0) - username = g_strdup (auth_info[i]); + username = auth_info[i]; else if (g_strcmp0 (auth_info_required[i], "hostname") == 0) - hostname = g_strdup (auth_info[i]); + hostname = auth_info[i]; else if (g_strcmp0 (auth_info_required[i], "password") == 0) - password = g_strdup (auth_info[i]); + password = auth_info[i]; } if (hostname != NULL && username != NULL && password != NULL) { key = g_strconcat (username, "@", hostname, NULL); g_hash_table_insert (cups_backend->auth, key, g_strdup (password)); + GTK_NOTE (PRINTING, + g_print ("CUPS backend: storing password for %s\n", key)); } g_free (cups_backend->username); cups_backend->username = g_strdup (username); - GTK_NOTE (PRINTING, - g_print ("CUPS backend: storing password for %s\n", key)); - for (l = cups_backend->requests; l; l = l->next) { GtkPrintCupsDispatchWatch *dispatch = l->data; @@ -1027,6 +1145,11 @@ gtk_print_backend_cups_set_password (GtkPrintBackend *backend, dispatch->request->auth_info = g_new0 (gchar *, length + 1); for (i = 0; i < length; i++) dispatch->request->auth_info[i] = g_strdup (auth_info[i]); + + if (store_auth_info && password != NULL) + cups_secret_store (auth_info_required, auth_info, + gtk_cups_request_ipp_get_string (dispatch->request, + IPP_TAG_URI, "printer-uri")); } dispatch->backend->authentication_lock = FALSE; dispatch->request->need_auth_info = FALSE; @@ -1043,6 +1166,31 @@ gtk_print_backend_cups_set_password (GtkPrintBackend *backend, } } +static void +gtk_print_backend_cups_set_password (GtkPrintBackend *backend, + gchar **auth_info_required, + gchar **auth_info) +{ + gtk_print_backend_cups_set_password_full (backend, auth_info_required, auth_info, FALSE); +} + +/* Offers to remember the password asked for a job (not for the server). */ +static gboolean +gtk_print_backend_cups_can_store_password (GtkPrintBackend *backend) +{ + GtkPrintBackendCups *cups_backend = GTK_PRINT_BACKEND_CUPS (backend); + GList *l; + + if (!cups_backend->secrets_available) + return FALSE; + + for (l = cups_backend->requests; l; l = l->next) + if (((GtkPrintCupsDispatchWatch *) l->data)->request->need_auth_info) + return TRUE; + + return FALSE; +} + static gboolean request_password (gpointer data) { @@ -1349,6 +1497,7 @@ request_auth_info (gpointer user_data) g_free (auth_info_default); g_free (auth_info_display); + g_free (auth_info_visible); g_free (printer_name); g_free (prompt); @@ -1357,6 +1506,399 @@ request_auth_info (gpointer user_data) return FALSE; } +/* Passwords that printers need for each job (auth-info-required, as for + * printers shared by Windows) can be kept in the user's keyring through the + * freedesktop.org Secret Service API. The entries are the same as GTK+ 3 + * makes, so both find each other's: label and "uri" attribute are the + * printer URI, "user", "server" and "domain" attributes hold the other + * fields and the secret is the password as text/plain. + * The session bus is used only when a printer asks for a password. + */ + +#define SECRETS_BUS "org.freedesktop.secrets" +#define SECRETS_PATH "/org/freedesktop/secrets" +#define SECRETS_COLLECTION "/org/freedesktop/secrets/aliases/default" +#define SECRETS_IFACE(x) "org.freedesktop.Secret." x + +typedef enum +{ + SECRET_SEARCH, + SECRET_UNLOCK, + SECRET_PROMPT, + SECRET_ATTRIBUTES, + SECRET_SESSION, + SECRET_GET, + SECRET_CREATE +} SecretStep; + +typedef struct +{ + GtkPrintCupsDispatchWatch *dispatch; /* looking up for it; NULL when storing */ + GDBusConnection *bus; + SecretStep step; + gchar *uri; + gchar **required; /* names of the auth_info fields */ + gchar **auth_info; + gchar *item; + gchar *session; + guint prompt_signal; + guint prompt_returned : 1; /* Prompt() and Completed can come in any order */ + guint prompt_completed : 1; + guint dismissed : 1; +} CupsSecret; + +static void cups_secret_reply (GObject *source, GAsyncResult *res, gpointer data); + +static void +cups_secret_call (CupsSecret *secret, + const gchar *path, + const gchar *interface, + const gchar *method, + GVariant *parameters, + const GVariantType *reply_type, + SecretStep step) +{ + secret->step = step; + g_dbus_connection_call (secret->bus, SECRETS_BUS, path, interface, method, + parameters, reply_type, G_DBUS_CALL_FLAGS_NONE, + -1, NULL, cups_secret_reply, secret); +} + +static void +cups_secret_open_session (CupsSecret *secret) +{ + cups_secret_call (secret, SECRETS_PATH, SECRETS_IFACE ("Service"), "OpenSession", + g_variant_new ("(sv)", "plain", g_variant_new_string ("")), + G_VARIANT_TYPE ("(vo)"), SECRET_SESSION); +} + +static void +cups_secret_finish (CupsSecret *secret, + gboolean found, + GError *error) +{ + GtkPrintCupsDispatchWatch *dispatch = secret->dispatch; + guint i; + + if (error != NULL) + GTK_NOTE (PRINTING, g_print ("CUPS backend: keyring: %s\n", error->message)); + + if (dispatch != NULL) + { + if (error == NULL) + dispatch->backend->secrets_available = TRUE; + else if (secret->bus == NULL || + g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_SERVICE_UNKNOWN) || + g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_NAME_HAS_NO_OWNER)) + dispatch->backend->secrets_unavailable = TRUE; + + if (found) + gtk_print_backend_cups_set_password (GTK_PRINT_BACKEND (dispatch->backend), + secret->required, secret->auth_info); + else + dispatch->backend->authentication_lock = FALSE; + } + + g_clear_error (&error); + + if (secret->prompt_signal != 0) + g_dbus_connection_signal_unsubscribe (secret->bus, secret->prompt_signal); + if (secret->session != NULL) + g_dbus_connection_call (secret->bus, SECRETS_BUS, secret->session, + SECRETS_IFACE ("Session"), "Close", NULL, NULL, + G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL, NULL); + if (secret->auth_info != NULL) + for (i = 0; secret->required[i] != NULL; i++) + overwrite_and_free (secret->auth_info[i]); + g_free (secret->auth_info); + g_strfreev (secret->required); + g_free (secret->uri); + g_free (secret->item); + g_free (secret->session); + if (secret->bus != NULL) + g_object_unref (secret->bus); + g_free (secret); + + if (dispatch != NULL) + { + if (found) + check_auth_info (dispatch); + else + request_auth_info (dispatch); + } +} + +/* Goes on once the keyring is unlocked. */ +static void +cups_secret_unlocked (CupsSecret *secret) +{ + if (secret->dismissed) + cups_secret_finish (secret, FALSE, NULL); + else if (secret->session != NULL) + cups_secret_finish (secret, TRUE, NULL); /* stored after a prompt */ + else if (secret->dispatch != NULL) + cups_secret_call (secret, secret->item, "org.freedesktop.DBus.Properties", "Get", + g_variant_new ("(ss)", SECRETS_IFACE ("Item"), "Attributes"), + G_VARIANT_TYPE ("(v)"), SECRET_ATTRIBUTES); + else + cups_secret_open_session (secret); +} + +static void +cups_secret_prompt_completed (GDBusConnection *bus, + const gchar *sender, + const gchar *path, + const gchar *interface, + const gchar *signal, + GVariant *parameters, + gpointer data) +{ + CupsSecret *secret = data; + gboolean dismissed = TRUE; + + g_dbus_connection_signal_unsubscribe (bus, secret->prompt_signal); + secret->prompt_signal = 0; + + if (g_variant_is_of_type (parameters, G_VARIANT_TYPE ("(bv)"))) + g_variant_get (parameters, "(bv)", &dismissed, NULL); + secret->dismissed = dismissed; + secret->prompt_completed = TRUE; + + if (secret->prompt_returned) + cups_secret_unlocked (secret); +} + +/* Lets the keyring ask the user, if @prompt is not "/". */ +static void +cups_secret_prompt (CupsSecret *secret, + const gchar *prompt) +{ + if (strcmp (prompt, "/") == 0) + { + cups_secret_unlocked (secret); + return; + } + + secret->prompt_returned = secret->prompt_completed = FALSE; + secret->prompt_signal = + g_dbus_connection_signal_subscribe (secret->bus, SECRETS_BUS, SECRETS_IFACE ("Prompt"), + "Completed", prompt, NULL, G_DBUS_SIGNAL_FLAGS_NONE, + cups_secret_prompt_completed, secret, NULL); + cups_secret_call (secret, prompt, SECRETS_IFACE ("Prompt"), "Prompt", + g_variant_new ("(s)", ""), NULL, SECRET_PROMPT); +} + +static void +cups_secret_reply (GObject *source, + GAsyncResult *res, + gpointer data) +{ + CupsSecret *secret = data; + GError *error = NULL; + GVariant *reply, *value; + const gchar **unlocked, **locked; + const gchar *prompt; + gconstpointer password; + gsize length; + guint i; + + reply = g_dbus_connection_call_finish (secret->bus, res, &error); + if (reply == NULL) + { + cups_secret_finish (secret, FALSE, error); + return; + } + + switch (secret->step) + { + case SECRET_SEARCH: + g_variant_get (reply, "(^a&o^a&o)", &unlocked, &locked); + secret->item = g_strdup (unlocked[0] != NULL ? unlocked[0] : locked[0]); + i = unlocked[0] != NULL; + g_free (unlocked); + g_free (locked); + if (secret->item == NULL) + cups_secret_finish (secret, FALSE, NULL); + else if (i) + cups_secret_unlocked (secret); + else + cups_secret_call (secret, SECRETS_PATH, SECRETS_IFACE ("Service"), "Unlock", + g_variant_new ("(^ao)", (gchar *[]) { secret->item, NULL }), + G_VARIANT_TYPE ("(aoo)"), SECRET_UNLOCK); + break; + + case SECRET_UNLOCK: + case SECRET_CREATE: + g_variant_get (reply, secret->step == SECRET_UNLOCK ? "(@ao&o)" : "(&o&o)", NULL, &prompt); + cups_secret_prompt (secret, prompt); + break; + + case SECRET_PROMPT: + secret->prompt_returned = TRUE; + if (secret->prompt_completed) + cups_secret_unlocked (secret); + break; + + case SECRET_ATTRIBUTES: + g_variant_get (reply, "(v)", &value); + secret->auth_info = g_new0 (gchar *, g_strv_length (secret->required) + 1); + for (i = 0; secret->required[i] != NULL; i++) + { + const gchar *name = secret->required[i]; + const gchar *found = NULL; + + if (!g_variant_is_of_type (value, G_VARIANT_TYPE ("a{ss}"))) + break; + if (strcmp (name, "password") == 0) + continue; + if (strcmp (name, "username") == 0 && + !g_variant_lookup (value, "user", "&s", &found)) + g_variant_lookup (value, "username", "&s", &found); + else if (strcmp (name, "hostname") == 0 && + !g_variant_lookup (value, "server", "&s", &found)) + g_variant_lookup (value, "hostname", "&s", &found); + else if (strcmp (name, "domain") == 0) + g_variant_lookup (value, "domain", "&s", &found); + + if (found == NULL) + break; + secret->auth_info[i] = g_strdup (found); + } + g_variant_unref (value); + if (secret->required[i] != NULL) + cups_secret_finish (secret, FALSE, NULL); + else + cups_secret_open_session (secret); + break; + + case SECRET_SESSION: + g_variant_get (reply, "(vo)", NULL, &secret->session); + if (secret->dispatch != NULL) + cups_secret_call (secret, secret->item, SECRETS_IFACE ("Item"), "GetSecret", + g_variant_new ("(o)", secret->session), + G_VARIANT_TYPE ("((oayays))"), SECRET_GET); + else + { + GVariantBuilder attributes, properties; + const gchar *password = NULL; + + g_variant_builder_init (&attributes, G_VARIANT_TYPE ("a{ss}")); + g_variant_builder_add (&attributes, "{ss}", "uri", secret->uri); + for (i = 0; secret->required[i] != NULL; i++) + { + const gchar *name = secret->required[i]; + + if (strcmp (name, "password") == 0) + password = secret->auth_info[i]; + else if (secret->auth_info[i] != NULL) + g_variant_builder_add (&attributes, "{ss}", + strcmp (name, "username") == 0 ? "user" : + strcmp (name, "hostname") == 0 ? "server" : name, + secret->auth_info[i]); + } + + g_variant_builder_init (&properties, G_VARIANT_TYPE ("a{sv}")); + g_variant_builder_add (&properties, "{sv}", SECRETS_IFACE ("Item.Label"), + g_variant_new_string (secret->uri)); + g_variant_builder_add (&properties, "{sv}", SECRETS_IFACE ("Item.Attributes"), + g_variant_builder_end (&attributes)); + + cups_secret_call (secret, SECRETS_COLLECTION, SECRETS_IFACE ("Collection"), "CreateItem", + g_variant_new ("(a{sv}(o@ay@ays)b)", &properties, secret->session, + g_variant_new_fixed_array (G_VARIANT_TYPE_BYTE, "", 0, 1), + g_variant_new_fixed_array (G_VARIANT_TYPE_BYTE, password, + strlen (password), 1), + "text/plain", TRUE), + G_VARIANT_TYPE ("(oo)"), SECRET_CREATE); + } + break; + + case SECRET_GET: + g_variant_get (reply, "((o@ay@ays))", NULL, NULL, &value, NULL); + password = g_variant_get_fixed_array (value, &length, 1); + for (i = 0; strcmp (secret->required[i], "password") != 0; i++) + ; + secret->auth_info[i] = g_strndup (password, length); + g_variant_unref (value); + cups_secret_finish (secret, TRUE, NULL); + break; + } + + g_variant_unref (reply); +} + +static void +cups_secret_got_bus (GObject *source, + GAsyncResult *res, + gpointer data) +{ + CupsSecret *secret = data; + GError *error = NULL; + + secret->bus = g_bus_get_finish (res, &error); + if (secret->bus == NULL) + cups_secret_finish (secret, FALSE, error); + else if (secret->dispatch != NULL) + cups_secret_call (secret, SECRETS_PATH, SECRETS_IFACE ("Service"), "SearchItems", + g_variant_new_parsed ("({'uri': %s},)", secret->uri), + G_VARIANT_TYPE ("(aoao)"), SECRET_SEARCH); + else + cups_secret_call (secret, SECRETS_PATH, SECRETS_IFACE ("Service"), "Unlock", + g_variant_new ("(^ao)", (gchar *[]) { SECRETS_COLLECTION, NULL }), + G_VARIANT_TYPE ("(aoo)"), SECRET_UNLOCK); +} + +/* Asks for the password in the dialog unless the keyring has it. */ +static void +lookup_auth_info (GtkPrintCupsDispatchWatch *dispatch) +{ + CupsSecret *secret; + const gchar *uri; + guint i; + + if (dispatch->backend->authentication_lock) + return; + + uri = gtk_cups_request_ipp_get_string (dispatch->request, IPP_TAG_URI, "printer-uri"); + for (i = 0; dispatch->request->auth_info_required[i] != NULL; i++) + if (strcmp (dispatch->request->auth_info_required[i], "password") == 0) + break; + if (dispatch->backend->secrets_unavailable || uri == NULL || + dispatch->request->auth_info_required[i] == NULL) + { + request_auth_info (dispatch); + return; + } + + dispatch->backend->authentication_lock = TRUE; + + secret = g_new0 (CupsSecret, 1); + secret->dispatch = dispatch; + secret->uri = g_strdup (uri); + secret->required = g_strdupv (dispatch->request->auth_info_required); + g_bus_get (G_BUS_TYPE_SESSION, NULL, cups_secret_got_bus, secret); +} + +static void +cups_secret_store (gchar **auth_info_required, + gchar **auth_info, + const gchar *printer_uri) +{ + CupsSecret *secret; + guint i, length = g_strv_length (auth_info_required); + + if (printer_uri == NULL) + return; + + secret = g_new0 (CupsSecret, 1); + secret->uri = g_strdup (printer_uri); + secret->required = g_strdupv (auth_info_required); + secret->auth_info = g_new0 (gchar *, length + 1); + for (i = 0; i < length; i++) + secret->auth_info[i] = g_strdup (auth_info[i]); + g_bus_get (G_BUS_TYPE_SESSION, NULL, cups_secret_got_bus, secret); +} + static gboolean cups_dispatch_watch_check (GSource *source) { @@ -1554,7 +2096,7 @@ cups_request_execute (GtkPrintBackendCups *print_backend, { dispatch->callback = callback; dispatch->callback_data = user_data; - request_auth_info (dispatch); + lookup_auth_info (dispatch); } else { @@ -2612,6 +3154,8 @@ cups_request_avahi_printer_info (const gchar *printer_uri, NULL, NULL, backend->username); + /* Hand the connection over: the request closes it when it is freed */ + request->own_http = TRUE; gtk_cups_request_set_ipp_version (request, 1, 1); @@ -2700,7 +3244,8 @@ avahi_service_resolver_cb (GObject *source_object, gint interface; gint protocol; gint aprotocol; - gint i, j; + gsize length; + gint i; output = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source_object), res, @@ -2726,12 +3271,16 @@ avahi_service_resolver_cb (GObject *source_object, { child = g_variant_get_child_value (txt, i); - tmp = g_new0 (gchar, g_variant_n_children (child) + 1); - for (j = 0; j < g_variant_n_children (child); j++) + length = g_variant_get_size (child); + if (length == 0) { - tmp[j] = g_variant_get_byte (g_variant_get_child_value (child, j)); + g_variant_unref (child); + continue; } + tmp = g_strndup (g_variant_get_data (child), length); + g_variant_unref (child); + if (g_str_has_prefix (tmp, "rp=")) { suffix = g_strdup (tmp + 3); @@ -2742,6 +3291,8 @@ avahi_service_resolver_cb (GObject *source_object, g_free (tmp); } + g_variant_unref (txt); + if (suffix) { if (g_strcmp0 (type, "_ipp._tcp") == 0) @@ -3027,6 +3578,21 @@ avahi_request_printer_list (GtkPrintBackendCups *cups_backend) } #endif +/* + * A handler of ::printer-added or ::printer-list-done can destroy the + * backend (gtk_print_backend_destroy (), as gtk_enumerate_printers () + * does when its function returns TRUE); that frees its printers. + * The weak reference is notified when it is disposed. + */ +static void +backend_disposed_cb (gpointer data, + GObject *where_the_object_was) +{ + gboolean *backend_disposed = data; + + *backend_disposed = TRUE; +} + static void cups_request_printer_list_cb (GtkPrintBackendCups *cups_backend, GtkCupsResult *result, @@ -3039,9 +3605,12 @@ cups_request_printer_list_cb (GtkPrintBackendCups *cups_backend, GList *removed_printer_checklist; gchar *remote_default_printer = NULL; GList *iter; + gboolean backend_disposed = FALSE; GDK_THREADS_ENTER (); + g_object_weak_ref (G_OBJECT (backend), backend_disposed_cb, &backend_disposed); + list_has_changed = FALSE; GTK_NOTE (PRINTING, @@ -3151,11 +3720,15 @@ cups_request_printer_list_cb (GtkPrintBackendCups *cups_backend, } /* remove name from checklist if it was found */ - node = g_list_find_custom (removed_printer_checklist, - info->printer_name, - (GCompareFunc) find_printer); - removed_printer_checklist = g_list_delete_link (removed_printer_checklist, - node); + if (removed_printer_checklist != NULL) + { + node = g_list_find_custom (removed_printer_checklist, + info->printer_name, + (GCompareFunc) find_printer); + if (node != NULL) + removed_printer_checklist = g_list_delete_link (removed_printer_checklist, + node); + } printer = gtk_print_backend_find_printer (backend, info->printer_name); if (!printer) @@ -3219,13 +3792,14 @@ cups_request_printer_list_cb (GtkPrintBackendCups *cups_backend, g_free (info->state_msg); g_slice_free (PrinterSetupInfo, info); - if (attr == NULL) + if (attr == NULL || backend_disposed) break; } /* look at the removed printers checklist and mark any printer - as inactive if it is in the list, emitting a printer_removed signal */ - if (removed_printer_checklist != NULL) + as inactive if it is in the list, emitting a printer_removed signal; + the printers of a destroyed backend are gone */ + if (removed_printer_checklist != NULL && !backend_disposed) { for (iter = removed_printer_checklist; iter; iter = iter->next) { @@ -3237,15 +3811,18 @@ cups_request_printer_list_cb (GtkPrintBackendCups *cups_backend, list_has_changed = TRUE; } } - - g_list_free (removed_printer_checklist); } -done: - if (list_has_changed) - g_signal_emit_by_name (backend, "printer-list-changed"); + g_list_free (removed_printer_checklist); - gtk_print_backend_set_list_done (backend); +done: + if (!backend_disposed) + { + if (list_has_changed) + g_signal_emit_by_name (backend, "printer-list-changed"); + + gtk_print_backend_set_list_done (backend); + } if (!cups_backend->got_default_printer && remote_default_printer != NULL) { @@ -3260,6 +3837,9 @@ done: } #endif + if (!backend_disposed) + g_object_weak_unref (G_OBJECT (backend), backend_disposed_cb, &backend_disposed); + GDK_THREADS_LEAVE (); } @@ -3413,6 +3993,11 @@ cups_request_ppd_cb (GtkPrintBackendCups *print_backend, /* let ppdOpenFd take over the ownership of the open file */ g_io_channel_seek_position (data->ppd_io, 0, G_SEEK_SET, NULL); data->printer->ppd_file = ppdOpenFd (dup (g_io_channel_unix_get_fd (data->ppd_io))); +#if (CUPS_VERSION_MAJOR == 1 && CUPS_VERSION_MINOR >= 2) || CUPS_VERSION_MAJOR > 1 + /* the option names and choices in the language of the user, where + * the PPD has translations for it */ + ppdLocalize (data->printer->ppd_file); +#endif ppdMarkDefaults (data->printer->ppd_file); @@ -3650,12 +4235,9 @@ cups_parse_user_options (const char *filename, if (!*lineptr) continue; - /* NUL-terminate the name, stripping the instance name */ name = lineptr; while (!isspace (*lineptr) && *lineptr) { - if (*lineptr == '/') - *lineptr = '\0'; lineptr++; } @@ -3664,7 +4246,9 @@ cups_parse_user_options (const char *filename, *lineptr++ = '\0'; - if (strncasecmp (name, printer_name, strlen (printer_name)) != 0) + /* the whole name: neither "printer/instance" nor "printer2" are + * options for "printer" */ + if (g_ascii_strcasecmp (name, printer_name) != 0) continue; /* We found our printer, parse the options */ @@ -5267,23 +5851,29 @@ set_option_from_settings (GtkPrinterOption *option, gtk_printer_option_set (option, cups_value); else { - int res = gtk_print_settings_get_resolution (settings); - int res_x = gtk_print_settings_get_resolution_x (settings); - int res_y = gtk_print_settings_get_resolution_y (settings); - - if (res_x != res_y) - { - value = g_strdup_printf ("%dx%ddpi", res_x, res_y); - gtk_printer_option_set (option, value); - g_free (value); - } - else if (res != 0) + if (gtk_print_settings_get_int_with_default (settings, GTK_PRINT_SETTINGS_RESOLUTION, -1) != -1 || + gtk_print_settings_get_int_with_default (settings, GTK_PRINT_SETTINGS_RESOLUTION_X, -1) != -1 || + gtk_print_settings_get_int_with_default (settings, GTK_PRINT_SETTINGS_RESOLUTION_Y, -1) != -1 || + option->value == NULL || option->value[0] == '\0') { - value = g_strdup_printf ("%ddpi", res); - gtk_printer_option_set (option, value); - g_free (value); - } - } + int res = gtk_print_settings_get_resolution (settings); + int res_x = gtk_print_settings_get_resolution_x (settings); + int res_y = gtk_print_settings_get_resolution_y (settings); + + if (res_x != res_y) + { + value = g_strdup_printf ("%dx%ddpi", res_x, res_y); + gtk_printer_option_set (option, value); + g_free (value); + } + else if (res != 0) + { + value = g_strdup_printf ("%ddpi", res); + gtk_printer_option_set (option, value); + g_free (value); + } + } + } } else if (strcmp (option->name, "gtk-paper-type") == 0) map_settings_to_option (option, media_type_map, G_N_ELEMENTS (media_type_map), @@ -5434,13 +6024,8 @@ localtime_to_utctime (const char *local_time) " %I %p ", " %p %I "}; const char *formats_1[] = {" %H : %M : %S ", " %H : %M "}; const char *end = NULL; - struct tm *actual_local_time; - struct tm *actual_utc_time; struct tm local_print_time; - struct tm utc_now; - struct tm local_now; struct tm utc_print_time; - struct tm diff_time; gchar *utc_time = NULL; int i, n; @@ -5466,31 +6051,24 @@ localtime_to_utctime (const char *local_time) if (end != NULL && end[0] == '\0') { - time_t rawtime; - struct tm *tmp_tm; + GDateTime *now; + gint64 offset, secs; - time (&rawtime); - - tmp_tm = gmtime (&rawtime); - if (tmp_tm == NULL) + /* The offset of local time now, from GDateTime: time () has no + * answer after 2038 where time_t is 32 bits */ + now = _gtk_date_time_new_now_local (); + if (now == NULL) return NULL; - utc_now = *tmp_tm; + offset = g_date_time_get_utc_offset (now) / G_USEC_PER_SEC; + g_date_time_unref (now); - tmp_tm = localtime (&rawtime); - if (tmp_tm == NULL) - return NULL; - local_now = *tmp_tm; + secs = local_print_time.tm_hour * 3600 + local_print_time.tm_min * 60 + + local_print_time.tm_sec - offset; + secs = ((secs % 86400) + 86400) % 86400; - actual_utc_time = &utc_now; - actual_local_time = &local_now; - - diff_time.tm_hour = actual_utc_time->tm_hour - actual_local_time->tm_hour; - diff_time.tm_min = actual_utc_time->tm_min - actual_local_time->tm_min; - diff_time.tm_sec = actual_utc_time->tm_sec - actual_local_time->tm_sec; - - utc_print_time.tm_hour = ((local_print_time.tm_hour + diff_time.tm_hour) + 24) % 24; - utc_print_time.tm_min = ((local_print_time.tm_min + diff_time.tm_min) + 60) % 60; - utc_print_time.tm_sec = ((local_print_time.tm_sec + diff_time.tm_sec) + 60) % 60; + utc_print_time.tm_hour = secs / 3600; + utc_print_time.tm_min = (secs / 60) % 60; + utc_print_time.tm_sec = secs % 60; utc_time = g_strdup_printf ("%02d:%02d:%02d", utc_print_time.tm_hour, diff --git a/modules/printbackends/cups/gtkprintbackendcups.h b/modules/printbackends/cups/gtkprintbackendcups.h index 81c1d987a..3f9476a3f 100644 --- a/modules/printbackends/cups/gtkprintbackendcups.h +++ b/modules/printbackends/cups/gtkprintbackendcups.h @@ -33,7 +33,7 @@ G_BEGIN_DECLS typedef struct _GtkPrintBackendCups GtkPrintBackendCups; GtkPrintBackend *gtk_print_backend_cups_new (void); -GType gtk_print_backend_cups_get_type (void) G_GNUC_CONST; +GType gtk_print_backend_cups_get_type (void); G_END_DECLS diff --git a/modules/printbackends/cups/gtkprintercups.h b/modules/printbackends/cups/gtkprintercups.h index d10bd7ec3..1e8205897 100644 --- a/modules/printbackends/cups/gtkprintercups.h +++ b/modules/printbackends/cups/gtkprintercups.h @@ -81,7 +81,7 @@ struct _GtkPrinterCupsClass }; -GType gtk_printer_cups_get_type (void) G_GNUC_CONST; +GType gtk_printer_cups_get_type (void); void gtk_printer_cups_register_type (GTypeModule *module); GtkPrinterCups *gtk_printer_cups_new (const char *name, GtkPrintBackend *backend); diff --git a/modules/printbackends/file/gtkprintbackendfile.c b/modules/printbackends/file/gtkprintbackendfile.c index 90cae3cdb..38d055da4 100644 --- a/modules/printbackends/file/gtkprintbackendfile.c +++ b/modules/printbackends/file/gtkprintbackendfile.c @@ -253,13 +253,21 @@ output_file_from_settings (GtkPrintSettings *settings, if (locale_name != NULL) { - gchar *current_dir = g_get_current_dir (); - path = g_build_filename (current_dir, locale_name, NULL); - g_free (locale_name); + const gchar *document_dir = g_get_user_special_dir (G_USER_DIRECTORY_DOCUMENTS); + + if (document_dir == NULL) + { + gchar *current_dir = g_get_current_dir (); + path = g_build_filename (current_dir, locale_name, NULL); + g_free (current_dir); + } + else + path = g_build_filename (document_dir, locale_name, NULL); uri = g_filename_to_uri (path, NULL, NULL); + + g_free (locale_name); g_free (path); - g_free (current_dir); } } @@ -272,7 +280,7 @@ _cairo_write (void *closure, unsigned int length) { GIOChannel *io = (GIOChannel *)closure; - gsize written; + gsize written = 0; GError *error; error = NULL; @@ -282,14 +290,20 @@ _cairo_write (void *closure, while (length > 0) { - g_io_channel_write_chars (io, (const gchar *) data, length, &written, &error); + GIOStatus status; - if (error != NULL) - { - GTK_NOTE (PRINTING, - g_print ("FILE Backend: Error writting to temp file, %s\n", error->message)); + status = g_io_channel_write_chars (io, (const gchar *) data, length, &written, &error); + + if (status == G_IO_STATUS_ERROR) + { + if (error != NULL) + { + GTK_NOTE (PRINTING, + g_print ("FILE Backend: Error writting to temp file, %s\n", error->message)); + + g_error_free (error); + } - g_error_free (error); return CAIRO_STATUS_WRITE_ERROR; } @@ -372,6 +386,17 @@ file_print_cb (GtkPrintBackendFile *print_backend, gtk_print_job_set_status (ps->job, (error != NULL)?GTK_PRINT_STATUS_FINISHED_ABORTED:GTK_PRINT_STATUS_FINISHED); + /* the file printed to is a recently used file, as one saved */ + if (error == NULL && ps->job) + { + gchar *uri; + + uri = output_file_from_settings (gtk_print_job_get_settings (ps->job), NULL); + if (uri) + gtk_recent_manager_add_item (gtk_recent_manager_get_default (), uri); + g_free (uri); + } + if (ps->job) g_object_unref (ps->job); diff --git a/modules/printbackends/file/gtkprintbackendfile.h b/modules/printbackends/file/gtkprintbackendfile.h index 5492e4ec9..353b6d6fb 100644 --- a/modules/printbackends/file/gtkprintbackendfile.h +++ b/modules/printbackends/file/gtkprintbackendfile.h @@ -34,7 +34,7 @@ G_BEGIN_DECLS typedef struct _GtkPrintBackendFile GtkPrintBackendFile; GtkPrintBackend *gtk_print_backend_file_new (void); -GType gtk_print_backend_file_get_type (void) G_GNUC_CONST; +GType gtk_print_backend_file_get_type (void); G_END_DECLS diff --git a/modules/printbackends/lpr/gtkprintbackendlpr.c b/modules/printbackends/lpr/gtkprintbackendlpr.c index aea3683f9..0d645c471 100644 --- a/modules/printbackends/lpr/gtkprintbackendlpr.c +++ b/modules/printbackends/lpr/gtkprintbackendlpr.c @@ -169,7 +169,7 @@ _cairo_write (void *closure, unsigned int length) { GIOChannel *io = (GIOChannel *)closure; - gsize written; + gsize written = 0; GError *error; error = NULL; @@ -179,14 +179,20 @@ _cairo_write (void *closure, while (length > 0) { - g_io_channel_write_chars (io, (const gchar*)data, length, &written, &error); + GIOStatus status; - if (error != NULL) - { - GTK_NOTE (PRINTING, - g_print ("LPR Backend: Error writting to temp file, %s\n", error->message)); + status = g_io_channel_write_chars (io, (const gchar*)data, length, &written, &error); + + if (status == G_IO_STATUS_ERROR) + { + if (error != NULL) + { + GTK_NOTE (PRINTING, + g_print ("LPR Backend: Error writting to temp file, %s\n", error->message)); + + g_error_free (error); + } - g_error_free (error); return CAIRO_STATUS_WRITE_ERROR; } diff --git a/modules/printbackends/lpr/gtkprintbackendlpr.h b/modules/printbackends/lpr/gtkprintbackendlpr.h index ecceaa928..fa04a7b65 100644 --- a/modules/printbackends/lpr/gtkprintbackendlpr.h +++ b/modules/printbackends/lpr/gtkprintbackendlpr.h @@ -34,7 +34,7 @@ G_BEGIN_DECLS typedef struct _GtkPrintBackendLpr GtkPrintBackendLpr; GtkPrintBackend *gtk_print_backend_lpr_new (void); -GType gtk_print_backend_lpr_get_type (void) G_GNUC_CONST; +GType gtk_print_backend_lpr_get_type (void); G_END_DECLS diff --git a/modules/printbackends/papi/gtkprintbackendpapi.c b/modules/printbackends/papi/gtkprintbackendpapi.c index 694db62a9..934abf0da 100644 --- a/modules/printbackends/papi/gtkprintbackendpapi.c +++ b/modules/printbackends/papi/gtkprintbackendpapi.c @@ -194,7 +194,7 @@ _cairo_write (void *closure, unsigned int length) { GIOChannel *io = (GIOChannel *)closure; - gsize written; + gsize written = 0; GError *error = NULL; GTK_NOTE (PRINTING, @@ -202,14 +202,20 @@ _cairo_write (void *closure, while (length > 0) { - g_io_channel_write_chars (io, (char *)data, length, &written, &error); + GIOStatus status; - if (error != NULL) - { - GTK_NOTE (PRINTING, - g_print ("PAPI Backend: Error writting to temp file, %s\n", error->message)); + status = g_io_channel_write_chars (io, (char *)data, length, &written, &error); + + if (status == G_IO_STATUS_ERROR) + { + if (error != NULL) + { + GTK_NOTE (PRINTING, + g_print ("PAPI Backend: Error writting to temp file, %s\n", error->message)); + + g_error_free (error); + } - g_error_free (error); return CAIRO_STATUS_WRITE_ERROR; } diff --git a/modules/printbackends/papi/gtkprintbackendpapi.h b/modules/printbackends/papi/gtkprintbackendpapi.h index fdee549fa..5611ad71b 100644 --- a/modules/printbackends/papi/gtkprintbackendpapi.h +++ b/modules/printbackends/papi/gtkprintbackendpapi.h @@ -35,7 +35,7 @@ G_BEGIN_DECLS typedef struct _GtkPrintBackendPapi GtkPrintBackendPapi; GtkPrintBackend *gtk_print_backend_papi_new (void); -GType gtk_print_backend_papi_get_type (void) G_GNUC_CONST; +GType gtk_print_backend_papi_get_type (void); G_END_DECLS diff --git a/modules/printbackends/papi/gtkprinterpapi.h b/modules/printbackends/papi/gtkprinterpapi.h index 300cf1711..73e71a4cb 100644 --- a/modules/printbackends/papi/gtkprinterpapi.h +++ b/modules/printbackends/papi/gtkprinterpapi.h @@ -52,7 +52,7 @@ struct _GtkPrinterPapiClass }; -GType gtk_printer_papi_get_type (void) G_GNUC_CONST; +GType gtk_printer_papi_get_type (void); void gtk_printer_papi_register_type (GTypeModule *module); GtkPrinterPapi *gtk_printer_papi_new (const char *name, GtkPrintBackend *backend); diff --git a/modules/printbackends/test/gtkprintbackendtest.c b/modules/printbackends/test/gtkprintbackendtest.c index e118b78cf..b185cf886 100644 --- a/modules/printbackends/test/gtkprintbackendtest.c +++ b/modules/printbackends/test/gtkprintbackendtest.c @@ -256,7 +256,7 @@ _cairo_write (void *closure, unsigned int length) { GIOChannel *io = (GIOChannel *)closure; - gsize written; + gsize written = 0; GError *error; error = NULL; @@ -266,14 +266,20 @@ _cairo_write (void *closure, while (length > 0) { - g_io_channel_write_chars (io, (const gchar *) data, length, &written, &error); + GIOStatus status; - if (error != NULL) - { - GTK_NOTE (PRINTING, - g_print ("TEST Backend: Error writing to temp test, %s\n", error->message)); + status = g_io_channel_write_chars (io, (const gchar *) data, length, &written, &error); + + if (status == G_IO_STATUS_ERROR) + { + if (error != NULL) + { + GTK_NOTE (PRINTING, + g_print ("TEST Backend: Error writing to temp test, %s\n", error->message)); + + g_error_free (error); + } - g_error_free (error); return CAIRO_STATUS_WRITE_ERROR; } diff --git a/modules/printbackends/test/gtkprintbackendtest.h b/modules/printbackends/test/gtkprintbackendtest.h index 8ee33be74..6ed5818e9 100644 --- a/modules/printbackends/test/gtkprintbackendtest.h +++ b/modules/printbackends/test/gtkprintbackendtest.h @@ -34,7 +34,7 @@ G_BEGIN_DECLS typedef struct _GtkPrintBackendTest GtkPrintBackendTest; GtkPrintBackend *gtk_print_backend_test_new (void); -GType gtk_print_backend_test_get_type (void) G_GNUC_CONST; +GType gtk_print_backend_test_get_type (void); G_END_DECLS diff --git a/perf/gtkwidgetprofiler.h b/perf/gtkwidgetprofiler.h index 59c478894..5f0287fce 100644 --- a/perf/gtkwidgetprofiler.h +++ b/perf/gtkwidgetprofiler.h @@ -43,7 +43,7 @@ struct _GtkWidgetProfilerClass { gdouble elapsed); }; -GType gtk_widget_profiler_get_type (void) G_GNUC_CONST; +GType gtk_widget_profiler_get_type (void); GtkWidgetProfiler *gtk_widget_profiler_new (void); diff --git a/perf/typebuiltins.h.template b/perf/typebuiltins.h.template index ea31ae834..b918b0728 100644 --- a/perf/typebuiltins.h.template +++ b/perf/typebuiltins.h.template @@ -13,7 +13,7 @@ G_BEGIN_DECLS /*** END file-production ***/ /*** BEGIN value-header ***/ -GType @enum_name@_get_type (void) G_GNUC_CONST; +GType @enum_name@_get_type (void); #define @ENUMPREFIX@_TYPE_@ENUMSHORT@ (@enum_name@_get_type ()) /*** END value-header ***/ diff --git a/po-properties/Makevars b/po-properties/Makevars index 379c4eebd..586cf7811 100644 --- a/po-properties/Makevars +++ b/po-properties/Makevars @@ -13,7 +13,7 @@ subdir = po-properties top_builddir = .. # These options get passed to xgettext. -XGETTEXT_OPTIONS = --keyword=_ --keyword=N_ +XGETTEXT_OPTIONS = --from-code=UTF-8 --keyword=_ --keyword=N_ # This is the copyright holder that gets inserted into the header of the # $(DOMAIN).pot file. Set this to the copyright holder of the surrounding diff --git a/po/Makevars b/po/Makevars index 8b08dc880..9ea6a00e0 100644 --- a/po/Makevars +++ b/po/Makevars @@ -13,7 +13,7 @@ subdir = po top_builddir = .. # These options get passed to xgettext. -XGETTEXT_OPTIONS = --keyword=_ --keyword=N_ +XGETTEXT_OPTIONS = --from-code=UTF-8 --keyword=_ --keyword=N_ # This is the copyright holder that gets inserted into the header of the # $(DOMAIN).pot file. Set this to the copyright holder of the surrounding diff --git a/po/POTFILES.in b/po/POTFILES.in index 94143bead..8c52eaa76 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -76,6 +76,7 @@ gtk/gtkfilechooserembed.c gtk/gtkfilechooserentry.c gtk/gtkfilechoosersettings.c gtk/gtkfilechooserutils.c +gtk/gtkfileoperation.c gtk/gtkfilechooserwidget.c gtk/gtkfilefilter.c gtk/gtkfilesel.c diff --git a/po/af.po b/po/af.po index 7908f29ac..4aab9287b 100644 --- a/po/af.po +++ b/po/af.po @@ -2574,6 +2574,10 @@ msgstr "Lêerstelselwortel" msgid "Authentication" msgstr "Toepassing" +#: ../gtk/gtkprintbackend.c +msgid "_Remember password" +msgstr "On_thou wagwoord" + #: gtk/gtkprinteroptionwidget.c:695 msgid "Not available" msgstr "Nie beskikbaar nie" diff --git a/po/ar.po b/po/ar.po index dea110fba..fe398ce3e 100644 --- a/po/ar.po +++ b/po/ar.po @@ -1658,6 +1658,10 @@ msgstr "جذر نظام الملفات" msgid "Authentication" msgstr "الاستيثاق" +#: ../gtk/gtkprintbackend.c +msgid "_Remember password" +msgstr "_تذكر كلمة السر" + #: gtk/gtkprinteroptionwidget.c:695 msgid "Not available" msgstr "غير متوفر" diff --git a/po/as.po b/po/as.po index dd057477e..ff326907c 100644 --- a/po/as.po +++ b/po/as.po @@ -2559,6 +2559,10 @@ msgstr "নথিপত্ৰপ্ৰণালী ৰূট" msgid "Authentication" msgstr "প্ৰমাণীকৰণ" +#: ../gtk/gtkprintbackend.c +msgid "_Remember password" +msgstr "পাছৱৰ্ড মনত ৰাখক (_R)" + #: gtk/gtkprinteroptionwidget.c:695 msgid "Not available" msgstr "পোৱা নাযাই" diff --git a/po/be.po b/po/be.po index 8fc115657..f51ff1330 100644 --- a/po/be.po +++ b/po/be.po @@ -1656,6 +1656,10 @@ msgstr "Корань файлавай сістэмы" msgid "Authentication" msgstr "Праверка тоеснасці" +#: ../gtk/gtkprintbackend.c +msgid "_Remember password" +msgstr "_Запомніць пароль" + #: ../gtk/gtkprinteroptionwidget.c:694 msgid "Not available" msgstr "Няма" diff --git a/po/bg.po b/po/bg.po index 8a6c9a713..d1a9992e9 100644 --- a/po/bg.po +++ b/po/bg.po @@ -2612,6 +2612,10 @@ msgstr "Корен на файловата система" msgid "Authentication" msgstr "Идентификация" +#: ../gtk/gtkprintbackend.c +msgid "_Remember password" +msgstr "Запомняне на _паролата" + #: gtk/gtkprinteroptionwidget.c:695 msgid "Not available" msgstr "Не е достъпен" diff --git a/po/br.po b/po/br.po index 9014cddd8..fe556fb33 100644 --- a/po/br.po +++ b/po/br.po @@ -2515,6 +2515,10 @@ msgstr "Gwrizienn ar reizhiad restroù" msgid "Authentication" msgstr "Dilesa" +#: ../gtk/gtkprintbackend.c +msgid "_Remember password" +msgstr "Derc'hel soñj ar _ger-tremen" + #: gtk/gtkprinteroptionwidget.c:695 msgid "Not available" msgstr "Dihegerz" diff --git a/po/bs.po b/po/bs.po index 8844b6d26..9b967514a 100644 --- a/po/bs.po +++ b/po/bs.po @@ -2715,6 +2715,10 @@ msgstr "Datotečni sistem" msgid "Authentication" msgstr "_Lokacija:" +#: ../gtk/gtkprintbackend.c +msgid "_Remember password" +msgstr "_Zapamti šifru" + #: gtk/gtkprinteroptionwidget.c:695 msgid "Not available" msgstr "" diff --git a/po/ca.po b/po/ca.po index 14ab34843..ce0cdaffc 100644 --- a/po/ca.po +++ b/po/ca.po @@ -2609,6 +2609,10 @@ msgstr "Arrel del sistema de fitxers" msgid "Authentication" msgstr "Autenticació" +#: ../gtk/gtkprintbackend.c +msgid "_Remember password" +msgstr "_Recorda la contrasenya" + #: gtk/gtkprinteroptionwidget.c:695 msgid "Not available" msgstr "No està disponible" diff --git a/po/ca@valencia.po b/po/ca@valencia.po index 5128fbcf5..e82ba2ae1 100644 --- a/po/ca@valencia.po +++ b/po/ca@valencia.po @@ -2609,6 +2609,10 @@ msgstr "Arrel del sistema de fitxers" msgid "Authentication" msgstr "Autenticació" +#: ../gtk/gtkprintbackend.c +msgid "_Remember password" +msgstr "_Recorda la contrasenya" + #: gtk/gtkprinteroptionwidget.c:695 msgid "Not available" msgstr "No està disponible" diff --git a/po/cs.po b/po/cs.po index f7ab5ffe7..c7c6cd183 100644 --- a/po/cs.po +++ b/po/cs.po @@ -1671,6 +1671,10 @@ msgstr "Kořen systému souborů" msgid "Authentication" msgstr "Ověření" +#: ../gtk/gtkprintbackend.c +msgid "_Remember password" +msgstr "Pamat_ovat si heslo" + #: ../gtk/gtkprinteroptionwidget.c:694 msgid "Not available" msgstr "Nedostupné" diff --git a/po/da.po b/po/da.po index 5aded49d7..1870b853a 100644 --- a/po/da.po +++ b/po/da.po @@ -1694,6 +1694,10 @@ msgstr "Filsystemets rod" msgid "Authentication" msgstr "Godkendelse" +#: ../gtk/gtkprintbackend.c +msgid "_Remember password" +msgstr "_Husk adgangskode" + #: ../gtk/gtkprinteroptionwidget.c:695 msgid "Not available" msgstr "Ikke tilgængelig" diff --git a/po/de.po b/po/de.po index 49e158bfb..7d9d7633b 100644 --- a/po/de.po +++ b/po/de.po @@ -966,6 +966,46 @@ msgstr "_Verborgene Dateien anzeigen" msgid "Show _Size Column" msgstr "Spalte »_Größe« anzeigen" +#: ../gtk/gtkfilechooserdefault.c +msgid "_Rename…" +msgstr "_Umbenennen …" + +#: ../gtk/gtkfilechooserdefault.c +msgid "Move to _Trash" +msgstr "In den _Papierkorb verschieben" + +#: ../gtk/gtkfilechooserdefault.c +msgid "_Copy Location" +msgstr "P_fad kopieren" + +#: ../gtk/gtkfilechooserdefault.c +msgid "Show _Thumbnails" +msgstr "Vorschau_bilder anzeigen" + +#: ../gtk/gtkfilechooserdefault.c +msgid "Arrange Items" +msgstr "Objekte anordnen" + +#: ../gtk/gtkfilechooserdefault.c +msgid "_Ascending" +msgstr "_Aufsteigend" + +#: ../gtk/gtkfilechooserdefault.c +msgid "_Descending" +msgstr "A_bsteigend" + +#: ../gtk/gtkfilechooserdefault.c +msgid "List View" +msgstr "Listenansicht" + +#: ../gtk/gtkfilechooserdefault.c +msgid "Icon View" +msgstr "Symbolansicht" + +#: ../gtk/gtkfilechooserdefault.c +msgid "Compact View" +msgstr "Kompaktansicht" + #: ../gtk/gtkfilechooserdefault.c:4264 ../gtk/gtkfilesel.c:730 msgid "Files" msgstr "Dateien" @@ -1700,6 +1740,10 @@ msgstr "Dateisystem-Wurzel" msgid "Authentication" msgstr "Legitimation" +#: ../gtk/gtkprintbackend.c +msgid "_Remember password" +msgstr "Passwort _behalten" + #: ../gtk/gtkprinteroptionwidget.c:725 msgid "Not available" msgstr "Nicht verfügbar" @@ -6086,3 +6130,389 @@ msgstr "" #~ msgid "X" #~ msgstr "X" + +#: gtk/gtkfileoperation.c +#, c-format +msgid "%s (copy)" +msgstr "%s (Kopie)" + +#: gtk/gtkfileoperation.c +#, c-format +msgid "%s (copy %d)" +msgstr "%s (Kopie %d)" + +#: gtk/gtkfileoperation.c +msgid "Preparing to copy…" +msgstr "Kopieren wird vorbereitet …" + +#: gtk/gtkfileoperation.c +msgid "Preparing to move…" +msgstr "Verschieben wird vorbereitet …" + +#: gtk/gtkfileoperation.c +#, c-format +msgid "Copying “%s”: %u of %u files, %s of %s" +msgstr "„%s“ wird kopiert: %u von %u Dateien, %s von %s" + +#: gtk/gtkfileoperation.c +#, c-format +msgid "Moving “%s”: %u of %u files, %s of %s" +msgstr "„%s“ wird verschoben: %u von %u Dateien, %s von %s" + +#: gtk/gtkfileoperation.c +#, c-format +msgid "A folder named “%s” already exists in “%s”." +msgstr "Ein Ordner namens „%s“ existiert bereits in „%s“." + +#: gtk/gtkfileoperation.c +#, c-format +msgid "A file named “%s” already exists in “%s”." +msgstr "Eine Datei namens „%s“ existiert bereits in „%s“." + +#: gtk/gtkfileoperation.c +msgid "Merging adds the contents to the folder there; files of the same name are asked for." +msgstr "Zusammenführen fügt den Inhalt zum vorhandenen Ordner hinzu; bei Dateien gleichen Namens wird nachgefragt." + +#: gtk/gtkfileoperation.c +msgid "Replacing it overwrites its contents." +msgstr "Ersetzen überschreibt ihren Inhalt." + +#: gtk/gtkfileoperation.c +msgid "It can be kept under another name." +msgstr "Sie kann unter einem anderen Namen behalten werden." + +#: gtk/gtkfileoperation.c +msgid "_New name:" +msgstr "_Neuer Name:" + +#: gtk/gtkfileoperation.c +msgid "Do this for _all further conflicts" +msgstr "Für _alle weiteren Konflikte so verfahren" + +#: gtk/gtkfileoperation.c +msgid "_Skip" +msgstr "Ü_berspringen" + +#: gtk/gtkfileoperation.c +msgid "Re_name" +msgstr "_Umbenennen" + +#: gtk/gtkfileoperation.c +msgid "_Merge" +msgstr "_Zusammenführen" + +#: gtk/gtkfileoperation.c +#, c-format +msgid "“%s” could not be copied." +msgstr "„%s“ konnte nicht kopiert werden." + +#: gtk/gtkfileoperation.c +#, c-format +msgid "“%s” could not be moved." +msgstr "„%s“ konnte nicht verschoben werden." + +#: gtk/gtkfileoperation.c +msgid "Skip _all further errors" +msgstr "_Alle weiteren Fehler überspringen" + +#: gtk/gtkfileoperation.c +msgid "A folder can not be copied or moved into itself." +msgstr "Ein Ordner kann nicht in sich selbst kopiert oder verschoben werden." + +#: gtk/gtkfilechooserdefault.c +msgid "Show T_ype Column" +msgstr "Spalte »_Typ« anzeigen" + +#: gtk/gtkfilechooserdefault.c +msgid "Type" +msgstr "Typ" + +#: gtk/gtkfilechooserdefault.c +msgid "Folder" +msgstr "Ordner" + +#: gtk/gtkfilechooserdefault.c +msgid "Program" +msgstr "Programm" + +#: gtk/gtkfilechooserdefault.c +msgid "Audio" +msgstr "Klänge" + +#: gtk/gtkfilechooserdefault.c +msgid "Image" +msgstr "Bild" + +#: gtk/gtkfilechooserdefault.c +msgid "Archive" +msgstr "Archiv" + +#: gtk/gtkfilechooserdefault.c +msgid "Markup" +msgstr "Markup" + +#: gtk/gtkfilechooserdefault.c +msgid "Text" +msgstr "Text" + +#: gtk/gtkfilechooserdefault.c +msgid "Video" +msgstr "Video" + +#: gtk/gtkfilechooserdefault.c +msgid "Contacts" +msgstr "Kontakte" + +#: gtk/gtkfilechooserdefault.c +msgid "Calendar" +msgstr "Kalender" + +#: gtk/gtkfilechooserdefault.c +msgid "Document" +msgstr "Dokument" + +#: gtk/gtkfilechooserdefault.c +msgid "Presentation" +msgstr "Präsentation" + +#: gtk/gtkfilechooserdefault.c +msgid "Spreadsheet" +msgstr "Tabellenkalkulation" + +#: gtk/gtkfilechooserdefault.c +msgid "Sort by _Type" +msgstr "Nach _Typ sortieren" + +#: gtk/gtkfilechooserdefault.c +msgid "Sort by _Name" +msgstr "Nach _Name sortieren" + +#: gtk/gtkfilechooserdefault.c +msgid "Sort by _Size" +msgstr "Nach _Größe sortieren" + +#: gtk/gtkfilechooserdefault.c +msgid "Sort by Modification _Date" +msgstr "Nach Än_derungsdatum sortieren" + +#: gtk/gtkfilechooserdefault.c +msgid "Back" +msgstr "Zurück" + +#: gtk/gtkfilechooserdefault.c +msgid "Forward" +msgstr "Vor" + +#: gtk/gtkfileoperation.c +msgid "_Undo Copy" +msgstr "Kopieren _rückgängig machen" + +#: gtk/gtkfileoperation.c +msgid "_Redo Copy" +msgstr "Kopieren _wiederholen" + +#: gtk/gtkfileoperation.c +msgid "_Undo Move" +msgstr "Verschieben _rückgängig machen" + +#: gtk/gtkfileoperation.c +msgid "_Redo Move" +msgstr "Verschieben _wiederholen" + +#: gtk/gtkfileoperation.c +msgid "_Undo Link" +msgstr "Verknüpfen _rückgängig machen" + +#: gtk/gtkfileoperation.c +msgid "_Redo Link" +msgstr "Verknüpfen _wiederholen" + +#: gtk/gtkfileoperation.c +msgid "_Undo Move to Trash" +msgstr "Papierkorb _rückgängig machen" + +#: gtk/gtkfileoperation.c +msgid "_Redo Move to Trash" +msgstr "Papierkorb _wiederholen" + +#: gtk/gtkfileoperation.c +msgid "_Undo Rename" +msgstr "Umbenennen _rückgängig machen" + +#: gtk/gtkfileoperation.c +msgid "_Redo Rename" +msgstr "Umbenennen _wiederholen" + +#: gtk/gtkfileoperation.c +msgid "_Undo Create Folder" +msgstr "Ordner anlegen _rückgängig machen" + +#: gtk/gtkfileoperation.c +msgid "_Redo Create Folder" +msgstr "Ordner anlegen _wiederholen" + +#: gtk/gtkfileoperation.c +msgid "Preparing…" +msgstr "Wird vorbereitet …" + +#: gtk/gtkfileoperation.c +#, c-format +msgid "Linking “%s”: %u of %u files" +msgstr "„%s“ wird verknüpft: %u von %u Dateien" + +#: gtk/gtkfileoperation.c +#, c-format +msgid "Moving “%s” to the Trash: %u of %u files" +msgstr "„%s“ wird in den Papierkorb verschoben: %u von %u Dateien" + +#: gtk/gtkfileoperation.c +#, c-format +msgid "Undoing: “%s”, %u of %u" +msgstr "Rückgängig: „%s“, %u von %u" + +#: gtk/gtkfileoperation.c +#, c-format +msgid "Redoing: “%s”, %u of %u" +msgstr "Wiederholen: „%s“, %u von %u" + +#: gtk/gtkfileoperation.c +#, c-format +msgid "No link to “%s” could be made." +msgstr "Zu „%s“ konnte keine Verknüpfung angelegt werden." + +#: gtk/gtkfileoperation.c +#, c-format +msgid "“%s” could not be moved to the Trash." +msgstr "„%s“ konnte nicht in den Papierkorb verschoben werden." + +#: gtk/gtkfileoperation.c +#, c-format +msgid "Undoing failed for “%s”." +msgstr "Rückgängig machen ist für „%s“ fehlgeschlagen." + +#: gtk/gtkfileoperation.c +#, c-format +msgid "Redoing failed for “%s”." +msgstr "Wiederholen ist für „%s“ fehlgeschlagen." + +#: gtk/gtkfileoperation.c +msgid "It is no longer in the Trash." +msgstr "Es ist nicht mehr im Papierkorb." + +#: gtk/gtkfileoperation.c +msgid "Links can only be made to local files." +msgstr "Verknüpfungen können nur zu lokalen Dateien angelegt werden." + +#: gtk/gtkfileoperation.c +#, c-format +msgid "The shell could not move the file to the Recycle Bin (error %d)" +msgstr "Die Shell konnte die Datei nicht in den Papierkorb verschieben (Fehler %d)" + +#: gtk/gtkfileoperation.c +msgid "_Undo" +msgstr "_Rückgängig" + +#: gtk/gtkfileoperation.c +msgid "_Redo" +msgstr "_Wiederholen" + +#: gtk/gtkfileoperation.c +msgid "The shell could not put the file back from the Recycle Bin" +msgstr "Die Shell konnte die Datei nicht aus dem Papierkorb zurücklegen" + +#: gtk/gtkfilechooserdefault.c +msgid "_Move Here" +msgstr "Hierher _verschieben" + +#: gtk/gtkfilechooserdefault.c +msgid "_Copy Here" +msgstr "Hierher _kopieren" + +#: gtk/gtkfilechooserdefault.c +msgid "_Link Here" +msgstr "Hierher ver_knüpfen" + +#: gtk/gtkfilechooserdefault.c +msgid "_Select" +msgstr "_Auswählen" + +#: gtk/gtkfilechooserdefault.c +msgid "Paste _Into Folder" +msgstr "In den Ordner _einfügen" + +#: gtk/gtkfilechooserdefault.c +msgid "The file could not be saved" +msgstr "Die Datei konnte nicht gespeichert werden" + +#: gtk/gtkfilechooserdefault.c +msgid "The program it came from could not write it there." +msgstr "Das Programm, aus dem sie kommt, konnte sie dort nicht schreiben." + +#: gtk/gtkfilechooserdefault.c +msgid "_Unmount" +msgstr "_Aushängen" + +#: gtk/gtkfilechooserdefault.c +msgid "_Eject" +msgstr "_Auswerfen" + +#: gtk/gtkfilechooserdefault.c +#, c-format +msgid "“%s” could not be ejected" +msgstr "„%s“ konnte nicht ausgeworfen werden" + +#: gtk/gtkfilechooserdefault.c +#, c-format +msgid "“%s” could not be unmounted" +msgstr "„%s“ konnte nicht ausgehängt werden" + +#: gtk/gtkfilechooserdefault.c +#, c-format +msgid "%s free of %s" +msgstr "%s von %s frei" + +#: gtk/gtkfileoperation.c +#, c-format +msgid "There is not enough space in “%s”." +msgstr "In „%s“ ist nicht genug Platz." + +#: gtk/gtkfileoperation.c +msgid "_Continue Anyway" +msgstr "_Trotzdem fortfahren" + +#: gtk/gtkfileoperation.c +#, c-format +msgid "%s are needed, %s are free. What fits can be copied anyway." +msgstr "%s werden gebraucht, %s sind frei. Was passt, kann trotzdem kopiert werden." + +#: gtk/gtkfilechooserdefault.c +msgid "Connect to Server" +msgstr "Mit Server verbinden" + +#: gtk/gtkfilechooserdefault.c +msgid "Connect to Server…" +msgstr "Mit Server verbinden …" + +#: gtk/gtkfilechooserdefault.c +msgid "Server _Address:" +msgstr "Server_adresse:" + +#: gtk/gtkfilechooserdefault.c +msgid "For example:" +msgstr "Zum Beispiel:" + +#: gtk/gtkfilechooserdefault.c +msgid "The server could not be opened" +msgstr "Der Server konnte nicht geöffnet werden" + +#: gtk/gtkfilechooserdefault.c +msgid "This program can only open local files, and the server has no local path here." +msgstr "Dieses Programm kann nur lokale Dateien öffnen, und der Server hat hier keinen lokalen Pfad." + +#: gtk/gtkfilechooserdefault.c +msgid "The server could not be connected" +msgstr "Mit dem Server konnte keine Verbindung hergestellt werden" + +#: gtk/gtkfilechooserdefault.c +msgid "C_onnect" +msgstr "_Verbinden" diff --git a/po/el.po b/po/el.po index 3b7bb0fda..28a4985de 100644 --- a/po/el.po +++ b/po/el.po @@ -1684,6 +1684,10 @@ msgstr "Ρίζα συστήματος αρχείων" msgid "Authentication" msgstr "Πιστοποίηση" +#: ../gtk/gtkprintbackend.c +msgid "_Remember password" +msgstr "Απο_μνημόνευση κωδικού" + #: ../gtk/gtkprinteroptionwidget.c:695 msgid "Not available" msgstr "Μη διαθέσιμο" diff --git a/po/en_GB.po b/po/en_GB.po index 954c675d4..6ae3d47b3 100644 --- a/po/en_GB.po +++ b/po/en_GB.po @@ -1669,6 +1669,10 @@ msgstr "File System Root" msgid "Authentication" msgstr "Authentication" +#: ../gtk/gtkprintbackend.c +msgid "_Remember password" +msgstr "_Remember password" + #: ../gtk/gtkprinteroptionwidget.c:694 msgid "Not available" msgstr "Not available" diff --git a/po/eo.po b/po/eo.po index dada2fd5e..3a8cd0823 100644 --- a/po/eo.po +++ b/po/eo.po @@ -2629,6 +2629,10 @@ msgstr "Dosiersistemo" msgid "Authentication" msgstr "Aplikaĵo" +#: ../gtk/gtkprintbackend.c +msgid "_Remember password" +msgstr "_Memori pasvorton" + #: gtk/gtkprinteroptionwidget.c:695 msgid "Not available" msgstr "Ne atingebla" diff --git a/po/es.po b/po/es.po index bac842aec..de45fd898 100644 --- a/po/es.po +++ b/po/es.po @@ -1699,6 +1699,10 @@ msgstr "Sistema de archivos raíz" msgid "Authentication" msgstr "Autenticación" +#: ../gtk/gtkprintbackend.c +msgid "_Remember password" +msgstr "_Recordar la contraseña" + #: ../gtk/gtkprinteroptionwidget.c:694 msgid "Not available" msgstr "No disponible" diff --git a/po/et.po b/po/et.po index f2a1c6f55..9d51751bb 100644 --- a/po/et.po +++ b/po/et.po @@ -1349,6 +1349,10 @@ msgstr "Failisüsteemi juurkataloog" msgid "Authentication" msgstr "Autentimine" +#: ../gtk/gtkprintbackend.c +msgid "_Remember password" +msgstr "_Jäta parool meelde" + msgid "Not available" msgstr "Pole saadaval" diff --git a/po/eu.po b/po/eu.po index 746623266..4effd3583 100644 --- a/po/eu.po +++ b/po/eu.po @@ -1304,6 +1304,10 @@ msgstr "Erroko fitxategi-sistema" msgid "Authentication" msgstr "Autentifikazioa" +#: ../gtk/gtkprintbackend.c +msgid "_Remember password" +msgstr "_Gogoratu pasahitza" + #: ../gtk/gtkprinteroptionwidget.c:695 msgid "Not available" msgstr "Ez dago erabilgarri" diff --git a/po/fa.po b/po/fa.po index cebdb0386..311e1028f 100644 --- a/po/fa.po +++ b/po/fa.po @@ -2659,6 +2659,10 @@ msgstr "سیستم پرونده‌ها" msgid "Authentication" msgstr "_مکان:" +#: ../gtk/gtkprintbackend.c +msgid "_Remember password" +msgstr "_به‌خاطرسپاری گذرواژه" + #: gtk/gtkprinteroptionwidget.c:695 msgid "Not available" msgstr "" diff --git a/po/fi.po b/po/fi.po index 8398c7b96..5ce038ebb 100644 --- a/po/fi.po +++ b/po/fi.po @@ -2572,6 +2572,10 @@ msgstr "Tiedostojärjestelmän juuri" msgid "Authentication" msgstr "Todennus" +#: ../gtk/gtkprintbackend.c +msgid "_Remember password" +msgstr "_Muista salasana" + #: gtk/gtkprinteroptionwidget.c:695 msgid "Not available" msgstr "Ei saatavilla" diff --git a/po/fr.po b/po/fr.po index b6cf9a904..af21566ff 100644 --- a/po/fr.po +++ b/po/fr.po @@ -1679,6 +1679,10 @@ msgstr "Racine du système de fichiers" msgid "Authentication" msgstr "Authentification" +#: ../gtk/gtkprintbackend.c +msgid "_Remember password" +msgstr "_Se souvenir du mot de passe" + #: ../gtk/gtkprinteroptionwidget.c:695 msgid "Not available" msgstr "Pas disponible" diff --git a/po/ga.po b/po/ga.po index f73e59e99..f0e06ab40 100644 --- a/po/ga.po +++ b/po/ga.po @@ -2572,6 +2572,10 @@ msgstr "Fréamh Chóras Comhaid" msgid "Authentication" msgstr "Fíordheimhniú" +#: ../gtk/gtkprintbackend.c +msgid "_Remember password" +msgstr "_Meabhraigh focal faire" + #: gtk/gtkprinteroptionwidget.c:695 msgid "Not available" msgstr "Níl ar fáil" diff --git a/po/gl.po b/po/gl.po index 95a4fbd05..7b20e08de 100644 --- a/po/gl.po +++ b/po/gl.po @@ -1682,6 +1682,10 @@ msgstr "Sistema de ficheiros raíz" msgid "Authentication" msgstr "Autenticación" +#: ../gtk/gtkprintbackend.c +msgid "_Remember password" +msgstr "_Lembrar o contrasinal" + #: ../gtk/gtkprinteroptionwidget.c:695 msgid "Not available" msgstr "Non dispoñíbel" diff --git a/po/gu.po b/po/gu.po index 1560a4a4f..1924be75d 100644 --- a/po/gu.po +++ b/po/gu.po @@ -1688,6 +1688,10 @@ msgstr "ફાઈલ સિસ્ટમ રુટ" msgid "Authentication" msgstr "સત્તાધિકરણ" +#: ../gtk/gtkprintbackend.c +msgid "_Remember password" +msgstr "પાસવર્ડ યાદ રાખો (_R)" + #: ../gtk/gtkprinteroptionwidget.c:695 msgid "Not available" msgstr "ઉપલબ્ધ નથી" diff --git a/po/he.po b/po/he.po index a39da3d85..9b2010e75 100644 --- a/po/he.po +++ b/po/he.po @@ -1678,6 +1678,10 @@ msgstr "שורש מערכת הקבצים" msgid "Authentication" msgstr "אימות" +#: ../gtk/gtkprintbackend.c +msgid "_Remember password" +msgstr "_שמירת הססמה" + #: ../gtk/gtkprinteroptionwidget.c:734 msgid "Not available" msgstr "לא זמין" diff --git a/po/hi.po b/po/hi.po index da918199e..88adca878 100644 --- a/po/hi.po +++ b/po/hi.po @@ -2582,6 +2582,10 @@ msgstr "फ़ाइल सिस्टम रूट" msgid "Authentication" msgstr "सत्यापन" +#: ../gtk/gtkprintbackend.c +msgid "_Remember password" +msgstr "पासवर्ड याद रखें (_R)" + #: gtk/gtkprinteroptionwidget.c:695 msgid "Not available" msgstr "उपलब्ध नहीं" diff --git a/po/hr.po b/po/hr.po index 0cc868b4f..59d145579 100644 --- a/po/hr.po +++ b/po/hr.po @@ -2668,6 +2668,10 @@ msgstr "Datotečni sustav" msgid "Authentication" msgstr "_Mjesto:" +#: ../gtk/gtkprintbackend.c +msgid "_Remember password" +msgstr "_Zapamti lozinku" + #: gtk/gtkprinteroptionwidget.c:695 msgid "Not available" msgstr "" diff --git a/po/hu.po b/po/hu.po index 25b7879d8..01f115df0 100644 --- a/po/hu.po +++ b/po/hu.po @@ -1686,6 +1686,10 @@ msgstr "Fájlrendszer gyökere" msgid "Authentication" msgstr "Hitelesítés" +#: ../gtk/gtkprintbackend.c +msgid "_Remember password" +msgstr "_Jelszó megjegyzése" + #: ../gtk/gtkprinteroptionwidget.c:734 msgid "Not available" msgstr "Nem érhető el" diff --git a/po/id.po b/po/id.po index e6a4771c8..5f15b308d 100644 --- a/po/id.po +++ b/po/id.po @@ -1615,6 +1615,10 @@ msgstr "Akar Sistem Berkas" msgid "Authentication" msgstr "Otentikasi" +#: ../gtk/gtkprintbackend.c +msgid "_Remember password" +msgstr "Ingat _sandi" + #: ../gtk/gtkprinteroptionwidget.c:734 msgid "Not available" msgstr "Tidak tersedia" diff --git a/po/is.po b/po/is.po index a96baac68..5e8ee5b5f 100644 --- a/po/is.po +++ b/po/is.po @@ -2687,6 +2687,10 @@ msgstr "Skráarkerfi" msgid "Authentication" msgstr "S_taðsetning:" +#: ../gtk/gtkprintbackend.c +msgid "_Remember password" +msgstr "_Muna lykilorð" + #: gtk/gtkprinteroptionwidget.c:695 msgid "Not available" msgstr "" diff --git a/po/it.po b/po/it.po index c45403430..b2f0e0563 100644 --- a/po/it.po +++ b/po/it.po @@ -1730,6 +1730,10 @@ msgstr "Radice del file system" msgid "Authentication" msgstr "Autenticazione" +#: ../gtk/gtkprintbackend.c +msgid "_Remember password" +msgstr "_Ricorda password" + #: ../gtk/gtkprinteroptionwidget.c:694 msgid "Not available" msgstr "Non disponibile" diff --git a/po/ja.po b/po/ja.po index a0e2797d7..a6108a356 100644 --- a/po/ja.po +++ b/po/ja.po @@ -1680,6 +1680,10 @@ msgstr "ファイル・システムのルート" msgid "Authentication" msgstr "認証" +#: ../gtk/gtkprintbackend.c +msgid "_Remember password" +msgstr "パスワードを記憶する(_R)" + #: ../gtk/gtkprinteroptionwidget.c:734 msgid "Not available" msgstr "利用できません" diff --git a/po/ka.po b/po/ka.po index 2f08f124e..1cdeb6c47 100644 --- a/po/ka.po +++ b/po/ka.po @@ -2599,6 +2599,10 @@ msgstr "ფაილური სისტემის ფუძე" msgid "Authentication" msgstr "პროგრამა" +#: ../gtk/gtkprintbackend.c +msgid "_Remember password" +msgstr "პაროლის დამახსოვრება" + #: gtk/gtkprinteroptionwidget.c:695 msgid "Not available" msgstr "მიუწვდომელია" diff --git a/po/kk.po b/po/kk.po index 615290ee0..cfd4c6810 100644 --- a/po/kk.po +++ b/po/kk.po @@ -1648,6 +1648,10 @@ msgstr "Файлдық жүйенің түбірі" msgid "Authentication" msgstr "Аутентификация" +#: ../gtk/gtkprintbackend.c +msgid "_Remember password" +msgstr "Парольді ес_те сақтау" + #: ../gtk/gtkprinteroptionwidget.c:695 msgid "Not available" msgstr "Қол жетерлік емес" diff --git a/po/kn.po b/po/kn.po index 867091f83..73cbec190 100644 --- a/po/kn.po +++ b/po/kn.po @@ -2572,6 +2572,10 @@ msgstr "ಕಡತ ವ್ಯವಸ್ಥೆ ಮೂಲ" msgid "Authentication" msgstr "ದೃಢೀಕರಣ" +#: ../gtk/gtkprintbackend.c +msgid "_Remember password" +msgstr "ಗುಪ್ತಪದವನ್ನು ನೆನಪಿನಲ್ಲಿಡು (_R)" + #: gtk/gtkprinteroptionwidget.c:695 msgid "Not available" msgstr "ಲಭ್ಯವಿರುವುದಿಲ್ಲ" diff --git a/po/ko.po b/po/ko.po index 730367d6a..e354fca2b 100644 --- a/po/ko.po +++ b/po/ko.po @@ -1682,6 +1682,10 @@ msgstr "파일 시스템 루트" msgid "Authentication" msgstr "인증" +#: ../gtk/gtkprintbackend.c +msgid "_Remember password" +msgstr "암호 저장(_R)" + #: ../gtk/gtkprinteroptionwidget.c:695 msgid "Not available" msgstr "없음" diff --git a/po/lt.po b/po/lt.po index dd732ef67..4e2ef56c3 100644 --- a/po/lt.po +++ b/po/lt.po @@ -2570,6 +2570,10 @@ msgstr "Failų sistemos šakninis aplankas" msgid "Authentication" msgstr "Tapatybės patvirtinimas" +#: ../gtk/gtkprintbackend.c +msgid "_Remember password" +msgstr "Į_siminti slaptažodį" + #: gtk/gtkprinteroptionwidget.c:695 msgid "Not available" msgstr "Neprieinama" diff --git a/po/lv.po b/po/lv.po index 6df51f848..2d3980714 100644 --- a/po/lv.po +++ b/po/lv.po @@ -2559,6 +2559,10 @@ msgstr "Failu sistēmas sakne" msgid "Authentication" msgstr "Autentificēšana" +#: ../gtk/gtkprintbackend.c +msgid "_Remember password" +msgstr "Atce_rēties paroli" + #: gtk/gtkprinteroptionwidget.c:695 msgid "Not available" msgstr "Nav pieejams" diff --git a/po/mr.po b/po/mr.po index 912d09741..6f3e70c43 100644 --- a/po/mr.po +++ b/po/mr.po @@ -2546,6 +2546,10 @@ msgstr "फाइल प्रणाली रूट" msgid "Authentication" msgstr "ऑथेंटीकेशन" +#: ../gtk/gtkprintbackend.c +msgid "_Remember password" +msgstr "पासवर्ड लक्षात ठेवा (_R)" + #: gtk/gtkprinteroptionwidget.c:695 msgid "Not available" msgstr "उपलब्ध नाही" diff --git a/po/ms.po b/po/ms.po index 3404d0cc4..7cb3667e0 100644 --- a/po/ms.po +++ b/po/ms.po @@ -2695,6 +2695,10 @@ msgstr "Sistemfail" msgid "Authentication" msgstr "_Lokasi:" +#: ../gtk/gtkprintbackend.c +msgid "_Remember password" +msgstr "_Ingat kata laluan" + #: gtk/gtkprinteroptionwidget.c:695 msgid "Not available" msgstr "" diff --git a/po/nb.po b/po/nb.po index 4fda6ad23..8155b64c2 100644 --- a/po/nb.po +++ b/po/nb.po @@ -1671,6 +1671,10 @@ msgstr "Filsystemrot" msgid "Authentication" msgstr "Autentisering" +#: ../gtk/gtkprintbackend.c +msgid "_Remember password" +msgstr "Husk passo_rd" + #: ../gtk/gtkprinteroptionwidget.c:725 msgid "Not available" msgstr "Ikke tilgjengelig" diff --git a/po/ne.po b/po/ne.po index b6bf25844..d031f43e8 100644 --- a/po/ne.po +++ b/po/ne.po @@ -2632,6 +2632,10 @@ msgstr "फाइल प्रणाली" msgid "Authentication" msgstr "" +#: ../gtk/gtkprintbackend.c +msgid "_Remember password" +msgstr "पासवर्ड सम्झनुहोस्" + #: gtk/gtkprinteroptionwidget.c:695 msgid "Not available" msgstr "" diff --git a/po/nl.po b/po/nl.po index 194f8dadb..5c463cc7d 100644 --- a/po/nl.po +++ b/po/nl.po @@ -1761,6 +1761,10 @@ msgstr "Hoofdmap bestandssysteem" msgid "Authentication" msgstr "Aanmeldingscontrole" +#: ../gtk/gtkprintbackend.c +msgid "_Remember password" +msgstr "Wachtwoord o_nthouden" + # niet aanwezig/beschikbaar #: ../gtk/gtkprinteroptionwidget.c:694 msgid "Not available" diff --git a/po/pa.po b/po/pa.po index 9aebc6f35..60868d312 100644 --- a/po/pa.po +++ b/po/pa.po @@ -2540,6 +2540,10 @@ msgstr "ਫਾਇਲ ਸਿਸਟਮ ਰੂਟ" msgid "Authentication" msgstr "ਪਰਮਾਣਕਿਤਾ" +#: ../gtk/gtkprintbackend.c +msgid "_Remember password" +msgstr "ਪਾਸਵਰਡ ਯਾਦ ਰੱਖੋ(_R)" + #: gtk/gtkprinteroptionwidget.c:695 msgid "Not available" msgstr "ਉਪਲੱਬਧ ਨਹੀਂ" diff --git a/po/pl.po b/po/pl.po index 4820e0319..69c40d031 100644 --- a/po/pl.po +++ b/po/pl.po @@ -1625,6 +1625,10 @@ msgstr "System plików" msgid "Authentication" msgstr "Uwierzytelnianie" +#: ../gtk/gtkprintbackend.c +msgid "_Remember password" +msgstr "_Zapamiętanie hasła" + #: ../gtk/gtkprinteroptionwidget.c:734 msgid "Not available" msgstr "Niedostępne" diff --git a/po/pt.po b/po/pt.po index 4566207e1..2d96e33a1 100644 --- a/po/pt.po +++ b/po/pt.po @@ -1662,6 +1662,10 @@ msgstr "Raiz do Sistema de Ficheiros" msgid "Authentication" msgstr "Autenticação" +#: ../gtk/gtkprintbackend.c +msgid "_Remember password" +msgstr "_Recordar a palavra-passe" + #: ../gtk/gtkprinteroptionwidget.c:695 msgid "Not available" msgstr "Indisponível" diff --git a/po/pt_BR.po b/po/pt_BR.po index 965dbb3ce..a53a7fdf2 100644 --- a/po/pt_BR.po +++ b/po/pt_BR.po @@ -1684,6 +1684,10 @@ msgstr "Raiz do sistema de arquivos" msgid "Authentication" msgstr "Autenticação" +#: ../gtk/gtkprintbackend.c +msgid "_Remember password" +msgstr "Lemb_rar senha" + #: ../gtk/gtkprinteroptionwidget.c:695 msgid "Not available" msgstr "Não disponível" diff --git a/po/ro.po b/po/ro.po index 47c3204dc..372fce212 100644 --- a/po/ro.po +++ b/po/ro.po @@ -1680,6 +1680,10 @@ msgstr "Rădăcina sistemului de fișiere" msgid "Authentication" msgstr "Autentificare" +#: ../gtk/gtkprintbackend.c +msgid "_Remember password" +msgstr "Ține minte pa_rola" + #: ../gtk/gtkprinteroptionwidget.c:725 msgid "Not available" msgstr "Indisponibil" diff --git a/po/ru.po b/po/ru.po index 00a57f477..5b937162a 100644 --- a/po/ru.po +++ b/po/ru.po @@ -2597,6 +2597,10 @@ msgstr "Корень файловой системы" msgid "Authentication" msgstr "Проверка доступа" +#: ../gtk/gtkprintbackend.c +msgid "_Remember password" +msgstr "_Запомнить пароль" + #: gtk/gtkprinteroptionwidget.c:695 msgid "Not available" msgstr "Недоступно" diff --git a/po/sk.po b/po/sk.po index 52e9a7b7b..4ba69d9f8 100644 --- a/po/sk.po +++ b/po/sk.po @@ -2566,6 +2566,10 @@ msgstr "Koreň súborového systému" msgid "Authentication" msgstr "Overenie totožnosti" +#: ../gtk/gtkprintbackend.c +msgid "_Remember password" +msgstr "_Zapamätať heslo" + #: gtk/gtkprinteroptionwidget.c:695 msgid "Not available" msgstr "Nie je k dispozícií" diff --git a/po/sl.po b/po/sl.po index 5f95aa91d..c56644594 100644 --- a/po/sl.po +++ b/po/sl.po @@ -1656,6 +1656,10 @@ msgstr "Koren datotečnega sistema" msgid "Authentication" msgstr "Overitev" +#: ../gtk/gtkprintbackend.c +msgid "_Remember password" +msgstr "Zapomni si _geslo" + #: ../gtk/gtkprinteroptionwidget.c:695 msgid "Not available" msgstr "Ni na voljo" diff --git a/po/sr.po b/po/sr.po index 9c010f33f..2438d1cfb 100644 --- a/po/sr.po +++ b/po/sr.po @@ -2595,6 +2595,10 @@ msgstr "Корен система датотека" msgid "Authentication" msgstr "Пријава" +#: ../gtk/gtkprintbackend.c +msgid "_Remember password" +msgstr "_Запамти лозинку" + #: gtk/gtkprinteroptionwidget.c:695 msgid "Not available" msgstr "Није доступно" diff --git a/po/sr@latin.po b/po/sr@latin.po index 6230b7f60..3e2f82eb4 100644 --- a/po/sr@latin.po +++ b/po/sr@latin.po @@ -2599,6 +2599,10 @@ msgstr "Koren sistema datoteka" msgid "Authentication" msgstr "Prijava" +#: ../gtk/gtkprintbackend.c +msgid "_Remember password" +msgstr "_Zapamti lozinku" + #: gtk/gtkprinteroptionwidget.c:695 msgid "Not available" msgstr "Nije dostupno" diff --git a/po/sv.po b/po/sv.po index 0ee9f8117..bb899020a 100644 --- a/po/sv.po +++ b/po/sv.po @@ -1653,6 +1653,10 @@ msgstr "Filsystemsrot" msgid "Authentication" msgstr "Autentisering" +#: ../gtk/gtkprintbackend.c +msgid "_Remember password" +msgstr "Kom ihåg löseno_rdet" + #: ../gtk/gtkprinteroptionwidget.c:695 msgid "Not available" msgstr "Inte tillgänglig" diff --git a/po/ta.po b/po/ta.po index 3190944e0..2e5e811ae 100644 --- a/po/ta.po +++ b/po/ta.po @@ -2566,6 +2566,10 @@ msgstr "கோப்பு அமைப்பு மூலம்" msgid "Authentication" msgstr "அங்கீகாரம்" +#: ../gtk/gtkprintbackend.c +msgid "_Remember password" +msgstr "கடவுச்சொல்லை நினைவில் கொள் (_R)" + #: gtk/gtkprinteroptionwidget.c:695 msgid "Not available" msgstr "இல்லை" diff --git a/po/te.po b/po/te.po index c5ccd50bf..e3e76f021 100644 --- a/po/te.po +++ b/po/te.po @@ -2551,6 +2551,10 @@ msgstr "దస్త్ర వ్యవస్థ రూట్" msgid "Authentication" msgstr "దృవీకరణము" +#: ../gtk/gtkprintbackend.c +msgid "_Remember password" +msgstr "రహస్యపదాన్ని గుర్తించుము(_R)" + #: gtk/gtkprinteroptionwidget.c:695 msgid "Not available" msgstr "అందుబాటులో లేదు" diff --git a/po/th.po b/po/th.po index 7dbbf2716..c53b539e6 100644 --- a/po/th.po +++ b/po/th.po @@ -1654,6 +1654,10 @@ msgstr "รากของระบบแฟ้ม" msgid "Authentication" msgstr "การยืนยันตัวบุคคล" +#: ../gtk/gtkprintbackend.c +msgid "_Remember password" +msgstr "_จำรหัสผ่าน" + #: ../gtk/gtkprinteroptionwidget.c:734 msgid "Not available" msgstr "ไม่มี" diff --git a/po/tr.po b/po/tr.po index fe83a4f35..23d6a460e 100644 --- a/po/tr.po +++ b/po/tr.po @@ -2861,6 +2861,10 @@ msgstr "Dosya Sistemi Kökü" msgid "Authentication" msgstr "Uygulama" +#: ../gtk/gtkprintbackend.c +msgid "_Remember password" +msgstr "Parolayı _anımsa" + #: gtk/gtkprinteroptionwidget.c:695 msgid "Not available" msgstr "Kullanılamaz" diff --git a/po/ug.po b/po/ug.po index 84736323f..5ea7c54b6 100644 --- a/po/ug.po +++ b/po/ug.po @@ -1653,6 +1653,10 @@ msgstr "ھۆججەت سىستېما غولى" msgid "Authentication" msgstr "سالاھىيەت دەلىللەش" +#: ../gtk/gtkprintbackend.c +msgid "_Remember password" +msgstr "ئىمنى ئەستە تۇت(_R)" + #: ../gtk/gtkprinteroptionwidget.c:695 msgid "Not available" msgstr "ئىشلەتكىلى بولمايدۇ" diff --git a/po/uk.po b/po/uk.po index 9132f4934..68cfda60a 100644 --- a/po/uk.po +++ b/po/uk.po @@ -2576,6 +2576,10 @@ msgstr "Корінь файлової системи" msgid "Authentication" msgstr "Автентифікація" +#: ../gtk/gtkprintbackend.c +msgid "_Remember password" +msgstr "_Запам'ятати пароль" + #: gtk/gtkprinteroptionwidget.c:695 msgid "Not available" msgstr "Недоступно" diff --git a/po/vi.po b/po/vi.po index 3b1599e83..92c300dc3 100644 --- a/po/vi.po +++ b/po/vi.po @@ -2559,6 +2559,10 @@ msgstr "Gốc hệ tập tin" msgid "Authentication" msgstr "Xác thực" +#: ../gtk/gtkprintbackend.c +msgid "_Remember password" +msgstr "_Nhớ mật khẩu" + #: gtk/gtkprinteroptionwidget.c:695 msgid "Not available" msgstr "Không sẵn sàng" diff --git a/po/zh_CN.po b/po/zh_CN.po index 89751ee94..d713d4851 100644 --- a/po/zh_CN.po +++ b/po/zh_CN.po @@ -1664,6 +1664,10 @@ msgstr "根文件系统" msgid "Authentication" msgstr "认证" +#: ../gtk/gtkprintbackend.c +msgid "_Remember password" +msgstr "记住密码(_R)" + #: ../gtk/gtkprinteroptionwidget.c:725 msgid "Not available" msgstr "不可用" diff --git a/po/zh_HK.po b/po/zh_HK.po index 57990598b..e0669e0c0 100644 --- a/po/zh_HK.po +++ b/po/zh_HK.po @@ -1638,6 +1638,10 @@ msgstr "檔案系統根" msgid "Authentication" msgstr "驗證" +#: ../gtk/gtkprintbackend.c +msgid "_Remember password" +msgstr "記住密碼(_R)" + #: ../gtk/gtkprinteroptionwidget.c:695 msgid "Not available" msgstr "不存在" diff --git a/po/zh_TW.po b/po/zh_TW.po index a0dcead1e..b63d80ae9 100644 --- a/po/zh_TW.po +++ b/po/zh_TW.po @@ -1642,6 +1642,10 @@ msgstr "檔案系統根" msgid "Authentication" msgstr "驗證" +#: ../gtk/gtkprintbackend.c +msgid "_Remember password" +msgstr "記住密碼(_R)" + #: ../gtk/gtkprinteroptionwidget.c:695 msgid "Not available" msgstr "不存在" diff --git a/tests/gtkoffscreenbox.h b/tests/gtkoffscreenbox.h index aa1d15d77..18c662915 100644 --- a/tests/gtkoffscreenbox.h +++ b/tests/gtkoffscreenbox.h @@ -36,7 +36,7 @@ struct _GtkOffscreenBoxClass GtkBinClass parent_class; }; -GType gtk_offscreen_box_get_type (void) G_GNUC_CONST; +GType gtk_offscreen_box_get_type (void); GtkWidget* gtk_offscreen_box_new (void); void gtk_offscreen_box_add1 (GtkOffscreenBox *offscreen, GtkWidget *child);