Class: WMCtrl

Inherits:
Object
  • Object
show all
Defined in:
lib/wmctrl/version.rb,
ext/wmctrl.c

Constant Summary collapse

VERSION =
"0.0.4"

Instance Method Summary collapse

Instance Method Details

#action_window(wid, cmd, *args) ⇒ Object

Manage windows.

Examples:

wm.action_window(wid, :close)
wm.action_window(wid, :move_resize, grav, x, y, w, h)
wm.action_window(wid, :change_state, add, prop1, prop2 = nil)
wm.action_window(wid, :change_state, remove, prop1, prop2 = nil)
wm.action_window(wid, :change_state, toggle, prop1, prop2 = nil)
wm.action_window(wid, :move_to_desktop, desktop_id)
wm.action_window(wid, :move_to_current)
wm.action_window(wid, :set_title_long, str)
wm.action_window(wid, :set_title_short, str)
wm.action_window(wid, :set_title_both, str)

Parameters:

  • wid

    Window ID

  • cmd (Symbol)

    Symbol of command

  • args (Array)

    Arguments for the command



1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
# File 'ext/wmctrl.c', line 1132

static VALUE rb_wmctrl_action_window(int argc, VALUE *argv, VALUE self) {
  Window wid;
  int mode;
  ID sym_id;
  Display **ptr, *disp;
  Data_Get_Struct(self, Display*, ptr);
  disp = *ptr;
  if (argc < 2) {
    rb_raise(rb_eArgError, "Need more than one argument.");
  }
  wid = get_target_window(disp, argv[0]);
  sym_id = SYM2ID(argv[1]);
  if (sym_id == id_activate) {
    mode = 'a';
  } else if (sym_id == id_close) {
    mode = 'c';
  } else if (sym_id == id_move_resize) {
    mode = 'e';
  } else if (sym_id == id_change_state) {
    mode = 'b';
  } else if (sym_id == id_move_to_desktop) {
    mode = 't';
  } else if (sym_id == id_move_to_current) {
    mode = 'R';
  } else if (sym_id == id_set_title_long) {
    mode = 'N';
  } else if (sym_id == id_set_title_short) {
    mode = 'I';
  } else if (sym_id == id_set_title_both) {
    mode = 'T';
  } else {
    rb_raise(rb_eStandardError, "Invalid argument of action_window.");
  }
  if (action_window(disp, wid, mode, argc - 2, (argv + 2))) {
    return Qtrue;
  } else {
    return Qfalse;
  }
}

#change_geometryObject



721
722
723
724
725
726
727
728
729
730
731
732
733
# File 'ext/wmctrl.c', line 721

static VALUE rb_wmctrl_change_geometry (VALUE self, VALUE xnum, VALUE ynum) {
  long x, y;
  Display **ptr, *disp;
  Data_Get_Struct(self, Display*, ptr);
  disp = *ptr;
  x = NUM2LONG(xnum);
  y = NUM2LONG(ynum);
  if (x < 0 || y < 0) {
    rb_raise(rb_eArgError, "Arguments must be nonnegative integers.");
  }
  client_msg(disp, DefaultRootWindow(disp), "_NET_DESKTOP_GEOMETRY", x, y, 0, 0, 0);
  return Qtrue;
}

#change_number_of_desktopsObject

Change number of desktops.



736
737
738
739
740
741
742
743
744
745
746
747
# File 'ext/wmctrl.c', line 736

static VALUE rb_wmctrl_change_number_of_desktops (VALUE self, VALUE num) {
  long n;
  Display **ptr, *disp;
  Data_Get_Struct(self, Display*, ptr);
  disp = *ptr;
  n = NUM2LONG(num);
  if (n < 0) {
    rb_raise(rb_eArgError, "An argument must be a nonnegative integer.");
  }
  client_msg(disp, DefaultRootWindow(disp), "_NET_NUMBER_OF_DESKTOPS", n, 0, 0, 0, 0);
  return Qtrue;
}

#change_viewportObject



707
708
709
710
711
712
713
714
715
716
717
718
719
# File 'ext/wmctrl.c', line 707

static VALUE rb_wmctrl_change_viewport (VALUE self, VALUE xnum, VALUE ynum) {
  long x, y;
  Display **ptr, *disp;
  Data_Get_Struct(self, Display*, ptr);
  disp = *ptr;
  x = NUM2LONG(xnum);
  y = NUM2LONG(ynum);
  if (x < 0 || y < 0) {
    rb_raise(rb_eArgError, "Arguments must be nonnegative integers.");
  }
  client_msg(disp, DefaultRootWindow(disp), "_NET_DESKTOP_VIEWPORT", x, y, 0, 0, 0);
  return Qtrue;
}

