Class: Volay::Widget::SystemTray

Inherits:
Events
  • Object
show all
Defined in:
lib/volay/widget/system_tray.rb

Overview

Events class

Constant Summary collapse

LEFT_CLICK =
1
RIGHT_CLICK =
3

Instance Attribute Summary

Attributes inherited from Events

#app

Instance Method Summary collapse

Methods inherited from Events

#initialize

Constructor Details

This class inherits a constructor from Volay::Widget::Events

Instance Method Details

#get_position(window) ⇒ Object

Retrieve the good position to be above the status icon

Parameters:

  • window (Gtk::Window)

    Window



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/volay/widget/system_tray.rb', line 60

def get_position(window)
  screen, rectangle, orientation = @app.get_object('status_icon').geometry
  window.set_screen(screen)
  monitor_num = screen.get_monitor_at_point(rectangle.x, rectangle.y)
  monitor = screen.get_monitor_geometry(monitor_num)
  window_width, window_height = window.size

  if orientation == Gtk::Orientation::VERTICAL
    if monitor.width - rectangle.x == rectangle.width
      # right panel
      posx = monitor.x + monitor.width - window_width - rectangle.width
    else
      # left panel
      posx = rectangle.x + rectangle.width
      posy = rectangle.y
    end
  else
    if (rectangle.y + rectangle.height + window_height <=
        monitor.y + monitor.height)
      posy = rectangle.y + rectangle.height
    else
      posy = rectangle.y - window_height
      if (rectangle.x + window_width <= monitor.x + monitor.width)
        posx = rectangle.x
      else
        posx = monitor.x + monitor.width - window_width
      end
    end
  end

  [posx, posy]
end

#on_popup_menu_quit_activateObject

When quit button is clicked



50
51
52
# File 'lib/volay/widget/system_tray.rb', line 50

def on_popup_menu_quit_activate
  Gtk.main_quit
end

#on_status_icon_button_press_event(_widget, event) ⇒ Object

When left click on the status icon, popup the window menu

Parameters:

  • widget (Gtk::Widget)

    Widget

  • event (Gtk::Event)

    Event



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/volay/widget/system_tray.rb', line 16

def on_status_icon_button_press_event(_widget, event)
  return unless event.is_a?(Gdk::EventButton) &&
                event.button == LEFT_CLICK
  return on_system_tray_window_focus_out_event if
    @app.get_object('system_tray_window').visible?

  window = @app.get_object('system_tray_window')
  posx, posy = get_position(window)
  window.move(posx, posy)
  @app.get_object('system_tray_window').show_all
end

#on_status_icon_popup_menu(_widget, _event, time) ⇒ Object

When right click on the status icon

Parameters:

  • widget (Gtk::Widget)

    Widget

  • event (Gtk::Event)

    Event

  • time (Integer)

    Time



41
42
43
44
45
# File 'lib/volay/widget/system_tray.rb', line 41

def on_status_icon_popup_menu(_widget, _event, time)
  popup_menu = @app.get_object('popup_menu')
  popup_menu.show_all
  popup_menu.popup(nil, nil, 0, time)
end

#on_system_tray_window_focus_out_eventObject

When click outside the window



31
32
33
# File 'lib/volay/widget/system_tray.rb', line 31

def on_system_tray_window_focus_out_event
  @app.get_object('system_tray_window').hide
end