2 winnie - an experimental window system
4 Copyright (C) 2013 Eleni Maria Stea
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.
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.
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/>.
19 Author: Eleni Maria Stea <elene.mst@gmail.com>
36 static Subsys *subsys;
40 if(!init_shared_memory()) {
44 if(!(subsys = (Subsys*)sh_malloc(sizeof *subsys))) {
52 if(!init_window_manager()) {
56 if(!init_keyboard()) {
68 wm->invalidate_region(get_screen_size());
72 void winnie_shutdown()
78 destroy_window_manager();
82 destroy_shared_memory();
90 if(((fd = shm_open(SHMNAME, O_RDWR, S_IRWXU)) == -1)) {
91 fprintf(stderr, "Failed to open shared memory: %s\n", strerror(errno));
95 if((pool = mmap(0, POOL_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0)) == (void*)-1) {
96 fprintf(stderr, "Failed to map shared memory: %s\n", strerror(errno));
100 subsys = (Subsys*)pool;
102 if(!client_open_gfx(pool, subsys->graphics_offset)) {
103 fprintf(stderr, "Failed to open graphics.\n");
107 if(!client_open_keyboard(pool, subsys->keyboard_offset)) {
108 fprintf(stderr, "Failed to open keyboard.\n");
112 if(!client_open_mouse(pool, subsys->mouse_offset)) {
113 fprintf(stderr, "Failed to open mouse.\n");
117 if(!client_open_text(pool, subsys->text_offset)) {
118 fprintf(stderr, "Failed to open text.\n");
122 if(!client_open_wm(pool, subsys->wm_offset)) {
123 fprintf(stderr, "Failed to open the window manager.\n");
133 client_close_keyboard();
134 client_close_mouse();
138 if(munmap(pool, POOL_SIZE) == -1) {
139 fprintf(stderr, "Failed to unmap shared memory: %s\n", strerror(errno));
143 long winnie_get_time()
145 static struct timeval init_tv;
148 gettimeofday(&tv, 0);
150 if(!tv.tv_sec && !tv.tv_usec) {
155 return (tv.tv_usec - init_tv.tv_usec) / 1000 + (tv.tv_sec - init_tv.tv_sec) * 1000;