#infoObject

Get hash of information of window manager.



628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
# File 'ext/wmctrl.c', line 628

static VALUE rb_wmctrl_info (VALUE self) {
  Display **ptr, *disp;
  Window *sup_window = NULL;
  gchar *wm_name = NULL;
  gchar *wm_class = NULL;
  unsigned long *wm_pid = NULL;
  unsigned long *showing_desktop = NULL;
  gboolean name_is_utf8 = TRUE;
  VALUE ret = rb_hash_new();

  Data_Get_Struct(self, Display*, ptr);
  disp = *ptr;

  if (! (sup_window = (Window *)get_property(disp, DefaultRootWindow(disp),
					     XA_WINDOW, "_NET_SUPPORTING_WM_CHECK", NULL))) {
    if (! (sup_window = (Window *)get_property(disp, DefaultRootWindow(disp),
					       XA_CARDINAL, "_WIN_SUPPORTING_WM_CHECK", NULL))) {
      fputs("Cannot get window manager info properties.\n"
	    "(_NET_SUPPORTING_WM_CHECK or _WIN_SUPPORTING_WM_CHECK)\n", stderr);
      return EXIT_FAILURE;
    }
  }

  /* WM_NAME */
  if (! (wm_name = get_property(disp, *sup_window,
				XInternAtom(disp, "UTF8_STRING", False), "_NET_WM_NAME", NULL))) {
    name_is_utf8 = FALSE;
    if (! (wm_name = get_property(disp, *sup_window,
				  XA_STRING, "_NET_WM_NAME", NULL))) {
      p_verbose("Cannot get name of the window manager (_NET_WM_NAME).\n");
    }
  }

  /* WM_CLASS */
  if (! (wm_class = get_property(disp, *sup_window,
				 XInternAtom(disp, "UTF8_STRING", False), "WM_CLASS", NULL))) {
    name_is_utf8 = FALSE;
    if (! (wm_class = get_property(disp, *sup_window,
				   XA_STRING, "WM_CLASS", NULL))) {
      p_verbose("Cannot get class of the window manager (WM_CLASS).\n");
    }
  }

  /* WM_PID */
  if (! (wm_pid = (unsigned long *)get_property(disp, *sup_window,
						XA_CARDINAL, "_NET_WM_PID", NULL))) {
    p_verbose("Cannot get pid of the window manager (_NET_WM_PID).\n");
  }

  /* _NET_SHOWING_DESKTOP */
  if (! (showing_desktop = (unsigned long *)get_property(disp, DefaultRootWindow(disp),
							 XA_CARDINAL, "_NET_SHOWING_DESKTOP", NULL))) {
    p_verbose("Cannot get the _NET_SHOWING_DESKTOP property.\n");
  }

  rb_hash_aset(ret, key_name, (wm_name ? RB_UTF8_STRING_NEW2(wm_name) : Qnil));
  rb_hash_aset(ret, key_class, (wm_class ? RB_UTF8_STRING_NEW2(wm_class) : Qnil));
  rb_hash_aset(ret, key_pid, (wm_pid ? UINT2NUM(*wm_pid) : Qnil));
  rb_hash_aset(ret, key_showing_desktop,
	       (showing_desktop ? RB_UTF8_STRING_NEW2(*showing_desktop == 1 ? "ON" : "OFF") : Qnil));

  g_free(sup_window);
  g_free(wm_name);
  g_free(wm_class);
  g_free(wm_pid);
  g_free(showing_desktop);

  return ret;
}

#list_desktopsObject

Get list of information of desktops.



391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
# File 'ext/wmctrl.c', line 391

