testwindows.c 24.7 KB
Newer Older
1
#include <gtk/gtk.h>
2
#ifdef GDK_WINDOWING_X11
3
#include <X11/Xlib.h>
4
#endif
5 6 7 8 9 10 11

static GtkWidget *darea;
static GtkTreeStore *window_store = NULL;
static GtkWidget *treeview;

static void update_store (void);

12 13
static GtkWidget *main_window;

14 15 16 17

GdkWindow *
create_window (GdkWindow *parent,
	       int x, int y, int w, int h,
18
	       GdkRGBA *color)
19 20 21 22
{
  GdkWindowAttr attributes;
  gint attributes_mask;
  GdkWindow *window;
23
  GdkRGBA *bg;
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43

  attributes.x = x;
  attributes.y = y;
  attributes.width = w;
  attributes.height = h;
  attributes.window_type = GDK_WINDOW_CHILD;
  attributes.event_mask = GDK_STRUCTURE_MASK
			| GDK_BUTTON_MOTION_MASK
			| GDK_BUTTON_PRESS_MASK
			| GDK_BUTTON_RELEASE_MASK
			| GDK_EXPOSURE_MASK
			| GDK_ENTER_NOTIFY_MASK
			| GDK_LEAVE_NOTIFY_MASK;
  attributes.wclass = GDK_INPUT_OUTPUT;
      
  attributes_mask = GDK_WA_X | GDK_WA_Y;
      
  window = gdk_window_new (parent, &attributes, attributes_mask);
  gdk_window_set_user_data (window, darea);

44
  bg = g_new (GdkRGBA, 1);
45 46 47 48
  if (color)
    *bg = *color;
  else
    {
49 50 51 52
      bg->red = g_random_double ();
      bg->blue = g_random_double ();
      bg->green = g_random_double ();
      bg->alpha = 1.0;
53 54
    }
  
55
  gdk_window_set_background_rgba (window, bg);
56 57 58 59 60 61 62
  g_object_set_data_full (G_OBJECT (window), "color", bg, g_free);
  
  gdk_window_show (window);
  
  return window;
}

63 64 65 66 67
static void
add_window_cb (GtkTreeModel      *model,
	       GtkTreePath       *path,
	       GtkTreeIter       *iter,
	       gpointer           data)
68
{
69
  GList **selected = data;
70 71 72
  GdkWindow *window;

  gtk_tree_model_get (GTK_TREE_MODEL (window_store),
73
		      iter,
74 75
		      0, &window,
		      -1);
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91

  *selected = g_list_prepend (*selected, window);
}

static GList *
get_selected_windows (void)
{
  GtkTreeSelection *sel;
  GList *selected;

  sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));

  selected = NULL;
  gtk_tree_selection_selected_foreach (sel, add_window_cb, &selected);
  
  return selected;
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
}

static gboolean
find_window_helper (GtkTreeModel *model,
		    GdkWindow *window,
		    GtkTreeIter *iter,
		    GtkTreeIter *selected_iter)
{
  GtkTreeIter child_iter;
  GdkWindow *w;

  do
    {
      gtk_tree_model_get (model, iter,
			  0, &w,
			  -1);
      if (w == window)
	{
	  *selected_iter = *iter;
	  return TRUE;
	}
      
      if (gtk_tree_model_iter_children (model,
					&child_iter,
					iter))
	{
	  if (find_window_helper (model, window, &child_iter, selected_iter))
	    return TRUE;
	}
    } while (gtk_tree_model_iter_next (model, iter));

  return FALSE;
}

static gboolean
find_window (GdkWindow *window,
	     GtkTreeIter *window_iter)
{
  GtkTreeIter iter;

  if (!gtk_tree_model_get_iter_first  (GTK_TREE_MODEL (window_store), &iter))
    return FALSE;

  return find_window_helper (GTK_TREE_MODEL (window_store),
			     window,
			     &iter,
			     window_iter);
}

