~ubuntu-branches/ubuntu/wily/libgksuui1.0/wily

« back to all changes in this revision

Viewing changes to debian/patches/01_warn_on_capslock.diff

  • Committer: Bazaar Package Importer
  • Author(s): Michael Vogt
  • Date: 2006-01-13 18:50:23 UTC
  • Revision ID: james.westby@ubuntu.com-20060113185023-ha3d5sblq0w1ujf9
Tags: 1.0.7-1ubuntu1
* debian/patches/01_warn_on_capslock.diff:
  - display a small warning when capslock is on (ubuntu #27477)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
=== modified file 'libgksuui/gksuui-dialog.c'
 
2
--- libgksuui/gksuui-dialog.c   
 
3
+++ libgksuui/gksuui-dialog.c   
 
4
@@ -19,6 +19,8 @@
 
5
  */
 
6
 
 
7
 #include <gtk/gtk.h>
 
8
+#include <gdk/gdkx.h>
 
9
+#include <X11/XKBlib.h>
 
10
 
 
11
 #include "defines.h"
 
12
 #include "../config.h"
 
13
@@ -30,6 +32,7 @@
 
14
 
 
15
 static void
 
16
 gksuui_dialog_init (GksuuiDialog *gksuui_dialog);
 
17
+
 
18
 
 
19
 GType
 
20
 gksuui_dialog_get_type (void)
 
21
@@ -63,6 +66,36 @@
 
22
 {
 
23
 }
 
24
 
 
25
+/** 
 
26
+ * Helper that can detect if caps lock is pressed
 
27
+ */
 
28
+static gboolean
 
29
+is_capslock_on (void)
 
30
+{
 
31
+  XkbStateRec states;
 
32
+  Display *dsp;
 
33
+
 
34
+  dsp = GDK_DISPLAY ();
 
35
+  if (XkbGetState (dsp, XkbUseCoreKbd, &states) != Success)
 
36
+      return FALSE;
 
37
+
 
38
+  return (states.locked_mods & LockMask) != 0;
 
39
+}
 
40
+
 
41
+static gboolean
 
42
+gksuui_dialog_keypress_cb(GtkWidget *widget, GdkEventKey *event, gpointer user_data)
 
43
+{
 
44
+   GksuuiDialog *dialog = user_data;
 
45
+
 
46
+   if (is_capslock_on()) 
 
47
+      gtk_widget_show(dialog->label_warn_capslock);
 
48
+   else 
 
49
+      gtk_widget_hide(dialog->label_warn_capslock);
 
50
+
 
51
+   return FALSE;
 
52
+}
 
53
+
 
54
+
 
55
 static void
 
56
 gksuui_dialog_init (GksuuiDialog *gksuui_dialog)
 
57
 {
 
58
@@ -125,6 +158,14 @@
 
59
   gtk_box_pack_start (GTK_BOX(gksuui_dialog->hbox), gksuui_dialog->entry_vbox, 
 
60
                      TRUE, TRUE, 0);
 
61
   gtk_widget_show (gksuui_dialog->entry_vbox);
 
62
+
 
63
+  /* label capslock warning */
 
64
+  gksuui_dialog->label_warn_capslock = gtk_label_new (_("<i>You have capslock on</i>"));
 
65
+  gtk_label_set_justify (GTK_LABEL(gksuui_dialog->label_warn_capslock), 
 
66
+                        GTK_JUSTIFY_CENTER);
 
67
+  gtk_label_set_use_markup (GTK_LABEL(gksuui_dialog->label_warn_capslock), TRUE);
 
68
+  gtk_box_pack_start (GTK_BOX(gksuui_dialog->entry_vbox), 
 
69
+                     gksuui_dialog->label_warn_capslock, TRUE, TRUE, 0);
 
70
 
 
71
   /* label */
 
72
   gksuui_dialog->label = gtk_label_new (_("<span weight=\"bold\" size=\"larger\">"
 
73
@@ -152,6 +193,8 @@
 
74
   
 
75
   /* entry */
 
76
   gksuui_dialog->entry = gtk_entry_new();
 
77
+  g_signal_connect (G_OBJECT(gksuui_dialog->entry), "key-press-event",
 
78
+                   G_CALLBACK(gksuui_dialog_keypress_cb), gksuui_dialog);
 
79
   g_signal_connect_swapped (G_OBJECT(gksuui_dialog->entry), "activate",
 
80
                            G_CALLBACK(gtk_button_clicked), 
 
81
                            gksuui_dialog->ok_button);
 
82
@@ -162,6 +205,11 @@
 
83
   gtk_widget_show (gksuui_dialog->entry);
 
84
   gtk_widget_grab_focus(gksuui_dialog->entry);
 
85
 
 
86
+  /* expose event */
 
87
+  g_signal_connect (G_OBJECT(gksuui_dialog), "focus-in-event",
 
88
+                   G_CALLBACK(gksuui_dialog_keypress_cb), gksuui_dialog);
 
89
+
 
90
+
 
91
   gtk_widget_pop_composite_child ();
 
92
 }
 
93
 
 
94
=== modified file 'libgksuui/gksuui-dialog.h'
 
95
--- libgksuui/gksuui-dialog.h   
 
96
+++ libgksuui/gksuui-dialog.h   
 
97
@@ -64,6 +64,7 @@
 
98
   GtkWidget *image;
 
99
   GtkWidget *entry_vbox;
 
100
   GtkWidget *label;
 
101
+  GtkWidget *label_warn_capslock;
 
102
   GtkWidget *entry;
 
103
   GtkWidget *ok_button;
 
104
   GtkWidget *cancel_button;
 
105