static VALUE rb_wmctrl_list_desktops (VALUE self) {
  Display **ptr, *disp;
  unsigned long *num_desktops = NULL;
  unsigned long *cur_desktop = NULL;
  unsigned long desktop_list_size = 0;
  unsigned long *desktop_geometry = NULL;
  unsigned long desktop_geometry_size = 0;
  unsigned long *desktop_viewport = NULL;
  unsigned long desktop_viewport_size = 0;
  unsigned long *desktop_workarea = NULL;
  unsigned long desktop_workarea_size = 0;
  gchar *list = NULL;
  unsigned int i;
  unsigned int id;
  Window root;
  const gchar *error_message = NULL;
  VALUE ret = Qnil;
  VALUE *ret_arys;

  Data_Get_Struct(self, Display*, ptr);
  disp = *ptr;

  root = DefaultRootWindow(disp);

  if (! (num_desktops = (unsigned long *)get_property(disp, root,
						      XA_CARDINAL, "_NET_NUMBER_OF_DESKTOPS", NULL))) {
    if (! (num_desktops = (unsigned long *)get_property(disp, root,
							XA_CARDINAL, "_WIN_WORKSPACE_COUNT", NULL))) {
      error_message = "Cannot get number of desktops properties. (_NET_NUMBER_OF_DESKTOPS or _WIN_WORKSPACE_COUNT)";
      goto cleanup;
    }
  }

  if (! (cur_desktop = (unsigned long *)get_property(disp, root,
						     XA_CARDINAL, "_NET_CURRENT_DESKTOP", NULL))) {
    if (! (cur_desktop = (unsigned long *)get_property(disp, root,
						       XA_CARDINAL, "_WIN_WORKSPACE", NULL))) {
      error_message = "Cannot get current desktop properties. (_NET_CURRENT_DESKTOP or _WIN_WORKSPACE property)";
      goto cleanup;
    }
  }

  if ((list = get_property(disp, root, XInternAtom(disp, "UTF8_STRING", False),
			   "_NET_DESKTOP_NAMES", &desktop_list_size)) == NULL) {
    /* If charaset is not utf8 then there may be bugs here. */
    if ((list = get_property(disp, root,
			     XA_STRING,
			     "_WIN_WORKSPACE_NAMES", &desktop_list_size)) == NULL) {
      p_verbose("Cannot get desktop names properties. "
		"(_NET_DESKTOP_NAMES or _WIN_WORKSPACE_NAMES)"
		"\n");
      /* ignore the error - list the desktops without names */
    }
  }

  /* common size of all desktops */
  if (! (desktop_geometry = (unsigned long *)get_property(disp, DefaultRootWindow(disp),
							  XA_CARDINAL, "_NET_DESKTOP_GEOMETRY", &desktop_geometry_size))) {
    p_verbose("Cannot get common size of all desktops (_NET_DESKTOP_GEOMETRY).\n");
  }

  /* desktop viewport */
  if (! (desktop_viewport = (unsigned long *)get_property(disp, DefaultRootWindow(disp),
							  XA_CARDINAL, "_NET_DESKTOP_VIEWPORT", &desktop_viewport_size))) {
    p_verbose("Cannot get common size of all desktops (_NET_DESKTOP_VIEWPORT).\n");
  }

  /* desktop workarea */
  if (! (desktop_workarea = (unsigned long *)get_property(disp, DefaultRootWindow(disp),
							  XA_CARDINAL, "_NET_WORKAREA", &desktop_workarea_size))) {
    if (! (desktop_workarea = (unsigned long *)get_property(disp, DefaultRootWindow(disp),
							    XA_CARDINAL, "_WIN_WORKAREA", &desktop_workarea_size))) {
      p_verbose("Cannot get _NET_WORKAREA property.\n");
    }
  }

  ret_arys = (VALUE *)g_malloc0(*num_desktops * sizeof(VALUE));
  for (i = 0; i < *num_desktops; i++) {
    ret_arys[i] = rb_hash_new();
    rb_hash_aset(ret_arys[i], key_id, UINT2NUM(i));
    if (i == *cur_desktop) {
      rb_hash_aset(ret_arys[i], key_current, Qtrue);
    } else {
      rb_hash_aset(ret_arys[i], key_current, Qnil);
    }
  }

  if (list) {
    id = 0;
    rb_hash_aset(ret_arys[id], key_title, RB_UTF8_STRING_NEW2(list));
    id++;
    for (i = 0; i < desktop_list_size; i++) {
      if (list[i] == '\0') {
	if (id >= *num_desktops) {
	  break;
	}
	rb_hash_aset(ret_arys[id], key_title, RB_UTF8_STRING_NEW2(list + i + 1));
	id++;
      }
    }
  }

  /* prepare desktop geometry strings */
  if (desktop_geometry && desktop_geometry_size > 0) {
    if (desktop_geometry_size == 2 * sizeof(*desktop_geometry)) {
      /* only one value - use it for all desktops */
      p_verbose("WM provides _NET_DESKTOP_GEOMETRY value common for all desktops.\n");
      for (i = 0; i < *num_desktops; i++) {
	rb_hash_aset(ret_arys[i], key_geometry,
		     rb_ary_new3(2, INT2NUM(desktop_geometry[0]), INT2NUM(desktop_geometry[1])));
      }
    }
    else {
      /* seperate values for desktops of different size */
      p_verbose("WM provides separate _NET_DESKTOP_GEOMETRY value for each desktop.\n");
      for (i = 0; i < *num_desktops; i++) {
  	if (i < desktop_geometry_size / sizeof(*desktop_geometry) / 2) {
	  rb_hash_aset(ret_arys[i], key_geometry,
		       rb_ary_new3(2, INT2NUM(desktop_geometry[i*2]), INT2NUM(desktop_geometry[i*2+1])));
  	}
  	else {
	  rb_hash_aset(ret_arys[i], key_geometry, Qnil);
  	}
      }
    }
  }
  else {
    for (i = 0; i < *num_desktops; i++) {
      rb_hash_aset(ret_arys[i], key_geometry, Qnil);
    }
  }

  /* prepare desktop viewport strings */
  if (desktop_viewport && desktop_viewport_size > 0) {
    if (desktop_viewport_size == 2 * sizeof(*desktop_viewport)) {
      /* only one value - use it for current desktop */
      p_verbose("WM provides _NET_DESKTOP_VIEWPORT value only for the current desktop.\n");
      for (i = 0; i < *num_desktops; i++) {
  	if (i == *cur_desktop) {
	  rb_hash_aset(ret_arys[i], key_viewport,
		       rb_ary_new3(2, INT2NUM(desktop_viewport[0]), INT2NUM(desktop_viewport[1])));
  	}
  	else {
	  rb_hash_aset(ret_arys[i], key_viewport, Qnil);
  	}
      }
    }
    else {
      /* seperate values for each of desktops */
      for (i = 0; i < *num_desktops; i++) {
  	if (i < desktop_viewport_size / sizeof(*desktop_viewport) / 2) {
	  rb_hash_aset(ret_arys[i], key_viewport,
		       rb_ary_new3(2, INT2NUM(desktop_viewport[i*2]), INT2NUM(desktop_viewport[i*2+1])));
  	}
  	else {
	  rb_hash_aset(ret_arys[i], key_viewport, Qnil);
  	}
      }
    }
  }
  else {
    for (i = 0; i < *num_desktops; i++) {
      rb_hash_aset(ret_arys[i], key_viewport, Qnil);
    }
  }

  /* prepare desktop workarea strings */
  if (desktop_workarea && desktop_workarea_size > 0) {
    if (desktop_workarea_size == 4 * sizeof(*desktop_workarea)) {
      /* only one value - use it for current desktop */
      p_verbose("WM provides _NET_WORKAREA value only for the current desktop.\n");
      for (i = 0; i < *num_desktops; i++) {
  	if (i == *cur_desktop) {
	  rb_hash_aset(ret_arys[i], key_workarea,
		       rb_ary_new3(4, INT2NUM(desktop_workarea[0]), INT2NUM(desktop_workarea[1]),
				   INT2NUM(desktop_workarea[2]), INT2NUM(desktop_workarea[3])));
  	}
  	else {
	  rb_hash_aset(ret_arys[i], key_workarea, Qnil);
  	}
      }
    }
    else {
      /* seperate values for each of desktops */
      for (i = 0; i < *num_desktops; i++) {
  	if (i < desktop_workarea_size / sizeof(*desktop_workarea) / 4) {
	  rb_hash_aset(ret_arys[i], key_workarea,
		       rb_ary_new3(4, INT2NUM(desktop_workarea[i*4]), INT2NUM(desktop_workarea[i*4+1]),
				   INT2NUM(desktop_workarea[i*4+2]), INT2NUM(desktop_workarea[i*4+3])));
  	}
  	else {
	  rb_hash_aset(ret_arys[i], key_workarea, Qnil);
  	}
      }
    }
  }
  else {
    for (i = 0; i < *num_desktops; i++) {
      rb_hash_aset(ret_arys[i], key_workarea, Qnil);
    }
  }

  ret = rb_ary_new4(*num_desktops, ret_arys);

  p_verbose("Total number of desktops: %lu\n", *num_desktops);
  p_verbose("Current desktop ID (counted from zero): %lu\n", *cur_desktop);
  goto cleanup;

 cleanup:
  g_free(num_desktops);
  g_free(cur_desktop);
  g_free(desktop_geometry);
  g_free(desktop_viewport);
  g_free(desktop_workarea);
  g_free(list);
  if (error_message) {
    rb_raise(rb_eStandardError, "%s", error_message);
  }
  return ret;
}

