Class: Rumai::Client

Inherits:
WidgetNode show all
Includes:
Chain
Defined in:
lib/rumai/wm.rb

Overview

A graphical program that is running in your current X Windows session.

Constant Summary collapse

TAG_DELIMITER =

tag manipulations


'+'.freeze

Instance Attribute Summary

Attributes included from WidgetImpl

#id

Attributes inherited from Node

#path

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Chain

#next, #prev

Methods included from WidgetImpl

#==, #current?

Methods inherited from Node

#[], #children, #clear, #create, #directory?, #each, #each_line, #entries, #exist?, #method_missing, #open, #parent, #read, #remove, #stat, #write

Methods included from ExportInstanceMethods

extended

Constructor Details

#initialize(client_id) ⇒ Client

Returns a new instance of Client.



105
106
107
# File 'lib/rumai/wm.rb', line 105

def initialize client_id
  super client_id, '/client'
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Rumai::Node

Class Method Details

.currObject

Returns the currently focused client.



112
113
114
# File 'lib/rumai/wm.rb', line 112

def self.curr
  new FOCUSED_WIDGET_ID
end

Instance Method Details

#area(view = View.curr) ⇒ Object

Returns the area that contains this client within the given view.



324
325
326
# File 'lib/rumai/wm.rb', line 324

def area view = View.curr
  view.area_of_client self
end

#chainObject

Returns a list of all clients in the current view.



123
124
125
# File 'lib/rumai/wm.rb', line 123

def chain
  View.curr.clients
end

#float(view = View.curr) ⇒ Object Also known as: unmanage

Puts this client into the floating area of the given view.



287
288
289
# File 'lib/rumai/wm.rb', line 287

def float view = View.curr
  send :toggle, view unless float? view
end

#float!(view = View.curr) ⇒ Object Also known as: manage!

Toggles the floating status of this client in the given view.



301
302
303
# File 'lib/rumai/wm.rb', line 301

def float! view = View.curr
  send :toggle, view
end

#float?(view = View.curr) ⇒ Boolean

Checks if this client is in the floating area of the given view.

Returns:

  • (Boolean)


280
281
282
# File 'lib/rumai/wm.rb', line 280

def float? view = View.curr
  area(view).floating?
end

#focus(view = nil) ⇒ Object

Focuses this client within the given view.



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/rumai/wm.rb', line 134

def focus view = nil
  if exist? and not focus?
    (view ? [view] : self.views).each do |v|
      if a = self.area(v) and a.exist?
        v.focus
        a.focus

        # slide focus from the current client onto this client
        arr = a.client_ids
        src = arr.index Client.curr.id
        dst = arr.index @id

        distance = (src - dst).abs
        direction = src < dst ? :down : :up

        distance.times { v.select direction }
        break
      end
    end
  end
end

#fullscreenObject

Maximizes this client to occupy the entire screen on the current view.



216
217
218
# File 'lib/rumai/wm.rb', line 216

def fullscreen
  ctl.write 'Fullscreen on'
end

#fullscreen!Object

Toggles the fullscreen status of this client on the current view.



230
231
232
# File 'lib/rumai/wm.rb', line 230

def fullscreen!
  ctl.write 'Fullscreen toggle'
end

#fullscreen?Boolean

Checks if this client is currently fullscreen on the current view.

Returns:

  • (Boolean)


237
238
239
240
241
242
243
# File 'lib/rumai/wm.rb', line 237

def fullscreen?
  #
  # If the client's dimensions match those of the
  # floating area, then we know it is fullscreen.
  #
  View.curr.manifest =~ /^# #{FLOATING_AREA_ID} (\d+) (\d+)\n.*^#{FLOATING_AREA_ID} #{@id} \d+ \d+ \1 \2 /m
end

#groupObject

Adds this client to the current grouping.



435
436
437
438
439
# File 'lib/rumai/wm.rb', line 435

def group
  with_tags do
    push CLIENT_GROUPING_TAG
  end
end

#group!Object

Toggles the presence of this client in the current grouping.



451
452
453
454
455
456
457
# File 'lib/rumai/wm.rb', line 451

def group!
  if group?
    ungroup
  else
    group
  end
end

#group?Boolean

Checks if this client is included in the current grouping.

Returns:

  • (Boolean)


428
429
430
# File 'lib/rumai/wm.rb', line 428

def group?
  tags.include? CLIENT_GROUPING_TAG
end

#grow(direction, amount = 1, view = View.curr) ⇒ Object

Grows this client by the given amount in the given direction on the given view.



186
187
188
# File 'lib/rumai/wm.rb', line 186

def grow direction, amount = 1, view = View.curr
  reshape :grow, view, direction, amount
end

#killObject

Terminates this client nicely (requests this window to be closed).



201
202
203
# File 'lib/rumai/wm.rb', line 201

def kill
  ctl.write :kill
end

#manage?(view = View.curr) ⇒ Boolean

Checks if this client is in the managed area of the given view.

Returns:

  • (Boolean)


307
308
309
# File 'lib/rumai/wm.rb', line 307

def manage? view = View.curr
  not float? view
