added license GPL
[winnie] / 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 bool winnie_init()
30 {
31         if(!init_shared_memory()) {
32                 return false;
33         }
34
35         if(!init_gfx()) {
36                 return false;
37         }
38
39         if(!init_window_manager()) {
40                 return false;
41         }
42
43         if(!init_keyboard()) {
44                 return false;
45         }
46
47         if(!init_mouse()) {
48                 return false;
49         }
50
51         if(!init_text()) {
52                 return false;
53         }
54
55         wm->invalidate_region(get_screen_size());
56         return true;
57 }
58
59 void winnie_shutdown()
60 {
61         destroy_gfx();
62         destroy_keyboard();
63         destroy_mouse();
64         destroy_text();
65
66         destroy_shared_memory();
67 }
68
69 long winnie_get_time()
70 {
71         static struct timeval init_tv;
72         struct timeval tv;
73
74         gettimeofday(&tv, 0);
75
76         if(!tv.tv_sec && !tv.tv_usec) {
77                 init_tv = tv;
78                 return 0;
79         }
80
81         return (tv.tv_usec - init_tv.tv_usec) / 1000 + (tv.tv_sec - init_tv.tv_sec) * 1000;
82 }