~darkxst/ubuntu/saucy/gnome-shell/upstart_log

« back to all changes in this revision

Viewing changes to src/st/st-entry.c

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2013-05-31 12:01:12 UTC
  • mfrom: (1.1.49) (19.1.36 experimental)
  • Revision ID: package-import@ubuntu.com-20130531120112-ew91khxf051x9i2r
Tags: 3.8.2-1ubuntu1
* Merge with Debian (LP: #1185869, #1185721). Remaining changes:
  - debian/control.in:
    + Build-depend on libsystemd-login-dev & libsystemd-daemon-dev
    + Depend on gdm instead of gdm3
    + Don't recommend gnome-session-fallback
  - debian/patches/40_change-pam-name-to-match-gdm.patch:
  - debian/patches/revert-suspend-break.patch:
    + Disabled, not needed on Ubuntu
  - debian/patches/ubuntu-lightdm-user-switching.patch:
    + Allow user switching when using LightDM. Thanks Gerhard Stein
      for rebasing against gnome-shell 3.8!
  - debian/patches/ubuntu_lock_on_suspend.patch
    + Respect Ubuntu's lock-on-suspend setting.
      Disabled until it can be rewritten.
  - debian/patches/git_relock_screen_after_crash.patch:
    + Add Upstream fix for unlocked session after crash (LP: #1064584)
* Note that the new GNOME Classic mode (which requires installing
  gnome-shell-extensions) won't work until gnome-session 3.8 is
  available in Ubuntu

Show diffs side-by-side

added added

removed removed

Lines of Context:
65
65
#include "st-clipboard.h"
66
66
#include "st-private.h"
67
67
 
 
68
#include <clutter/x11/clutter-x11.h>
 
69
#include <X11/Xlib.h>
 
70
#include <X11/cursorfont.h>
 
71
 
68
72
#include "st-widget-accessible.h"
69
73
 
70
74
#define HAS_FOCUS(actor) (clutter_actor_get_stage (actor) && clutter_stage_get_key_focus ((ClutterStage *) clutter_actor_get_stage (actor)) == actor)
78
82
  PROP_CLUTTER_TEXT,
79
83
  PROP_HINT_TEXT,
80
84
  PROP_TEXT,
 
85
  PROP_INPUT_PURPOSE,
 
86
  PROP_INPUT_HINTS,
81
87
};
82
88
 
83
89
/* signals */
105
111
 
106
112
  gboolean      hint_visible;
107
113
  gboolean      capslock_warning_shown;
 
114
  gboolean      has_ibeam;
108
115
};
109
116
 
110
117
static guint entry_signals[LAST_SIGNAL] = { 0, };
131
138
      st_entry_set_text (entry, g_value_get_string (value));
132
139
      break;
133
140
 
 
141
    case PROP_INPUT_PURPOSE:
 
142
      st_entry_set_input_purpose (entry, g_value_get_enum (value));
 
143
      break;
 
144
 
 
145
    case PROP_INPUT_HINTS:
 
146
      st_entry_set_input_hints (entry, g_value_get_flags (value));
 
147
      break;
 
148
 
134
149
    default:
135
150
      G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
136
151
      break;
159
174
      g_value_set_string (value, clutter_text_get_text (CLUTTER_TEXT (priv->entry)));
160
175
      break;
161
176
 
 
177
    case PROP_INPUT_PURPOSE:
 
178
      g_value_set_enum (value, st_im_text_get_input_purpose (ST_IM_TEXT (priv->entry)));
 
179
      break;
 
180
 
 
181
    case PROP_INPUT_HINTS:
 
182
      g_value_set_flags (value, st_im_text_get_input_hints (ST_IM_TEXT (priv->entry)));
 
183
      break;
 
184
 
162
185
    default:
163
186
      G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
164
187
      break;
538
561
}
539
562
 
540
563
static gboolean
 
