summaryrefslogtreecommitdiff
path: root/mate-dictionary/src/gdict-applet.c
diff options
context:
space:
mode:
Diffstat (limited to 'mate-dictionary/src/gdict-applet.c')
-rw-r--r--mate-dictionary/src/gdict-applet.c107
1 files changed, 84 insertions, 23 deletions
diff --git a/mate-dictionary/src/gdict-applet.c b/mate-dictionary/src/gdict-applet.c
index 47da6d31..b635456a 100644
--- a/mate-dictionary/src/gdict-applet.c
+++ b/mate-dictionary/src/gdict-applet.c
@@ -1,24 +1,24 @@
-/* gdict-applet.c - MATE Dictionary Applet
+/* Copyright (C) 2005 Emmanuele Bassi <[email protected]>
+ * Copyright (C) 2012-2021 MATE Developers
*
- * Copyright (c) 2005 Emmanuele Bassi <[email protected]>
+ * This file is part of MATE Utils.
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
+ * MATE Utils is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
*
- * This program is distributed in the hope that it will be useful,
+ * MATE Utils 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ * along with MATE Utils. If not, see <https://www.gnu.org/licenses/>.
*/
#ifdef HAVE_CONFIG_H
-#include "config.h"
+#include <config.h>
#endif
#include <stdio.h>
@@ -38,6 +38,11 @@
#include "gdict-common.h"
#include "gdict-aligned-window.h"
+#if defined (ENABLE_WAYLAND) && defined (GDK_WINDOWING_WAYLAND)
+#include <gdk/gdkwayland.h>
+#include <gtk-layer-shell/gtk-layer-shell.h>
+#endif
+
#define GDICT_APPLET_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GDICT_TYPE_APPLET, GdictAppletClass))
#define GDICT_APPLET_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GDICT_TYPE_APPLET, GdictAppletClass))
@@ -95,7 +100,6 @@ struct _GdictAppletPrivate
G_DEFINE_TYPE_WITH_PRIVATE (GdictApplet, gdict_applet, PANEL_TYPE_APPLET);
-
static void
set_atk_name_description (GtkWidget *widget,
const char *name,
@@ -133,7 +137,17 @@ set_window_default_size (GdictApplet *applet)
font_size = pango_font_description_get_size (gtk_widget_get_style (defbox)->font_desc);
font_size = PANGO_PIXELS (font_size);
- width = font_size * WINDOW_NUM_COLUMNS;
+#if defined (ENABLE_WAYLAND) && defined (GDK_WINDOWING_WAYLAND)
+ display = gtk_widget_get_display (widget);
+ if (GDK_IS_WAYLAND_DISPLAY (display))
+ width = font_size * WINDOW_NUM_COLUMNS - 100;
+
+ else
+#endif
+ {
+ width = font_size * WINDOW_NUM_COLUMNS;
+ }
+
height = font_size * WINDOW_NUM_ROWS;
/* Use at least the requisition size of the window... */
@@ -142,7 +156,6 @@ set_window_default_size (GdictApplet *applet)
height = MAX (height, req.height);
/* ... but make it no larger than half the monitor size */
- display = gtk_widget_get_display (widget);
monitor_num = gdk_display_get_monitor_at_window (display,
gtk_widget_get_window (widget));
gdk_monitor_get_geometry (monitor_num, &monitor);
@@ -315,6 +328,15 @@ gdict_applet_build_window (GdictApplet *applet)
G_CALLBACK (window_show_cb),
applet);
+#if defined (ENABLE_WAYLAND) && defined (GDK_WINDOWING_WAYLAND)
+ GdkDisplay *display = gdk_screen_get_display (gdk_screen_get_default());
+ if ((GDK_IS_WAYLAND_DISPLAY (display)) && (!gtk_layer_is_layer_window (GTK_WINDOW (window))))
+ {
+ gtk_layer_init_for_window (GTK_WINDOW (window));
+ gtk_layer_set_layer (GTK_WINDOW (window), GTK_LAYER_SHELL_LAYER_TOP);
+ gtk_layer_set_keyboard_mode (GTK_WINDOW (window), GTK_LAYER_SHELL_KEYBOARD_MODE_ON_DEMAND);
+ }
+#endif
frame = gtk_frame_new (NULL);
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
gtk_container_add (GTK_CONTAINER (window), frame);
@@ -338,6 +360,14 @@ gdict_applet_build_window (GdictApplet *applet)
bbox = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL);
gtk_button_box_set_layout (GTK_BUTTON_BOX (bbox), GTK_BUTTONBOX_END);
gtk_box_set_spacing (GTK_BOX (bbox), 6);
+
+#if defined (ENABLE_WAYLAND) && defined (GDK_WINDOWING_WAYLAND)
+ if (GDK_IS_WAYLAND_DISPLAY (display))
+ {
+ gtk_box_pack_start (GTK_BOX (bbox), priv->entry, TRUE, TRUE, 0);
+ gtk_button_box_set_child_non_homogeneous(GTK_BUTTON_BOX (bbox), priv->entry, TRUE);
+ }
+#endif
gtk_box_pack_end (GTK_BOX (vbox), bbox, FALSE, FALSE, 0);
gtk_widget_show (bbox);
@@ -386,6 +416,11 @@ gdict_applet_build_window (GdictApplet *applet)
gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, FALSE, 0);
gtk_widget_show (button);
+#if defined (ENABLE_WAYLAND) && defined (GDK_WINDOWING_WAYLAND)
+ if (GDK_IS_WAYLAND_DISPLAY (display))
+ gtk_widget_show (priv->entry);
+#endif
+
gtk_window_set_default (GTK_WINDOW (window), priv->defbox);
priv->window = window;
@@ -483,6 +518,11 @@ gdict_applet_icon_button_press_event_cb (GtkWidget *widget,
if (event->button != 1)
g_signal_stop_emission_by_name (priv->toggle, "button-press-event");
+#if defined (ENABLE_WAYLAND) && defined (GDK_WINDOWING_WAYLAND)
+ GdkDisplay *display = gdk_screen_get_display (gdk_screen_get_default());
+ if ((GDK_IS_WAYLAND_DISPLAY (display)) && (GTK_IS_WIDGET (priv->window)) && (event->button == 1))
+ gtk_widget_show_all (GTK_WIDGET (priv->window));
+#endif
return FALSE;
}
@@ -571,13 +611,23 @@ gdict_applet_draw (GdictApplet *applet)
/* entry */
priv->entry = gtk_entry_new ();
+#if defined (ENABLE_WAYLAND) && defined (GDK_WINDOWING_WAYLAND)
+ GdkDisplay *display = gdk_screen_get_display (gdk_screen_get_default());
+ if (GDK_IS_WAYLAND_DISPLAY (display))
+ {
+ gtk_entry_set_icon_from_icon_name (GTK_ENTRY(priv->entry), GTK_ENTRY_ICON_PRIMARY, "gtk-edit");
+ gtk_entry_set_icon_activatable (GTK_ENTRY(priv->entry), GTK_ENTRY_ICON_PRIMARY, FALSE);
+ /*Fill the available space since we must move the entry to the popup window for wayland*/
+ }
+#endif
+ gtk_entry_set_width_chars (GTK_ENTRY (priv->entry), 12);
+
gtk_widget_set_tooltip_text (priv->entry, _("Type the word you want to look up"));
set_atk_name_description (priv->entry,
_("Dictionary entry"),
_("Look up words in dictionaries"));
gtk_editable_set_editable (GTK_EDITABLE (priv->entry), TRUE);
- gtk_entry_set_width_chars (GTK_ENTRY (priv->entry), 12);
g_signal_connect (priv->entry, "activate",
G_CALLBACK (gdict_applet_entry_activate_cb),
applet);
@@ -587,8 +637,19 @@ gdict_applet_draw (GdictApplet *applet)
g_signal_connect (priv->entry, "key-press-event",
G_CALLBACK (gdict_applet_entry_key_press_cb),
applet);
+
+#if defined (ENABLE_WAYLAND) && defined (GDK_WINDOWING_WAYLAND)
+ if (GDK_IS_WAYLAND_DISPLAY (display))
+ {
+ GtkStyleContext *context = gtk_widget_get_style_context (priv->entry);
+ gtk_style_context_add_class (context, "view");
+ }
+ else
+#endif
+ {
gtk_box_pack_end (GTK_BOX (box), priv->entry, FALSE, FALSE, 0);
gtk_widget_show (priv->entry);
+ }
if (text)
{
@@ -1184,7 +1245,6 @@ gdict_applet_factory (MatePanelApplet *applet,
gpointer data)
{
gboolean retval = FALSE;
- gchar *ui_path;
GdictApplet *dictionary_applet = GDICT_APPLET (applet);
GdictAppletPrivate *priv = dictionary_applet->priv;
@@ -1192,16 +1252,17 @@ gdict_applet_factory (MatePanelApplet *applet,
{
/* Set up the menu */
priv->context_menu_action_group = gtk_action_group_new ("Dictionary Applet Actions");
+#ifdef ENABLE_NLS
gtk_action_group_set_translation_domain(priv->context_menu_action_group,
GETTEXT_PACKAGE);
+#endif /* ENABLE_NLS */
gtk_action_group_add_actions(priv->context_menu_action_group,
gdict_applet_menu_actions,
G_N_ELEMENTS (gdict_applet_menu_actions),
applet);
- ui_path = g_build_filename(PKGDATADIR, "dictionary-applet-menu.xml", NULL);
- mate_panel_applet_setup_menu_from_file (applet, ui_path,
+ mate_panel_applet_setup_menu_from_file (applet,
+ PKGDATADIR "/dictionary-applet-menu.xml",
priv->context_menu_action_group);
- g_free (ui_path);
gtk_widget_show (GTK_WIDGET (applet));
@@ -1215,9 +1276,9 @@ gdict_applet_factory (MatePanelApplet *applet,
}
/* this defines the main () for the applet */
-MATE_PANEL_APPLET_OUT_PROCESS_FACTORY ("DictionaryAppletFactory",
- GDICT_TYPE_APPLET,
- "mate-dictionary-applet",
- gdict_applet_factory,
- NULL);
+PANEL_APPLET_FACTORY ("DictionaryAppletFactory",
+ GDICT_TYPE_APPLET,
+ "mate-dictionary-applet",
+ gdict_applet_factory,
+ NULL);