summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaghuram Subramani <raghus2247@gmail.com>2025-01-06 06:29:51 -0500
committerRaghuram Subramani <raghus2247@gmail.com>2025-01-06 06:29:51 -0500
commitaf75fce2fb87fb0e285b1c876fb14bccb3c0def7 (patch)
treedac5f798a5c408535fc23fc9506bdb46169d505d
parent0a7d0b7da40be1e1eb14ae87093a2db3514544f0 (diff)
simplify
-rw-r--r--.gitignore1
-rw-r--r--libwinnie/src/sdl/gfx.cc26
-rw-r--r--libwinnie/src/sdl/gfx.h3
-rw-r--r--libwinnie/src/sdl/keyboard.cc9
-rw-r--r--libwinnie/src/sdl/keyboard.h3
-rw-r--r--libwinnie/src/sdl/mouse.cc20
-rw-r--r--libwinnie/src/sdl/mouse.h3
-rw-r--r--libwinnie/src/shalloc.cc213
-rw-r--r--libwinnie/src/shalloc.h38
-rw-r--r--libwinnie/src/text.cc23
-rw-r--r--libwinnie/src/text.h3
-rw-r--r--libwinnie/src/winnie.cc60
-rw-r--r--libwinnie/src/wm.cc19
-rw-r--r--libwinnie/src/wm.h3
-rw-r--r--winnie/plugins.conf2
15 files changed, 31 insertions, 395 deletions
diff --git a/.gitignore b/.gitignore
index e3531ad..e7ff4cc 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
*.d
*.o
*.so
+winnie/wserver
diff --git a/libwinnie/src/sdl/gfx.cc b/libwinnie/src/sdl/gfx.cc
index 5671764..a955358 100644
--- a/libwinnie/src/sdl/gfx.cc
+++ b/libwinnie/src/sdl/gfx.cc
@@ -23,9 +23,9 @@ Author: Eleni Maria Stea <elene.mst@gmail.com>
#include <stdio.h>
#include <stdlib.h>
#include <SDL/SDL.h>
+#include <stdint.h>
#include "sdl/gfx.h"
-#include "shalloc.h"
#include "winnie.h"
static SDL_Surface *fbsurf;
@@ -46,11 +46,11 @@ bool init_gfx()
return false;
}
- if(!(gfx = (Graphics*)sh_malloc(sizeof *gfx))) {
+ if(!(gfx = (Graphics*)malloc(sizeof *gfx))) {
return false;
}
- get_subsys()->graphics_offset = (int)((char*)gfx - (char*)get_pool());
+ get_subsys()->graphics_offset = (intptr_t)(gfx);
Rect scr_rect(0, 0, 1280, 853);
gfx->screen_rect = scr_rect;
@@ -62,7 +62,7 @@ bool init_gfx()
}
SDL_ShowCursor(0);
- if(!(gfx->pixmap = (Pixmap*)sh_malloc(sizeof(Pixmap)))) {
+ if(!(gfx->pixmap = (Pixmap*)malloc(sizeof(Pixmap)))) {
fprintf(stderr, "Failed to allocate pixmap.\n");
return false;
}
@@ -71,7 +71,7 @@ bool init_gfx()
gfx->pixmap->height = gfx->screen_rect.height;
int fbsize = gfx->pixmap->width * gfx->pixmap->height * gfx->color_depth / 8;
- if(!(gfx->pixmap->pixels = (unsigned char*)sh_malloc(fbsize))) {
+ if(!(gfx->pixmap->pixels = (unsigned char*)malloc(fbsize))) {
fprintf(stderr, "failed to allocate the pixmap framebuffer.\n");
return false;
}
@@ -83,23 +83,13 @@ bool init_gfx()
void destroy_gfx()
{
- sh_free(gfx->pixmap->pixels);
+ free(gfx->pixmap->pixels);
gfx->pixmap->pixels = 0;
- sh_free(gfx->pixmap);
- sh_free(gfx);
+ free(gfx->pixmap);
+ free(gfx);
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;
diff --git a/libwinnie/src/sdl/gfx.h b/libwinnie/src/sdl/gfx.h
index cb1c7ef..c14c22a 100644
--- a/libwinnie/src/sdl/gfx.h
+++ b/libwinnie/src/sdl/gfx.h
@@ -28,9 +28,6 @@ Author: Eleni Maria Stea <elene.mst@gmail.com>
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();
diff --git a/libwinnie/src/sdl/keyboard.cc b/libwinnie/src/sdl/keyboard.cc
index b9241f4..93f2e20 100644
--- a/libwinnie/src/sdl/keyboard.cc
+++ b/libwinnie/src/sdl/keyboard.cc
@@ -37,15 +37,6 @@ void destroy_keyboard()
{
}
-bool client_open_keyboard(void *smem_start, int offset)
-{
- return true;
-}
-
-void client_close_keyboard()
-{
-}
-
int get_keyboard_fd()
{
return -1;
diff --git a/libwinnie/src/sdl/keyboard.h b/libwinnie/src/sdl/keyboard.h
index 4d55cba..548ddbb 100644
--- a/libwinnie/src/sdl/keyboard.h
+++ b/libwinnie/src/sdl/keyboard.h
@@ -25,9 +25,6 @@ Author: Eleni Maria Stea <elene.mst@gmail.com>
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();
diff --git a/libwinnie/src/sdl/mouse.cc b/libwinnie/src/sdl/mouse.cc
index 80f33fb..b5eac68 100644
--- a/libwinnie/src/sdl/mouse.cc
+++ b/libwinnie/src/sdl/mouse.cc
@@ -22,8 +22,10 @@ Author: Eleni Maria Stea <elene.mst@gmail.com>
#ifdef WINNIE_SDL
#include <SDL/SDL.h>
+#include <stdlib.h>
+#include <stdint.h>
+
#include "sdl/mouse.h"
-#include "shalloc.h"
#include "wm.h"
#include "window.h"
#include "winnie.h"
@@ -40,10 +42,10 @@ static Mouse *mouse;
bool init_mouse()
{
- if(!(mouse = (Mouse*)sh_malloc(sizeof *mouse))) {
+ if(!(mouse = (Mouse*)malloc(sizeof *mouse))) {
return false;
}
- get_subsys()->mouse_offset = (int)((char*)mouse - (char*)get_pool());
+ get_subsys()->mouse_offset = (intptr_t)(mouse);
memset(mouse, 0, sizeof *mouse);
return true;
@@ -51,17 +53,7 @@ bool init_mouse()
void destroy_mouse()
{
- 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()
-{
+ free(mouse);
}
void set_mouse_bounds(const Rect &rect)
diff --git a/libwinnie/src/sdl/mouse.h b/libwinnie/src/sdl/mouse.h
index 9e55496..6fbe711 100644
--- a/libwinnie/src/sdl/mouse.h
+++ b/libwinnie/src/sdl/mouse.h
@@ -27,9 +27,6 @@ struct Rect;
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();
diff --git a/libwinnie/src/shalloc.cc b/libwinnie/src/shalloc.cc
deleted file mode 100644
index 1bb7db2..0000000
--- a/libwinnie/src/shalloc.cc
+++ /dev/null
@@ -1,213 +0,0 @@
-/*
-winnie - an experimental window system
-
-Copyright (C) 2013 Eleni Maria Stea
-
-This program is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-Author: Eleni Maria Stea <elene.mst@gmail.com>
-*/
-
-#include <assert.h>
-#include <stdio.h>
-#include <stdint.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <errno.h>
-#include <fcntl.h>
-#include <sys/mman.h>
-#include <sys/stat.h>
-#include <unistd.h>
-
-#include <map>
-
-#include "shalloc.h"
-
-#define BLOCK_SIZE 512
-
-#define NUM_BLOCKS (POOL_SIZE / BLOCK_SIZE)
-#define BITMAP_SIZE (NUM_BLOCKS / 32)
-
-static bool is_allocated(int block_number);
-static int addr_to_block(unsigned char *addr);
-static unsigned char *block_to_addr(int block_number);
-static void alloc_blocks(int block_pos, int num_blocks);
-static void free_blocks(int block_pos, int num_blocks);
-
-static void print_stats();
-static int fd;
-
-static unsigned char *pool;
-static std::map<int, int> alloc_sizes; //starting block -> number of blocks
-
-// 0 means not allocated 1 means allocated
-static uint32_t bitmap[BITMAP_SIZE];
-
-struct Statistics {
- int alloc_num;
- int free_num;
- int alloc_memsize;
- int free_memsize;
-};
-
-static Statistics stats;
-
-bool init_shared_memory()
-{
- if(((fd = shm_open(SHMNAME, O_RDWR | O_CREAT, S_IRWXU)) == -1)) {
- fprintf(stderr, "Failed to open shared memory: %s\n", strerror(errno));
- return false;
- }
- ftruncate(fd, POOL_SIZE);
-
- if((pool = (unsigned char*)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));
- }
-
- for(int i=0; i<BITMAP_SIZE; i++) {
- bitmap[i] = 0;
- }
-
- alloc_sizes.clear();
- memset(&stats, 0, sizeof stats);
-
- return true;
-}
-
-void destroy_shared_memory()
-{
- print_stats();
- if(munmap(pool, POOL_SIZE) == -1) {
- fprintf(stderr, "Failed to unmap shared memory: %s\n", strerror(errno));
- }
- shm_unlink(SHMNAME);
-}
-
-void *sh_malloc(size_t bytes)
-{
- if(!bytes) {
- return 0;
- }
-
- int num_blocks = (bytes + BLOCK_SIZE - 1) / BLOCK_SIZE;
-
- int free_block;
- int ctr = 0;
- for(int i=0; i<NUM_BLOCKS; i++) {
- if(!is_allocated(i)) {
- if(!ctr) {
- free_block = i;
- }
- ctr++;
- }
- else {
- ctr = 0;
- }
-
- if(ctr == num_blocks) {
- alloc_blocks(free_block, num_blocks);
- return block_to_addr(free_block);
- }
- }
-
- return 0;
-}
-
-void sh_free(void *ptr)
-{
- int block = addr_to_block((unsigned char*)ptr);
- std::map<int, int>::iterator it;
- if((it = alloc_sizes.find(block)) != alloc_sizes.end()) {
- int num_blocks = it->second;
- free_blocks(block, num_blocks);
- alloc_sizes.erase(it);
- }
- else {
- fprintf(stderr, "Attempt to free non-existent blocks from: %d\n", block);
- }
-}
-
-void *get_pool()
-{
- return (void*)pool;
-}
-
-static bool is_allocated(int block_number)
-{
- int idx = block_number / 32;
- int bit_num = block_number % 32;
-
- if((bitmap[idx] >> bit_num) & 1) {
- return true;
- }
-
- return false;
-}
-
-static int addr_to_block(unsigned char *addr)
-{
- assert(addr >= pool);
- assert(addr < pool + POOL_SIZE);
-
- return (addr - pool) / BLOCK_SIZE;
-}
-
-static unsigned char *block_to_addr(int block_number)
-{
- assert(block_number >= 0);
- assert(block_number < NUM_BLOCKS);
-
- return pool + block_number * BLOCK_SIZE;
-}
-
-static void alloc_blocks(int block_pos, int num_blocks)
-{
- for(int i=0; i<num_blocks; i++) {
- int block_number = i + block_pos;
- int idx = block_number / 32;
- int bit_num = block_number % 32;
-
- bitmap[idx] |= ((uint32_t)1 << bit_num); // or pow(2, i)
- }
-
- alloc_sizes[block_pos] = num_blocks;
-
- stats.alloc_num++;
- stats.alloc_memsize += BLOCK_SIZE * num_blocks;
-}
-
-static void free_blocks(int block_pos, int num_blocks)
-{
- for(int i=0; i<num_blocks; i++) {
- int block_number = i + block_pos;
- int idx = block_number / 32;
- int bit_num = block_number % 32;
-
- bitmap[idx] &= ~((uint32_t)1 << bit_num);
- }
-
- stats.free_num++;
- stats.free_memsize += BLOCK_SIZE * num_blocks;
-}
-
-static void print_stats()
-{
- printf("Total allocated memory: %d\n", stats.alloc_memsize);
- printf("Total deallocated memory: %d\n", stats.free_memsize);
- printf("Number of allocations: %d\n", stats.alloc_num);
- printf("Number of deallocations: %d\n", stats.free_num);
-}
-
diff --git a/libwinnie/src/shalloc.h b/libwinnie/src/shalloc.h
deleted file mode 100644
index 3518d53..0000000
--- a/libwinnie/src/shalloc.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
-winnie - an experimental window system
-
-Copyright (C) 2013 Eleni Maria Stea
-
-This program is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-Author: Eleni Maria Stea <elene.mst@gmail.com>
-*/
-
-#ifndef SHALLOC_H_
-#define SHALLOC_H_
-
-#include <cstring>
-
-#define POOL_SIZE 16777216
-#define SHMNAME "/winnie.shm"
-
-bool init_shared_memory();
-void destroy_shared_memory();
-
-void *sh_malloc(size_t bytes);
-void sh_free(void *ptr);
-
-void *get_pool();
-
-#endif // SHALLOC_H_
diff --git a/libwinnie/src/text.cc b/libwinnie/src/text.cc
index 0abe6ac..81fa8d7 100644
--- a/libwinnie/src/text.cc
+++ b/libwinnie/src/text.cc
@@ -19,11 +19,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
Author: Eleni Maria Stea <elene.mst@gmail.com>
*/
+#include <stdlib.h>
#include <ft2build.h>
#include <freetype/freetype.h>
+#include <stdint.h>
#include "sdl/gfx.h"
-#include "shalloc.h"
#include "text.h"
#include "winnie.h"
@@ -44,11 +45,11 @@ static Text *text;
bool init_text()
{
- if(!(text = (Text*)sh_malloc(sizeof *text))) {
+ if(!(text = (Text*)malloc(sizeof *text))) {
return false;
}
- get_subsys()->text_offset = (int)((char*)text - (char*)get_pool());
+ get_subsys()->text_offset = (intptr_t)(text);
if(FT_Init_FreeType(&text->ft_lib)) {
fprintf(stderr, "Failed to initialize the FreeType library!\n");
@@ -72,17 +73,7 @@ bool init_text()
void destroy_text()
{
- 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()
-{
+ free(text);
}
void draw_text(const char *txt, Pixmap *pixmap)
@@ -126,14 +117,14 @@ static int draw_glyph(Pixmap *pixmap, int x, int y, char c)
Rect clipping_rect = get_clipping_rect();
- for(int i=0; i<ft_bmp->rows; i++) {
+ for(unsigned int i=0; i<ft_bmp->rows; i++) {
int dest_y = i + y;
if(dest_y >= clipping_rect.y + clipping_rect.height) {
break;
}
if(dest_y >= clipping_rect.y) {
- for(int j=0; j<ft_bmp->width; j++) {
+ for(unsigned int j=0; j<ft_bmp->width; j++) {
int dest_x = j + x;
if(dest_x >= clipping_rect.x + clipping_rect.width) {
diff --git a/libwinnie/src/text.h b/libwinnie/src/text.h
index d71670f..a94388a 100644
--- a/libwinnie/src/text.h
+++ b/libwinnie/src/text.h
@@ -25,9 +25,6 @@ Author: Eleni Maria Stea <elene.mst@gmail.com>
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);
diff --git a/libwinnie/src/winnie.cc b/libwinnie/src/winnie.cc
index 2e94b24..d5021eb 100644
--- a/libwinnie/src/winnie.cc
+++ b/libwinnie/src/winnie.cc
@@ -30,18 +30,13 @@ Author: Eleni Maria Stea <elene.mst@gmail.com>
#include "sdl/keyboard.h"
#include "sdl/mouse.h"
-#include "shalloc.h"
#include "winnie.h"
static Subsys *subsys;
bool winnie_init()
{
- if(!init_shared_memory()) {
- return false;
- }
-
- if(!(subsys = (Subsys*)sh_malloc(sizeof *subsys))) {
+ if(!(subsys = (Subsys*)malloc(sizeof *subsys))) {
return false;
}
@@ -77,67 +72,18 @@ void winnie_shutdown()
destroy_text();
destroy_window_manager();
- sh_free(subsys);
-
- destroy_shared_memory();
+ free(subsys);
}
-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;
- }
-
- 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;
- }
+ subsys = (Subsys*)malloc(sizeof(Subsys));
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()
diff --git a/libwinnie/src/wm.cc b/libwinnie/src/wm.cc
index 9255667..4d0f6d0 100644
--- a/libwinnie/src/wm.cc
+++ b/libwinnie/src/wm.cc
@@ -23,11 +23,11 @@ Author: Eleni Maria Stea <elene.mst@gmail.com>
#include <limits.h>
#include <stdexcept>
#include <stdio.h> // TODO
+#include <stdint.h>
#include "sdl/gfx.h"
#include "sdl/mouse.h"
#include "mouse_cursor.h"
-#include "shalloc.h"
#include "text.h"
#include "window.h"
#include "winnie.h"
@@ -44,13 +44,13 @@ static void motion(Window *win, int x, int y);
bool init_window_manager()
{
void *wm_mem;
- if(!(wm_mem = sh_malloc(sizeof *wm))) {
+ if(!(wm_mem = malloc(sizeof *wm))) {
return false;
}
wm = new (wm_mem) WindowManager;
- get_subsys()->wm_offset = (int)((char*)wm - (char*)get_pool());
+ get_subsys()->wm_offset = (intptr_t)(wm);
return true;
}
@@ -58,18 +58,7 @@ bool init_window_manager()
void destroy_window_manager()
{
wm->~WindowManager();
- 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()
-{
+ free(wm);
}
void WindowManager::create_frame(Window *win)
diff --git a/libwinnie/src/wm.h b/libwinnie/src/wm.h
index 48fffc5..854f501 100644
--- a/libwinnie/src/wm.h
+++ b/libwinnie/src/wm.h
@@ -33,9 +33,6 @@ class 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;
diff --git a/winnie/plugins.conf b/winnie/plugins.conf
index 4778c9f..395a826 100644
--- a/winnie/plugins.conf
+++ b/winnie/plugins.conf
@@ -1 +1,3 @@
../clock/winnie_clock.so
+../sysmon/winnie_sysmon.so
+../tunnel/winnie_tunnel.so