From 9d431a14cfb4a08a3df6ec04cf0c6fe3c64b65f8 Mon Sep 17 00:00:00 2001 From: moguno Date: Sun, 1 Sep 2013 00:22:24 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=AD=E3=83=B3=E3=82=B0=E3=83=97=E3=83=AC=E3=82?= =?UTF-8?q?=B9=E3=81=AB=E5=AF=BE=E5=BF=9C=E3=81=97=E3=81=9F=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/mui/cairo_cell_renderer_message.rb | 11 ++++++ core/mui/gtk_extension.rb | 58 ++++++++++++++++++++++++++----- core/mui/gtk_keyconfig.rb | 10 ++++++ 3 files changed, 71 insertions(+), 8 deletions(-) diff --git a/core/mui/cairo_cell_renderer_message.rb b/core/mui/cairo_cell_renderer_message.rb index 95dc6c3..c328358 100644 --- a/core/mui/cairo_cell_renderer_message.rb +++ b/core/mui/cairo_cell_renderer_message.rb @@ -155,6 +155,8 @@ module Gtk end def event_hooks + @long_press ||= ::Gtk::LongPressHelper.new + last_pressed = nil ssc(:click, @tree){ |r, e, path, column, cell_x, cell_y| record = @tree.get_record(path) @@ -166,11 +168,20 @@ module Gtk last_pressed = record.miracle_painter if e.button == 1 last_pressed.pressed(cell_x, cell_y) end + + @long_press.button_pressed { + Delayer.new(:ui_response) { + Plugin::GUI.keypress(::Gtk::buttonname([:long_press, e.button, e.state]), @tree.imaginary) + } + } + Delayer.new(:ui_response) { Plugin::GUI.keypress(::Gtk::buttonname([e.event_type, e.button, e.state]), @tree.imaginary) } end false } ssc(:button_release_event, @tree){ |r, e, path, column, cell_x, cell_y| + @long_press.button_released + if e.button == 1 and last_pressed record = @tree.get_record(path) if record diff --git a/core/mui/gtk_extension.rb b/core/mui/gtk_extension.rb index 9716c95..1da2a45 100644 --- a/core/mui/gtk_extension.rb +++ b/core/mui/gtk_extension.rb @@ -83,17 +83,57 @@ module Gtk r << 'Super + ' if (state & Gdk::Window::SUPER_MASK) != 0 r << 'Hyper + ' if (state & Gdk::Window::HYPER_MASK) != 0 r << "Button #{button} " - case type - when Gdk::Event::BUTTON_PRESS - r << 'Click' - when Gdk::Event::BUTTON2_PRESS - r << 'Double Click' - when Gdk::Event::BUTTON3_PRESS - r << 'Triple Click' + + t = nil + + if type.is_a?(Symbol) + case type + when :long_press + t = 'Long Press' + end + else + case type + when Gdk::Event::BUTTON_PRESS + t = 'Click' + when Gdk::Event::BUTTON2_PRESS + t = 'Double Click' + when Gdk::Event::BUTTON3_PRESS + t = 'Triple Click' + end + end + + if t + r << t + return r else return '(割り当てなし)' end - return r end end + end end + + class LongPressHelper + PRESS_TIME = 0.5 + + @long_pressing = nil + + def button_pressed(&proc) + button_released + atomic do + @long_pressing = Thread.new { + sleep PRESS_TIME + proc.call + } + end + end + + def button_released + atomic do + if @long_pressing + @long_pressing.kill + @long_pressing = nil + end + end + end + end end =begin rdoc @@ -259,6 +299,8 @@ module Gtk end end + + module MUI Skin = ::Skin end diff --git a/core/mui/gtk_keyconfig.rb b/core/mui/gtk_keyconfig.rb index 268de84..a314794 100644 --- a/core/mui/gtk_keyconfig.rb +++ b/core/mui/gtk_keyconfig.rb @@ -17,6 +17,7 @@ class Gtk::KeyConfig < Gtk::Button @change_hook = nil super(*args) self.add(buttonlabel) + @long_press = ::Gtk::LongPressHelper.new self.signal_connect('clicked', &method(:clicked_event)) end @@ -44,6 +45,7 @@ class Gtk::KeyConfig < Gtk::Button box.pack_start(button) button.signal_connect(:key_press_event, &key_set(label)) button.signal_connect(:button_press_event, &button_set(label)) + button.signal_connect(:button_release_event) { @long_press.button_released } dialog.vbox.add(box) dialog.show_all dialog.run @@ -59,6 +61,14 @@ class Gtk::KeyConfig < Gtk::Button def button_set(label) lambda{ |widget, event| + @long_press.button_pressed { + Delayer.new(:ui_response) { + self.keycode = Gtk.buttonname([:long_press, event.button, event.state]) + buttonlabel.text = label.text = keycode + self.change_hook.call(keycode) if self.change_hook + } + } + self.keycode = Gtk.buttonname([event.event_type, event.button, event.state]) buttonlabel.text = label.text = keycode self.change_hook.call(keycode) if self.change_hook -- 1.7.10.2 (Apple Git-33)