File indexing completed on 2024-03-24 05:49:53
0001 /***************************************************************************** 0002 * Copyright 2003 - 2011 Craig Drummond <craig.p.drummond@gmail.com> * 0003 * Copyright 2013 - 2015 Yichao Yu <yyc1992@gmail.com> * 0004 * * 0005 * This program is free software; you can redistribute it and/or modify * 0006 * it under the terms of the GNU Lesser General Public License as * 0007 * published by the Free Software Foundation; either version 2.1 of the * 0008 * License, or (at your option) version 3, or any later version accepted * 0009 * by the membership of KDE e.V. (or its successor approved by the * 0010 * membership of KDE e.V.), which shall act as a proxy defined in * 0011 * Section 6 of version 3 of the license. * 0012 * * 0013 * This program is distributed in the hope that it will be useful, * 0014 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 0016 * Lesser General Public License for more details. * 0017 * * 0018 * You should have received a copy of the GNU Lesser General Public * 0019 * License along with this library. If not, * 0020 * see <http://www.gnu.org/licenses/>. * 0021 *****************************************************************************/ 0022 0023 #include "shadowhelper.h" 0024 0025 #include <gdk/gdkx.h> 0026 #include <common/common.h> 0027 #include "qt_settings.h" 0028 #include <qtcurve-utils/x11shadow.h> 0029 #include <qtcurve-utils/gtkprops.h> 0030 0031 namespace QtCurve { 0032 namespace Shadow { 0033 0034 static unsigned realizeSignalId = 0; 0035 static unsigned long realizeHookId = 0; 0036 0037 static void 0038 installX11Shadows(GtkWidget* widget) 0039 { 0040 if (qtSettings.debug == DEBUG_ALL) 0041 printf(DEBUG_PREFIX "%s\n", __FUNCTION__); 0042 GdkWindow *window = gtk_widget_get_window(widget); 0043 qtcX11ShadowInstall(GDK_WINDOW_XID(window)); 0044 } 0045 0046 static bool 0047 acceptWidget(GtkWidget* widget) 0048 { 0049 if (qtSettings.debug == DEBUG_ALL) 0050 printf(DEBUG_PREFIX "%s %p\n", __FUNCTION__, widget); 0051 0052 if (widget && GTK_IS_WINDOW(widget)) { 0053 if (qtSettings.app == GTK_APP_OPEN_OFFICE) { 0054 return true; 0055 } else { 0056 GdkWindowTypeHint hint = 0057 gtk_window_get_type_hint(GTK_WINDOW(widget)); 0058 if (qtSettings.debug == DEBUG_ALL) 0059 printf(DEBUG_PREFIX "%s %d\n", __FUNCTION__, (int)hint); 0060 return (hint == GDK_WINDOW_TYPE_HINT_MENU || 0061 hint == GDK_WINDOW_TYPE_HINT_DROPDOWN_MENU || 0062 hint == GDK_WINDOW_TYPE_HINT_POPUP_MENU || 0063 hint == GDK_WINDOW_TYPE_HINT_COMBO || 0064 hint == GDK_WINDOW_TYPE_HINT_TOOLTIP /* || */ 0065 /* (hint == GDK_WINDOW_TYPE_HINT_UTILITY && */ 0066 /* !qtcWidgetGetParent(widget) && isMozilla()) */ 0067 /* // Firefox URL combo */); 0068 } 0069 } 0070 return false; 0071 } 0072 0073 static gboolean 0074 destroy(GtkWidget *widget, void*) 0075 { 0076 if (qtSettings.debug == DEBUG_ALL) 0077 printf(DEBUG_PREFIX "%s %p\n", __FUNCTION__, widget); 0078 0079 GtkWidgetProps props(widget); 0080 if (props->shadowSet) { 0081 props->shadowDestroy.disconn(); 0082 props->shadowSet = false; 0083 } 0084 return false; 0085 } 0086 0087 static bool 0088 registerWidget(GtkWidget* widget) 0089 { 0090 if (qtSettings.debug == DEBUG_ALL) 0091 printf(DEBUG_PREFIX "%s %p\n", __FUNCTION__, widget); 0092 // check widget 0093 if (!(widget && GTK_IS_WINDOW(widget))) 0094 return false; 0095 0096 GtkWidgetProps props(widget); 0097 // make sure that widget is not already registered 0098 if (props->shadowSet) 0099 return false; 0100 0101 // check if window is accepted 0102 if (!acceptWidget(widget)) 0103 return false; 0104 0105 // try install shadows 0106 installX11Shadows(widget); 0107 0108 props->shadowSet = true; 0109 props->shadowDestroy.conn("destroy", destroy); 0110 return true; 0111 } 0112 0113 static gboolean 0114 realizeHook(GSignalInvocationHint*, unsigned, const GValue *params, void*) 0115 { 0116 GtkWidget *widget = GTK_WIDGET(g_value_get_object(params)); 0117 0118 if (qtSettings.debug == DEBUG_ALL) 0119 printf(DEBUG_PREFIX "%s %p\n", __FUNCTION__, widget); 0120 0121 if (!GTK_IS_WIDGET(widget)) 0122 return false; 0123 registerWidget(widget); 0124 return true; 0125 } 0126 0127 void initialize() 0128 { 0129 if (qtSettings.debug == DEBUG_ALL) 0130 printf(DEBUG_PREFIX "%s %d\n", __FUNCTION__, qtSettings.app); 0131 if (!realizeSignalId) { 0132 realizeSignalId = g_signal_lookup("realize", GTK_TYPE_WIDGET); 0133 if (realizeSignalId) { 0134 realizeHookId = g_signal_add_emission_hook( 0135 realizeSignalId, (GQuark)0, realizeHook, 0136 0, nullptr); 0137 } 0138 } 0139 } 0140 0141 } 0142 }