--- /dev/null
+src = $(wildcard src/*.cc) $(wildcard src/fbdev/*.cc) $(wildcard src/sdl/*.cc)
+obj = $(src:.cc=.o)
+dep = $(obj:.o=.d)
+bin = clock
+
+dbg = -g
+opt = -O0
+inc = -Isrc -I../libwinnie/src
+
+backend = SDL
+
+ifeq ($(backend), SDL)
+ def = -DWINNIE_SDL
+ libs = -lSDL
+else
+ def = -DWINNIE_FBDEV
+endif
+
+CXX = g++
+CXXFLAGS = -pedantic -Wall $(dbg) $(opt) $(inc) $(def) `freetype-config --cflags`
+LDFLAGS = -L../libwinnie/ $(libs) `freetype-config --libs` -lrt -lwinnie
+
+$(bin): $(obj)
+ $(CXX) -o $@ $(obj) $(LDFLAGS) -Wl,-rpath=../libwinnie
+
+-include $(dep)
+
+%.d: %.cc
+ @$(CPP) $(CXXFLAGS) $< -MM -MT $(@:.d=.o) >$@
+
+.PHONY: clean
+clean:
+ rm -f $(obj) $(bin) $(dep)
+
sh_free(gfx);
}
+bool client_open_gfx(void *smem_start, int offset)
+{
+ gfx = (unsigned char*)smem_start + offset;
+ return true;
+}
+
+void client_close_gfx()
+{
+}
+
unsigned char *get_framebuffer()
{
return gfx->pixmap->pixels;
sh_free(keyboard);
}
+bool client_open_keyboard(void *smem_start, int offset)
+{
+ keyboard = (unsigned char*)smem_start + offset;
+ return true;
+}
+
+void client_close_keyboard()
+{
+}
+
int get_keyboard_fd()
{
return keyboard->dev_fd;
sh_free(mouse);
}
+bool client_open_mouse(void *smem_start, int offset)
+{
+ mouse = (unsigned char*)smem_start + offset;
+ return true;
+}
+
+void client_close_mouse()
+{
+}
+
void set_mouse_bounds(const Rect &rect)
{
mouse->bounds = rect;
bool init_gfx();
void destroy_gfx();
+bool client_open_gfx(void *smem_start, int offset);
+void client_close_gfx();
+
unsigned char *get_framebuffer();
Pixmap *get_framebuffer_pixmap();
bool init_keyboard();
void destroy_keyboard();
+bool client_open_keyboard(void *smem_start, int offset);
+void client_close_keyboard();
+
int get_keyboard_fd();
void process_keyboard_event();
bool init_mouse();
void destroy_mouse();
+bool client_open_mouse(void *smem_start, int offset);
+void client_close_mouse();
+
void set_mouse_bounds(const Rect &rect);
int get_mouse_fd();
SDL_Quit();
}
+bool client_open_gfx(void *smem_start, int offset)
+{
+ gfx = (Graphics*)((unsigned char*)smem_start + offset);
+ return true;
+}
+
+void client_close_gfx()
+{
+}
+
unsigned char *get_framebuffer()
{
return gfx->pixmap->pixels;
{
}
+bool client_open_keyboard(void *smem_start, int offset)
+{
+ return true;
+}
+
+void client_close_keyboard()
+{
+}
+
int get_keyboard_fd()
{
return -1;
sh_free(mouse);
}
+bool client_open_mouse(void *smem_start, int offset)
+{
+ mouse = (Mouse*)((unsigned char*)smem_start + offset);
+ return true;
+}
+
+void client_close_mouse()
+{
+}
+
void set_mouse_bounds(const Rect &rect)
{
}
#include <assert.h>
#include <stdio.h>
-#include <stdlib.h>
#include <stdint.h>
+#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include "shalloc.h"
-#define SHMNAME "/winnie.shm"
-
-#define POOL_SIZE 16777216
#define BLOCK_SIZE 512
#define NUM_BLOCKS (POOL_SIZE / BLOCK_SIZE)
#include <cstring>
+#define POOL_SIZE 16777216
+#define SHMNAME "/winnie.shm"
+
bool init_shared_memory();
void destroy_shared_memory();
sh_free(text);
}
+bool client_open_text(void *smem_start, int offset)
+{
+ text = (Text*)((unsigned char*)smem_start + offset);
+ return true;
+}
+
+void client_close_text()
+{
+}
+
void draw_text(const char *txt, Pixmap *pixmap)
{
if(!pixmap) {
bool init_text();
void destroy_text();
+bool client_open_text(void *smem_start, int offset);
+void client_close_text();
+
void draw_text(const char *txt, Pixmap *pixmap = 0);
void set_text_position(int x, int y);
void set_text_color(int r, int g, int b);
Author: Eleni Maria Stea <elene.mst@gmail.com>
*/
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+
+#include <errno.h>
+#include <fcntl.h>
+#include <sys/mman.h>
#include <sys/time.h>
#include "keyboard.h"
destroy_shared_memory();
}
+static int fd;
+static void *pool;
+
+bool winnie_open()
+{
+ if(((fd = shm_open(SHMNAME, O_RDWR, S_IRWXU)) == -1)) {
+ fprintf(stderr, "Failed to open shared memory: %s\n", strerror(errno));
+ return false;
+ }
+
+ if((pool = mmap(0, POOL_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0)) == (void*)-1) {
+ fprintf(stderr, "Failed to map shared memory: %s\n", strerror(errno));
+ return false;
+ }
+ shm_unlink(SHMNAME);
+
+ subsys = (Subsys*)pool;
+
+ if(!client_open_gfx(pool, subsys->graphics_offset)) {
+ fprintf(stderr, "Failed to open graphics.\n");
+ return false;
+ }
+
+ if(!client_open_keyboard(pool, subsys->keyboard_offset)) {
+ fprintf(stderr, "Failed to open keyboard.\n");
+ return false;
+ }
+
+ if(!client_open_mouse(pool, subsys->mouse_offset)) {
+ fprintf(stderr, "Failed to open mouse.\n");
+ return false;
+ }
+
+ if(!client_open_text(pool, subsys->text_offset)) {
+ fprintf(stderr, "Failed to open text.\n");
+ return false;
+ }
+
+ if(!client_open_wm(pool, subsys->wm_offset)) {
+ fprintf(stderr, "Failed to open the window manager.\n");
+ return false;
+ }
+
+ return true;
+}
+
+void winnie_close()
+{
+ client_close_gfx();
+ client_close_keyboard();
+ client_close_mouse();
+ client_close_text();
+ client_close_wm();
+
+ if(munmap(pool, POOL_SIZE) == -1) {
+ fprintf(stderr, "Failed to unmap shared memory: %s\n", strerror(errno));
+ }
+}
+
long winnie_get_time()
{
static struct timeval init_tv;
bool winnie_init();
void winnie_shutdown();
+bool winnie_open();
+void winnie_close();
+
long winnie_get_time();
Subsys *get_subsys();
sh_free(wm);
}
+
+bool client_open_wm(void *smem_start, int offset)
+{
+ wm = (WindowManager*) ((unsigned char*)smem_start + offset);
+ return true;
+}
+
+void client_close_wm()
+{
+}
+
void WindowManager::create_frame(Window *win)
{
Window *frame = new Window;
bool init_window_manager();
void destroy_window_manager();
+bool client_open_wm(void *smem_start, int offset);
+void client_close_wm();
+
class WindowManager {
private:
std::list<Window*> windows;
CXX = g++
CXXFLAGS = -pedantic -Wall $(dbg) $(opt) $(inc) $(def) `freetype-config --cflags`
-LDFLAGS = -L../libwinnie/ $(libs) `freetype-config --libs` -lrt -lwinnie
+LDFLAGS = -L../libwinnie $(libs) `freetype-config --libs` -lrt -lwinnie
$(bin): $(obj)
$(CXX) -o $@ $(obj) $(LDFLAGS) -Wl,-rpath=../libwinnie
#include "winnie.h"
-static void display(Window *win);
-static void keyboard(Window *win, int key, bool pressed);
-static void button(Window *win, int bn, bool pressed, int x, int y);
-static void motion(Window *win, int x, int y);
static void cleanup();
int main()
atexit(cleanup);
- Window *win1 = new Window;
- win1->set_title("Clipping the win title");
- win1->move(200, 100);
- win1->resize(200, 300);
- win1->set_display_callback(display);
- win1->set_keyboard_callback(keyboard);
- win1->set_mouse_button_callback(button);
- win1->set_mouse_motion_callback(motion);
-
- Window *win2 = new Window;
- win2->set_title("window 2");
- win2->move(300, 100);
- win2->resize(200, 300);
- win2->set_display_callback(display);
- win2->set_keyboard_callback(keyboard);
- win2->set_mouse_button_callback(button);
- win2->set_mouse_motion_callback(motion);
-
- wm->add_window(win1);
- wm->add_window(win2);
-
Pixmap bg;
if(!(bg.load("data/bg.ppm"))) {
fprintf(stderr, "failed to load pixmap\n");
}
}
-static void display(Window *win)
-{
- fill_rect(win->get_absolute_rect(), 128, 128, 128);
-}
-
-static void keyboard(Window *win, int key, bool pressed)
-{
- switch(key) {
- case 'q':
- exit(0);
- }
-}
-
-static void button(Window *win, int bn, bool pressed, int x, int y)
-{
- printf("WINDOW(%p) button %d %s\n", (void*)win, bn, pressed ? "press" : "release");
-}
-
-static void motion(Window *win, int x, int y)
-{
- printf("WINDOW(%p) motion %d %d\n", (void*)win, x, y);
-}
-
static void cleanup()
{
winnie_shutdown();