class Rabbit::Frame
Attributes
Public Class Methods
Source
# File lib/rabbit/frame.rb, line 53 def initialize(canvas) @canvas = canvas @geometry = nil @stack = nil @terminal = nil @running = true end
Public Instance Methods
Source
# File lib/rabbit/frame.rb, line 61 def destroyed? @window.nil? or @window.destroyed? end
Source
# File lib/rabbit/frame.rb, line 121 def fullscreen_available? true end
Source
# File lib/rabbit/frame.rb, line 142 def in_terminal? return false if @terminal.nil? @stack.visible_child_name == "terminal" end
Source
# File lib/rabbit/frame.rb, line 112 def init_gui(width, height, main_window, window_type=nil) init_window(width, height, window_type) @fullscreen = false @main_window = main_window @terminal.show if @terminal @stack.show if @stack @canvas.post_init_gui end
Source
# File lib/rabbit/frame.rb, line 80 def parse(source, callback=nil, &block) @canvas.parse(source, callback, &block) end
Source
# File lib/rabbit/frame.rb, line 65 def quit @running = false @window.destroy unless destroyed? @window = nil true end
Source
# File lib/rabbit/frame.rb, line 92 def toggle_fullscreen if fullscreen? unfullscreen else fullscreen end end
Source
# File lib/rabbit/frame.rb, line 129 def toggle_terminal return if @terminal.nil? if @stack.visible_child_name == "terminal" if @stack.respond_to?(:pages) @stack.visible_child = @stack.pages[0].child else @stack.visible_child = @stack.children[0] end else @stack.visible_child_name = "terminal" end end
Source
# File lib/rabbit/frame.rb, line 88 def unfullscreen @window.unfullscreen end
Source
# File lib/rabbit/frame.rb, line 108 def update_title(new_title) @window.title = Utils.unescape_title(new_title) end
Private Instance Methods
Source
# File lib/rabbit/frame.rb, line 227 def init_stack @stack = Gtk::Stack.new if Gtk::StackTransitionType.const_defined?(:ROTATE_LEFT_RIGHT) @stack.transition_type = :rotate_left_right else @stack.transition_type = :slide_left_right end @window.child = @stack end
Source
# File lib/rabbit/frame.rb, line 264 def init_terminal @terminal = Vte::Terminal.new # TODO: Support theme terminal_font_description = ENV["RABBIT_TERMINAL_FONT_DESCRIPTION"] if terminal_font_description @terminal.font_desc = Pango::FontDescription.new(terminal_font_description) end terminal_color_foreground = ENV["RABBIT_TERMINAL_COLOR_FOREGROUND"] if terminal_color_foreground @terminal.color_foreground = terminal_color_foreground end terminal_color_background = ENV["RABBIT_TERMINAL_COLOR_BACKGROUND"] if terminal_color_background @terminal.color_background = terminal_color_background end @terminal.enable_sixel = true if @terminal.respond_to?(:enable_sixel=) @stack.add_named(@terminal, "terminal") pid = nil in_terminal = false @stack.signal_connect("notify::visible-child-name") do |_, param| if @stack.visible_child_name == "terminal" if @running pid = @terminal.spawn if pid.nil? @canvas.pre_terminal unless in_terminal in_terminal = true end else @canvas.post_terminal if in_terminal in_terminal = false end end @terminal.signal_connect(:child_exited) do pid = nil if @stack.visible_child_name == "terminal" @canvas.activate("ToggleTerminal") end end end
Source
# File lib/rabbit/frame.rb, line 148 def init_window(width, height, window_type=nil) window_type ||= :toplevel @window = Gtk::ApplicationWindow.new(::Rabbit.application) @window.set_default_size(width, height) @window.parse_geometry(@geometry) if @geometry init_stack set_window_signal_destroy setup_dnd @window.show # @window.surface is only available after @window.show. if Gtk::Version::MAJOR < 4 @window.signal_connect(:configure_event) do |_, event| GLib::Idle.add do width = @stack.allocated_width height = @stack.allocated_height @canvas.renderer.update_size(width, height) GLib::Source::REMOVE end false end @window.signal_connect(:window_state_event) do |widget, event| if event.changed_mask.fullscreen? @fullscreen = event.new_window_state.fullscreen? if @fullscreen @canvas.fullscreened else @canvas.unfullscreened end elsif event.changed_mask.iconified? if event.new_window_state.iconified? @canvas.iconified end end false end else previous_width = nil previous_height = nil previous_fullscreen = @fullscreen = @window.fullscreen? previous_minimized = false @surface = @window.surface # This is to guard from GC. @surface.signal_connect(:notify) do |surface, param| case param.name when "width", "height" GLib::Idle.add do width = @stack.width height = @stack.height if previous_width != width or previous_height != height @canvas.renderer.update_size(width, height) previous_width = width previous_height = height end GLib::Source::REMOVE end when "state" state = surface.state @canvas.reload_source if state.focused? fullscreen = state.fullscreen? if previous_fullscreen != fullscreen @fullscreen = fullscreen if @fullscreen @canvas.fullscreened else @canvas.unfullscreened end previous_fullscreen = @fullscreen end minimized = state.minimized? if previous_minimized != minimized @canvas.iconified if minimized previous_minimized = minimized end end end end @canvas.attach_to(self, @window, @stack) init_terminal if defined?(Vte::Terminal) end
Source
# File lib/rabbit/frame.rb, line 237 def set_window_signal_destroy @window.signal_connect("destroy") do @canvas.detach end end
Source
# File lib/rabbit/frame.rb, line 243 def setup_dnd return if Gtk::Version::MAJOR >= 4 # TODO @window.drag_dest_set(:all, [["text/uri-list", 0, 0], ["_NETSCAPE_URL", 0, 0]], :copy) @window.signal_connect("drag-data-received") do |*args| widget, context, x, y, selection_data, info, time = args uri = selection_data.data.chomp Gtk.idle_add do parse(Source::URI.new(nil, uri)) false end Gtk::Drag.finish(context, true, false, time) end @window.signal_connect("drag-drop") do |widget, context, x, y, time| true end end