static void
142
toggle_selection_window (GdkWindow *window)
143
{
144
  GtkTreeSelection *selection;
145
  GtkTreeIter iter;
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161

  selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));

  if (window != NULL &&
      find_window (window, &iter))
    {
      if (gtk_tree_selection_iter_is_selected (selection, &iter))
	gtk_tree_selection_unselect_iter (selection,  &iter);
      else
	gtk_tree_selection_select_iter (selection,  &iter);
    }
}

static void
unselect_windows (void)
{
162 163
  GtkTreeSelection *selection;

164 165 166 167 168 169 170 171 172 173 174 175
  selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
  
  gtk_tree_selection_unselect_all (selection);
}


static void
select_window (GdkWindow *window)
{
  GtkTreeSelection *selection;
  GtkTreeIter iter;

176 177 178 179 180
  selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));

  if (window != NULL &&
      find_window (window, &iter))
    gtk_tree_selection_select_iter (selection,  &iter);
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
}

static void
select_windows (GList *windows)
{
  GtkTreeSelection *selection;
  GtkTreeIter iter;
  GList *l;

  selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
  gtk_tree_selection_unselect_all (selection);
  
  for (l = windows; l != NULL; l = l->next)
    {
      if (find_window (l->data, &iter))
	gtk_tree_selection_select_iter (selection,  &iter);
    }
198 199 200 201 202 203 204
}

static void
add_window_clicked (GtkWidget *button, 
		    gpointer data)
{
  GdkWindow *parent;
205
  GList *l;
206

207 208 209 210
  l = get_selected_windows ();
  if (l != NULL)
    parent = l->data;
  else
211
    parent = gtk_widget_get_window (darea);
212 213

  g_list_free (l);
214 215 216 217 218 219 220 221 222
  
  create_window (parent, 10, 10, 100, 100, NULL);
  update_store ();
}

static void
remove_window_clicked (GtkWidget *button, 
		       gpointer data)
{
223 224 225
  GList *l, *selected;

  selected = get_selected_windows ();
226

227 228
  for (l = selected; l != NULL; l = l->next)
    gdk_window_destroy (l->data);
229

230 231 232
  g_list_free (selected);

  update_store ();
233 234 235 236 237 238 239 240
}

static void save_children (GString *s, GdkWindow *window);

static void
save_window (GString *s,
	     GdkWindow *window)
{
241
  gint x, y;
242
  GdkRGBA *color;
243 244 245 246

  gdk_window_get_position (window, &x, &y);
  color = g_object_get_data (G_OBJECT (window), "color");
  
247
  g_string_append_printf (s, "%d,%d %dx%d (%f,%f,%f,%f) %d %d\n",
248 249 250
			  x, y,
                          gdk_window_get_width (window),
                          gdk_window_get_height (window),
251
			  color->red, color->green, color->blue, color->alpha,
252
			  gdk_window_has_native (window),
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276
			  g_list_length (gdk_window_peek_children (window)));

  save_children (s, window);
}


static void
save_children (GString *s,
	       GdkWindow *window)
{
  GList *l;
  GdkWindow *child;

  for (l = g_list_reverse (gdk_window_peek_children (window));
       l != NULL;
       l = l->next)
    {
      child = l->data;

      save_window (s, child);
    }
}


277 278 279 280 281 282 283
static void
refresh_clicked (GtkWidget *button, 
		 gpointer data)
{
  gtk_widget_queue_draw (darea);
}

284 285 286 287 288 289 290 291 292 293
static void
save_clicked (GtkWidget *button, 
	      gpointer data)
{
  GString *s;
  GtkWidget *dialog;
  GFile *file;

  s = g_string_new ("");

294
  save_children (s, gtk_widget_get_window (darea));
295 296 297 298

  dialog = gtk_file_chooser_dialog_new ("Filename for window data",
					NULL,
					GTK_FILE_CHOOSER_ACTION_SAVE,
299 300
					"_Cancel", GTK_RESPONSE_CANCEL,
					"_Save", GTK_RESPONSE_ACCEPT,
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
					NULL);
  
  gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog), TRUE);
  
  if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
    {
      file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (dialog));

      g_file_replace_contents (file,
			       s->str, s->len,
			       NULL, FALSE,
			       0, NULL, NULL, NULL);

      g_object_unref (file);
    }

  gtk_widget_destroy (dialog);
  g_string_free (s, TRUE);
}