#list_windows(get_state = nil) ⇒ Object

Get list of information of windows.

Parameters:

  • get_state (Boolean)

    If the value is true then we get some properties at the same time



246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
# File 'ext/wmctrl.c', line 246

static VALUE rb_wmctrl_list_windows (int argc, VALUE *argv, VALUE self) {
  Display **ptr, *disp;
  Window *client_list;
  Window window_active;
  unsigned long client_list_size;
  unsigned int i;
  int get_state;
  VALUE get_state_obj, window_ary;
  Data_Get_Struct(self, Display*, ptr);
  disp = *ptr;
  rb_scan_args(argc, argv, "01", &get_state_obj);
  get_state = RTEST(get_state_obj);

  if ((client_list = get_client_list(disp, &client_list_size)) == NULL) {
    /* return EXIT_FAILURE; */
    return Qfalse;
  }

  window_active = get_active_window(disp);
  window_ary = rb_ary_new2(client_list_size);

  for (i = 0; i < client_list_size / sizeof(Window); i++) {
    VALUE window_obj = rb_hash_new();
    gchar *title_utf8 = get_window_title(disp, client_list[i]); /* UTF8 */
    gchar *client_machine;
    gchar *class_out = get_window_class(disp, client_list[i]); /* UTF8 */
    unsigned long *desktop;

    rb_hash_aset(window_obj, key_id, INT2NUM(client_list[i]));
    rb_hash_aset(window_obj, key_title, (title_utf8 ? RB_UTF8_STRING_NEW2(title_utf8) : Qnil));
    rb_hash_aset(window_obj, key_class, (class_out ? RB_UTF8_STRING_NEW2(class_out) : Qnil));

    if (window_active == client_list[i]) {
      rb_hash_aset(window_obj, key_active, Qtrue);
    } else {
      rb_hash_aset(window_obj, key_active, Qnil);
    }

    /* desktop ID */
    if ((desktop = (unsigned long *)get_property(disp, client_list[i],
  						 XA_CARDINAL, "_NET_WM_DESKTOP", NULL)) == NULL) {
      desktop = (unsigned long *)get_property(disp, client_list[i], XA_CARDINAL, "_WIN_WORKSPACE", NULL);
    }
    /* special desktop ID -1 means "all desktops", so we
       have to convert the desktop value to signed long */
    rb_hash_aset(window_obj, key_desktop, INT2NUM(desktop ? (signed long)*desktop : 0));

    /* client machine */
    client_machine = get_property(disp, client_list[i], XA_STRING, "WM_CLIENT_MACHINE", NULL);
    rb_hash_aset(window_obj, key_client_machine, (client_machine ? RB_UTF8_STRING_NEW2(client_machine) : Qnil));

    if (get_state) {
      unsigned long *pid;
      int x, y, junkx, junky;
      unsigned long j;
      unsigned int wwidth, wheight, bw, depth;
      Window junkroot;
      unsigned long state_size;
      Atom *window_state;
      gchar *state_name;
      VALUE state_ary;
      Atom *extents;
      unsigned long extents_size;
      VALUE extents_ary;
      Atom *strut;
      unsigned long strut_size;
      VALUE strut_ary;

      /* pid */
      pid = (unsigned long *)get_property(disp, client_list[i], XA_CARDINAL, "_NET_WM_PID", NULL);
      rb_hash_aset(window_obj, key_pid, (pid ? ULONG2NUM(*pid) : Qnil));
      g_free(pid);

      /* geometry */
      XGetGeometry (disp, client_list[i], &junkroot, &junkx, &junky, &wwidth, &wheight, &bw, &depth);
      XTranslateCoordinates (disp, client_list[i], junkroot, -bw, -bw, &x, &y, &junkroot);

      rb_hash_aset(window_obj, key_geometry,
		   rb_ary_new3(4, INT2NUM(x), INT2NUM(y), INT2NUM(wwidth), INT2NUM(wheight)));

      /* state */
      if ((window_state = (Atom *)get_property(disp, client_list[i],
					       XA_ATOM, "_NET_WM_STATE", &state_size)) != NULL) {
	state_ary = rb_ary_new();
	for (j = 0; j < state_size / sizeof(Atom); j++) {
	  state_name = XGetAtomName(disp, window_state[j]);
	  rb_ary_push(state_ary, rb_str_new2(state_name));
	  g_free(state_name);
	}
	g_free(window_state);
      } else {
	state_ary = Qnil;
      }
      rb_hash_aset(window_obj, key_state, state_ary);

      /* frame extents */
      if ((extents = (unsigned long *)get_property(disp, client_list[i],
      						   XA_CARDINAL, "_NET_FRAME_EXTENTS", &extents_size)) != NULL) {
	extents_ary = rb_ary_new();
      	for (j = 0; j < extents_size / sizeof(unsigned long); j++) {
      	  rb_ary_push(extents_ary, ULONG2NUM(extents[j]));
      	}
	/* exterior frame */
	if (extents) {
	  rb_hash_aset(window_obj, key_exterior_frame,
		       rb_ary_new3(4, INT2NUM(x - (int)extents[0]), INT2NUM(y - (int)extents[2]),
				   INT2NUM(wwidth + (int)extents[0] + (int)extents[1]),
				   INT2NUM(wheight + (int)extents[2] + (int)extents[3])));
	}
      	g_free(extents);
      } else {
      	extents_ary = Qnil;
      }
      rb_hash_aset(window_obj, key_frame_extents, extents_ary);

      /* strut partial or strut */
      if ((strut = (unsigned long *)get_property(disp, client_list[i],
						 XA_CARDINAL, "_NET_WM_STRUT_PARTIAL", &strut_size)) == NULL) {
	strut = (unsigned long *)get_property(disp, client_list[i], XA_CARDINAL, "_NET_WM_STRUT", &strut_size);
      }
      if (strut) {
	strut_ary = rb_ary_new();
      	for (j = 0; j < strut_size / sizeof(unsigned long); j++) {
      	  rb_ary_push(strut_ary, ULONG2NUM(strut[j]));
      	}
      	g_free(strut);
      } else {
      	strut_ary = Qnil;
      }
      rb_hash_aset(window_obj, key_strut, strut_ary);
    }

    rb_ary_push(window_ary, window_obj);

    g_free(title_utf8);
    g_free(desktop);
    g_free(client_machine);
    g_free(class_out);
  }
  g_free(client_list);

  return window_ary;
}

