Skip to content

Commit

Permalink
add support for X input method (#691)
Browse files Browse the repository at this point in the history
  • Loading branch information
Determinant authored and jwilm committed Jul 25, 2017
1 parent 49c73f6 commit 4c4c2f5
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,4 +331,18 @@ impl Display {
pub fn get_window_id(&self) -> Option<usize> {
self.window.get_window_id()
}

/// Adjust the XIM editor position according to the new location of the cursor
pub fn update_ime_position(&mut self, terminal: &Term) {
use index::{Point, Line, Column};
use term::SizeInfo;
let Point{line: Line(row), col: Column(col)} = terminal.cursor().point;
let SizeInfo{cell_width: cw,
cell_height: ch,
padding_x: px,
padding_y: py, ..} = *terminal.size_info();
let nspot_y = (py + (row + 1) as f32 * ch) as i16;
let nspot_x = (px + col as f32 * cw) as i16;
self.window().send_xim_spot(nspot_x, nspot_y);
}
}
2 changes: 2 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ fn run(mut config: Config, options: cli::Options) -> Result<(), Box<Error>> {

// Maybe draw the terminal
if terminal.needs_draw() {
// Try to update the position of the input method editor
display.update_ime_position(&terminal);
// Handle pending resize events
//
// The second argument is a list of types that want to be notified
Expand Down
7 changes: 6 additions & 1 deletion src/term/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ impl IndexMut<CharsetIndex> for Charsets {
#[derive(Default, Copy, Clone)]
pub struct Cursor {
/// The location of this cursor
point: Point,
pub point: Point,

/// Template cell when using this cursor
template: Cell,
Expand Down Expand Up @@ -1054,6 +1054,11 @@ impl Term {
&self.mode
}

#[inline]
pub fn cursor(&self) -> &Cursor {
&self.cursor
}

pub fn swap_alt(&mut self) {
if self.alt {
let template = self.empty_cell;
Expand Down
32 changes: 32 additions & 0 deletions src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ impl Window {
title: &str
) -> Result<Window> {
let event_loop = EventsLoop::new();

Window::platform_window_init();
let window = WindowBuilder::new()
.with_title(title);
let context = ContextBuilder::new()
Expand Down Expand Up @@ -282,6 +284,36 @@ impl Window {
}
}

#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "dragonfly", target_os = "openbsd"))]
pub fn platform_window_init() {
/// Set up env to make XIM work correctly
use x11_dl::xlib;
use libc::{setlocale, LC_CTYPE};
let xlib = xlib::Xlib::open().expect("get xlib");
unsafe {
/// Use empty c string to fallback to LC_CTYPE in environment variables
setlocale(LC_CTYPE, b"\0".as_ptr() as *const _);
/// Use empty c string for implementation dependent behavior,
/// which might be the XMODIFIERS set in env
(xlib.XSetLocaleModifiers)(b"\0".as_ptr() as *const _);
}
}

/// TODO: change this directive when adding functions for other platforms
#[cfg(not(any(target_os = "linux", target_os = "freebsd", target_os = "dragonfly", target_os = "openbsd")))]
pub fn platform_window_init() {
}

#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "dragonfly", target_os = "openbsd"))]
pub fn send_xim_spot(&self, x: i16, y: i16) {
use glutin::os::unix::WindowExt;
self.window.send_xim_spot(x, y);
}

#[cfg(not(any(target_os = "linux", target_os = "freebsd", target_os = "dragonfly", target_os = "openbsd")))]
pub fn send_xim_spot(&self, x: i16, y: i16) {
}

#[cfg(not(target_os = "macos"))]
pub fn get_window_id(&self) -> Option<usize> {
use glutin::os::unix::WindowExt;
Expand Down

4 comments on commit 4c4c2f5

@Mic92
Copy link
Contributor

@Mic92 Mic92 commented on 4c4c2f5 Jul 25, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit breaks the build on nixos:
cc @Determinant

these derivations will be built:
  /nix/store/ygngr3nh9vjsggii1k4qja7i0j6fa2j5-alacritty-unstable-2017-07-25.drv
building path(s)
‘/nix/store/3zhadp0kxfkzxk8m55spfsdmc75j5q5q-alacritty-unstable-2017-07-25’
unpacking sources

unpacking source archive
/nix/store/4021a9dcrwvi5bbdv6sgq70n42zcc2xm-alacritty-4c4c2f5f5c81e6efb580e50ea993606160809469-src

source root is alacritty-4c4c2f5f5c81e6efb580e50ea993606160809469-src
Using cargo deps from
/nix/store/yc2ijzqqavp1chw9gxwwfy2prhdfs564-alacritty-unstable-2017-07-25-fetch
Using indexHash '-ba82b75dd6681d6f'
Using rust registry from
/nix/store/sdh30zc7q9pf5f8jm8gv16w74dmvyxyg-rustRegistry-2017-07-17
warning:

custom registry support via the `registry.index` configuration is being removed,
this functionality will not work in the future

warning:

custom registry support via the `registry.index` configuration is being removed,
this functionality will not work in the future



patching sources
Patching pkg-config registry dep

configuring


building
Running cargo build --release
warning: custom registry support via the `registry.index` configuration is being
removed, this functionality will not work in the future
warning: package replacement is not used:
https://github.com/rust-lang/crates.io-index#winit:0.7.5
   Compiling winapi-build v0.1.1 (registry file:///dev/null)
   Compiling unicode-width v0.1.4 (registry file:///dev/null)
   Compiling pkg-config v0.3.9 (registry file:///dev/null)
   Compiling khronos_api
 v1.0.1 (registry file:///dev/null)
   Compiling copypasta v0.0.1
(file:///tmp/nix-build-alacritty-unstable-2017-07-25.drv-0/alacritty-4c4c2f5f5c81e6efb580e50ea993606160809469-src/copypasta)
   Compiling bitflags v0.8.2 (registry file:///dev/null)
   Compiling ws2_32-sys v0.2.1 (registry file:///dev/null)
   Compiling rustc-serialize v0.3.24 (registry file:///dev/null)
   Compiling cfg-if v0.1.0 (registry file:///dev/null
)
   Compiling strsim v0.6.0 (registry file:///dev/null)
   Compiling siphasher v0.2.2 (registry file:///dev/null)

   Compiling linked-hash-map v0.3.0 (registry file:///dev/null)
   Compiling owning_ref v0.2.4 (registry file:///dev/null)
   Compiling kernel32-sys v0.2.2 (registry file:///dev/null)
   Compiling freetype-sys v0.4.0 (registry file:///dev/null)
   Compiling lazy_static v0.2.8 (registry file:///dev/null)
   Compiling xdg v2.1.0 (registry file:///dev/null)
   Compiling heapsize v0.3.9 (registry file:///dev/null)
   Compiling ansi_term v0.9.0 (registry file:///dev/null)
   Compiling libc v0.2.23 (registry file:///dev/null)
   Compiling bitflags v0.4.0 (registry file:///dev/null)

   Compiling semver v0.1.20 (registry file:///dev/null)
   Compiling errno v0.2.3 (registry file:///dev/null)
   Compiling rand v0.3.15 (registry file:///dev/null)
   Compiling inotify v0.2.3 (registry file:///dev/null)
   Compiling shared_library v0.1.5 (registry file:///dev/null)
   Compiling thread-id v3.1.0 (registry file:///dev/null)
   Compiling nix v0.5.1 (registry file:///dev/null)
   Compiling bitflags v0.7.0 (registry file:///dev/null)
   Compiling utf8parse v0.1.0 (registry file:///dev/null)
   Compiling slab v0.1.3 (registry file:///dev/null)
   Compiling num-traits v0.1.37 (registry file:///dev/null)
   Compiling winapi v0.2.8 (registry file:///dev/null)
   Compiling num-integer v0.1.34 (registry
file:///dev/null)
   Compiling unicode-xid v0.0.4 (registry file:///dev/null)
   Compiling synom v0.11.3 (registry file:///dev/null)
   Compiling servo-fontconfig-sys v2.11.3
(https://github.com/jwilm/libfontconfig#618a5297)

   Compiling dtoa v0.4.1 (registry file:///dev/null)
   Compiling slab v0.3.0 (registry file:///dev/null)
   Compiling num-bigint v0.1.37 (registry file:///dev/null)
   Compiling num-complex v0.1.37 (registry file:///dev/null)
   Compiling smallvec v0.4.0 (registry file:///dev/null)
   Compiling parking_lot_core v0.2.2 (registry file:///dev/null)

   Compiling log v0.3.8 (registry file:///dev/null)
   Compiling odds v0.2.25 (registry file:///dev/null
)
   Compiling vec_map v0.8.0 (registry file:///dev/null)
   Compiling rustc_version v0.1.7 (registry file:///dev/null)
   Compiling nodrop v0.1.9 (registry file:///dev/null)

   Compiling arraydeque v0.2.3 (registry file:///dev/null)
   Compiling fs2 v0.2.5 (registry file:///dev/null)

   Compiling walkdir v0.1.8 (registry file:///dev/null)
   Compiling memmap v0.4.0 (registry file:///dev/null)
   Compiling tempfile v2.1.5 (registry file:///dev/null)
   Compiling nix v0.7.0 (registry file:///dev/null)
   Compiling gcc v0.3.49 (registry file:///dev/null)
   Compiling num-rational v0.1.36 (registry file:///dev/null)
   Compiling void v1.0.2 (registry file:///dev/null)
   Compiling itoa v0.3.1 (registry file:///dev/null)
   Compiling parking_lot v0.3.8 (registry file:///dev/null)
   Compiling time v0.1.37 (registry file:///dev/null)
   Compiling phf_shared v0.7.21 (registry file:///dev/null)
   Compiling phf_generator v0.7.21 (registry file:///dev/null)
   Compiling phf_codegen v0.7.21 (registry file:///dev/null)
   Compiling phf v0.7.21 (registry file:///dev/null)
   Compiling target_build_utils v0.3.1 (registry file:///dev/null)
   Compiling fnv v1.0.5 (registry file:///dev/null)
   Compiling foreign-types v0.2.0 (registry file:///dev/null)
   Compiling xml-rs v0.3.6 (registry file:///dev/null)
   Compiling libz-sys v1.0.13 (registry file:///dev/null)
   Compiling cmake v0.1.24 (registry file:///dev/null)
   Compiling bytes v0.3.0 (registry file:///dev/null)
   Compiling expat-sys v2.1.4 (registry file:///dev/null)
   Compiling filetime v0.1.10 (registry file:///dev/null)
   Compiling net2 v0.2.29 (registry file:///dev/null)

   Compiling vte v0.3.1 (registry file:///dev/null)
   Compiling num-iter v0.1.33 (registry file:///dev/null)
   Compiling num v0.1.37 (registry
file:///dev/null)
   Compiling gl_generator v0.5.3 (registry file:///dev/null)
   Compiling wayland-scanner v0.9.9 (registry file:///dev/null)

   Compiling miow v0.1.5 (registry
file:///dev/null)
   Compiling mio v0.5.1 (registry file:///dev/null)

   Compiling wayland-client v0.9.9 (registry file:///dev/null)

   Compiling unicode-segmentation v1.2.0 (registry file:///dev/null)
   Compiling byteorder v1.0.0 (registry file:///dev/null)
   Compiling notify v2.6.3 (registry file:///dev/null)
   Compiling term_size v0.3.0 (registry file:///dev/null)
   Compiling x11-dl v2.14.0 (registry file:///dev/null)
   Compiling glutin v0.9.1 (registry file:///dev/null)
   Compiling alacritty v0.1.0
(file:///tmp/nix-build-alacritty-unstable-2017-07-25.drv-0/alacritty-4c4c2f5f5c81e6efb580e50ea993606160809469-src)
   Compiling osmesa-sys v0.1.2 (registry file:///dev/null)
   Compiling quote v0.3.15 (registry file:///dev/null)
   Compiling syn v0.11.11 (registry file:///dev/null)
   Compiling yaml-rust v0.3.5 (registry file:///dev/null)
   Compiling lazycell v0.4.0 (registry file:///dev/null)
   Compiling mio v0.6.2 (registry file:///dev/null)
   Compiling atty v0.2.2 (registry file:///dev/null)
   Compiling clap v2.24.2 (registry file:///dev/null)
   Compiling servo-fontconfig v0.2.0
(https://github.com/jwilm/rust-fontconfig#419135e5)
   Compiling freetype-rs v0.13.0 (registry file:///dev/null)
   Compiling cgmath v0.7.0 (registry file:///dev/null)
   Compiling serde v0.9.15 (registry file:///dev/null)
   Compiling serde_codegen_internals v0.14.2 (registry
file:///dev/null)
   Compiling serde_derive v0.9.15 (registry file:///dev/null)
   Compiling serde_json v0.9.10 (registry file:///dev/null)
   Compiling euclid
 v0.12.0 (registry file:///dev/null
)
   Compiling font v0.1.0
(file:///tmp/nix-build-alacritty-unstable-2017-07-25.drv-0/alacritty-4c4c2f5f5c81e6efb580e50ea993606160809469-src/font)
   Compiling serde_yaml v0.6.2 (registry file:///dev/null)

   Compiling libloading v0.3.4 (registry file:///dev/null)
   Compiling dlib v0.3.1 (registry file:///dev/null)
   Compiling wayland-sys v0.9.9 (registry file:///dev/null)
   Compiling wayland-kbd v0.9.1 (registry file:///dev/null)
   Compiling wayland-window v
0.6.1 (registry file:///dev/null)
   Compiling winit v0.7.5 (registry file:///dev/null)
error: no method named `send_xim_spot` found for type `glutin::GlWindow` in the
current scope
   --> src/window.rs:310:21
    |
310 |         self.window.send_xim_spot(x, y);
    |                     ^^^^^^^^^^^^^
error: aborting due to previous error
error:

Could not compile `alacritty`.


To learn more, run the command again with --verbose.


builder for
‘/nix/store/ygngr3nh9vjsggii1k4qja7i0j6fa2j5-alacritty-unstable-2017-07-25.drv’
failed with exit code 101
error: build of
‘/nix/store/ygngr3nh9vjsggii1k4qja7i0j6fa2j5-alacritty-unstable-2017-07-25.drv’
failed

@Determinant
Copy link
Contributor Author

@Determinant Determinant commented on 4c4c2f5 Jul 25, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Mic92 Sorry to hear that. But it looks quite strange because line 310 is conditional introduced by #[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "dragonfly", target_os = "openbsd"))]. Does nixos fall into any one of these categories? Also this directive was consistent with the directive in winit: https://github.com/tomaka/winit/blob/master/src/os/unix.rs#L1. What do you think, @jwilm ?

@Mic92
Copy link
Contributor

@Mic92 Mic92 commented on 4c4c2f5 Jul 25, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nixos is a linux distribution and rust detect it this as that properly.

@jwilm
Copy link
Contributor

@jwilm jwilm commented on 4c4c2f5 Jul 26, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably due to this:

warning: custom registry support via the `registry.index` configuration is being
removed, this functionality will not work in the future
warning: package replacement is not used:
https://github.com/rust-lang/crates.io-index#winit:0.7.5

Please sign in to comment.