Last active
March 14, 2017 14:44
-
-
Save tarao/028b5b01906f8db0f5fe8164b869eed2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'fiddle/import' | |
require 'shellwords' | |
Libuim = `/sbin/ldconfig -p`.split(/[\r\n]/).map do |line| | |
line.strip.split(/\s+/)[0] | |
end.find do |line| | |
line =~ /\Alibuim[.]so[.][0-9]+\z/ | |
end | |
module UIM | |
extend Fiddle::Importer | |
dlload Libuim | |
extern 'int uim_helper_init_client_fd(void*)' | |
extern 'void uim_helper_close_client_fd(int)' | |
extern 'void uim_helper_send_message(int, char*)' | |
def self.connect() | |
Helper.new | |
end | |
def self.on() | |
scheme_exp = %q{ | |
(or (and custom-activate-default-im-name? default-im-name) | |
(and enable-im-toggle? toggle-im-alt-im) | |
(car enabled-im-list)) | |
} | |
im_name = %x{ uim-sh -e #{scheme_exp.shellescape} } | |
puts im_name | |
Helper.new.im_change_whole_desktop(im_name).close() | |
end | |
def self.off() | |
Helper.new.im_change_whole_desktop('direct').close() | |
end | |
class Helper | |
def initialize() | |
@fd = UIM.uim_helper_init_client_fd(nil) | |
end | |
def close() | |
UIM.uim_helper_close_client_fd(@fd) | |
return self | |
end | |
def send_message(str) | |
UIM.uim_helper_send_message(@fd, str) | |
return self | |
end | |
def im_change_whole_desktop(im_name) | |
send_message("im_change_whole_desktop\n#{im_name}\n") | |
return self | |
end | |
end | |
end | |
case ARGV[0] | |
when 'on' then | |
UIM.on() | |
when 'off' then | |
UIM.off() | |
else | |
puts("#{File.basename($0)} {on|off}") | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment