summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfujiwarat <takao.fujiwara1@gmail.com>2015-06-15 11:19:28 +0900
committerfujiwarat <takao.fujiwara1@gmail.com>2015-06-15 11:19:28 +0900
commit7fd6077f19a5a39cdcd9c7fde0d9c8234ae5592e (patch)
treeba7a2a99d2180666817e8614eb2ae5fb7e7b134c
parentbd7673e73c2a8c54d2a827603a960d76dab7be1b (diff)
downloadibus-7fd6077f19a5a39cdcd9c7fde0d9c8234ae5592e.tar.gz
Support vertical writing with IBUS_INPUT_HINT_VERTICAL_WRITING
GTK_INPUT_HINT_VERTICAL_WRITING has been supported in gtk 3.18 Put the vertical lookup table at the left top of the cursor position in case of the vertical mode. Also the gtk client tries to get the character width not to overlap the character when the client window is moved to the screen left. BUG=https://code.google.com/p/ibus/issues/detail?id=1780 Review URL: https://codereview.appspot.com/242140043
-rw-r--r--src/ibustypes.h6
-rw-r--r--ui/gtk3/candidatearea.vala7
-rw-r--r--ui/gtk3/candidatepanel.vala89
-rw-r--r--ui/gtk3/panel.vala4
4 files changed, 96 insertions, 10 deletions
diff --git a/src/ibustypes.h b/src/ibustypes.h
index 86fc2ccb..06370a27 100644
--- a/src/ibustypes.h
+++ b/src/ibustypes.h
@@ -2,7 +2,7 @@
/* vim:set et sts=4: */
/* ibus - The Input Bus
* Copyright (C) 2008-2013 Peng Huang <shawn.p.huang@gmail.com>
- * Copyright (C) 2008-2013 Red Hat, Inc.
+ * Copyright (C) 2008-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
@@ -280,6 +280,7 @@ typedef enum
* first word of each sentence
* @IBUS_INPUT_HINT_INHIBIT_OSK: Suggest to not show an onscreen keyboard
* (e.g for a calculator that already has all the keys).
+ * @IBUS_INPUT_HINT_VERTICAL_WRITING: The text is vertical.
*
* Describes hints that might be taken into account by engines. Note
* that engines may already tailor their behaviour according to the
@@ -295,7 +296,8 @@ typedef enum
IBUS_INPUT_HINT_UPPERCASE_CHARS = 1 << 4,
IBUS_INPUT_HINT_UPPERCASE_WORDS = 1 << 5,
IBUS_INPUT_HINT_UPPERCASE_SENTENCES = 1 << 6,
- IBUS_INPUT_HINT_INHIBIT_OSK = 1 << 7
+ IBUS_INPUT_HINT_INHIBIT_OSK = 1 << 7,
+ IBUS_INPUT_HINT_VERTICAL_WRITING = 1 << 8
} IBusInputHints;
#endif
diff --git a/ui/gtk3/candidatearea.vala b/ui/gtk3/candidatearea.vala
index f3f60edb..c969312f 100644
--- a/ui/gtk3/candidatearea.vala
+++ b/ui/gtk3/candidatearea.vala
@@ -2,7 +2,8 @@
*
* ibus - The Input Bus
*
- * Copyright(c) 2011-2014 Peng Huang <shawn.p.huang@gmail.com>
+ * Copyright(c) 2011-2015 Peng Huang <shawn.p.huang@gmail.com>
+ * Copyright(c) 2015 Takao Fujiwara <takao.fujiwara1@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -56,6 +57,10 @@ class CandidateArea : Gtk.Box {
set_vertical(vertical, true);
}
+ public bool get_vertical() {
+ return m_vertical;
+ }
+
public void set_vertical(bool vertical, bool force = false) {
if (!force && m_vertical == vertical)
return;
diff --git a/ui/gtk3/candidatepanel.vala b/ui/gtk3/candidatepanel.vala
index c3260446..823c54af 100644
--- a/ui/gtk3/candidatepanel.vala
+++ b/ui/gtk3/candidatepanel.vala
@@ -2,7 +2,8 @@
*
* ibus - The Input Bus
*
- * Copyright(c) 2011-2014 Peng Huang <shawn.p.huang@gmail.com>
+ * Copyright(c) 2011-2015 Peng Huang <shawn.p.huang@gmail.com>
+ * Copyright(c) 2015 Takao Fujiwara <takao.fujiwara1@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -21,7 +22,8 @@
*/
public class CandidatePanel : Gtk.Box{
- private bool m_vertical = true;
+ private bool m_vertical_panel_system = true;
+ private bool m_vertical_writing;
private Gtk.Window m_toplevel;
private Gtk.Box m_vbox;
@@ -53,7 +55,7 @@ public class CandidatePanel : Gtk.Box{
m_toplevel.button_press_event.connect((w, e) => {
if (e.button != 1 || (e.state & Gdk.ModifierType.CONTROL_MASK) == 0)
return false;
- set_vertical(!m_vertical);
+ set_vertical(!m_vertical_panel_system);
return true;
});
m_toplevel.size_allocate.connect((w, a) => {
@@ -74,9 +76,9 @@ public class CandidatePanel : Gtk.Box{
}
public void set_vertical(bool vertical) {
- if (m_vertical == vertical)
+ if (m_vertical_panel_system == vertical)
return;
- m_vertical = vertical;
+ m_vertical_panel_system = vertical;
m_candidate_area.set_vertical(vertical);
}
@@ -89,7 +91,7 @@ public class CandidatePanel : Gtk.Box{
m_candidate_area.set_vertical(false);
break;
case IBus.Orientation.SYSTEM:
- m_candidate_area.set_vertical(m_vertical);
+ m_candidate_area.set_vertical(m_vertical_panel_system);
break;
}
}
@@ -204,6 +206,11 @@ public class CandidatePanel : Gtk.Box{
update();
}
+ public void set_content_type(uint purpose, uint hints) {
+ m_vertical_writing =
+ ((hints & IBus.InputHints.VERTICAL_WRITING) != 0);
+ }
+
private void update() {
if (m_candidate_area.get_visible() ||
m_preedit_label.get_visible() ||
@@ -246,7 +253,7 @@ public class CandidatePanel : Gtk.Box{
m_aux_label.set_padding(8, 0);
m_aux_label.set_no_show_all(true);
- m_candidate_area = new CandidateArea(m_vertical);
+ m_candidate_area = new CandidateArea(m_vertical_panel_system);
m_candidate_area.candidate_clicked.connect(
(w, i, b, s) => candidate_clicked(i, b, s));
m_candidate_area.page_up.connect((c) => page_up());
@@ -280,6 +287,13 @@ public class CandidatePanel : Gtk.Box{
}
private void adjust_window_position() {
+ if (!m_vertical_writing)
+ adjust_window_position_horizontal();
+ else
+ adjust_window_position_vertical();
+ }
+
+ private void adjust_window_position_horizontal() {
Gdk.Point cursor_right_bottom = {
m_cursor_location.x + m_cursor_location.width,
m_cursor_location.y + m_cursor_location.height
@@ -313,4 +327,65 @@ public class CandidatePanel : Gtk.Box{
move(x, y);
}
+
+ private void adjust_window_position_vertical() {
+ /* Not sure in which top or left cursor appears
+ * in the vertical writing mode.
+ * Max (m_cursor_location.width, m_cursor_location.height)
+ * can be considered as a char size.
+ */
+ int char_size = int.max(m_cursor_location.width,
+ m_cursor_location.height);
+ Gdk.Point cursor_right_bottom = {
+ m_cursor_location.x + char_size,
+ m_cursor_location.y + char_size
+ };
+
+ Gtk.Allocation allocation;
+ m_toplevel.get_allocation(out allocation);
+ Gdk.Point hwindow_right_bottom = {
+ m_cursor_location.x + allocation.width,
+ cursor_right_bottom.y + allocation.height
+ };
+ Gdk.Point vwindow_left_bottom = {
+ m_cursor_location.x - allocation.width,
+ m_cursor_location.y + allocation.height
+ };
+
+ Gdk.Window root = Gdk.get_default_root_window();
+ int root_width = root.get_width();
+ int root_height = root.get_height();
+
+ int x, y;
+ if (!m_candidate_area.get_vertical()) {
+ if (hwindow_right_bottom.x > root_width)
+ x = root_width - allocation.width;
+ else
+ x = m_cursor_location.x;
+
+ if (hwindow_right_bottom.y > root_height)
+ y = m_cursor_location.y - allocation.height;
+ else
+ y = cursor_right_bottom.y;
+ } else {
+ if (vwindow_left_bottom.x > root_width)
+ x = root_width - allocation.width;
+ else if (vwindow_left_bottom.x < 0)
+ x = cursor_right_bottom.x;
+ else
+ x = vwindow_left_bottom.x;
+
+ if (vwindow_left_bottom.y > root_height)
+ y = root_height - allocation.height;
+ else
+ y = m_cursor_location.y;
+ }
+
+ if (x < 0)
+ x = 0;
+ if (y < 0)
+ y = 0;
+
+ move(x, y);
+ }
}
diff --git a/ui/gtk3/panel.vala b/ui/gtk3/panel.vala
index 7fc6f0b4..e2bd99d7 100644
--- a/ui/gtk3/panel.vala
+++ b/ui/gtk3/panel.vala
@@ -1267,6 +1267,10 @@ class Panel : IBus.PanelService {
m_candidate_panel.set_lookup_table(null);
}
+ public override void set_content_type(uint purpose, uint hints) {
+ m_candidate_panel.set_content_type(purpose, hints);
+ }
+
public override void state_changed() {
/* Do not change the order of m_engines during running switcher. */
if (m_switcher_is_running)