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

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

near, #next, next, prev, #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

Constructor Details

- (Client) initialize(client_id)

A new instance of Client



121
122
123
# File 'lib/rumai/wm.rb', line 121

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

+ (Object) curr

Returns the currently focused client.



128
129
130
# File 'lib/rumai/wm.rb', line 128

def self.curr
  new FOCUSED_WIDGET_ID
end

Instance Method Details

- (Object) area(view = View.curr)

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



340
341
342
# File 'lib/rumai/wm.rb', line 340

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

- (Object) chain

Returns a list of all clients in the current view.



139
140
141
# File 'lib/rumai/wm.rb', line 139

def chain
  View.curr.clients
end

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

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



303
304
305
# File 'lib/rumai/wm.rb', line 303

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

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

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



317
318
319
# File 'lib/rumai/wm.rb', line 317

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

- (Boolean) float?(view = View.curr)

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

Returns:

  • (Boolean)


296
297
298
# File 'lib/rumai/wm.rb', line 296

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

- (Object) focus(view = nil)

Focuses this client within the given view.



150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'lib/rumai/wm.rb', line 150

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

- (Object) fullscreen

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



232
233
234
# File 'lib/rumai/wm.rb', line 232

def fullscreen
  ctl.write 'Fullscreen on'
end

- (Object) fullscreen!

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



246
247
248
# File 'lib/rumai/wm.rb', line 246

def fullscreen!
  ctl.write 'Fullscreen toggle'
end

- (Boolean) fullscreen?

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

Returns:

  • (Boolean)


253
254
255
256
257
258
259
# File 'lib/rumai/wm.rb', line 253

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

- (Object) group

Adds this client to the current grouping.



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

def group
  with_tags do
    push CLIENT_GROUPING_TAG
  end
end

- (Object) group!

Toggles the presence of this client in the current grouping.



467
468
469
470
471
472
473
# File 'lib/rumai/wm.rb', line 467

def group!
  if group?
    ungroup
  else
    group
  end
end

- (Boolean) group?

Checks if this client is included in the current grouping.

Returns:

  • (Boolean)


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

def group?
  tags.include? CLIENT_GROUPING_TAG
end

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

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



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

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

- (Object) kill

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



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

def kill
  ctl.write :kill
end

- (Boolean) manage?(view = View.curr)

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

Returns:

  • (Boolean)


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

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

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

Moves 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 nudge direction, amount = 1, view = View.curr
  reshape :nudge, view, direction, amount
end

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

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



175
176
177
178
# File 'lib/rumai/wm.rb', line 175

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

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

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



210
211
212
# File 'lib/rumai/wm.rb', line 210

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

- (Object) slay

Terminates this client forcefully.



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

def slay
  ctl.write :slay
end

- (Object) stick

Makes this client sticky (appears in all views).



271
272
273
# File 'lib/rumai/wm.rb', line 271

def stick
  tag CLIENT_STICKY_TAG
end

- (Object) stick!

Toggles the stickyness of this client.



285
286
287
288
289
290
291
# File 'lib/rumai/wm.rb', line 285

def stick!
  if stick?
    unstick
  else
    stick
  end
end

- (Boolean) stick?

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

Returns:

  • (Boolean)


264
265
266
# File 'lib/rumai/wm.rb', line 264

def stick?
  tags.include? CLIENT_STICKY_TAG
end

- (Object) swap(area_or_id, view = View.curr)

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



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

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

- (Object) tag(*tags)

Adds the given tags to this client.



420
421
422
423
424
# File 'lib/rumai/wm.rb', line 420

def tag *tags
  with_tags do
    concat tags
  end
end

- (Object) tags

Returns the tags associated with this client.



360
361
362
# File 'lib/rumai/wm.rb', line 360

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

- (Object) tags=(*tags)

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.



381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
# File 'lib/rumai/wm.rb', line 381

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

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

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



310
311
312
# File 'lib/rumai/wm.rb', line 310

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

- (Object) unfullscreen

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



239
240
241
# File 'lib/rumai/wm.rb', line 239

def unfullscreen
  ctl.write 'Fullscreen off'
end

- (Object) ungroup

Removes this client to the current grouping.



460
461
462
# File 'lib/rumai/wm.rb', line 460

def ungroup
  untag CLIENT_GROUPING_TAG
end

- (Object) unstick

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



278
279
280
# File 'lib/rumai/wm.rb', line 278

def unstick
  untag CLIENT_STICKY_TAG
end

- (Object) untag(*tags)

Removes the given tags from this client.



429
430
431
432
433
434
435
# File 'lib/rumai/wm.rb', line 429

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

- (Object) views

Returns the views that contain this client.



347
348
349
# File 'lib/rumai/wm.rb', line 347

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

- (Object) with_tags(&block)

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



411
412
413
414
415
# File 'lib/rumai/wm.rb', line 411

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