File: test_display_switch.adb

package info (click to toggle)
libgtkada 2.24.4dfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 12,208 kB
  • ctags: 1,676
  • sloc: ada: 119,686; ansic: 4,719; sh: 3,003; makefile: 690; xml: 338; perl: 70
file content (100 lines) | stat: -rw-r--r-- 3,486 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
-----------------------------------------------------------------------
--          GtkAda - Ada95 binding for the Gimp Toolkit              --
--                                                                   --
--                   Copyright (C) 2008-2013, AdaCore                --
--                                                                   --
-- This library is free software; you can redistribute it and/or     --
-- modify it under the terms of the GNU General Public               --
-- License as published by the Free Software Foundation; either      --
-- version 2 of the License, or (at your option) any later version.  --
--                                                                   --
-- This library is distributed in the hope that it will be useful,   --
-- but WITHOUT ANY WARRANTY; without even the implied warranty of    --
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU --
-- General Public License for more details.                          --
--                                                                   --
-- You should have received a copy of the GNU General Public         --
-- License along with this library; if not, write to the             --
-- Free Software Foundation, Inc., 59 Temple Place - Suite 330,      --
-- Boston, MA 02111-1307, USA.                                       --
--                                                                   --
-----------------------------------------------------------------------

--  This program demonstrates how to switch between displays under X11.

with GNAT.OS_Lib;

with Gtk.Main;

with Gdk.Display; use Gdk.Display;
with Gdk.Display_Manager; use Gdk.Display_Manager;

with Gtk.Window; use Gtk.Window;
with Gtk.Button; use Gtk.Button;
with Gtkada.Handlers; use Gtkada.Handlers;

with Ada.Text_IO; use Ada.Text_IO;
with Gtk.Widget;

procedure Test_Display_Switch is
   Window : Gtk_Window;
   Button : Gtk_Button;

   procedure On_Click
     (Button : access Gtk.Widget.Gtk_Widget_Record'Class) is
   begin
      Destroy (Window);
      Gtk.Main.Main_Quit;
   end On_Click;

begin
   Put_Line ("Enter the display used to initialize GtkAda: ");

   declare
      S : constant String := Get_Line;
   begin
      Put_Line ("Initializing with '" & S & "'");

      GNAT.OS_Lib.Setenv ("DISPLAY", S);

      --  Initialize GtkAda.
      Gtk.Main.Set_Locale;
      Gtk.Main.Init;

      Put_Line ("Initialization done.");
   end;

   New_Line;

   loop
      Put_Line ("Enter the display used to display the window: ");
      declare
         S    : constant String := Get_Line;
         Disp : Gdk.Display.Gdk_Display;
      begin
         Put_Line ("Displaying on '" & S & "'");

         --  Change the display
         Disp := Gdk.Display.Open (S);
         Gdk.Display_Manager.Set_Default_Display
           (Display_Manager_Get,  Disp);

         --  Create a window with a button
         Gtk_New (Window);
         Gtk_New (Button,
                  "hello on display '"
                  & S &  "' (click to select another display");
         Add (Window, Button);

         --  Connect the button to the callback
         Gtkada.Handlers.Widget_Callback.Connect
           (Button, "clicked", On_Click'Unrestricted_Access);

         --  Show the window
         Show_All (Window);

         --  Launch a main loop.
         Gtk.Main.Main; --  The program waits here until the button is pressed
      end;
   end loop;
end Test_Display_Switch;