conquer-dzen 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8a955af97495e65642ac3d57a421a2b7b1b98734
4
- data.tar.gz: 70f07a3cfdb533f7dffe83809ff9c3e279be1604
3
+ metadata.gz: f305b9b87b16a67532e4b46cf7de063bdbab24c9
4
+ data.tar.gz: 1b1197177d069587a8b85cc579f463553bd14953
5
5
  SHA512:
6
- metadata.gz: 9d6b53355f7a3b65892c5b5d80e4fab91ad630003350e205c04bbe04dfaf0cc5a6bbf116e1c4322981371387c92205938a56cd04c702c333f8d4e1b219ec8c0e
7
- data.tar.gz: 46215af95e50b82b5398377ef2779a6ff43f11f3261debbbbf87a7b76a66acd37e444f8ed28501c6e591bc332cb1a17c1e6cc311b3cc74f4ecbb13f80bcf91ca
6
+ metadata.gz: 10962e1f4b4b1b48213ee608c93bd244bae611d9ac675b4f4c4d844abb4a473c7a74d2cc2b5dd71603384873df544e5fd9bbb92b51a075855f3013cf7df686b3
7
+ data.tar.gz: a98ca3c54381f41541fcab9066b536cd18ca9494e7834f9da80bcedce8c0acc681cbe2710259268213f4313b7bdebcf9761c338304035d8def47a2f61355e448
@@ -1,11 +1,15 @@
1
1
  require 'celluloid/current'
2
+ require 'conquer/dzen/positioning'
2
3
 
3
4
  module Conquer
4
5
  module Dzen
5
6
  module Interaction
6
7
  class TooltipListener
8
+ MARGIN = 5
9
+
7
10
  include Celluloid
8
11
  include Celluloid::Notifications
12
+ include Positioning
9
13
 
10
14
  def initialize
11
15
  @current_tooltip = nil
@@ -13,24 +17,37 @@ module Conquer
13
17
  end
14
18
 
15
19
  def show_tooltip(_, title, text, width = 150)
16
- Process.kill('TERM', @current_tooltip) if @current_tooltip
20
+ Process.kill('TERM', @current_tooltip.pid) if @current_tooltip
21
+ lines = text.lines.map { |line| shift(MARGIN) { line } }
22
+ mouse = mouse_location
23
+ dzen_command = dzen_command(mouse, lines.size, width + 2 * MARGIN)
24
+ async.run_dzen(dzen_command, title, lines.join)
25
+ end
17
26
 
18
- lines = text.lines.size
19
- mouse = `xdotool getmouselocation`.match(
20
- /^x:(?<x>\d+) y:(?<y>\d+) screen:(?<screen>\d+)/
21
- )
22
- dzen_command = [
23
- 'dzen2', '-x', mouse[:x], '-y', mouse[:y], '-l', lines.to_s,
27
+ private
28
+
29
+ def dzen_command(mouse, line_count, width)
30
+ [
31
+ 'dzen2', '-x', mouse[:x], '-y', mouse[:y], '-l', line_count.to_s,
24
32
  '-w', width.to_s, '-e', 'onstart=uncollapse;button1=exit',
25
33
  '-xs', mouse[:screen]
26
34
  ]
27
- pipe = ::IO.popen(dzen_command, 'w+')
28
- @current_tooltip = pipe.pid
35
+ end
36
+
37
+ def run_dzen(dzen_command, title, text)
38
+ ::IO.popen(dzen_command, 'w+') do |pipe|
39
+ @current_tooltip = pipe
40
+ pipe.puts title
41
+ pipe.puts text
42
+ pipe.flush
43
+ loop { sleep(100) }
44
+ end
45
+ end
29
46
 
30
- pipe.puts title
31
- pipe.puts text
32
- pipe.flush
33
- pipe.pid
47
+ def mouse_location
48
+ `xdotool getmouselocation`.match(
49
+ /^x:(?<x>\d+) y:(?<y>\d+) screen:(?<screen>\d+)/
50
+ )
34
51
  end
35
52
  end
36
53
  end
@@ -1,5 +1,5 @@
1
1
  module Conquer
2
2
  module Dzen
3
- VERSION = '0.1.2'.freeze
3
+ VERSION = '0.1.3'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: conquer-dzen
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joakim Reinert