created libwinnie (library), winnie (the server application) and clients
[winnie] / libwinnie / src / winnie.cc
1 /*
2 winnie - an experimental window system
3
4 Copyright (C) 2013 Eleni Maria Stea
5
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
19 Author: Eleni Maria Stea <elene.mst@gmail.com>
20 */
21
22 #include <sys/time.h>
23
24 #include "keyboard.h"
25 #include "mouse.h"
26 #include "shalloc.h"
27 #include "winnie.h"
28
29 static Subsys *subsys;
30
31 bool winnie_init()
32 {
33         if(!init_shared_memory()) {
34                 return false;
35         }
36
37         if(!(subsys = (Subsys*)sh_malloc(sizeof *subsys))) {
38                 return false;
39         }
40
41         if(!init_gfx()) {
42                 return false;
43         }
44
45         if(!init_window_manager()) {
46                 return false;
47         }
48
49         if(!init_keyboard()) {
50                 return false;
51         }
52
53         if(!init_mouse()) {
54                 return false;
55         }
56
57         if(!init_text()) {
58                 return false;
59         }
60
61         wm->invalidate_region(get_screen_size());
62         return true;
63 }
64
65 void winnie_shutdown()
66 {
67         destroy_gfx();
68         destroy_keyboard();
69         destroy_mouse();
70         destroy_text();
71         destroy_window_manager();
72
73         sh_free(subsys);
74
75         destroy_shared_memory();
76 }
77
78 long winnie_get_time()
79 {
80         static struct timeval init_tv;
81         struct timeval tv;
82
83         gettimeofday(&tv, 0);
84
85         if(!tv.tv_sec && !tv.tv_usec) {
86                 init_tv = tv;
87                 return 0;
88         }
89
90         return (tv.tv_usec - init_tv.tv_usec) / 1000 + (tv.tv_sec - init_tv.tv_sec) * 1000;
91 }
92
93 Subsys *get_subsys()
94 {
95         return subsys;
96 }