#showing_desktopObject

Minimize windows to show desktop.



699
700
701
702
703
704
705
# File 'ext/wmctrl.c', line 699

static VALUE rb_wmctrl_showing_desktop (VALUE self, VALUE state) {
  Display **ptr, *disp;
  Data_Get_Struct(self, Display*, ptr);
  disp = *ptr;
  client_msg(disp, DefaultRootWindow(disp), "_NET_SHOWING_DESKTOP", RTEST(state), 0, 0, 0, 0);
  return Qtrue;
}

#supportedObject



1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
# File 'ext/wmctrl.c', line 1172

static VALUE rb_wmctrl_supported (VALUE self)
{
  Atom *list;
  unsigned long size;
  unsigned int i;
  gchar *prop_name;
  VALUE ret;
  Display **ptr, *disp;
  Data_Get_Struct(self, Display*, ptr);
  disp = *ptr;

  
  if (!(list = (Atom *)get_property(disp, DefaultRootWindow(disp), XA_ATOM, "_NET_SUPPORTED", &size))) {
    rb_raise(rb_eStandardError, "Cannot get _NET_SUPPORTED property.");
  }

  ret = rb_ary_new();
  for (i = 0; i < size / sizeof(Atom); i++) {
    prop_name = XGetAtomName(disp, list[i]);
    rb_ary_push(ret, rb_str_new2(prop_name));
    g_free(prop_name);
  }
  g_free(list);
  return ret;
}

#switch_desktopObject

Switch desktop.



613
614
615
616
617
618
619
620
621
622
623
624
625
# File 'ext/wmctrl.c', line 613

static VALUE rb_wmctrl_switch_desktop (VALUE self, VALUE desktop_id) {
  int target;
  Display **ptr, *disp;
  Data_Get_Struct(self, Display*, ptr);
  disp = *ptr;

  target = FIX2INT(desktop_id);
  if (target < 0) {
    rb_raise(rb_eStandardError, "Invalid desktop ID: %d", target);
  }
  client_msg(disp, DefaultRootWindow(disp), "_NET_CURRENT_DESKTOP", (unsigned long)target, 0, 0, 0, 0);
  return Qtrue;
}