end

#nudge(direction, amount = 1, view = View.curr) ⇒ Object

Moves this client by the given amount in the given direction on the given view.



178
179
180
# File 'lib/rumai/wm.rb', line 178

def nudge direction, amount = 1, view = View.curr
  reshape :nudge, view, direction, amount
end

#send(area_or_id, view = View.curr) ⇒ Object Also known as: move

Sends this client to the given destination within the given view.



159
160
161
162
# File 'lib/rumai/wm.rb', line 159

def send area_or_id, view = View.curr
  dst = area_to_id(area_or_id)
  view.ctl.write "send #{@id} #{dst}"
end

#shrink(direction, amount = 1, view = View.curr) ⇒ Object

Shrinks this client by the given amount in the given direction on the given view.



194
195
196
# File 'lib/rumai/wm.rb', line 194

def shrink direction, amount = 1, view = View.curr
  reshape :grow, view, direction, -amount.to_i
end

#slayObject

Terminates this client forcefully.



208
209
210
# File 'lib/rumai/wm.rb', line 208

def slay
  ctl.write :slay
end

#stickObject

Makes this client sticky (appears in all views).



255
256
257
# File 'lib/rumai/wm.rb', line 255

def stick
  tag CLIENT_STICKY_TAG
end

#stick!Object

Toggles the stickyness of this client.



269
270
271
272
273
274
275
# File 'lib/rumai/wm.rb', line 269

def stick!
  if stick?
    unstick
  else
    stick
  end
end

#stick?Boolean

Checks if this client is sticky (appears in all views).

Returns:

  • (Boolean)


248
249
250
# File 'lib/rumai/wm.rb', line 248

def stick?
  tags.include? CLIENT_STICKY_TAG
end

#swap(area_or_id, view = View.curr) ⇒ Object

Swaps this client with the given destination within the given view.



169
170
171
172
# File 'lib/rumai/wm.rb', line 169

def swap area_or_id, view = View.curr
  dst = area_to_id(area_or_id)
  view.ctl.write "swap #{@id} #{dst}"
end

#tag(*tags) ⇒ Object

Adds the given tags to this client.



404
405
406
407
408
# File 'lib/rumai/wm.rb', line 404

def tag *tags
  with_tags do
    concat tags
  end
end

#tagsObject

Returns the tags associated with this client.



344
345
346
# File 'lib/rumai/wm.rb', line 344

def tags
  self[:tags].read.split TAG_DELIMITER
end

#tags=(*tags) ⇒ Object

Modifies the tags associated with this client.

If a tag name is ‘~’, this client is placed into the floating layer of the current view.

If a tag name begins with ‘~’, then this client is placed into the floating layer of the view corresponding to that tag.

If a tag name is ‘!’, this client is placed into the managed layer of the current view.

If a tag name begins with ‘!’, then this client is placed into the managed layer of the view corresponding to that tag.



365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
# File 'lib/rumai/wm.rb', line 365

def tags= *tags
  float = []
  manage = []
  inherit = []

  tags.join(TAG_DELIMITER).split(TAG_DELIMITER).each do |tag|
    case tag
    when '~'  then float   << Rumai.curr_tag
    when /^~/ then float   << $'
    when '!'  then manage  << Rumai.curr_tag
    when /^!/ then manage  << $'
    else           inherit << tag
    end
  end

  self[:tags].write((float + manage + inherit).uniq.join(TAG_DELIMITER))

  float.each do |tag|
    self.float View.new(tag)
  end

  manage.each do |tag|
    self.manage View.new(tag)
  end
end

#unfloat(view = View.curr) ⇒ Object Also known as: manage

Puts this client into the managed area of the given view.



294
295
296
# File 'lib/rumai/wm.rb', line 294

def unfloat view = View.curr
  send :toggle, view if float? view
end

#unfullscreenObject

Restores this client back to its original size on the current view.



223
224
225
# File 'lib/rumai/wm.rb', line 223

def unfullscreen
  ctl.write 'Fullscreen off'
end

#ungroupObject

Removes this client to the current grouping.



444
445
446
# File 'lib/rumai/wm.rb', line 444

def ungroup
  untag CLIENT_GROUPING_TAG
end

#unstickObject

Makes this client unsticky (does not appear in all views).



262
263
264
# File 'lib/rumai/wm.rb', line 262

def unstick
  untag CLIENT_STICKY_TAG
end

#untag(*tags) ⇒ Object

Removes the given tags from this client.



413
414
415
416
417
418
419
# File 'lib/rumai/wm.rb', line 413

def untag *tags
  with_tags do
    tags.flatten.each do |tag|
      delete tag.to_s
    end
  end
end

#viewsObject

Returns the views that contain this client.



331
332
333
# File 'lib/rumai/wm.rb', line 331

def views
  tags.map! {|t| View.new t }
end

#with_tags(&block) ⇒ Object

Evaluates the given block within the context of this client’s list of tags.



395
396
397
398
399
# File 'lib/rumai/wm.rb', line 395

def with_tags &block
  arr = self.tags
  arr.instance_eval(&block)
  self.tags = arr
end