static void
destroy_children (GdkWindow *window)
{
  GList *l;
  GdkWindow *child;

  for (l = gdk_window_peek_children (window);
       l != NULL;
       l = l->next)
    {
      child = l->data;
      
      destroy_children (child);
      gdk_window_destroy (child);
    }
}

static char **
parse_window (GdkWindow *parent, char **lines)
{
341 342
  int x, y, w, h, native, n_children;
  double r, g, b, a;
343
  GdkWindow *window;
344
  GdkRGBA color;
345 346 347 348 349
  int i;

  if (*lines == NULL)
    return lines;
  
350 351
  if (sscanf(*lines, "%d,%d %dx%d (%lf,%lf,%lf,%lf) %d %d",
	     &x, &y, &w, &h, &r, &g, &b, &a, &native, &n_children) == 10)
352 353 354 355 356
    {
      lines++;
      color.red = r;
      color.green = g;
      color.blue = b;
357
      color.alpha = a;
358 359
      window = create_window (parent, x, y, w, h, &color);
      if (native)
360
	gdk_window_ensure_native (window);
361 362 363 364 365 366 367 368 369 370 371 372 373
      
      for (i = 0; i < n_children; i++)
	lines = parse_window (window, lines);
    }
  else
    lines++;
  
  return lines;
}
  
static void
load_file (GFile *file)
{
374
  GdkWindow *window;
375 376 377 378 379
  char *data;
  char **lines, **l;
  
  if (g_file_load_contents (file, NULL, &data, NULL, NULL, NULL))
    {
380 381 382
      window = gtk_widget_get_window (darea);

      destroy_children (window);
383 384 385 386 387

      lines = g_strsplit (data, "\n", -1);

      l = lines;
      while (*l != NULL)
388
	l = parse_window (window, l);
389 390 391 392 393 394 395 396 397 398 399
    }

  update_store ();
}

static void
move_window_clicked (GtkWidget *button, 
		     gpointer data)
{
  GdkWindow *window;
  GtkDirectionType direction;
400
  GList *selected, *l;
401 402 403 404
  gint x, y;

  direction = GPOINTER_TO_INT (data);
    
405
  selected = get_selected_windows ();
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
  for (l = selected; l != NULL; l = l->next)
    {
      window = l->data;
      
      gdk_window_get_position (window, &x, &y);
      
      switch (direction) {
      case GTK_DIR_UP:
	y -= 10;
	break;
      case GTK_DIR_DOWN:
	y += 10;
	break;
      case GTK_DIR_LEFT:
	x -= 10;
	break;
      case GTK_DIR_RIGHT:
	x += 10;
	break;
      default:
	break;
      }

      gdk_window_move (window, x, y);
    }
432

433
  g_list_free (selected);
434 435
}

436 437 438 439 440 441 442
static void
manual_clicked (GtkWidget *button, 
		gpointer data)
{
  GdkWindow *window;
  GList *selected, *l;
  int x, y, w, h;
443
  GtkWidget *dialog, *grid, *label, *xspin, *yspin, *wspin, *hspin;
444 445 446 447 448 449 450 451
  

  selected = get_selected_windows ();

  if (selected == NULL)
    return;

  gdk_window_get_position (selected->data, &x, &y);
452 453
  w = gdk_window_get_width (selected->data);
  h = gdk_window_get_height (selected->data);
454 455 456 457

  dialog = gtk_dialog_new_with_buttons ("Select new position and size",
					GTK_WINDOW (main_window),
					GTK_DIALOG_MODAL,
458
					"_OK", GTK_RESPONSE_OK,
459 460 461
					NULL);
  

462
  grid = gtk_grid_new ();
463
  gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))),
464
		      grid,
465 466 467 468 469
		      FALSE, FALSE,
		      2);

  
  label = gtk_label_new ("x:");
470
  gtk_widget_set_halign (label, GTK_ALIGN_START);
471
  gtk_grid_attach (GTK_GRID (grid), label, 0, 0, 1, 1);
472
  label = gtk_label_new ("y:");
473
  gtk_widget_set_halign (label, GTK_ALIGN_START);