564
clutter_text_button_press_event (ClutterActor       *actor,
 
565
                                 ClutterButtonEvent *event,
 
566
                                 gpointer            user_data)
 
567
{
 
568
  GtkSettings *settings = gtk_settings_get_default ();
 
569
  gboolean primary_paste_enabled;
 
570
 
 
571
  g_object_get (settings,
 
572
                "gtk-enable-primary-paste", &primary_paste_enabled,
 
573
                NULL);
 
574
 
 
575
  if (primary_paste_enabled && event->button == 2)
 
576
    {
 
577
      StClipboard *clipboard;
 
578
 
 
579
      clipboard = st_clipboard_get_default ();
 
580
 
 
581
      /* By the time the clipboard callback is called,
 
582
       * the rest of the signal handlers will have
 
583
       * run, making the text cursor to be in the correct
 
584
       * place.
 
585
       */
 
586
      st_clipboard_get_text (clipboard,
 
587
                             ST_CLIPBOARD_TYPE_PRIMARY,
 
588
                             st_entry_clipboard_callback,
 
589
                             user_data);
 
590
    }
 
591
 
 
592
  return FALSE;
 
593
}
 
594
 
 
595
static gboolean
541
596
st_entry_key_press_event (ClutterActor    *actor,
542
597
                          ClutterKeyEvent *event)
543
598
{
555
610
 
556
611
      clipboard = st_clipboard_get_default ();
557
612
 
558
 
      st_clipboard_get_text (clipboard, st_entry_clipboard_callback, actor);
 
613
      st_clipboard_get_text (clipboard,
 
614
                             ST_CLIPBOARD_TYPE_CLIPBOARD,
 
615
                             st_entry_clipboard_callback,
 
616
                             actor);
559
617
 
560
618
      return TRUE;
561
619
    }
562
620
 
563
621
  /* copy */
564
622
  if ((event->modifier_state & CLUTTER_CONTROL_MASK)
565
 
      && event->keyval == CLUTTER_c)
 
623
      && event->keyval == CLUTTER_c &&
 
624
      clutter_text_get_password_char ((ClutterText*) priv->entry) == 0)
566
625
    {
567
626
      StClipboard *clipboard;
568
627
      gchar *text;
572
631
      text = clutter_text_get_selection ((ClutterText*) priv->entry);
573
632
 
574
633
      if (text && strlen (text))
575
 
        st_clipboard_set_text (clipboard, text);
 
634
        st_clipboard_set_text (clipboard,
 
635
                               ST_CLIPBOARD_TYPE_CLIPBOARD,
 
636
                               text);
576
637
 
577
638
      return TRUE;
578
639
    }
580
641
 
581
642
  /* cut */
582
643
  if ((event->modifier_state & CLUTTER_CONTROL_MASK)
583
 
      && event->keyval == CLUTTER_x)
 
644
      && event->keyval == CLUTTER_x &&
 
645
      clutter_text_get_password_char ((ClutterText*) priv->entry) == 0)
