|
Packit Service |
1d8f1c |
/* vim:set et sts=4 sw=4:
|
|
Packit Service |
1d8f1c |
*
|
|
Packit Service |
1d8f1c |
* ibus - The Input Bus
|
|
Packit Service |
1d8f1c |
*
|
|
Packit Service |
1d8f1c |
* Copyright(c) 2011-2015 Peng Huang <shawn.p.huang@gmail.com>
|
|
Packit Service |
1d8f1c |
* Copyright(c) 2015-2018 Takao Fujiwara <takao.fujiwara1@gmail.com>
|
|
Packit Service |
1d8f1c |
*
|
|
Packit Service |
1d8f1c |
* This library is free software; you can redistribute it and/or
|
|
Packit Service |
1d8f1c |
* modify it under the terms of the GNU Lesser General Public
|
|
Packit Service |
1d8f1c |
* License as published by the Free Software Foundation; either
|
|
Packit Service |
1d8f1c |
* version 2.1 of the License, or (at your option) any later version.
|
|
Packit Service |
1d8f1c |
*
|
|
Packit Service |
1d8f1c |
* This library is distributed in the hope that it will be useful,
|
|
Packit Service |
1d8f1c |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
1d8f1c |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Service |
1d8f1c |
* Lesser General Public License for more details.
|
|
Packit Service |
1d8f1c |
*
|
|
Packit Service |
1d8f1c |
* You should have received a copy of the GNU Lesser General Public
|
|
Packit Service |
1d8f1c |
* License along with this library; if not, write to the Free Software
|
|
Packit Service |
1d8f1c |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
|
Packit Service |
1d8f1c |
* USA
|
|
Packit Service |
1d8f1c |
*/
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
public class CandidatePanel : Gtk.Box{
|
|
Packit Service |
1d8f1c |
private bool m_vertical_panel_system = true;
|
|
Packit Service |
1d8f1c |
private bool m_vertical_writing;
|
|
Packit Service |
1d8f1c |
private Gtk.Window m_toplevel;
|
|
Packit Service |
1d8f1c |
private Gtk.Box m_vbox;
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
private Gtk.Label m_preedit_label;
|
|
Packit Service |
1d8f1c |
private Gtk.Label m_aux_label;
|
|
Packit Service |
1d8f1c |
private CandidateArea m_candidate_area;
|
|
Packit Service |
1d8f1c |
private HSeparator m_hseparator;
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
private Gdk.Rectangle m_cursor_location;
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
public signal void cursor_up();
|
|
Packit Service |
1d8f1c |
public signal void cursor_down();
|
|
Packit Service |
1d8f1c |
public signal void page_up();
|
|
Packit Service |
1d8f1c |
public signal void page_down();
|
|
Packit Service |
1d8f1c |
public signal void candidate_clicked(uint index,
|
|
Packit Service |
1d8f1c |
uint button,
|
|
Packit Service |
1d8f1c |
uint state);
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
public CandidatePanel() {
|
|
Packit Service |
1d8f1c |
// Call base class constructor
|
|
Packit Service |
1d8f1c |
GLib.Object(
|
|
Packit Service |
1d8f1c |
name : "IBusCandidate",
|
|
Packit Service |
1d8f1c |
orientation: Gtk.Orientation.HORIZONTAL,
|
|
Packit Service |
1d8f1c |
visible: true
|
|
Packit Service |
1d8f1c |
);
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
m_toplevel = new Gtk.Window(Gtk.WindowType.POPUP);
|
|
Packit Service |
1d8f1c |
m_toplevel.add_events(Gdk.EventMask.BUTTON_PRESS_MASK);
|
|
Packit Service |
1d8f1c |
m_toplevel.button_press_event.connect((w, e) => {
|
|
Packit Service |
1d8f1c |
if (e.button != 1 || (e.state & Gdk.ModifierType.CONTROL_MASK) == 0)
|
|
Packit Service |
1d8f1c |
return false;
|
|
Packit Service |
1d8f1c |
set_vertical(!m_vertical_panel_system);
|
|
Packit Service |
1d8f1c |
return true;
|
|
Packit Service |
1d8f1c |
});
|
|
Packit Service |
1d8f1c |
m_toplevel.size_allocate.connect((w, a) => {
|
|
Packit Service |
1d8f1c |
adjust_window_position();
|
|
Packit Service |
1d8f1c |
});
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
Handle handle = new Handle();
|
|
Packit Service |
1d8f1c |
handle.set_visible(true);
|
|
Packit Service |
1d8f1c |
pack_start(handle, false, false, 0);
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
m_vbox = new Gtk.Box(Gtk.Orientation.VERTICAL, 0);
|
|
Packit Service |
1d8f1c |
m_vbox.set_visible(true);
|
|
Packit Service |
1d8f1c |
pack_start(m_vbox, false, false, 0);
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
m_toplevel.add(this);
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
create_ui();
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
public void set_vertical(bool vertical) {
|
|
Packit Service |
1d8f1c |
if (m_vertical_panel_system == vertical)
|
|
Packit Service |
1d8f1c |
return;
|
|
Packit Service |
1d8f1c |
m_vertical_panel_system = vertical;
|
|
Packit Service |
1d8f1c |
m_candidate_area.set_vertical(vertical);
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
private void set_orientation(IBus.Orientation orientation) {
|
|
Packit Service |
1d8f1c |
switch (orientation) {
|
|
Packit Service |
1d8f1c |
case IBus.Orientation.VERTICAL:
|
|
Packit Service |
1d8f1c |
m_candidate_area.set_vertical(true);
|
|
Packit Service |
1d8f1c |
break;
|
|
Packit Service |
1d8f1c |
case IBus.Orientation.HORIZONTAL:
|
|
Packit Service |
1d8f1c |
m_candidate_area.set_vertical(false);
|
|
Packit Service |
1d8f1c |
break;
|
|
Packit Service |
1d8f1c |
case IBus.Orientation.SYSTEM:
|
|
Packit Service |
1d8f1c |
m_candidate_area.set_vertical(m_vertical_panel_system);
|
|
Packit Service |
1d8f1c |
break;
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
public void set_cursor_location(int x, int y, int width, int height) {
|
|
Packit Service |
1d8f1c |
Gdk.Rectangle location = Gdk.Rectangle(){
|
|
Packit Service |
1d8f1c |
x = x, y = y, width = width, height = height };
|
|
Packit Service |
1d8f1c |
if (m_cursor_location == location)
|
|
Packit Service |
1d8f1c |
return;
|
|
Packit Service |
1d8f1c |
m_cursor_location = location;
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
/* Do not call adjust_window_position() here because
|
|
Packit Service |
1d8f1c |
* m_toplevel is not shown yet and
|
|
Packit Service |
1d8f1c |
* m_toplevel.get_allocation() returns height = width = 1 */
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
private void set_labels(IBus.Text[] labels) {
|
|
Packit Service |
1d8f1c |
m_candidate_area.set_labels(labels);
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
private void set_attributes(Gtk.Label label, IBus.Text text) {
|
|
Packit Service |
1d8f1c |
Pango.AttrList attrs = get_pango_attr_list_from_ibus_text(text);
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
Gtk.StyleContext context = label.get_style_context();
|
|
Packit Service |
1d8f1c |
Gdk.RGBA color;
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
if (context.lookup_color("placeholder_text_color", out color)) {
|
|
Packit Service |
1d8f1c |
Pango.Attribute pango_attr = Pango.attr_foreground_new(
|
|
Packit Service |
1d8f1c |
(uint16)(color.red * uint16.MAX),
|
|
Packit Service |
1d8f1c |
(uint16)(color.green * uint16.MAX),
|
|
Packit Service |
1d8f1c |
(uint16)(color.blue * uint16.MAX));
|
|
Packit Service |
1d8f1c |
pango_attr.start_index = 0;
|
|
Packit Service |
1d8f1c |
pango_attr.end_index = label.get_text().length;
|
|
Packit Service |
1d8f1c |
attrs.insert((owned)pango_attr);
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
label.set_attributes(attrs);
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
public void set_preedit_text(IBus.Text? text, uint cursor) {
|
|
Packit Service |
1d8f1c |
if (text != null) {
|
|
Packit Service |
1d8f1c |
var str = text.get_text();
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
if (str.length > 0) {
|
|
Packit Service |
1d8f1c |
m_preedit_label.set_text(str);
|
|
Packit Service |
1d8f1c |
m_preedit_label.show();
|
|
Packit Service |
1d8f1c |
set_attributes(m_preedit_label, text);
|
|
Packit Service |
1d8f1c |
} else {
|
|
Packit Service |
1d8f1c |
m_preedit_label.set_text("");
|
|
Packit Service |
1d8f1c |
m_preedit_label.hide();
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
} else {
|
|
Packit Service |
1d8f1c |
m_preedit_label.set_text("");
|
|
Packit Service |
1d8f1c |
m_preedit_label.hide();
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
update();
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
public void set_auxiliary_text(IBus.Text? text) {
|
|
Packit Service |
1d8f1c |
if (text != null) {
|
|
Packit Service |
1d8f1c |
m_aux_label.set_text(text.get_text());
|
|
Packit Service |
1d8f1c |
Pango.AttrList attrs = get_pango_attr_list_from_ibus_text(text);
|
|
Packit Service |
1d8f1c |
m_aux_label.set_attributes(attrs);
|
|
Packit Service |
1d8f1c |
m_aux_label.show();
|
|
Packit Service |
1d8f1c |
} else {
|
|
Packit Service |
1d8f1c |
m_aux_label.set_text("");
|
|
Packit Service |
1d8f1c |
m_aux_label.hide();
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
update();
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
public void set_lookup_table(IBus.LookupTable? table) {
|
|
Packit Service |
1d8f1c |
IBus.Text[] candidates = {};
|
|
Packit Service |
1d8f1c |
uint cursor_in_page = 0;
|
|
Packit Service |
1d8f1c |
bool show_cursor = true;
|
|
Packit Service |
1d8f1c |
IBus.Text[] labels = {};
|
|
Packit Service |
1d8f1c |
IBus.Orientation orientation = IBus.Orientation.SYSTEM;
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
if (table != null) {
|
|
Packit Service |
1d8f1c |
uint page_size = table.get_page_size();
|
|
Packit Service |
1d8f1c |
uint ncandidates = table.get_number_of_candidates();
|
|
Packit Service |
1d8f1c |
uint cursor = table.get_cursor_pos();
|
|
Packit Service |
1d8f1c |
cursor_in_page = table.get_cursor_in_page();
|
|
Packit Service |
1d8f1c |
show_cursor = table.is_cursor_visible();
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
uint page_start_pos = cursor / page_size * page_size;
|
|
Packit Service |
1d8f1c |
uint page_end_pos = uint.min(page_start_pos + page_size, ncandidates);
|
|
Packit Service |
1d8f1c |
for (uint i = page_start_pos; i < page_end_pos; i++)
|
|
Packit Service |
1d8f1c |
candidates += table.get_candidate(i);
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
for (uint i = 0; i < page_size; i++) {
|
|
Packit Service |
1d8f1c |
IBus.Text? label = table.get_label(i);
|
|
Packit Service |
1d8f1c |
if (label != null)
|
|
Packit Service |
1d8f1c |
labels += label;
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
orientation = (IBus.Orientation)table.get_orientation();
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
m_candidate_area.set_candidates(candidates, cursor_in_page, show_cursor);
|
|
Packit Service |
1d8f1c |
set_labels(labels);
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
if (table != null) {
|
|
Packit Service |
1d8f1c |
// Do not change orientation if table is null to avoid recreate
|
|
Packit Service |
1d8f1c |
// candidates area.
|
|
Packit Service |
1d8f1c |
set_orientation(orientation);
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
if (candidates.length != 0)
|
|
Packit Service |
1d8f1c |
m_candidate_area.show_all();
|
|
Packit Service |
1d8f1c |
else
|
|
Packit Service |
1d8f1c |
m_candidate_area.hide();
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
update();
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
public void set_content_type(uint purpose, uint hints) {
|
|
Packit Service |
1d8f1c |
m_vertical_writing =
|
|
Packit Service |
1d8f1c |
((hints & IBus.InputHints.VERTICAL_WRITING) != 0);
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
private void update() {
|
|
Packit Service |
1d8f1c |
/* Do not call gtk_window_resize() in
|
|
Packit Service |
1d8f1c |
* GtkWidgetClass->get_preferred_width()
|
|
Packit Service |
1d8f1c |
* because the following warning is shown in GTK 3.20:
|
|
Packit Service |
1d8f1c |
* "Allocating size to GtkWindow %x without calling
|
|
Packit Service |
1d8f1c |
* gtk_widget_get_preferred_width/height(). How does the code
|
|
Packit Service |
1d8f1c |
* know the size to allocate?"
|
|
Packit Service |
1d8f1c |
* in gtk_widget_size_allocate_with_baseline() */
|
|
Packit Service |
1d8f1c |
m_toplevel.resize(1, 1);
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
if (m_candidate_area.get_visible() ||
|
|
Packit Service |
1d8f1c |
m_preedit_label.get_visible() ||
|
|
Packit Service |
1d8f1c |
m_aux_label.get_visible())
|
|
Packit Service |
1d8f1c |
m_toplevel.show();
|
|
Packit Service |
1d8f1c |
else
|
|
Packit Service |
1d8f1c |
m_toplevel.hide();
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
if (m_aux_label.get_visible() &&
|
|
Packit Service |
1d8f1c |
(m_candidate_area.get_visible() || m_preedit_label.get_visible()))
|
|
Packit Service |
1d8f1c |
m_hseparator.show();
|
|
Packit Service |
1d8f1c |
else
|
|
Packit Service |
1d8f1c |
m_hseparator.hide();
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
private void create_ui() {
|
|
Packit Service |
1d8f1c |
m_preedit_label = new Gtk.Label(null);
|
|
Packit Service |
1d8f1c |
m_preedit_label.set_size_request(20, -1);
|
|
Packit Service |
1d8f1c |
m_preedit_label.set_halign(Gtk.Align.START);
|
|
Packit Service |
1d8f1c |
m_preedit_label.set_valign(Gtk.Align.CENTER);
|
|
Packit Service |
1d8f1c |
/* Use Gtk.Widget.set_margin_start() since gtk 3.12 */
|
|
Packit Service |
1d8f1c |
m_preedit_label.set_padding(8, 0);
|
|
Packit Service |
1d8f1c |
m_preedit_label.set_no_show_all(true);
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
m_aux_label = new Gtk.Label(null);
|
|
Packit Service |
1d8f1c |
m_aux_label.set_size_request(20, -1);
|
|
Packit Service |
1d8f1c |
m_aux_label.set_halign(Gtk.Align.START);
|
|
Packit Service |
1d8f1c |
m_aux_label.set_valign(Gtk.Align.CENTER);
|
|
Packit Service |
1d8f1c |
/* Use Gtk.Widget.set_margin_start() since gtk 3.12 */
|
|
Packit Service |
1d8f1c |
m_aux_label.set_padding(8, 0);
|
|
Packit Service |
1d8f1c |
m_aux_label.set_no_show_all(true);
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
m_candidate_area = new CandidateArea(m_vertical_panel_system);
|
|
Packit Service |
1d8f1c |
m_candidate_area.candidate_clicked.connect(
|
|
Packit Service |
1d8f1c |
(w, i, b, s) => candidate_clicked(i, b, s));
|
|
Packit Service |
1d8f1c |
m_candidate_area.page_up.connect((c) => page_up());
|
|
Packit Service |
1d8f1c |
m_candidate_area.page_down.connect((c) => page_down());
|
|
Packit Service |
1d8f1c |
m_candidate_area.cursor_up.connect((c) => cursor_up());
|
|
Packit Service |
1d8f1c |
m_candidate_area.cursor_down.connect((c) => cursor_down());
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
m_hseparator = new HSeparator();
|
|
Packit Service |
1d8f1c |
m_hseparator.set_visible(true);
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
pack_all_widgets();
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
private void pack_all_widgets() {
|
|
Packit Service |
1d8f1c |
m_vbox.pack_start(m_preedit_label, false, false, 4);
|
|
Packit Service |
1d8f1c |
m_vbox.pack_start(m_aux_label, false, false, 4);
|
|
Packit Service |
1d8f1c |
m_vbox.pack_start(m_hseparator, false, false, 0);
|
|
Packit Service |
1d8f1c |
m_vbox.pack_start(m_candidate_area, false, false, 0);
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
public new void show() {
|
|
Packit Service |
1d8f1c |
m_toplevel.show_all();
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
public new void hide() {
|
|
Packit Service |
1d8f1c |
m_toplevel.hide();
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
private void move(int x, int y) {
|
|
Packit Service |
1d8f1c |
m_toplevel.move(x, y);
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
private void adjust_window_position() {
|
|
Packit Service |
1d8f1c |
if (!m_vertical_writing)
|
|
Packit Service |
1d8f1c |
adjust_window_position_horizontal();
|
|
Packit Service |
1d8f1c |
else
|
|
Packit Service |
1d8f1c |
adjust_window_position_vertical();
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
private Gdk.Rectangle get_monitor_geometry() {
|
|
Packit Service |
1d8f1c |
Gdk.Rectangle monitor_area = { 0, };
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
// Use get_monitor_geometry() instead of get_monitor_area().
|
|
Packit Service |
1d8f1c |
// get_monitor_area() excludes docks, but the lookup window should be
|
|
Packit Service |
1d8f1c |
// shown over them.
|
|
Packit Service |
1d8f1c |
#if VALA_0_34
|
|
Packit Service |
1d8f1c |
Gdk.Monitor monitor = Gdk.Display.get_default().get_monitor_at_point(
|
|
Packit Service |
1d8f1c |
m_cursor_location.x,
|
|
Packit Service |
1d8f1c |
m_cursor_location.y);
|
|
Packit Service |
1d8f1c |
monitor_area = monitor.get_geometry();
|
|
Packit Service |
1d8f1c |
#else
|
|
Packit Service |
1d8f1c |
Gdk.Screen screen = Gdk.Screen.get_default();
|
|
Packit Service |
1d8f1c |
int monitor_num = screen.get_monitor_at_point(m_cursor_location.x,
|
|
Packit Service |
1d8f1c |
m_cursor_location.y);
|
|
Packit Service |
1d8f1c |
screen.get_monitor_geometry(monitor_num, out monitor_area);
|
|
Packit Service |
1d8f1c |
#endif
|
|
Packit Service |
1d8f1c |
return monitor_area;
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
private void adjust_window_position_horizontal() {
|
|
Packit Service |
1d8f1c |
Gdk.Point cursor_right_bottom = {
|
|
Packit Service |
1d8f1c |
m_cursor_location.x,
|
|
Packit Service |
1d8f1c |
m_cursor_location.y + m_cursor_location.height
|
|
Packit Service |
1d8f1c |
};
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
Gtk.Allocation allocation;
|
|
Packit Service |
1d8f1c |
m_toplevel.get_allocation(out allocation);
|
|
Packit Service |
1d8f1c |
Gdk.Point window_right_bottom = {
|
|
Packit Service |
1d8f1c |
cursor_right_bottom.x + allocation.width,
|
|
Packit Service |
1d8f1c |
cursor_right_bottom.y + allocation.height
|
|
Packit Service |
1d8f1c |
};
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
Gdk.Rectangle monitor_area = get_monitor_geometry();
|
|
Packit Service |
1d8f1c |
int monitor_right = monitor_area.x + monitor_area.width;
|
|
Packit Service |
1d8f1c |
int monitor_bottom = monitor_area.y + monitor_area.height;
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
int x, y;
|
|
Packit Service |
1d8f1c |
if (window_right_bottom.x > monitor_right)
|
|
Packit Service |
1d8f1c |
x = monitor_right - allocation.width;
|
|
Packit Service |
1d8f1c |
else
|
|
Packit Service |
1d8f1c |
x = cursor_right_bottom.x;
|
|
Packit Service |
1d8f1c |
if (x < 0)
|
|
Packit Service |
1d8f1c |
x = 0;
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
if (window_right_bottom.y > monitor_bottom)
|
|
Packit Service |
1d8f1c |
y = m_cursor_location.y - allocation.height;
|
|
Packit Service |
1d8f1c |
else
|
|
Packit Service |
1d8f1c |
y = cursor_right_bottom.y;
|
|
Packit Service |
1d8f1c |
if (y < 0)
|
|
Packit Service |
1d8f1c |
y = 0;
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
move(x, y);
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
private void adjust_window_position_vertical() {
|
|
Packit Service |
1d8f1c |
/* Not sure in which top or left cursor appears
|
|
Packit Service |
1d8f1c |
* in the vertical writing mode.
|
|
Packit Service |
1d8f1c |
* Max (m_cursor_location.width, m_cursor_location.height)
|
|
Packit Service |
1d8f1c |
* can be considered as a char size.
|
|
Packit Service |
1d8f1c |
*/
|
|
Packit Service |
1d8f1c |
int char_size = int.max(m_cursor_location.width,
|
|
Packit Service |
1d8f1c |
m_cursor_location.height);
|
|
Packit Service |
1d8f1c |
Gdk.Point cursor_right_bottom = {
|
|
Packit Service |
1d8f1c |
m_cursor_location.x + char_size,
|
|
Packit Service |
1d8f1c |
m_cursor_location.y + char_size
|
|
Packit Service |
1d8f1c |
};
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
Gtk.Allocation allocation;
|
|
Packit Service |
1d8f1c |
m_toplevel.get_allocation(out allocation);
|
|
Packit Service |
1d8f1c |
Gdk.Point hwindow_right_bottom = {
|
|
Packit Service |
1d8f1c |
m_cursor_location.x + allocation.width,
|
|
Packit Service |
1d8f1c |
cursor_right_bottom.y + allocation.height
|
|
Packit Service |
1d8f1c |
};
|
|
Packit Service |
1d8f1c |
Gdk.Point vwindow_left_bottom = {
|
|
Packit Service |
1d8f1c |
m_cursor_location.x - allocation.width,
|
|
Packit Service |
1d8f1c |
m_cursor_location.y + allocation.height
|
|
Packit Service |
1d8f1c |
};
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
Gdk.Rectangle monitor_area = get_monitor_geometry();
|
|
Packit Service |
1d8f1c |
int monitor_right = monitor_area.x + monitor_area.width;
|
|
Packit Service |
1d8f1c |
int monitor_bottom = monitor_area.y + monitor_area.height;
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
int x, y;
|
|
Packit Service |
1d8f1c |
if (!m_candidate_area.get_vertical()) {
|
|
Packit Service |
1d8f1c |
if (hwindow_right_bottom.x > monitor_right)
|
|
Packit Service |
1d8f1c |
x = monitor_right - allocation.width;
|
|
Packit Service |
1d8f1c |
else
|
|
Packit Service |
1d8f1c |
x = m_cursor_location.x;
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
if (hwindow_right_bottom.y > monitor_bottom)
|
|
Packit Service |
1d8f1c |
y = m_cursor_location.y - allocation.height;
|
|
Packit Service |
1d8f1c |
else
|
|
Packit Service |
1d8f1c |
y = cursor_right_bottom.y;
|
|
Packit Service |
1d8f1c |
} else {
|
|
Packit Service |
1d8f1c |
if (vwindow_left_bottom.x > monitor_right)
|
|
Packit Service |
1d8f1c |
x = monitor_right - allocation.width;
|
|
Packit Service |
1d8f1c |
else if (vwindow_left_bottom.x < 0)
|
|
Packit Service |
1d8f1c |
x = cursor_right_bottom.x;
|
|
Packit Service |
1d8f1c |
else
|
|
Packit Service |
1d8f1c |
x = vwindow_left_bottom.x;
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
if (vwindow_left_bottom.y > monitor_bottom)
|
|
Packit Service |
1d8f1c |
y = monitor_bottom - allocation.height;
|
|
Packit Service |
1d8f1c |
else
|
|
Packit Service |
1d8f1c |
y = m_cursor_location.y;
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
if (x < 0)
|
|
Packit Service |
1d8f1c |
x = 0;
|
|
Packit Service |
1d8f1c |
if (y < 0)
|
|
Packit Service |
1d8f1c |
y = 0;
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
move(x, y);
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
}
|