aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.c
blob: e79b5d0132286af8f67e90a065c44bda1ecb7db2 (plain)
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
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
#include "actions.h"
#include "border.h"
#include "config.h"
#include "desktops.h"
#include "exec.h"
#include "fs.h"
#include "entry.h"
#include "keys.h"
#include "ipc.h"
#include "menu.h"
#include "view.h"

#ifdef USE_FERITE
# include "e_ferite.h"
#endif

#include <X11/Xproto.h>

#ifdef E_PROF
Evas_List __e_profiles = NULL;
#endif

static void cb_exit(void);
static void cb_exit(void)
{
   E_PROF_DUMP;
}

static void wm_running_error(Display * d, XErrorEvent * ev);
static void 
wm_running_error(Display * d, XErrorEvent * ev)
{
   if ((ev->request_code == X_ChangeWindowAttributes) && 
       (ev->error_code == BadAccess))
     {
	fprintf(stderr, "A window manager is already running. No point running now is there?\n");
	fprintf(stderr, "Exiting Enlightenment. Error.\n");
	exit(-2);
     }   
   UN(d);
}

void setup(void);
void
setup(void)
{
   e_grab();
   e_sync();
   e_border_adopt_children(0);
   e_ungrab();
}

int
main(int argc, char **argv)
{
   char *display = NULL;
   int   i;

   srand(time(NULL));
   atexit(cb_exit);
   e_exec_set_args(argc, argv);
   
   e_config_init();

   /* Check command line options here: */
   for (i = 1; i < argc; i++)
     {
	if ((   (!strcmp("-d",        argv[i])) 
	     || (!strcmp("-disp",     argv[i]))
	     || (!strcmp("-display",  argv[i]))
	     || (!strcmp("--display", argv[i]))) 
	    && (argc - i > 1))
	  {
	     display = argv[++i];
	  }
	else if (   (!strcmp("-h",     argv[i]))
		 || (!strcmp("-?",     argv[i]))
		 || (!strcmp("-help",  argv[i]))
		 || (!strcmp("--help", argv[i])))
	  {
	     printf("enlightenment options:                           \n"
		    "\t[-d | -disp | -display --display] display_name \n"
		    "\t[-v | -version | --version]                    \n");
	     exit(0);
	  }
	else if (   (!strcmp("-v",        argv[i]))
		 || (!strcmp("-version",  argv[i]))
		 || (!strcmp("--version", argv[i])))
	  {
	     printf("Enlightenment Version: %s\n", ENLIGHTENMENT_VERSION);
	     exit(0);
	  }
     }
   
   if (!e_display_init(display))
     {
	fprintf(stderr, "Enlightenment Error: cannot connect to display!\n");
	fprintf(stderr, "Exiting Enlightenment. Error.\n");
	exit(-1);
     }

   e_ev_signal_init();
   e_event_filter_init();
   e_ev_x_init();
   
   /* become a wm */
   e_grab();
   e_sync();
   e_set_error_handler(wm_running_error);
   e_window_set_events(0, XEV_CHILD_REDIRECT | XEV_PROPERTY | XEV_COLORMAP);
   e_sync();
   e_reset_error_handler();
   e_ungrab();

   e_fs_init();
   e_desktops_init();
   e_border_init();
   e_action_init();
   e_menu_init();
   e_view_init();
   e_entry_init();
   e_keys_init();
   e_guides_init();
   e_place_init();
   e_cursors_init();
   
#ifdef USE_FERITE
   e_ferite_init();
#endif
   
   setup();
   
   e_event_loop();

#ifdef USE_FERITE
   e_ferite_deinit();
#endif
   
   return 0;
}