584
646
    {
585
647
      StClipboard *clipboard;
586
648
      gchar *text;
591
653
 
592
654
      if (text && strlen (text))
593
655
        {
594
 
          st_clipboard_set_text (clipboard, text);
 
656
          st_clipboard_set_text (clipboard,
 
657
                                 ST_CLIPBOARD_TYPE_CLIPBOARD,
 
658
                                 text);
595
659
 
596
660
          /* now delete the text */
597
661
          clutter_text_delete_selection ((ClutterText *) priv->entry);
614
678
}
615
679
 
616
680
static void
 
681
st_entry_set_cursor (StEntry  *entry,
 
682
                     gboolean  use_ibeam)
 
683
{
 
684
  Display *dpy;
 
685
  ClutterActor *stage, *actor = CLUTTER_ACTOR (entry);
 
686
  Window wid;
 
687
  static Cursor ibeam = None;
 
688
 
 
689
  dpy = clutter_x11_get_default_display ();
 
690
  stage = clutter_actor_get_stage (actor);
 
691
 
 
692
  if (stage == NULL)
 
693
    {
 
694
      g_warn_if_fail (!entry->priv->has_ibeam);
 
695
      return;
 
696
    }
 
697
 
 
698
  wid = clutter_x11_get_stage_window (CLUTTER_STAGE (stage));
 
699
 
 
700
  if (ibeam == None)
 
701
    ibeam = XCreateFontCursor (dpy, XC_xterm);
 
702
 
 
703
  if (use_ibeam)
 
704
    XDefineCursor (dpy, wid, ibeam);
 
705
  else
 
706
    XUndefineCursor (dpy, wid);
 
707
 
 
708
  entry->priv->has_ibeam = use_ibeam;
 
709
}
 
710
 
 
711
static gboolean
 
712
st_entry_crossing_event (ClutterActor         *actor,
 
713
                         ClutterCrossingEvent *event)
 
714
{
 
715
  if (event->source == ST_ENTRY (actor)->priv->entry && event->related != NULL)
 
716
    st_entry_set_cursor (ST_ENTRY (actor), (event->type == CLUTTER_ENTER));
 
717
 
 
718
  return FALSE;
 
719
}
 
720
 
 
721
static void
 
722
st_entry_unmap (ClutterActor *actor)
 
723
{
 
724
  if (ST_ENTRY (actor)->priv->has_ibeam)
 
725
    st_entry_set_cursor (ST_ENTRY (actor), FALSE);
 
726
 
 
727
  CLUTTER_ACTOR_CLASS (st_entry_parent_class)->unmap (actor);
 
728
}
 
729
 
 
730
static void
617
731
st_entry_class_init (StEntryClass *klass)
618
732
{
619
733
  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
631
745
  actor_class->get_preferred_width = st_entry_get_preferred_width;
632
746
  actor_class->get_preferred_height = st_entry_get_preferred_height;
633
747
  actor_class->allocate = st_entry_allocate;
 
748
  actor_class->unmap = st_entry_unmap;
634
749
 
635
750
  actor_class->key_press_event = st_entry_key_press_event;
636
751
  actor_class->key_focus_in = st_entry_key_focus_in;
637
752
 
 
753
  actor_class->enter_event = st_entry_crossing_event;
 
754
  actor_class->leave_event = st_entry_crossing_event;
 
755
 
638
756
  widget_class->style_changed = st_entry_style_changed;
639
757
  widget_class->navigate_focus = st_entry_navigate_focus;
640
758
  widget_class->get_accessible_type = st_entry_accessible_get_type;
659
777
                               NULL, G_PARAM_READWRITE);
660
778
  g_object_class_install_property (gobject_class, PROP_TEXT, pspec);
661
779
 
 
780
  pspec = g_param_spec_enum ("input-purpose",
 
781
                             "Purpose",
 
782
                             "Purpose of the text field",
 
783
                             GTK_TYPE_INPUT_PURPOSE,
 
784
                             GTK_INPUT_PURPOSE_FREE_FORM,
 
785
                             G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
 
786
  g_object_class_install_property (gobject_class,
 
787
                                   PROP_INPUT_PURPOSE,
 
788
                                   pspec);
 
789
 
 
790
  pspec = g_param_spec_flags ("input-hints",
 
791
                              "hints",
 
792
                              "Hints for the text field behaviour",
 
793
                              GTK_TYPE_INPUT_HINTS,
 
794
                              GTK_INPUT_HINT_NONE,
 
795
                              G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
 
796
  g_object_class_install_property (gobject_class,
 
797
                                   PROP_INPUT_HINTS,
 
798
                                   pspec);
 
799
 
662
800
  /* signals */
663
801
  /**
664
802
   * StEntry::primary-icon-clicked:
709
847
  g_signal_connect (priv->entry, "notify::password-char",
710
848
                    G_CALLBACK (clutter_text_password_char_cb), entry);
711
849
 
 
850
  g_signal_connect (priv->entry, "button-press-event",
 
851
                    G_CALLBACK (clutter_text_button_press_event), entry);
 
852
 
712
853
  priv->spacing = 6.0f;
713
854
 
714
855
  clutter_actor_add_child (CLUTTER_ACTOR (entry), priv->entry);
863
1004
  return entry->priv->hint;
864
1005
}
865
1006
 
 
1007
/**
 
1008
 * st_entry_set_input_purpose:
 
1009
 * @entry: a #StEntry
 
1010
 * @purpose: the purpose
 
1011
 *
 
1012
 * Sets the #StEntry:input-purpose property which
 
1013
 * can be used by on-screen keyboards and other input
 
1014
 * methods to adjust their behaviour.
 
1015
 */
 
1016
void
 
1017
st_entry_set_input_purpose (StEntry        *entry,
 
1018
                            GtkInputPurpose purpose)
 
1019
{
 
1020
  StIMText *imtext;
 
1021
 
 
1022
  g_return_if_fail (ST_IS_ENTRY (entry));
 
1023
 
 
1024
  imtext = ST_IM_TEXT (entry->priv->entry);
 
1025
 
 
1026
  if (st_im_text_get_input_purpose (imtext) != purpose)
 
1027
    {
 
1028
      st_im_text_set_input_purpose (imtext, purpose);
 
1029
 
 
1030
      g_object_notify (G_OBJECT (entry), "input-purpose");
 
1031
    }
 
1032
}
 
1033
 
 
1034
/**
 
1035
 * st_entry_get_input_purpose:
 
1036
 * @entry: a #StEntry
 
1037
 *
 
1038
 * Gets the value of the #StEntry:input-purpose property.
 
1039
 */
 
1040
GtkInputPurpose
 
1041
st_entry_get_input_purpose (StEntry *entry)
 
1042
{
 
1043
  g_return_val_if_fail (ST_IS_ENTRY (entry), GTK_INPUT_PURPOSE_FREE_FORM);
 
1044
 
 
1045
  return st_im_text_get_input_purpose (ST_IM_TEXT (entry->priv->entry));
 
1046
}
 
1047
 
 
1048
/**
 
1049
 * st_entry_set_input_hints:
 
1050
 * @entry: a #StEntry
 
1051
 * @hints: the hints
 
1052
 *
 
1053
 * Sets the #StEntry:input-hints property, which
 
1054
 * allows input methods to fine-tune their behaviour.
 
1055
 */
 
1056
void
 
1057
st_entry_set_input_hints (StEntry      *entry,
 
1058
                          GtkInputHints hints)
 
1059
{
 
1060
  StIMText *imtext;
 
1061
 
 
1062
  g_return_if_fail (ST_IS_ENTRY (entry));
 
1063
 
 
1064
  imtext = ST_IM_TEXT (entry->priv->entry);
 
1065
 
 
1066
  if (st_im_text_get_input_hints (imtext) != hints)
 
1067
    {
 
1068
      st_im_text_set_input_hints (imtext, hints);
 
1069
 
 
1070
      g_object_notify (G_OBJECT (entry), "input-hints");
 
1071
    }
 
1072
}
 
1073
 
 
1074
/**
 
1075
 * st_entry_get_input_hints:
 
1076
 * @entry: a #StEntry
 
1077
 *
 
1078
 * Gets the value of the #StEntry:input-hints property.
 
1079
 */
 
1080
GtkInputHints
 
1081
st_entry_get_input_hints (StEntry *entry)
 
1082
{
 
1083
  g_return_val_if_fail (ST_IS_ENTRY (entry), GTK_INPUT_HINT_NONE);
 
1084
 
 
1085
  return st_im_text_get_input_hints (ST_IM_TEXT (entry->priv->entry));
 
1086
}
 
1087
 
866
1088
static gboolean
867
1089
_st_entry_icon_press_cb (ClutterActor       *actor,
868
1090
                         ClutterButtonEvent *event,