474
  gtk_grid_attach (GTK_GRID (grid), label, 0, 1, 1, 1);
475
  label = gtk_label_new ("width:");
476
  gtk_widget_set_halign (label, GTK_ALIGN_START);
477
  gtk_grid_attach (GTK_GRID (grid), label, 0, 2, 1, 1);
478
  label = gtk_label_new ("height:");
479
  gtk_widget_set_halign (label, GTK_ALIGN_START);
480
  gtk_grid_attach (GTK_GRID (grid), label, 0, 3, 1, 1);
481 482

  xspin = gtk_spin_button_new_with_range (G_MININT, G_MAXINT, 1);
483
  gtk_widget_set_hexpand (xspin, TRUE);
484
  gtk_spin_button_set_value (GTK_SPIN_BUTTON (xspin), x);
485
  gtk_grid_attach (GTK_GRID (grid), xspin, 1, 0, 1, 1);
486
  yspin = gtk_spin_button_new_with_range (G_MININT, G_MAXINT, 1);
487
  gtk_widget_set_hexpand (yspin, TRUE);
488
  gtk_spin_button_set_value (GTK_SPIN_BUTTON (yspin), y);
489
  gtk_grid_attach (GTK_GRID (grid), yspin, 1, 1, 1, 1);
490
  wspin = gtk_spin_button_new_with_range (G_MININT, G_MAXINT, 1);
491
  gtk_widget_set_hexpand (wspin, TRUE);
492
  gtk_spin_button_set_value (GTK_SPIN_BUTTON (wspin), w);
493
  gtk_grid_attach (GTK_GRID (grid), wspin, 1, 2, 1, 1);
494
  hspin = gtk_spin_button_new_with_range (G_MININT, G_MAXINT, 1);
495
  gtk_widget_set_hexpand (hspin, TRUE);
496
  gtk_spin_button_set_value (GTK_SPIN_BUTTON (hspin), h);
497
  gtk_grid_attach (GTK_GRID (grid), hspin, 1, 3, 1, 1);
498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519
  
  gtk_widget_show_all (dialog);
  
  gtk_dialog_run (GTK_DIALOG (dialog));

  x = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (xspin));
  y = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (yspin));
  w = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (wspin));
  h = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (hspin));

  gtk_widget_destroy (dialog);
  
  for (l = selected; l != NULL; l = l->next)
    {
      window = l->data;
      
      gdk_window_move_resize (window, x, y, w, h);
    }

  g_list_free (selected);
}

520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541
static void
restack_clicked (GtkWidget *button,
		 gpointer data)
{
  GList *selected;

  selected = get_selected_windows ();

  if (g_list_length (selected) != 2)
    {
      g_warning ("select two windows");
    }

  gdk_window_restack (selected->data,
		      selected->next->data,
		      GPOINTER_TO_INT (data));

  g_list_free (selected);

  update_store ();
}

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
static void
scroll_window_clicked (GtkWidget *button, 
		       gpointer data)
{
  GdkWindow *window;
  GtkDirectionType direction;
  GList *selected, *l;
  gint dx, dy;

  direction = GPOINTER_TO_INT (data);
    
  selected = get_selected_windows ();

  dx = 0; dy = 0;
  switch (direction) {
  case GTK_DIR_UP:
    dy = 10;
    break;
  case GTK_DIR_DOWN:
    dy = -10;
    break;
  case GTK_DIR_LEFT:
    dx = 10;
    break;
  case GTK_DIR_RIGHT:
    dx = -10;
    break;
  default:
    break;
  }
  
  for (l = selected; l != NULL; l = l->next)
    {
      window = l->data;

      gdk_window_scroll (window, dx, dy);
    }

  g_list_free (selected);
}


584 585 586 587
static void
raise_window_clicked (GtkWidget *button, 
		      gpointer data)
{
588
  GList *selected, *l;
589 590
  GdkWindow *window;
    
591 592 593 594 595 596 597 598
  selected = get_selected_windows ();

  for (l = selected; l != NULL; l = l->next)
    {
      window = l->data;
      
      gdk_window_raise (window);
    }
599

600 601
  g_list_free (selected);
  
602 603 604 605 606 607 608
  update_store ();
}

