~golfish/netbook-remix-launcher/desktop

« back to all changes in this revision

Viewing changes to src/main.c

  • Committer: Neil J. Patel
  • Date: 2008-04-16 11:31:15 UTC
  • Revision ID: njpatel@gmail.com-20080416113115-ztljg0qms79anijd
* Inital import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2008 Canonical Ltd
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or
 
5
 * modify it under the terms of the GNU General Public
 
6
 * License as published by the Free Software Foundation; either
 
7
 * version 2 of the License, or (at your option) any later version.
 
8
 *
 
9
 * This library is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
12
 * Lesser General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU General Public
 
15
 * License along with this library; if not, write to the
 
16
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
17
 * Boston, MA 02111-1307, USA.
 
18
 *
 
19
 * Authored by Neil Jagdish Patel <neil.patel@canonical.com>
 
20
 *
 
21
 */
 
22
 
 
23
 
 
24
#include <glib.h>
 
25
 
 
26
#include <stdio.h>
 
27
#include <string.h>
 
28
#include <stdlib.h>
 
29
 
 
30
#include <gtk/gtk.h>
 
31
#include <gdk/gdkx.h>
 
32
 
 
33
#include <clutter/clutter.h>
 
34
#include <clutter/clutter-x11.h>
 
35
 
 
36
#include "launcher-app.h"
 
37
#include "launcher-defines.h"
 
38
 
 
39
/* Forwards */
 
40
static void set_window_hints (ClutterStage *stage);
 
41
 
 
42
static gboolean windowed = FALSE;
 
43
 
 
44
static GOptionEntry entries[] =
 
45
{
 
46
  {
 
47
    "windowed",
 
48
    'w', 0,
 
49
    G_OPTION_ARG_NONE,
 
50
    &windowed,
 
51
    "Launch in windowed mode (for testing, 800x640)",
 
52
    NULL
 
53
  },
 
54
  {
 
55
    NULL
 
56
  }
 
57
};
 
58
 
 
59
gint
 
60
main (gint argc, gchar *argv[])
 
61
{
 
62
  ClutterActor *stage;
 
63
  ClutterColor black = { 0x00, 0x00, 0x00, 0xff };
 
64
  LauncherApp *app;
 
65
  GError *error = NULL;
 
66
 
 
67
  g_thread_init (NULL);
 
68
  g_set_application_name ("Belmont Launcher");
 
69
 
 
70
  gtk_init (&argc, &argv);
 
71
  clutter_init_with_args (&argc, &argv,
 
72
                          " - Belmont Launcher", entries,
 
73
                          NULL,
 
74
                          &error);
 
75
  if (error)
 
76
  {
 
77
      g_print ("Unable to run Desktop Launcher: %s", error->message);
 
78
      g_error_free (error);
 
79
      return EXIT_FAILURE;
 
80
  }
 
81
 
 
82
  stage = clutter_stage_get_default ();
 
83
  clutter_actor_set_size (stage, 1024, 600);
 
84
 
 
85
  if (!windowed)
 
86
  {
 
87
    clutter_stage_fullscreen (CLUTTER_STAGE (stage));
 
88
    set_window_hints (CLUTTER_STAGE (stage));
 
89
  }
 
90
  clutter_stage_set_color (CLUTTER_STAGE (stage), &black);
 
91
 
 
92
  /* Init() the main application */
 
93
  app = launcher_app_get_default ();
 
94
 
 
95
  clutter_actor_show (stage);
 
96
  clutter_main ();
 
97
 
 
98
  g_object_unref (app);
 
99
 
 
100
  return EXIT_SUCCESS;
 
101
}
 
102
 
 
103
#if 0
 
104
/* 
 
105
 * Set a fake hint to the WM telling it there is a 'panel' beneath the
 
106
 * gnome-panel, so it won't set maximised windows to the full height, this
 
107
 * lets us draw the 'window-decorations' in clutter.
 
108
 * Functions taken from xutils.c (part of gnome-panel)
 
109
 */
 
110
enum {
 
111
        STRUT_LEFT = 0,
 
112
        STRUT_RIGHT = 1,
 
113
        STRUT_TOP = 2,
 
114
        STRUT_BOTTOM = 3,
 
115
        STRUT_LEFT_START = 4,
 
116
        STRUT_LEFT_END = 5,
 
117
        STRUT_RIGHT_START = 6,
 
118
        STRUT_RIGHT_END = 7,
 
119
        STRUT_TOP_START = 8,
 
120
        STRUT_TOP_END = 9,
 
121
        STRUT_BOTTOM_START = 10,
 
122
        STRUT_BOTTOM_END = 11
 
123
};
 
124
 
 
125
static void
 
126
set_panel_strut (Display *display, 
 
127
                 Window   window, 
 
128
                 gint     offset,
 
129
                 gint     x_start,
 
130
                 gint     x_end)
 
131
{
 
132
  gulong struts[12] = {0, };
 
133
  static Atom net_wm_strut = 0;
 
134
  static Atom net_wm_strut_partial = 0;
 
135
 
 
136
        if (net_wm_strut == 0)
 
137
                net_wm_strut = XInternAtom (display, "_NET_WM_STRUT", False);
 
138
        if (net_wm_strut_partial == 0)
 
139
                net_wm_strut_partial = XInternAtom (display, "_NET_WM_STRUT_PARTIAL", 
 
140
                                        False);
 
141
 
 
142
        struts [STRUT_TOP] = offset;
 
143
        struts [STRUT_TOP_START] = x_start;
 
144
        struts [STRUT_TOP_END] = x_end;
 
145
        
 
146
        gdk_error_trap_push ();
 
147
        XChangeProperty (display, window, net_wm_strut,
 
148
                   XA_CARDINAL, 32, PropModeReplace,
 
149
                   (guchar *) &struts, 4);
 
150
        XChangeProperty (display, window, net_wm_strut_partial,
 
151
                   XA_CARDINAL, 32, PropModeReplace,
 
152
                   (guchar *) &struts, 12);
 
153
        gdk_error_trap_pop ();
 
154
}
 
155
#endif
 
156
 
 
157
/*
 
158
 * Apply the 'desktop' window type to the clutter-stage window. Also, set the
 
159
 * 'panel' hints, to stop the windows from maximising the entire way.
 
160
 */
 
161
static void
 
162
set_window_hints (ClutterStage *stage)
 
163
{
 
164
  /*GdkScreen *screen = gdk_screen_get_default ();*/
 
165
  GdkDisplay *display = gdk_display_get_default (); 
 
166
  Display *xdisplay;
 
167
  Window stage_win;
 
168
  Atom atom;
 
169
 
 
170
  xdisplay = GDK_DISPLAY_XDISPLAY (display);
 
171
  stage_win = clutter_x11_get_stage_window (stage);
 
172
 
 
173
  /* 
 
174
   * Make the clutter window a 'desktop' window, i.e maximised, but behind 
 
175
   * everything else
 
176
   */
 
177
  atom = gdk_x11_get_xatom_by_name_for_display (display,
 
178
                                                "_NET_WM_WINDOW_TYPE_DESKTOP");
 
179
  XChangeProperty (xdisplay, stage_win,
 
180
                   gdk_x11_get_xatom_by_name_for_display (display,
 
181
                                                "_NET_WM_WINDOW_TYPE"),
 
182
                   XA_ATOM , 32, PropModeReplace, 
 
183
                   (guchar *)&atom, 1);
 
184
 
 
185
  /*set_panel_strut (xdisplay, stage_win, TOP_OFFSET, 
 
186
                   0, gdk_screen_get_width (screen));*/
 
187
}