├── .bzrignore
├── clock
├── Makefile
├── README
└── src
│ └── main.cc
├── libwinnie
├── Makefile
├── README
└── src
│ ├── event.h
│ ├── fbdev
│ ├── event.cc
│ ├── gfx.cc
│ ├── keyboard.cc
│ └── mouse.cc
│ ├── geom.cc
│ ├── geom.h
│ ├── gfx.cc
│ ├── gfx.h
│ ├── keyboard.h
│ ├── mouse.h
│ ├── mouse_cursor.h
│ ├── pixmap.cc
│ ├── pixmap.h
│ ├── sdl
│ ├── event.cc
│ ├── gfx.cc
│ ├── keyboard.cc
│ └── mouse.cc
│ ├── semaphore.cc
│ ├── semaphore.h
│ ├── shalloc.cc
│ ├── shalloc.h
│ ├── text.cc
│ ├── text.h
│ ├── window.cc
│ ├── window.h
│ ├── winnie.cc
│ ├── winnie.h
│ ├── wm.cc
│ └── wm.h
└── winnie
├── Makefile
├── README
└── src
└── main.cc
/.bzrignore:
--------------------------------------------------------------------------------
1 | *.d
2 |
--------------------------------------------------------------------------------
/clock/Makefile:
--------------------------------------------------------------------------------
1 | src = $(wildcard src/*.cc) $(wildcard src/fbdev/*.cc) $(wildcard src/sdl/*.cc)
2 | obj = $(src:.cc=.o)
3 | dep = $(obj:.o=.d)
4 | bin = clock
5 |
6 | dbg = -g
7 | opt = -O0
8 | inc = -Isrc -I../libwinnie/src
9 |
10 | backend = SDL
11 |
12 | ifeq ($(backend), SDL)
13 | def = -DWINNIE_SDL
14 | libs = -lSDL
15 | else
16 | def = -DWINNIE_FBDEV
17 | endif
18 |
19 | CXX = g++
20 | CXXFLAGS = -pedantic -Wall $(dbg) $(opt) $(inc) $(def) `freetype-config --cflags`
21 | LDFLAGS = -L../libwinnie/ $(libs) `freetype-config --libs` -lrt -lwinnie
22 |
23 | $(bin): $(obj)
24 | $(CXX) -o $@ $(obj) $(LDFLAGS) -Wl,-rpath=../libwinnie
25 |
26 | -include $(dep)
27 |
28 | %.d: %.cc
29 | @$(CPP) $(CXXFLAGS) $< -MM -MT $(@:.d=.o) >$@
30 |
31 | .PHONY: clean
32 | clean:
33 | rm -f $(obj) $(bin) $(dep)
34 |
35 |
--------------------------------------------------------------------------------
/clock/README:
--------------------------------------------------------------------------------
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 .
18 |
19 | Author: Eleni Maria Stea
20 | */
21 |
22 | A clock winnie client.
23 |
--------------------------------------------------------------------------------
/clock/src/main.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 .
18 |
19 | Author: Eleni Maria Stea
20 | */
21 |
22 | #include
23 | #include
24 | #include
25 |
26 | #include "winnie.h"
27 |
28 | static void display(Window *win);
29 | static void keyboard(Window *win, int key, bool pressed);
30 | static void button(Window *win, int bn, bool pressed, int x, int y);
31 | static void motion(Window *win, int x, int y);
32 |
33 | Subsys* subsys;
34 |
35 | int main()
36 | {
37 | if(!winnie_open()) {
38 | exit(1);
39 | }
40 |
41 | Window *clock_win = new Window;
42 | clock_win->set_title("Clipping the win title");
43 | clock_win->move(200, 100);
44 | clock_win->resize(200, 300);
45 | clock_win->set_display_callback(display);
46 | clock_win->set_keyboard_callback(keyboard);
47 | clock_win->set_mouse_button_callback(button);
48 | clock_win->set_mouse_motion_callback(motion);
49 |
50 | wm->add_window(clock_win);
51 |
52 | winnie_close();
53 | }
54 |
55 | static void display(Window *win)
56 | {
57 | fill_rect(win->get_absolute_rect(), 128, 128, 128);
58 | }
59 |
60 | static void keyboard(Window *win, int key, bool pressed)
61 | {
62 | switch(key) {
63 | case 'q':
64 | exit(0);
65 | }
66 | }
67 |
68 | static void button(Window *win, int bn, bool pressed, int x, int y)
69 | {
70 | printf("WINDOW(%p) button %d %s\n", (void*)win, bn, pressed ? "press" : "release");
71 | }
72 |
73 | static void motion(Window *win, int x, int y)
74 | {
75 | printf("WINDOW(%p) motion %d %d\n", (void*)win, x, y);
76 | }
77 |
--------------------------------------------------------------------------------
/libwinnie/Makefile:
--------------------------------------------------------------------------------
1 | PREFIX=/usr/local
2 | src = $(wildcard src/*.cc) $(wildcard src/fbdev/*.cc) $(wildcard src/sdl/*.cc)
3 | obj = $(src:.cc=.o)
4 | #dep = $(obj:.o=.d)
5 | lib_so = libwinnie.so
6 |
7 | dbg = -g
8 | opt = -O0
9 | inc = -Isrc
10 |
11 | backend = SDL
12 |
13 | ifeq ($(backend), SDL)
14 | def = -DWINNIE_SDL
15 | libs = -lSDL
16 | else
17 | def = -DWINNIE_FBDEV
18 | endif
19 |
20 | CXX = g++
21 | CXXFLAGS = -pedantic -Wall $(dbg) $(opt) $(inc) $(def) `freetype-config --cflags`
22 | LDFLAGS = $(libs) `freetype-config --libs` -lrt
23 |
24 | $(lib_so): $(obj)
25 | $(CXX) -o $@ -shared $(obj) $(LDFLAGS)
26 |
27 | .PHONY: clean
28 | clean:
29 | rm -f $(obj) $(lib_so)
30 |
31 | .PHONY: install
32 | install: $(lib_so)
33 | mkdir -p $(PREFIX)/lib
34 | mkdir -p $(PREFIX)/bin
35 | cp $(lib_so) $(PREFIX)/lib/$(lib_so)
36 | ldconfig
37 |
38 | .PHONY: uninstall
39 | uninstall:
40 | rm -f $(PREFIX)/lib/$(lib_so)
41 |
--------------------------------------------------------------------------------
/libwinnie/README:
--------------------------------------------------------------------------------
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 .
18 |
19 | Author: Eleni Maria Stea
20 | */
21 |
22 | The winnie library.
23 |
--------------------------------------------------------------------------------
/libwinnie/src/event.h:
--------------------------------------------------------------------------------
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 .
18 |
19 | Author: Eleni Maria Stea
20 | */
21 |
22 | #ifndef EVENT_H_
23 | #define EVENT_H_
24 |
25 | class Window;
26 |
27 | typedef void (*DisplayFuncType)(Window* win);
28 | typedef void (*KeyboardFuncType)(Window* win, int key, bool pressed);
29 | typedef void (*MouseButtonFuncType)(Window *win, int bn, bool pressed, int x, int y);
30 | typedef void (*MouseMotionFuncType)(Window *win, int x, int y);
31 |
32 | struct Callbacks {
33 | DisplayFuncType display;
34 | KeyboardFuncType keyboard;
35 | MouseButtonFuncType button;
36 | MouseMotionFuncType motion;
37 | };
38 |
39 | void process_events();
40 |
41 | #endif
42 |
--------------------------------------------------------------------------------
/libwinnie/src/fbdev/event.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 .
18 |
19 | Author: Eleni Maria Stea
20 | */
21 |
22 | #ifdef WINNIE_FBDEV
23 | #include
24 |
25 | #include
26 | #include
27 | #include
28 |
29 | #include "event.h"
30 | #include "wm.h"
31 | #include "keyboard.h"
32 | #include "mouse.h"
33 |
34 | void process_events()
35 | {
36 | int keyb_fd = get_keyboard_fd();
37 | int mouse_fd = get_mouse_fd();
38 |
39 | for(;;) {
40 | wm->process_windows();
41 |
42 | fd_set read_set;
43 |
44 | FD_ZERO(&read_set);
45 | FD_SET(keyb_fd, &read_set);
46 | FD_SET(mouse_fd, &read_set);
47 |
48 | int maxfd = keyb_fd > mouse_fd ? keyb_fd : mouse_fd;
49 |
50 | while(select(maxfd + 1, &read_set, 0, 0, 0) == -1 && errno == EINTR);
51 |
52 | if(FD_ISSET(keyb_fd, &read_set)) {
53 | process_keyboard_event();
54 | }
55 | if(FD_ISSET(mouse_fd, &read_set)) {
56 | process_mouse_event();
57 | }
58 | }
59 | }
60 | #endif // WINNIE_FBDEV
61 |
--------------------------------------------------------------------------------
/libwinnie/src/fbdev/gfx.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 .
18 |
19 | Author: Eleni Maria Stea
20 | */
21 |
22 | #ifdef WINNIE_FBDEV
23 | #include
24 | #include
25 | #include
26 | #include
27 | #include
28 |
29 | #include
30 | #include
31 | #include
32 | #include
33 | #include
34 |
35 | #include
36 |
37 | #include "gfx.h"
38 | #include "shalloc.h"
39 | #include "winnie.h"
40 |
41 | #define FRAMEBUFFER_SIZE(xsz, ysz, bpp) ((xsz) * (ysz) * (bpp) / CHAR_BIT)
42 |
43 | static unsigned char *framebuffer;
44 | static int dev_fd;
45 | static int rgb_order[3];
46 |
47 | struct Graphics {
48 | Rect screen_rect;
49 | Rect clipping_rect;
50 | int color_depth;
51 | Pixmap *pixmap;
52 | };
53 |
54 | static Graphics *gfx;
55 |
56 | bool init_gfx()
57 | {
58 | if(!(gfx = (Graphics*)sh_malloc(sizeof *gfx))) {
59 | return false;
60 | }
61 |
62 | get_subsys()->graphics_offset = (int)((char*)gfx - (char*)get_pool());
63 |
64 | dev_fd = -1;
65 |
66 | if((dev_fd = open("/dev/fb0", O_RDWR)) == -1) {
67 | fprintf(stderr, "Cannot open /dev/fb0 : %s\n", strerror(errno));
68 | return false;
69 | }
70 |
71 | fb_var_screeninfo sinfo;
72 | if(ioctl(dev_fd, FBIOGET_VSCREENINFO, &sinfo) == -1) {
73 | close(dev_fd);
74 | dev_fd = -1;
75 | fprintf(stderr, "Unable to get screen info : %s\n", strerror(errno));
76 | return false;
77 | }
78 |
79 | printf("width : %d height : %d\n : bpp : %d\n", sinfo.xres, sinfo.yres, sinfo.bits_per_pixel);
80 | printf("virtual w: %d virtual h: %d\n", sinfo.xres_virtual, sinfo.yres_virtual);
81 |
82 | gfx->screen_rect.x = gfx->screen_rect.y = 0;
83 | gfx->screen_rect.width = sinfo.xres_virtual;
84 | gfx->screen_rect.height = sinfo.yres_virtual;
85 | gfx->color_depth = sinfo.bits_per_pixel;
86 |
87 | rgb_order[0] = sinfo.red.offset / 8;
88 | rgb_order[1] = sinfo.green.offset / 8;
89 | rgb_order[2] = sinfo.blue.offset / 8;
90 |
91 | set_clipping_rect(gfx->screen_rect);
92 |
93 | int sz = FRAMEBUFFER_SIZE(gfx->screen_rect.width, gfx->screen_rect.height, gfx->color_depth);
94 | framebuffer = (unsigned char*)mmap(0, sz, PROT_READ | PROT_WRITE, MAP_SHARED, dev_fd, 0);
95 |
96 | if(framebuffer == (void*)-1) {
97 | close(dev_fd);
98 | dev_fd = -1;
99 | fprintf(stderr, "Cannot map the framebuffer to memory : %s\n", strerror(errno));
100 | return false;
101 | }
102 |
103 | // TODO: uncomment when I find how to use intelfb instead of i915 GRRRR.-
104 | fb_vblank vblank;
105 | if(ioctl(dev_fd, FBIOGET_VBLANK, &vblank) == -1) {
106 | // fprintf(stderr, "FBIOGET_VBLANK error: %s\n", strerror(errno));
107 | }
108 | /*
109 | else {
110 | printf("flags: %x\n", vblank.flags);
111 | printf("count: %d\n", vblank.count);
112 | printf("beam position: %d, %d\n", vblank.hcount, vblank.vcount);
113 | }
114 | */
115 |
116 | if(!(gfx->pixmap = (Pixmap*)sh_malloc(sizeof(Pixmap)))) {
117 | fprintf(stderr, "Failed to allocate pixmap.\n");
118 | return false;
119 | }
120 |
121 | gfx->pixmap->width = gfx->screen_rect.width;
122 | gfx->pixmap->height = gfx->screen_rect.height;
123 |
124 | int fbsize = gfx->pixmap->width * gfx->pixmap->height * gfx->color_depth / 8;
125 | if(!(gfx->pixmap->pixels = (unsigned char*)sh_malloc(fbsize))) {
126 | fprintf(stderr, "failed to allocate the pixmap framebuffer.\n");
127 | return false;
128 | }
129 |
130 | return true;
131 | }
132 |
133 | void destroy_gfx()
134 | {
135 | clear_screen(0, 0, 0);
136 | gfx_update(gfx->screen_rect);
137 |
138 | if(dev_fd != -1) {
139 | close(dev_fd);
140 | }
141 |
142 | dev_fd = -1;
143 |
144 | munmap(framebuffer, FRAMEBUFFER_SIZE(gfx->screen_rect.width, gfx->screen_rect.height, gfx->color_depth));
145 | framebuffer = 0;
146 |
147 | sh_free(gfx->pixmap->pixels);
148 | gfx->pixmap->pixels = 0;
149 | sh_free(gfx->pixmap);
150 | sh_free(gfx);
151 | }
152 |
153 | bool client_open_gfx(void *smem_start, int offset)
154 | {
155 | gfx = (Graphics*)((unsigned char*)smem_start + offset);
156 | return true;
157 | }
158 |
159 | void client_close_gfx()
160 | {
161 | }
162 |
163 | unsigned char *get_framebuffer()
164 | {
165 | return gfx->pixmap->pixels;
166 | }
167 |
168 | Pixmap *get_framebuffer_pixmap()
169 | {
170 | return gfx->pixmap;
171 | }
172 |
173 | Rect get_screen_size()
174 | {
175 | return gfx->screen_rect;
176 | }
177 |
178 | int get_color_depth()
179 | {
180 | return gfx->color_depth;
181 | }
182 |
183 | void set_clipping_rect(const Rect &rect)
184 | {
185 | gfx->clipping_rect = rect_intersection(rect, get_screen_size());
186 | }
187 |
188 | const Rect &get_clipping_rect()
189 | {
190 | return gfx->clipping_rect;
191 | }
192 |
193 | void set_cursor_visibility(bool visible)
194 | {
195 | fb_cursor curs;
196 | curs.enable = visible ? 1 : 0;
197 |
198 | if(ioctl(dev_fd, FBIO_CURSOR, &curs) == -1) {
199 | fprintf(stderr, "Cannot toggle cursor visibility : %s\n", strerror(errno));
200 | }
201 | }
202 |
203 | void gfx_update(const Rect &upd_rect)
204 | {
205 | Rect rect = rect_intersection(upd_rect, gfx->screen_rect);
206 | unsigned char *sptr = gfx->pixmap->pixels + (rect.y * gfx->screen_rect.width + rect.x) * 4;
207 | unsigned char *dptr = framebuffer + (rect.y * gfx->screen_rect.width + rect.x) * 4;
208 |
209 | for(int i=0; iscreen_rect.width * 4;
212 | dptr += gfx->screen_rect.width * 4;
213 | }
214 | }
215 |
216 | void wait_vsync()
217 | {
218 | unsigned long arg = 0;
219 | if(ioctl(dev_fd, FBIO_WAITFORVSYNC, &arg) == -1) {
220 | // printf("ioctl error %s\n", strerror(errno));
221 | }
222 | }
223 |
224 | void get_rgb_order(int *r, int *g, int *b)
225 | {
226 | *r = rgb_order[0];
227 | *g = rgb_order[1];
228 | *b = rgb_order[2];
229 | }
230 |
231 | #endif // WINNIE_FBDEV
232 |
--------------------------------------------------------------------------------
/libwinnie/src/fbdev/keyboard.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 .
18 |
19 | Author: Eleni Maria Stea
20 | */
21 |
22 | #ifdef WINNIE_FBDEV
23 | #include
24 | #include
25 | #include
26 | #include
27 |
28 | #include
29 | #include
30 | #include
31 | #include
32 |
33 | #include "keyboard.h"
34 | #include "shalloc.h"
35 | #include "window.h"
36 | #include "winnie.h"
37 | #include "wm.h"
38 |
39 | struct Keyboard {
40 | int dev_fd;
41 | enum {RAW, CANONICAL} ttystate;
42 | };
43 |
44 | static Keyboard *keyboard;
45 |
46 | bool init_keyboard()
47 | {
48 | if(!(keyboard = (Keyboard*)sh_malloc(sizeof *keyboard))) {
49 | return false;
50 | }
51 |
52 | get_subsys()->keyboard_offset = (int)((char*)keyboard - (char*)get_pool());
53 |
54 | keyboard->ttystate = keyboard->CANONICAL;
55 | keyboard->dev_fd = -1;
56 |
57 | if((keyboard->dev_fd = open("/dev/tty", O_RDWR)) == -1) {
58 | fprintf(stderr, "Cannot open /dev/tty : %s\n", strerror(errno));
59 | return false;
60 | }
61 |
62 | struct termios buf;
63 |
64 | if(tcgetattr(keyboard->dev_fd, &buf) < 0) {
65 | fprintf(stderr, "Cannot get the tty parameters : %s\n", strerror(errno));
66 | return false;
67 | }
68 |
69 | buf.c_lflag &= ~(ECHO | ICANON | IEXTEN | ISIG);
70 | buf.c_iflag &= ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON);
71 | buf.c_cflag &= ~(CSIZE | PARENB);
72 | buf.c_cflag |= CS8;
73 | buf.c_oflag &= ~(OPOST);
74 |
75 | if(tcsetattr(keyboard->dev_fd, TCSAFLUSH, &buf) < 0) {
76 | return false;
77 | }
78 |
79 | keyboard->ttystate = keyboard->RAW;
80 | return true;
81 | }
82 |
83 | void destroy_keyboard()
84 | {
85 | struct termios buf;
86 |
87 | if(tcgetattr(keyboard->dev_fd, &buf) < 0) {
88 | fprintf(stderr, "Cannot get the tty parameters : %s\n", strerror(errno));
89 | }
90 |
91 | buf.c_lflag |= (ECHO | ICANON | IEXTEN | ISIG);
92 | buf.c_iflag |= (BRKINT | ICRNL | INPCK | ISTRIP | IXON);
93 | buf.c_cflag |= (CSIZE | PARENB);
94 | buf.c_cflag &= CS8;
95 | buf.c_oflag |= (OPOST);
96 |
97 | if(tcsetattr(keyboard->dev_fd, TCSAFLUSH, &buf) < 0) {
98 | fprintf(stderr, "Cannot set the tty parameters : %s\n", strerror(errno));
99 | }
100 |
101 | keyboard->ttystate = keyboard->CANONICAL;
102 |
103 | if(keyboard->dev_fd != -1) {
104 | close(keyboard->dev_fd);
105 | keyboard->dev_fd = -1;
106 | }
107 |
108 | sh_free(keyboard);
109 | }
110 |
111 | bool client_open_keyboard(void *smem_start, int offset)
112 | {
113 | keyboard = (Keyboard*)((unsigned char*)smem_start + offset);
114 | return true;
115 | }
116 |
117 | void client_close_keyboard()
118 | {
119 | }
120 |
121 | int get_keyboard_fd()
122 | {
123 | return keyboard->dev_fd;
124 | }
125 |
126 | void process_keyboard_event()
127 | {
128 | char key;
129 | if(read(keyboard->dev_fd, &key, 1) < 1) {
130 | return;
131 | }
132 |
133 | if(key == 'q') {
134 | exit(0);
135 | }
136 |
137 | Window *focused_win = wm->get_focused_window();
138 | if(focused_win) {
139 | KeyboardFuncType keyb_callback = focused_win->get_keyboard_callback();
140 | if(keyb_callback) {
141 | keyb_callback(focused_win, key, true); //TODO: true??
142 | }
143 | }
144 |
145 | /* TODO:
146 | * - handle system-wide key combinations (alt-tab?)
147 | * - otherwise send keypress/release to focused window
148 | */
149 | }
150 | #endif // WINNIE_FBDEV
151 |
--------------------------------------------------------------------------------
/libwinnie/src/fbdev/mouse.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 .
18 |
19 | Author: Eleni Maria Stea
20 | */
21 |
22 | #ifdef WINNIE_FBDEV
23 | #include
24 | #include
25 | #include
26 | #include
27 | #include
28 |
29 | #include
30 | #include
31 | #include
32 | #include
33 |
34 | #include "geom.h"
35 | #include "gfx.h"
36 | #include "mouse.h"
37 | #include "shalloc.h"
38 | #include "window.h"
39 | #include "winnie.h"
40 | #include "wm.h"
41 |
42 | #define BN_LEFT 1
43 | #define BN_RIGHT 2
44 | #define BN_MIDDLE 4
45 |
46 | static int read_mouse();
47 |
48 | struct Mouse {
49 | int dev_fd;
50 | Rect bounds;
51 | int pointer_x;
52 | int pointer_y;
53 | int bnstate;
54 | };
55 |
56 | static Mouse *mouse;
57 |
58 | bool init_mouse()
59 | {
60 | if(!(mouse = (Mouse*)sh_malloc(sizeof *mouse))) {
61 | return false;
62 | }
63 | get_subsys()->mouse_offset = (int)((char*)mouse - (char*)get_pool());
64 | memset(mouse, 0, sizeof *mouse);
65 |
66 | mouse->dev_fd = -1;
67 |
68 | if((mouse->dev_fd = open("/dev/psaux", O_RDONLY | O_NONBLOCK)) == -1) {
69 | fprintf(stderr, "Cannot open /dev/psaux : %s\n", strerror(errno));
70 | return false;
71 | }
72 |
73 | set_mouse_bounds(get_screen_size());
74 | return true;
75 | }
76 |
77 | void destroy_mouse()
78 | {
79 | if(mouse->dev_fd != -1) {
80 | close(mouse->dev_fd);
81 | mouse->dev_fd = -1;
82 | }
83 | sh_free(mouse);
84 | }
85 |
86 | bool client_open_mouse(void *smem_start, int offset)
87 | {
88 | mouse = (Mouse*)((unsigned char*)smem_start + offset);
89 | return true;
90 | }
91 |
92 | void client_close_mouse()
93 | {
94 | }
95 |
96 | void set_mouse_bounds(const Rect &rect)
97 | {
98 | mouse->bounds = rect;
99 | }
100 |
101 | int get_mouse_fd()
102 | {
103 | return mouse->dev_fd;
104 | }
105 |
106 | void process_mouse_event()
107 | {
108 | /* TODO:
109 | * - read all pending events from mouse fd (use O_NONBLOCK so that
110 | * read will return -1 when there are no more events instead of blocking).
111 | */
112 |
113 | int prev_state = mouse->bnstate;
114 | int prev_x = mouse->pointer_x;
115 | int prev_y = mouse->pointer_y;
116 |
117 | if(read_mouse() == -1) {
118 | return;
119 | }
120 |
121 | Window *top;
122 | if(!(top = wm->get_grab_window())) {
123 | top = wm->get_window_at_pos(mouse->pointer_x, mouse->pointer_y);
124 | if(top) {
125 | wm->set_focused_window(top);
126 | }
127 | else {
128 | wm->set_focused_window(0);
129 | }
130 | }
131 |
132 | /* - send each pointer move and button press/release to the topmost window
133 | * with the pointer on it.
134 | */
135 |
136 | int dx = mouse->pointer_x - prev_x;
137 | int dy = mouse->pointer_y - prev_y;
138 |
139 | if((dx || dy) && top) {
140 | MouseMotionFuncType motion_callback = top->get_mouse_motion_callback();
141 | if(motion_callback) {
142 | Rect rect = top->get_absolute_rect();
143 | motion_callback(top, mouse->pointer_x - rect.x, mouse->pointer_y - rect.y);
144 | }
145 | }
146 |
147 | MouseButtonFuncType button_callback;
148 | if((mouse->bnstate != prev_state) && top && (button_callback = top->get_mouse_button_callback())) {
149 | int num_bits = sizeof mouse->bnstate * CHAR_BIT;
150 | for(int i=0; ibnstate >> i) & 1;
152 | int prev_s = (prev_state >> i) & 1;
153 | if(s != prev_s) {
154 | Rect rect = top->get_absolute_rect();
155 | button_callback(top, i, s, mouse->pointer_x - rect.x, mouse->pointer_y - rect.y);
156 | }
157 | }
158 | }
159 | }
160 |
161 | void get_pointer_pos(int *x, int *y)
162 | {
163 | *x = mouse->pointer_x;
164 | *y = mouse->pointer_y;
165 | }
166 |
167 | int get_button_state()
168 | {
169 | return mouse->bnstate;
170 | }
171 |
172 | int get_button(int bn)
173 | {
174 | if(bn < 0 || bn >= 3) {
175 | return 0;
176 | }
177 | return (mouse->bnstate & (1 << bn)) != 0;
178 | }
179 |
180 | static int read_mouse()
181 | {
182 | int rd;
183 | signed char state[3] = {0, 0, 0};
184 |
185 | if((rd = read(mouse->dev_fd, state, 3)) == -1) {
186 | fprintf(stderr, "Unable to get mouse state : %s\n", strerror(errno));
187 | return -1;
188 | }
189 |
190 | mouse->bnstate = state[0] & 7;
191 | mouse->pointer_x += state[1];
192 | mouse->pointer_y -= state[2];
193 |
194 | if(mouse->pointer_x < mouse->bounds.x) {
195 | mouse->pointer_x = mouse->bounds.x;
196 | }
197 |
198 | if(mouse->pointer_y < mouse->bounds.y) {
199 | mouse->pointer_y = mouse->bounds.y;
200 | }
201 |
202 | if(mouse->pointer_x > mouse->bounds.x + mouse->bounds.width - 1) {
203 | mouse->pointer_x = mouse->bounds.x + mouse->bounds.width - 1;
204 | }
205 |
206 | if(mouse->pointer_y > mouse->bounds.y + mouse->bounds.height - 1) {
207 | mouse->pointer_y = mouse->bounds.y + mouse->bounds.height - 1;
208 | }
209 |
210 | return 0;
211 | }
212 | #endif // WINNIE_FBDEV
213 |
--------------------------------------------------------------------------------
/libwinnie/src/geom.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 .
18 |
19 | Author: Eleni Maria Stea
20 | */
21 |
22 | #include "geom.h"
23 |
24 | Rect::Rect()
25 | {
26 | x = y = width = height = 0;
27 | }
28 |
29 | Rect::Rect(int x, int y, int w, int h)
30 | {
31 | this->x = x;
32 | this->y = y;
33 | width = w;
34 | height = h;
35 | }
36 |
37 | static inline int min(int x, int y)
38 | {
39 | return x < y ? x : y;
40 | }
41 |
42 | static inline int max(int x, int y)
43 | {
44 | return x > y ? x : y;
45 | }
46 |
47 | Rect rect_union(const Rect &a, const Rect &b)
48 | {
49 | Rect uni;
50 | uni.x = min(a.x, b.x);
51 | uni.y = min(a.y, b.y);
52 | uni.width = max(a.x + a.width, b.x + b.width) - uni.x;
53 | uni.height = max(a.y + a.height, b.y + b.height) - uni.y;
54 |
55 | return uni;
56 | }
57 |
58 | Rect rect_intersection(const Rect &a, const Rect &b)
59 | {
60 | Rect intersect;
61 | intersect.x = max(a.x, b.x);
62 | intersect.y = max(a.y, b.y);
63 | intersect.width = max(min(a.x + a.width, b.x + b.width) - intersect.x, 0);
64 | intersect.height = max(min(a.y + a.height, b.y + b.height) - intersect.y, 0);
65 |
66 | return intersect;
67 | }
68 |
--------------------------------------------------------------------------------
/libwinnie/src/geom.h:
--------------------------------------------------------------------------------
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 .
18 |
19 | Author: Eleni Maria Stea
20 | */
21 |
22 | #ifndef GEOM_H_
23 | #define GEOM_H_
24 |
25 | struct Rect {
26 | int x, y;
27 | int width, height;
28 |
29 | Rect();
30 | Rect(int x, int y, int w, int h);
31 | };
32 |
33 | Rect rect_union(const Rect &a, const Rect &b);
34 | Rect rect_intersection(const Rect &a, const Rect &b);
35 |
36 | #endif // GEOM_H_
37 |
--------------------------------------------------------------------------------
/libwinnie/src/gfx.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 .
18 |
19 | Author: Eleni Maria Stea
20 | */
21 |
22 | #include
23 |
24 | #include "geom.h"
25 | #include "gfx.h"
26 |
27 | void clear_screen(int r, int g, int b)
28 | {
29 | Rect screen_rect = get_screen_size();
30 | fill_rect(screen_rect, r, g, b);
31 | }
32 |
33 | void fill_rect(const Rect &rect, int r, int g, int b)
34 | {
35 | Rect drect = rect;
36 | Rect screen_rect = get_screen_size();
37 | Rect clipping_rect = get_clipping_rect();
38 |
39 | if(drect.x < clipping_rect.x) {
40 | drect.width -= clipping_rect.x - drect.x;
41 | drect.x = clipping_rect.x;
42 | }
43 |
44 | if(drect.y < clipping_rect.y) {
45 | drect.height -= clipping_rect.y - drect.y;
46 | drect.y = clipping_rect.y;
47 | }
48 |
49 | if(drect.x + drect.width >= clipping_rect.x + clipping_rect.width) {
50 | drect.width = clipping_rect.width + clipping_rect.x - drect.x;
51 | }
52 |
53 | if(drect.y + drect.height >= clipping_rect.y + clipping_rect.height) {
54 | drect.height = clipping_rect.height + clipping_rect.y - drect.y;
55 | }
56 |
57 | unsigned char *fb = get_framebuffer() + (drect.x + screen_rect.width * drect.y) * 4;
58 | for(int i=0; i= irect.width) {
93 | width -= xend - irect.width;
94 | }
95 |
96 | int yend = dest_y + height;
97 | if(yend >= irect.height) {
98 | height -= yend - irect.height;
99 | }
100 |
101 | if(width <= 0 || height <= 0) {
102 | return;
103 | }
104 |
105 | unsigned char *sptr = src_img + (src_rect.y * src_rect.width + src_rect.x) * 4;
106 | unsigned char *dptr = dest_img + (dest_y * dest_rect.width + dest_x) * 4;
107 |
108 | for(int i=0; i= irect.width) {
144 | width -= xend - irect.width;
145 | }
146 |
147 | int yend = dest_y + height;
148 | if(yend >= irect.height) {
149 | height -= yend - irect.height;
150 | }
151 |
152 | if(width <= 0 || height <= 0) {
153 | return;
154 | }
155 |
156 | unsigned char *sptr = src_img + (src_rect.y * src_rect.width + src_rect.x) * 4;
157 | unsigned char *dptr = dest_img + (dest_y * dest_rect.width + dest_x) * 4;
158 |
159 | for(int i=0; i.
18 |
19 | Author: Eleni Maria Stea
20 | */
21 |
22 | #ifndef GFX_H_
23 | #define GFX_H_
24 |
25 | #include "geom.h"
26 | #include "pixmap.h"
27 |
28 | bool init_gfx();
29 | void destroy_gfx();
30 |
31 | bool client_open_gfx(void *smem_start, int offset);
32 | void client_close_gfx();
33 |
34 | unsigned char *get_framebuffer();
35 | Pixmap *get_framebuffer_pixmap();
36 |
37 | Rect get_screen_size();
38 | int get_color_depth();
39 |
40 | void set_clipping_rect(const Rect &clip_rect);
41 | const Rect &get_clipping_rect();
42 |
43 | void clear_screen(int r, int g, int b);
44 | void fill_rect(const Rect &rect, int r, int g, int b);
45 |
46 | void set_cursor_visibility(bool visible);
47 |
48 | void blit(unsigned char *src_img, const Rect &src_rect, unsigned char* dest_img,
49 | const Rect &dest_rect, int dest_x, int dest_y);
50 |
51 | void blit_key(unsigned char *src_img, const Rect &src_rect, unsigned char* dest_img,
52 | const Rect &dest_rect, int dest_x, int dest_y, int key_r, int key_g, int key_b);
53 |
54 | void gfx_update(const Rect &rect);
55 |
56 | void wait_vsync(); // vertical synchronization
57 |
58 | void get_rgb_order(int *r, int *g, int *b);
59 |
60 | #endif //GFX_H_
61 |
--------------------------------------------------------------------------------
/libwinnie/src/keyboard.h:
--------------------------------------------------------------------------------
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 .
18 |
19 | Author: Eleni Maria Stea
20 | */
21 |
22 | #ifndef KEYBOARD_H_
23 | #define KEYBOARD_H_
24 |
25 | bool init_keyboard();
26 | void destroy_keyboard();
27 |
28 | bool client_open_keyboard(void *smem_start, int offset);
29 | void client_close_keyboard();
30 |
31 | int get_keyboard_fd();
32 | void process_keyboard_event();
33 |
34 | #endif // KEYBOARD_H_
35 |
--------------------------------------------------------------------------------
/libwinnie/src/mouse.h:
--------------------------------------------------------------------------------
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 .
18 |
19 | Author: Eleni Maria Stea
20 | */
21 |
22 | #ifndef MOUSE_H_
23 | #define MOUSE_H_
24 |
25 | struct Rect;
26 |
27 | bool init_mouse();
28 | void destroy_mouse();
29 |
30 | bool client_open_mouse(void *smem_start, int offset);
31 | void client_close_mouse();
32 |
33 | void set_mouse_bounds(const Rect &rect);
34 |
35 | int get_mouse_fd();
36 | void process_mouse_event();
37 |
38 | void get_pointer_pos(int *x, int *y);
39 | int get_button_state();
40 | int get_button(int bn);
41 |
42 | #endif // MOUSE_H_
43 |
--------------------------------------------------------------------------------
/libwinnie/src/mouse_cursor.h:
--------------------------------------------------------------------------------
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 .
18 |
19 | Author: Eleni Maria Stea
20 | */
21 |
22 | #ifndef MOUSE_CURSOR_H_
23 | #define MOUSE_CURSOR_H_
24 |
25 | const int mouse_cursor_width = 8;
26 | const int mouse_cursor_height = 16;
27 |
28 | const int mouse_cursor_bw[] = {
29 | 128, 128, 0, 0, 0, 0, 0, 0,
30 | 128, 255, 128, 0, 0, 0, 0, 0,
31 | 128, 255, 255, 128, 0, 0, 0, 0,
32 | 128, 255, 255, 255, 128, 0, 0, 0,
33 | 128, 255, 255, 255, 255, 128, 0, 0,
34 | 128, 255, 255, 255, 255, 255, 128, 0,
35 | 128, 255, 255, 255, 255, 255, 255, 128,
36 | 128, 255, 255, 255, 255, 255, 128, 0,
37 | 128, 255, 255, 255, 255, 128, 0, 0,
38 | 128, 255, 255, 255, 255, 128, 0, 0,
39 | 128, 255, 255, 255, 255, 255, 128, 0,
40 | 128, 255, 255, 255, 255, 255, 128, 0,
41 | 128, 255, 128, 128, 255, 255, 255, 128,
42 | 128, 128, 0, 128, 255, 255, 255, 128,
43 | 128, 0, 0, 0, 128, 255, 255, 128,
44 | 0, 0, 0, 0, 0, 128, 128, 128
45 | };
46 |
47 |
48 |
49 | #endif // MOUSE_CURSOR_H_
50 |
--------------------------------------------------------------------------------
/libwinnie/src/pixmap.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 .
18 |
19 | Author: Eleni Maria Stea
20 | */
21 |
22 | #include
23 | #include
24 | #include
25 | #include "pixmap.h"
26 |
27 | Pixmap::Pixmap()
28 | {
29 | width = height = 0;
30 | pixels = 0;
31 | }
32 |
33 | Pixmap::Pixmap(const Pixmap &pixmap)
34 | {
35 | width = height = 0;
36 | pixels = 0;
37 | set_image(pixmap.width, pixmap.height, pixmap.pixels);
38 | }
39 |
40 | Pixmap &Pixmap::operator=(const Pixmap &pixmap)
41 | {
42 | if(this != &pixmap) {
43 | set_image(pixmap.width, pixmap.height, pixmap.pixels);
44 | }
45 |
46 | return *this;
47 | }
48 |
49 | Pixmap::~Pixmap()
50 | {
51 | if(pixels) {
52 | delete [] pixels;
53 | }
54 | }
55 |
56 | int Pixmap::get_width() const
57 | {
58 | return width;
59 | }
60 |
61 | int Pixmap::get_height() const
62 | {
63 | return height;
64 | }
65 |
66 | Rect Pixmap::get_rect() const
67 | {
68 | Rect rect(0, 0, width, height);
69 | return rect;
70 | }
71 |
72 | bool Pixmap::set_image(int x, int y, unsigned char *pix)
73 | {
74 | delete [] pixels;
75 |
76 | pixels = new unsigned char[x * y * 4];
77 | width = x;
78 | height = y;
79 |
80 | if(pix) {
81 | memcpy(pixels, pix, x * y * 4);
82 | }
83 | return true;
84 | }
85 |
86 | const unsigned char *Pixmap::get_image() const
87 | {
88 | return pixels;
89 | }
90 |
91 | unsigned char *Pixmap::get_image()
92 | {
93 | return pixels;
94 | }
95 |
96 | bool Pixmap::load(const char *fname)
97 | {
98 | FILE *fp;
99 | int hdrline = 0;
100 |
101 | if(!(fp = fopen(fname, "rb"))) {
102 | fprintf(stderr, "failed to open pixmap: %s: %s\n", fname, strerror(errno));
103 | return false;
104 | }
105 |
106 | /* read ppm header */
107 | while(hdrline < 3) {
108 | char buf[64];
109 |
110 | if(!fgets(buf, sizeof buf, fp))
111 | goto err;
112 |
113 | /* skip comments */
114 | if(buf[0] == '#')
115 | continue;
116 |
117 | switch(hdrline++) {
118 | case 0:
119 | /* first header line should be P6 */
120 | if(strcmp(buf, "P6\n") != 0)
121 | goto err;
122 | break;
123 |
124 | case 1:
125 | /* second header line contains the pixmap dimensions */
126 | if(sscanf(buf, "%d %d", &width, &height) != 2)
127 | goto err;
128 | break;
129 | }
130 | }
131 |
132 | set_image(width, height, 0);
133 |
134 | for(int i=0; i.
18 |
19 | Author: Eleni Maria Stea
20 | */
21 |
22 | #ifndef PIXMAP_H_
23 | #define PIXMAP_H_
24 |
25 | #include "geom.h"
26 |
27 | class Pixmap {
28 | public:
29 | int width, height;
30 | unsigned char *pixels;
31 |
32 | Pixmap();
33 |
34 | Pixmap(const Pixmap &pixmap);
35 | Pixmap &operator=(const Pixmap& pixmap);
36 |
37 | ~Pixmap();
38 |
39 | int get_width() const;
40 | int get_height() const;
41 | Rect get_rect() const;
42 |
43 | bool set_image(int x, int y, unsigned char *pix = 0);
44 | const unsigned char *get_image() const;
45 | unsigned char *get_image();
46 |
47 | bool load(const char *fname);
48 | bool save(const char *fname) const;
49 | };
50 |
51 | #endif // PIXMAP_H_
52 |
--------------------------------------------------------------------------------
/libwinnie/src/sdl/event.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 .
18 |
19 | Author: Eleni Maria Stea
20 | */
21 |
22 | #ifdef WINNIE_SDL
23 | #include
24 | #include
25 |
26 | #include "event.h"
27 | #include "keyboard.h"
28 | #include "mouse.h"
29 | #include "wm.h"
30 |
31 | SDL_Event sdl_event;
32 | void process_events()
33 | {
34 | wm->process_windows();
35 | if(!SDL_WaitEvent(&sdl_event)) {
36 | return;
37 | }
38 |
39 | switch(sdl_event.type) {
40 | case SDL_KEYDOWN:
41 | case SDL_KEYUP:
42 | process_keyboard_event();
43 | break;
44 | case SDL_MOUSEMOTION:
45 | case SDL_MOUSEBUTTONDOWN:
46 | case SDL_MOUSEBUTTONUP:
47 | process_mouse_event();
48 | break;
49 | case SDL_QUIT:
50 | exit(0);
51 | default:
52 | break;
53 | }
54 | }
55 |
56 | #endif // WINNIE_SDL
57 |
--------------------------------------------------------------------------------
/libwinnie/src/sdl/gfx.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 .
18 |
19 | Author: Eleni Maria Stea
20 | */
21 |
22 | #ifdef WINNIE_SDL
23 | #include
24 | #include
25 | #include
26 |
27 | #include "gfx.h"
28 | #include "shalloc.h"
29 | #include "winnie.h"
30 |
31 | static SDL_Surface *fbsurf;
32 |
33 | struct Graphics {
34 | Rect screen_rect;
35 | Rect clipping_rect;
36 | int color_depth; // bits per pixel
37 | Pixmap *pixmap;
38 | };
39 |
40 | static Graphics *gfx;
41 |
42 | bool init_gfx()
43 | {
44 | if(SDL_Init(SDL_INIT_VIDEO) == -1) {
45 | fprintf(stderr, "failed to initialize SDL\n");
46 | return false;
47 | }
48 |
49 | if(!(gfx = (Graphics*)sh_malloc(sizeof *gfx))) {
50 | return false;
51 | }
52 |
53 | get_subsys()->graphics_offset = (int)((char*)gfx - (char*)get_pool());
54 |
55 | Rect scr_rect(0, 0, 1024, 768);
56 | gfx->screen_rect = scr_rect;
57 | gfx->color_depth = 32;
58 |
59 | if(!(fbsurf = SDL_SetVideoMode(gfx->screen_rect.width, gfx->screen_rect.height, gfx->color_depth, 0))) {
60 | fprintf(stderr, "Failed to set video mode\n");
61 | return false;
62 | }
63 | SDL_ShowCursor(0);
64 |
65 | if(!(gfx->pixmap = (Pixmap*)sh_malloc(sizeof(Pixmap)))) {
66 | fprintf(stderr, "Failed to allocate pixmap.\n");
67 | return false;
68 | }
69 |
70 | gfx->pixmap->width = gfx->screen_rect.width;
71 | gfx->pixmap->height = gfx->screen_rect.height;
72 |
73 | int fbsize = gfx->pixmap->width * gfx->pixmap->height * gfx->color_depth / 8;
74 | if(!(gfx->pixmap->pixels = (unsigned char*)sh_malloc(fbsize))) {
75 | fprintf(stderr, "failed to allocate the pixmap framebuffer.\n");
76 | return false;
77 | }
78 |
79 | set_clipping_rect(gfx->screen_rect);
80 |
81 | return true;
82 | }
83 |
84 | void destroy_gfx()
85 | {
86 | sh_free(gfx->pixmap->pixels);
87 | gfx->pixmap->pixels = 0;
88 | sh_free(gfx->pixmap);
89 | sh_free(gfx);
90 | SDL_Quit();
91 | }
92 |
93 | bool client_open_gfx(void *smem_start, int offset)
94 | {
95 | gfx = (Graphics*)((unsigned char*)smem_start + offset);
96 | return true;
97 | }
98 |
99 | void client_close_gfx()
100 | {
101 | }
102 |
103 | unsigned char *get_framebuffer()
104 | {
105 | return gfx->pixmap->pixels;
106 | }
107 |
108 | Pixmap *get_framebuffer_pixmap()
109 | {
110 | return gfx->pixmap;
111 | }
112 |
113 | Rect get_screen_size()
114 | {
115 | return gfx->screen_rect;
116 | }
117 |
118 | int get_color_depth()
119 | {
120 | return gfx->color_depth;
121 | }
122 |
123 | void set_clipping_rect(const Rect &rect)
124 | {
125 | gfx->clipping_rect = rect_intersection(rect, get_screen_size());
126 | }
127 |
128 | const Rect &get_clipping_rect()
129 | {
130 | return gfx->clipping_rect;
131 | }
132 |
133 |
134 | void set_cursor_visibility(bool visible)
135 | {
136 | }
137 |
138 | void gfx_update(const Rect &upd_rect)
139 | {
140 | if(SDL_MUSTLOCK(fbsurf)) {
141 | SDL_LockSurface(fbsurf);
142 | }
143 |
144 | Rect rect = rect_intersection(upd_rect, gfx->screen_rect);
145 |
146 | unsigned char *sptr = gfx->pixmap->pixels + (rect.y * gfx->screen_rect.width + rect.x) * 4;
147 | unsigned char *dptr = (unsigned char*)fbsurf->pixels + (rect.y * gfx->screen_rect.width + rect.x) * 4;
148 |
149 | for(int i=0; iscreen_rect.width * 4;
152 | dptr += gfx->screen_rect.width * 4;
153 | }
154 |
155 | if(SDL_MUSTLOCK(fbsurf)) {
156 | SDL_UnlockSurface(fbsurf);
157 | }
158 | SDL_UpdateRect(fbsurf, rect.x, rect.y, rect.width, rect.height);
159 | }
160 |
161 | void wait_vsync()
162 | {
163 | }
164 |
165 | void get_rgb_order(int *r, int *g, int *b)
166 | {
167 | *r = fbsurf->format->Rshift / 8;
168 | *g = fbsurf->format->Gshift / 8;
169 | *b = fbsurf->format->Bshift / 8;
170 | }
171 |
172 | #endif // WINNIE_SDL
173 |
--------------------------------------------------------------------------------
/libwinnie/src/sdl/keyboard.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 .
18 |
19 | Author: Eleni Maria Stea
20 | */
21 |
22 | #ifdef WINNIE_SDL
23 | #include
24 |
25 | #include "keyboard.h"
26 | #include "window.h"
27 | #include "wm.h"
28 |
29 | extern SDL_Event sdl_event;
30 |
31 | bool init_keyboard()
32 | {
33 | return true;
34 | }
35 |
36 | void destroy_keyboard()
37 | {
38 | }
39 |
40 | bool client_open_keyboard(void *smem_start, int offset)
41 | {
42 | return true;
43 | }
44 |
45 | void client_close_keyboard()
46 | {
47 | }
48 |
49 | int get_keyboard_fd()
50 | {
51 | return -1;
52 | }
53 |
54 | void process_keyboard_event()
55 | {
56 | int key = sdl_event.key.keysym.sym;
57 |
58 | Window *focused_win = wm->get_focused_window();
59 | if(focused_win) {
60 | KeyboardFuncType keyb_callback = focused_win->get_keyboard_callback();
61 | if(keyb_callback) {
62 | bool pressed = sdl_event.key.state == SDL_PRESSED;
63 | keyb_callback(focused_win, key, pressed);
64 | }
65 | }
66 | }
67 | #endif // WINNIE_SDL
68 |
--------------------------------------------------------------------------------
/libwinnie/src/sdl/mouse.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 .
18 |
19 | Author: Eleni Maria Stea
20 | */
21 |
22 | #ifdef WINNIE_SDL
23 | #include
24 |
25 | #include "mouse.h"
26 | #include "shalloc.h"
27 | #include "wm.h"
28 | #include "window.h"
29 | #include "winnie.h"
30 |
31 | extern SDL_Event sdl_event;
32 |
33 | struct Mouse {
34 | int pointer_x;
35 | int pointer_y;
36 | int bnstate;
37 | };
38 |
39 | static Mouse *mouse;
40 |
41 | bool init_mouse()
42 | {
43 | if(!(mouse = (Mouse*)sh_malloc(sizeof *mouse))) {
44 | return false;
45 | }
46 | get_subsys()->mouse_offset = (int)((char*)mouse - (char*)get_pool());
47 |
48 | memset(mouse, 0, sizeof *mouse);
49 | return true;
50 | }
51 |
52 | void destroy_mouse()
53 | {
54 | sh_free(mouse);
55 | }
56 |
57 | bool client_open_mouse(void *smem_start, int offset)
58 | {
59 | mouse = (Mouse*)((unsigned char*)smem_start + offset);
60 | return true;
61 | }
62 |
63 | void client_close_mouse()
64 | {
65 | }
66 |
67 | void set_mouse_bounds(const Rect &rect)
68 | {
69 | }
70 |
71 | int get_mouse_fd()
72 | {
73 | return -1;
74 | }
75 |
76 | void process_mouse_event()
77 | {
78 | int bn;
79 | MouseMotionFuncType motion_callback = 0;
80 | MouseButtonFuncType button_callback = 0;
81 |
82 | Window *win;
83 | if(!(win = wm->get_grab_window())) {
84 | win = wm->get_window_at_pos(mouse->pointer_x, mouse->pointer_y);
85 | if(win) {
86 | wm->set_focused_window(win);
87 | }
88 | else {
89 | wm->set_focused_window(0);
90 | }
91 | }
92 |
93 | switch(sdl_event.type) {
94 | case SDL_MOUSEMOTION:
95 | mouse->pointer_x = sdl_event.motion.x;
96 | mouse->pointer_y = sdl_event.motion.y;
97 | if(win && (motion_callback = win->get_mouse_motion_callback())) {
98 | Rect rect = win->get_absolute_rect();
99 | motion_callback(win, mouse->pointer_x - rect.x, mouse->pointer_y - rect.y);
100 | }
101 | break;
102 |
103 | case SDL_MOUSEBUTTONUP:
104 | case SDL_MOUSEBUTTONDOWN:
105 | bn = sdl_event.button.button - SDL_BUTTON_LEFT;
106 | if(sdl_event.button.state == SDL_PRESSED) {
107 | mouse->bnstate |= 1 << bn;
108 | }
109 | else {
110 | mouse->bnstate &= ~(1 << bn);
111 | }
112 | if(win && (button_callback = win->get_mouse_button_callback())) {
113 | Rect rect = win->get_absolute_rect();
114 | button_callback(win, bn, sdl_event.button.state, mouse->pointer_x - rect.x, mouse->pointer_y - rect.y);
115 | }
116 | }
117 | }
118 |
119 | void get_pointer_pos(int *x, int *y)
120 | {
121 | *x = mouse->pointer_x;
122 | *y = mouse->pointer_y;
123 | }
124 |
125 | int get_button_state()
126 | {
127 | return mouse->bnstate;
128 | }
129 |
130 | int get_button(int bn)
131 | {
132 | if(bn < 0 || bn >= 3) {
133 | return 0;
134 | }
135 | return (mouse->bnstate & (1 << bn)) != 0;
136 | }
137 | #endif // WINNIE_SDL
138 |
--------------------------------------------------------------------------------
/libwinnie/src/semaphore.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 .
18 |
19 | Author: Eleni Maria Stea
20 | */
21 |
22 | #include "semaphore.h"
23 |
--------------------------------------------------------------------------------
/libwinnie/src/semaphore.h:
--------------------------------------------------------------------------------
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 .
18 |
19 | Author: Eleni Maria Stea
20 | */
21 |
22 | #ifndef SEMAPHORE_H_
23 | #define SEMAPHORE_H_
24 |
25 | bool init_semaphore();
26 | void destroy_semaphore();
27 |
28 | #endif // SEMAPHORE_H_
29 |
--------------------------------------------------------------------------------
/libwinnie/src/shalloc.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 .
18 |
19 | Author: Eleni Maria Stea
20 | */
21 |
22 | #include
23 | #include
24 | #include
25 | #include
26 | #include
27 |
28 | #include
29 | #include
30 | #include
31 | #include
32 | #include
33 |
34 | #include