static void
lower_window_clicked (GtkWidget *button, 
		      gpointer data)
{
609
  GList *selected, *l;
610 611
  GdkWindow *window;
    
612 613 614 615 616 617 618 619
  selected = get_selected_windows ();

  for (l = selected; l != NULL; l = l->next)
    {
      window = l->data;
      
      gdk_window_lower (window);
    }
620

621 622
  g_list_free (selected);
  
623 624 625 626 627 628 629 630
  update_store ();
}


static void
smaller_window_clicked (GtkWidget *button, 
			gpointer data)
{
631
  GList *selected, *l;
632 633 634
  GdkWindow *window;
  int w, h;

635
  selected = get_selected_windows ();
636

637 638 639 640
  for (l = selected; l != NULL; l = l->next)
    {
      window = l->data;
      
641 642
      w = gdk_window_get_width (window) - 10;
      h = gdk_window_get_height (window) - 10;
643 644 645 646 647 648 649
      if (w < 1)
	w = 1;
      if (h < 1)
	h = 1;
      
      gdk_window_resize (window, w, h);
    }
650

651
  g_list_free (selected);
652 653 654 655 656 657
}

static void
larger_window_clicked (GtkWidget *button, 
			gpointer data)
{
658
  GList *selected, *l;
659 660 661
  GdkWindow *window;
  int w, h;

662
  selected = get_selected_windows ();
663

664 665 666 667
  for (l = selected; l != NULL; l = l->next)
    {
      window = l->data;
      
668 669
      w = gdk_window_get_width (window) + 10;
      h = gdk_window_get_height (window) + 10;
670 671 672
      
      gdk_window_resize (window, w, h);
    }
673

674
  g_list_free (selected);
675 676 677 678 679 680
}

static void
native_window_clicked (GtkWidget *button, 
			gpointer data)
{
681
  GList *selected, *l;
682 683
  GdkWindow *window;

684
  selected = get_selected_windows ();
685

686 687 688 689
  for (l = selected; l != NULL; l = l->next)
    {
      window = l->data;
      
690
      gdk_window_ensure_native (window);
691 692 693 694
    }
  
  g_list_free (selected);
  
695 696 697
  update_store ();
}

698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730
static void
alpha_clicked (GtkWidget *button, 
	       gpointer data)
{
  GList *selected, *l;
  GdkWindow *window;
  GdkRGBA *color;

  selected = get_selected_windows ();

  for (l = selected; l != NULL; l = l->next)
    {
      window = l->data;

      color = g_object_get_data (G_OBJECT (window), "color");
      if (GPOINTER_TO_INT(data) > 0)
	color->alpha += 0.2;
      else
	color->alpha -= 0.2;

      if (color->alpha < 0)
	color->alpha = 0;
      if (color->alpha > 1)
	color->alpha = 1;

      gdk_window_set_background_rgba (window, color);
    }
  
  g_list_free (selected);
  
  update_store ();
}

731 732 733 734
static gboolean
darea_button_release_event (GtkWidget *widget,
			    GdkEventButton *event)
{
735 736 737 738 739 740 741 742 743 744
  if ((event->state & GDK_CONTROL_MASK) != 0)
    {
      toggle_selection_window (event->window);
    }
  else
    {
      unselect_windows ();
      select_window (event->window);
    }
    
745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762
  return TRUE;
}

static void
render_window_cell (GtkTreeViewColumn *tree_column,
		    GtkCellRenderer   *cell,
		    GtkTreeModel      *tree_model,
		    GtkTreeIter       *iter,
		    gpointer           data)
{
  GdkWindow *window;
  char *name;

  gtk_tree_model_get (GTK_TREE_MODEL (window_store),
		      iter,
		      0, &window,
		      -1);

763
  if (gdk_window_has_native (window))
764 765 766
      name = g_strdup_printf ("%p (native)", window);
  else
      name = g_strdup_printf ("%p", window);
767

768 769
  g_object_set (cell,
		"text", name,
770
		NULL);
771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796
}

