~ubuntu-branches/ubuntu/precise/unity-2d/precise-security

« back to all changes in this revision

Viewing changes to tests/misc/lib/xdo/clipboard.rb

  • Committer: Package Import Robot
  • Author(s): Didier Roche, Didier Roche, Aurélien Gâteau
  • Date: 2012-01-13 09:12:36 UTC
  • mfrom: (1.1.25)
  • Revision ID: package-import@ubuntu.com-20120113091236-844z32uco10hs6ym
Tags: 5.2.0-0ubuntu1
[ Didier Roche ]
* New upstream release:
  - Select quicklist items with just one right click (LP: #688830)
  - Launcher - Dragging and dropping a running application in to the Trash
    should quit the application and (if the app is pinned to the Launcher)
    un-pin the application from the Launcher (LP: #870143)
  - Dash - "See more..." line should be base-aligned with section header
    (LP: #748101)
  - right click on the dash icon should display a list of the lenses
    (LP: #868452)
  - Top Bar - rename the "Desktop" title in the Top Bar (displayed when no
    window has focus)  to "Ubuntu Desktop" (LP: #869873)
  - Application title on quicklist should be bold (or more visible)
    (LP: #900400)
  - unity-2d-launcher crashed with SIGSEGV  when opening a folder on a CD
    (LP: #831868)
  - unity-2d-places crashed with SIGSEGV in QScriptValue::call()
    (LP: #836498)
  - unity-2d-launcher crashed with SIGSEGV in geis_finish() (LP: #850893)
  - unity-2d-places crashed with SIGABRT in raise() (LP: #857575)
  - unity-2d-launcher crashed with SIGSEGV in exit() (LP: #859596)
  - [spread] layout broken since bzr revision 799 of lp:unity-2d
    (LP: #900895)
  - [workspace switcher] keyboard navigation of workspace switcher broken
    for accessibility (LP: #744978)
  - [spread] workspace switcher performance is poor, especially on low
    powered CPUs (LP: #745764)
  - Launcher - the rendering of the BFB and Lens squircle does not match the
    design (LP: #838708)
  - [dash] Huge performance hit when scrolling search results with
    accessibility enabled (LP: #862956)
  - DBUS_STARTER_ADDRESS and DBUS_STARTER_BUS_TYPE aren't always unset from
    environment making gedit and possibly others fail to start (LP: #873027)
  - Win Key can not be disabled in Unity-2d (LP: #873580)
  - [dash] Unity-2d dash very slow to open (LP: #881756)
  - [tests] LauncherViewTest hanging (LP: #894380)
  - [tests] Unit tests failing due to lack of Xserver (LP: #894381)
  - [launcher] Alt+F1 broken: does not give the focus to the launcher's
    content (LP: #901505)
  - [tests] Add Automated User Experience testing (LP: #903495)
  - [workspace switcher] Performance can be poor when using the opengl
    backend because of window texture sizes that are not limited
    (LP: #808716)
  - [dash] no way to unmaximize (LP: #860400)
  - [launcher] In non-composite mode, background is black (LP: #879288)
  - [dash] Unity 2D shows 'Search' instead of 'Run Command' on ALT + F2
    (LP: #883392)
  - [launcher] Removing icon from launcher makes it hide immediately
    (LP: #884410)
  - OpenGL disabled regardless of use-opengl setting (LP: #887957)
  - if libdir does not equal lib (LP: #888164)
  - [launcher] Launcher stuck open while mouse moved to left corner of panel
    (LP: #892004)
  - [dash] Long results label are truncated instead of elided and a few
    pixels of the next line is visible (LP: #901491)
  - [launcher] Dash icon missing in PPA (LP: #903182)
  - [launcher] Tile context menu should appear at mouse click down event
    (LP: #813036)
  - [launcher] Trash tile highlight is truncated top and bottom
    (LP: #876589)
  - [dash] Text highlighting color is wrong (LP: #880222)
  - [launcher] left edge of panel should not reveal launcher (LP: #891636)
  - [dash] Word "Filter results" has underline when highlighted
    (LP: #893061)
  - [launcher] Alt+F1, change desktop, Alt+F1, hit Esc: launcher doesn't
    give away focus (LP: #897640)
  - Top Bar - rename the "Desktop" title in the Top Bar (displayed when no
    window has focus)  to "Ubuntu Desktop" (LP: #869873)
  - [launcher] Show desktop doesn't show launcher (LP: #898161)
  - [launcher] Context menu/tooltip not positioned at Tile center
    (LP: #898349)
  - The QT_LAYOUT_DIRECTION string needs a translator comment (LP: #863058)
  - unity panel menus don't stay open when clicked on second monitor
    (LP: #869196)
  - Dash- More fixes to layout and alignments (LP: #906235)
* debian/control:
  - bump libunitycore build-dep to 5.0.

[ Aurélien Gâteau ]
* debian/control:
  - bump build-dep versions.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#Encoding: UTF-8
 
2
#This file is part of Xdo. 
 
3
#Copyright © 2009, 2010 Marvin Gülker
 
4
#  Initia in potestate nostra sunt, de eventu fortuna iudicat. 
 
5
#
 
6
# Modified by Gerry Boland <gerry dot boland at canonical dot com> 
 
7
require File.join(File.dirname(__FILE__), '_xdo')
 
8
 
 
9
module XDo
 
10
  
 
11
  #A module for interaction with the X clipboard. Please note, that the X clipboard 
 
12
  #consists of three parts: The PRIMARY clipboard, the CLIPBOARD clipboard, and 
 
13
  #the SECONDARY clipboard. The clipboard you access normally via [CTRL]+[C] 
 
14
  #or by right-clicking and selecting "copy", is usually the CLIPBOARD clipboard (but that 
 
15
  #depends on the application you use). The three main methods of this module (#read, #write 
 
16
  #and #clear) take a list symbols of the clipboards to interact with. If you don't want to 
 
17
  #pass in the symbols, use the predefined read_xy, write_xy and clear_xy methods. They cannot 
 
18
  #access more than one clipboard at a time. 
 
19
  #The symbols for the clipboards are: 
 
20
  #[PRIMARY] :primary
 
21
  #[SECONDARY] :secondary
 
22
  #[CLIPBOARD] :clipboard
 
23
  #You cannot store complex objects like images via this interface, only strings. However, 
 
24
  #you could translate an image into a string (packed pixels maybe?) and put that on the 
 
25
  #clipboard -- for your own application this may be fine, but it won't magically allow 
 
26
  #a user to paste that image into a graphics program. 
 
27
  #
 
28
  #The +xsel+ program used by this module is quite outdated. As far as I can see, it's 
 
29
  #last update happened in 2002 and since I do not believe that software exists that 
 
30
  #won't break over a period of 8 years without a single modification while updating systems I'm about to 
 
31
  #switch to a newer one. +xclip+ is likely, but that one got it's last update in early 
 
32
  #2009... 
 
33
  module Clipboard
 
34
    
 
35
    class << self
 
36
      
 
37
      ##
 
38
      # :singleton-method: read_primary
 
39
      #Returns the contents of the PRIMARY clipboard. 
 
40
      #See #read for an explanation. 
 
41
      
 
42
      ##
 
43
      # :singleton-method: read_clipboard
 
44
      #Returns the contents of the CLIPBOARD clipboard. 
 
45
      #See #read for an explanation. 
 
46
      
 
47
      ##
 
48
      # :singleton-method: read_secondary
 
49
      #Returns the contents of the SECONDARY clipboard. 
 
50
      #See #read for an explanation. 
 
51
      
 
52
      ##
 
53
      # :singleton-method: write_primary
 
54
      #Writes to the PRIMARY clipboard. 
 
55
      #See #write for an explanation. 
 
56
      
 
57
      ##
 
58
      # :singleton-method: write_clipboard
 
59
      #Writes to the CLIPBOARD clipboard. 
 
60
      #See #write for an explanation. 
 
61
      
 
62
      ##
 
63
      # :singleton-method: write_secondary
 
64
      #Writes to the SECONDARY clipboard. 
 
65
      #See #write for an explanation. 
 
66
      
 
67
      ##
 
68
      # :singleton-method: clear_primary
 
69
      #Clears the PRIMARY clipboard. 
 
70
      #See #clear for an explanation. 
 
71
      
 
72
      ##
 
73
      # :singleton-method: clear_clipboard
 
74
      #Clears the CLIPBOARD clipboard. 
 
75
      #See #clear for an explanation. 
 
76
      
 
77
      ##
 
78
      # :singleton-method: clear_secondary     
 
79
      #Clears the SECONDARY clipboard. 
 
80
      #See #clear for an explanation. 
 
81
      
 
82
      #Reads text from a X clipboard. 
 
83
      #===Parameters
 
84
      #[<tt>*from</tt>] (<tt>:clipboard</tt>, <tt>:primary</tt>, <tt>:secondary</tt>) Specifies from which clipboards you want to read (in 70% of all cases you want to read from <tt>:clipboard</tt>). 
 
85
      #===Return value
 
86
      #A hash of form
 
87
      #  {:clip_sym => "clipboard_content"}
 
88
      #If you didn't pass any arguments to #read, the hash will contain keys for 
 
89
      #all clipboard, i.e. for <tt>:clipboard</tt>, <tt>:primary</tt> and <tt>:secondary</tt>. 
 
90
      #If you did, only those symbols will be included you passed. See 
 
91
      #the _Example_ section for an example of this. 
 
92
      #===Example
 
93
      #  XDo::Clipboard.read #| {:clipboard => "...", :primary => "...", :secondary => "..."}
 
94
      #  XDo::Clipboard.read(:primary) #| {:primary => "..."}
 
95
      #  XDo::Clipboard.read(:clipboard, :secondary) #| {clipboard => "...", :secondary => "..."}
 
96
      #===Remarks
 
97
      #You could also use one of the read_* methods for convenience.       
 
98
      def read(*from)
 
99
        if from.first.kind_of? Hash
 
100
          warn("#{caller.first}: Deprecation warning: Use symbols as a rest argument now!")
 
101
          from = from.first.keys
 
102
        end
 
103
        from.concat([:clipboard, :primary, :secondary]) if from.empty?
 
104
        
 
105
        hsh = {}
 
106
        hsh[:primary] = `#{XSEL}` if from.include? :primary
 
107
        hsh[:clipboard] = `#{XSEL} -b` if from.include? :clipboard
 
108
        hsh[:secondary] = `#{XSEL} -s` if from.include? :secondary
 
109
        hsh
 
110
      end
 
111
        
 
112
      
 
113
      #Writes text to a X clipboard. 
 
114
      #===Parameters
 
115
      #[<tt>*to</tt>] (<tt>:clipboard</tt>) Specifies to what clipboards you want to wrote to. 
 
116
      #===Return value
 
117
      #The text written. 
 
118
      #===Example
 
119
      #  XDo::Clipboard.write("I love Ruby") #You can now paste this via [CTRL] + [V]
 
120
      #  XDo::Clipboard.write("I love Ruby", :primary) #You can now paste this via a middle-mouse-button click
 
121
      #  XDo::Clipboard.write("I love Ruby", :clipboard, :primary) #Both of the above
 
122
      #===Remarks
 
123
      #You could also use one of the write_* methods for convenience. 
 
124
      def write(text, *to)
 
125
        if to.first.kind_of? Hash
 
126
          warn("#{caller.first}: Deprecation warning: Use symbols as a rest argument now!")
 
127
          to = to.first.keys
 
128
        end
 
129
        to << :clipboard if to.empty?
 
130
        
 
131
        IO.popen("xsel -i", "w"){|io| io.write(text)} if to.include? :primary
 
132
        IO.popen("xsel -b -i", "w"){|io| io.write(text)} if to.include? :clipboard
 
133
        IO.popen("xsel -s -i", "w"){|io| io.write(text)} if to.include? :secondary
 
134
        text
 
135
      end
 
136
      
 
137
      #Appends text to a X clipboard. 
 
138
      #===Parameters
 
139
      #[+text+] The text to append. 
 
140
      #[<tt>*to</tt>] (<tt>:clipboard</tt>) The clipboards to which you want to append. 
 
141
      #===Return value
 
142
      #Undefined. 
 
143
      #===Example
 
144
      #  XDo::Clipboard.write("I love ")
 
145
      #  XDo::Clipboard.append("Ruby")
 
146
      #  puts XDo::Clipboard.read(:clipboard)[:clipboard] #=> I love Ruby
 
147
      #  
 
148
      #  XDo::Clipboard.write("I love", :primary)
 
149
      #  XDo::Clipboard.append("Ruby", :primary, :clipboard)
 
150
      #  #If you now paste via [CTRL] + [V], you'll get 'Ruby'. If you 
 
151
      #  #paste via the middle mouse button, you'll get 'I love Ruby' 
 
152
      #  #(Assuming you didn't execute the first block of code, of course). 
 
153
      def append(text, *to)
 
154
        if to.first.kind_of? Hash
 
155
          warn("#{caller.first}: Deprecation warning: Use symbols as a rest argument now!")
 
156
          to = to.first.keys
 
157
        end
 
158
        to << :clipboard if to.empty?
 
159
        
 
160
        IO.popen("xsel -a -i", "w"){|io| io.write(text)} if to.include? :primary
 
161
        IO.popen("xsel -b -a -i", "w"){|io| io.write(text)} if to.include? :clipboard
 
162
        IO.popen("xsel -s -a -i", "w"){|io| io.write(text)} if to.include? :secondary
 
163
      end
 
164
      
 
165
      #Clears the specified clipboards. 
 
166
      #===Parameters
 
167
      #[<tt>*clips</tt>] (<tt>:primary</tt>, <tt>:clipboard</tt>, <tt>:secondary</tt>) The clipboards you want to clear. 
 
168
      #===Return value
 
169
      #nil. 
 
170
      #===Example
 
171
      #  XDo::Clipboard.write("I love Ruby")
 
172
      #  XDo::Clipboard.clear
 
173
      #  #Nothing can be pasted anymore
 
174
      #  
 
175
      #  XDo::Clipboard.write("I love Ruby", :clipboard, :primary)
 
176
      #  XDo::Clipboard.clear(:primary)
 
177
      #  #You can still paste via [CTRL] + [V], but not with the middle mouse button
 
178
      def clear(*clips)
 
179
        if clips.first.kind_of? Hash
 
180
          warn("#{caller.first}: Deprecation warning: Use symbols as a rest argument now!")
 
181
          clips = clips.first.keys
 
182
        end
 
183
        clips.concat([:primary, :clipboard, :secondary]) if clips.empty?
 
184
        
 
185
        `#{XSEL} -c` if clips.include? :primary
 
186
        `#{XSEL} -b -c` if clips.include? :clipboard
 
187
        `#{XSEL} -s -c` if clips.include? :secondary
 
188
        nil
 
189
      end
 
190
      
 
191
      [:primary, :clipboard, :secondary].each do |sym|
 
192
        
 
193
        define_method(:"read_#{sym}") do
 
194
          read(sym)[sym]
 
195
        end
 
196
        
 
197
        define_method(:"write_#{sym}") do |text|
 
198
          write(text, sym)
 
199
        end
 
200
        
 
201
        define_method(:"clear_#{sym}") do
 
202
          clear(sym)
 
203
        end
 
204
        
 
205
      end
 
206
      
 
207
    end
 
208
  end
 
209
end