static void
add_children (GtkTreeStore *store,
	      GdkWindow *window,
	      GtkTreeIter *window_iter)
{
  GList *l;
  GtkTreeIter child_iter;

  for (l = gdk_window_peek_children (window);
       l != NULL;
       l = l->next)
    {
      gtk_tree_store_append (store, &child_iter, window_iter);
      gtk_tree_store_set (store, &child_iter,
			  0, l->data,
			  -1);

      add_children (store, l->data, &child_iter);
    }
}

static void
update_store (void)
{
797
  GList *selected;
798

799
  selected = get_selected_windows ();
800 801 802

  gtk_tree_store_clear (window_store);

803
  add_children (window_store, gtk_widget_get_window (darea), NULL);
804 805
  gtk_tree_view_expand_all (GTK_TREE_VIEW (treeview));

806 807
  select_windows (selected);
  g_list_free (selected);
808 809 810 811 812 813 814
}


int
main (int argc, char **argv)
{
  GtkWidget *window, *vbox, *hbox, *frame;
815
  GtkWidget *button, *scrolled, *grid;
816 817
  GtkTreeViewColumn *column;
  GtkCellRenderer *renderer;
818
  GdkRGBA black = {0,0,0,1};
819 820 821 822
  GFile *file;
  
  gtk_init (&argc, &argv);

823
  main_window = window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
824 825 826 827
  gtk_container_set_border_width (GTK_CONTAINER (window), 0);

  g_signal_connect (G_OBJECT (window), "delete-event", gtk_main_quit, NULL);

828
  hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 5);
829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849
  gtk_container_add (GTK_CONTAINER (window), hbox);
  gtk_widget_show (hbox);

  frame = gtk_frame_new ("GdkWindows");
  gtk_box_pack_start (GTK_BOX (hbox),
		      frame,
		      FALSE, FALSE,
		      5);
  gtk_widget_show (frame);

  darea =  gtk_drawing_area_new ();
  gtk_widget_add_events (darea, GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK);
  gtk_widget_set_size_request (darea, 500, 500);
  g_signal_connect (darea, "button_release_event", 
		    G_CALLBACK (darea_button_release_event), 
		    NULL);

  
  gtk_container_add (GTK_CONTAINER (frame), darea);
  gtk_widget_realize (darea);
  gtk_widget_show (darea);
850
  gtk_widget_override_background_color (darea, 0, &black);
851 852 853


  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5);
854 855 856 857 858 859 860 861 862 863
  gtk_box_pack_start (GTK_BOX (hbox),
		      vbox,
		      FALSE, FALSE,
		      5);
  gtk_widget_show (vbox);

  window_store = gtk_tree_store_new (1, GDK_TYPE_WINDOW);
  
  treeview = gtk_tree_view_new_with_model (GTK_TREE_MODEL (window_store));
  gtk_tree_selection_set_mode (gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview)),
864
			       GTK_SELECTION_MULTIPLE);
865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886
  column = gtk_tree_view_column_new ();
  gtk_tree_view_column_set_title (column, "Window");
  renderer = gtk_cell_renderer_text_new ();
  gtk_tree_view_column_pack_start (column, renderer, TRUE);
  gtk_tree_view_column_set_cell_data_func (column,
					   renderer,
					   render_window_cell,
					   NULL, NULL);

  gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);


  scrolled = gtk_scrolled_window_new (NULL, NULL);
  gtk_widget_set_size_request (scrolled, 200, 400);
  gtk_container_add (GTK_CONTAINER (scrolled), treeview);
  gtk_box_pack_start (GTK_BOX (vbox),
		      scrolled,
		      FALSE, FALSE,
		      5);
  gtk_widget_show (scrolled);
  gtk_widget_show (treeview);
  
887 888 889
  grid = gtk_grid_new ();
  gtk_grid_set_row_homogeneous (GTK_GRID (grid), TRUE);
  gtk_grid_set_column_homogeneous (GTK_GRID (grid), TRUE);
890
  gtk_box_pack_start (GTK_BOX (vbox),
891
		      grid,
892 893
		      FALSE, FALSE,
		      2);
894
  gtk_widget_show (grid);
895 896 897

  button = gtk_button_new ();
  gtk_button_set_image (GTK_BUTTON (button),
898 899
			gtk_image_new_from_icon_name ("go-previous-symbolic",
                                                      GTK_ICON_SIZE_BUTTON));
900 901 902
  g_signal_connect (button, "clicked", 
		    G_CALLBACK (move_window_clicked), 
		    GINT_TO_POINTER (GTK_DIR_LEFT));
903
  gtk_grid_attach (GTK_GRID (grid), button, 0, 1, 1, 1);
904 905 906 907
  gtk_widget_show (button);

  button = gtk_button_new ();
  gtk_button_set_image (GTK_BUTTON (button),
908 909
			gtk_image_new_from_icon_name ("go-up-symbolic",
                                                      GTK_ICON_SIZE_BUTTON));
910 911 912
  g_signal_connect (button, "clicked", 
		    G_CALLBACK (move_window_clicked), 
		    GINT_TO_POINTER (GTK_DIR_UP));
913
  gtk_grid_attach (GTK_GRID (grid), button, 1, 0, 1, 1);
914 915 916 917
  gtk_widget_show (button);

  button = gtk_button_new ();
  gtk_button_set_image (GTK_BUTTON (button),
918 919
			gtk_image_new_from_icon_name ("go-next-symbolic",
                                                      GTK_ICON_SIZE_BUTTON));
920 921 922
  g_signal_connect (button, "clicked", 
		    G_CALLBACK (move_window_clicked), 
		    GINT_TO_POINTER (GTK_DIR_RIGHT));
923
  gtk_grid_attach (GTK_GRID (grid), button, 2, 1, 1, 1);
924 925 926 927
  gtk_widget_show (button);

  button = gtk_button_new ();
  gtk_button_set_image (GTK_BUTTON (button),
928 929
			gtk_image_new_from_icon_name ("go-down-symbolic",
                                                      GTK_ICON_SIZE_BUTTON));
930 931 932
  g_signal_connect (button, "clicked", 
		    G_CALLBACK (move_window_clicked), 
		    GINT_TO_POINTER (GTK_DIR_DOWN));
933
  gtk_grid_attach (GTK_GRID (grid), button, 1, 2, 1, 1);
934 935 936 937 938 939 940
  gtk_widget_show (button);


  button = gtk_button_new_with_label ("Raise");
  g_signal_connect (button, "clicked", 
		    G_CALLBACK (raise_window_clicked), 
		    NULL);
941
  gtk_grid_attach (GTK_GRID (grid), button, 0, 0, 1, 1);
942 943 944 945 946 947
  gtk_widget_show (button);

  button = gtk_button_new_with_label ("Lower");
  g_signal_connect (button, "clicked", 
		    G_CALLBACK (lower_window_clicked), 
		    NULL);
948
  gtk_grid_attach (GTK_GRID (grid), button, 0, 2, 1, 1);
949 950 951 952 953 954 955
  gtk_widget_show (button);


  button = gtk_button_new_with_label ("Smaller");
  g_signal_connect (button, "clicked", 
		    G_CALLBACK (smaller_window_clicked), 
		    NULL);
956
  gtk_grid_attach (GTK_GRID (grid), button, 2, 0, 1, 1);
957 958 959 960 961 962
  gtk_widget_show (button);

  button = gtk_button_new_with_label ("Larger");
  g_signal_connect (button, "clicked", 
		    G_CALLBACK (larger_window_clicked), 
		    NULL);
963
  gtk_grid_attach (GTK_GRID (grid), button, 2, 2, 1, 1);
964 965 966 967 968 969
  gtk_widget_show (button);

  button = gtk_button_new_with_label ("Native");
  g_signal_connect (button, "clicked", 
		    G_CALLBACK (native_window_clicked), 
		    NULL);
970
  gtk_grid_attach (GTK_GRID (grid), button, 1, 1, 1, 1);
971 972 973
  gtk_widget_show (button);


974 975
  button = gtk_button_new_with_label ("scroll");
  gtk_button_set_image (GTK_BUTTON (button),
976 977
			gtk_image_new_from_icon_name ("go-up-symbolic",
                                                      GTK_ICON_SIZE_BUTTON));
978 979 980
  g_signal_connect (button, "clicked", 
		    G_CALLBACK (scroll_window_clicked), 
		    GINT_TO_POINTER (GTK_DIR_UP));
981
  gtk_grid_attach (GTK_GRID (grid), button, 3, 0, 1, 1);
982 983 984 985
  gtk_widget_show (button);

  button = gtk_button_new_with_label ("scroll");
  gtk_button_set_image (GTK_BUTTON (button),
986 987
			gtk_image_new_from_icon_name ("go-down-symbolic",
                                                      GTK_ICON_SIZE_BUTTON));
988 989 990
  g_signal_connect (button, "clicked", 
		    G_CALLBACK (scroll_window_clicked), 
		    GINT_TO_POINTER (GTK_DIR_DOWN));
991
  gtk_grid_attach (GTK_GRID (grid), button, 3, 1, 1, 1);
992 993
  gtk_widget_show (button);

994 995 996 997
  button = gtk_button_new_with_label ("Manual");
  g_signal_connect (button, "clicked", 
		    G_CALLBACK (manual_clicked),
		    NULL);
998
  gtk_grid_attach (GTK_GRID (grid), button, 3, 2, 1, 1);
999
  gtk_widget_show (button);
1000

1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014
  button = gtk_button_new_with_label ("More transparent");
  g_signal_connect (button, "clicked",
		    G_CALLBACK (alpha_clicked),
		    GINT_TO_POINTER (-1));
  gtk_grid_attach (GTK_GRID (grid), button, 0, 3, 1, 1);
  gtk_widget_show (button);

  button = gtk_button_new_with_label ("Less transparent");
  g_signal_connect (button, "clicked",
		    G_CALLBACK (alpha_clicked),
		    GINT_TO_POINTER (1));
  gtk_grid_attach (GTK_GRID (grid), button, 1, 3, 1, 1);
  gtk_widget_show (button);

1015 1016 1017
  button = gtk_button_new_with_label ("Restack above");
  g_signal_connect (button, "clicked",
		    G_CALLBACK (restack_clicked),
1018
		    GINT_TO_POINTER (1));
1019
  gtk_grid_attach (GTK_GRID (grid), button, 2, 3, 1, 1);
1020 1021 1022 1023 1024 1025
  gtk_widget_show (button);

  button = gtk_button_new_with_label ("Restack below");
  g_signal_connect (button, "clicked",
		    G_CALLBACK (restack_clicked),
		    0);
1026
  gtk_grid_attach (GTK_GRID (grid), button, 3, 3, 1, 1);
1027 1028
  gtk_widget_show (button);

1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058
  button = gtk_button_new_with_label ("Add window");
  gtk_box_pack_start (GTK_BOX (vbox),
		      button,
		      FALSE, FALSE,
		      2);
  gtk_widget_show (button);
  g_signal_connect (button, "clicked", 
		    G_CALLBACK (add_window_clicked), 
		    NULL);
  
  button = gtk_button_new_with_label ("Remove window");
  gtk_box_pack_start (GTK_BOX (vbox),
		      button,
		      FALSE, FALSE,
		      2);
  gtk_widget_show (button);
  g_signal_connect (button, "clicked", 
		    G_CALLBACK (remove_window_clicked), 
		    NULL);

  button = gtk_button_new_with_label ("Save");
  gtk_box_pack_start (GTK_BOX (vbox),
		      button,
		      FALSE, FALSE,
		      2);
  gtk_widget_show (button);
  g_signal_connect (button, "clicked", 
		    G_CALLBACK (save_clicked), 
		    NULL);

1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069
  button = gtk_button_new_with_label ("Refresh");
  gtk_box_pack_start (GTK_BOX (vbox),
		      button,
		      FALSE, FALSE,
		      2);
  gtk_widget_show (button);
  g_signal_connect (button, "clicked", 
		    G_CALLBACK (refresh_clicked), 
		    NULL);

  
1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082
  gtk_widget_show (window);

  if (argc == 2)
    {
      file = g_file_new_for_commandline_arg (argv[1]);
      load_file (file);
      g_object_unref (file);
    }
  
  gtk_main ();

  return 0;
}