commit 234dfa1c2918437f40a27a2fe70d6faf72289eaf
parent b0c76c485b6b050d6b76fdf6397d7d4b93ce1efc
Author: lumidify <nobody@lumidify.org>
Date: Sat, 20 Feb 2021 22:01:32 +0100
Fix at least some of the millions of warnings
Why did I ever set '-w' in the Makefile? I don't remember doing that...
Diffstat:
11 files changed, 129 insertions(+), 92 deletions(-)
diff --git a/Makefile b/Makefile
@@ -5,7 +5,10 @@ VERSION = -999
DEV = 0
USE_PANGO = 0
-CFLAGS += -DUSE_PANGO=$(USE_PANGO) -DDEV=$(DEV) -D_POSIX_C_SOURCE=200809L -w -std=c99 `pkg-config --cflags x11 fontconfig`
+# FIXME: When using _POSIX_C_SOURCE on OpenBSD, strtonum isn't defined anymore -
+# should strtonum just only be used from the local copy?
+
+CFLAGS += -DUSE_PANGO=$(USE_PANGO) -DDEV=$(DEV) -std=c99 `pkg-config --cflags x11 fontconfig` -D_POSIX_C_SOURCE=200809L
LDFLAGS += -lm `pkg-config --libs x11 fontconfig`
# Note: this macro magic for debugging and pango rendering seems ugly; it should probably be changed
diff --git a/box.c b/box.c
@@ -36,20 +36,20 @@
#include "scrollbar.h"
#include "box.h"
-static void ltk_box_draw(ltk_box *box, ltk_rect clip);
+static void ltk_box_draw(ltk_widget *self, ltk_rect clip);
static ltk_box *ltk_box_create(ltk_window *window, const char *id, ltk_orientation orient);
-static void ltk_box_destroy(ltk_box *box, int shallow);
-static void ltk_recalculate_box(ltk_box *box);
-static void ltk_box_child_size_change(ltk_box *box, ltk_widget *widget);
+static void ltk_box_destroy(ltk_widget *self, int shallow);
+static void ltk_recalculate_box(ltk_widget *self);
+static void ltk_box_child_size_change(ltk_widget *self, ltk_widget *widget);
/* FIXME: Why is sticky unsigned short? */
static int ltk_box_add(ltk_window *window, ltk_widget *widget, ltk_box *box, unsigned short sticky, char **errstr);
-static int ltk_box_remove(ltk_window *window, ltk_widget *widget, ltk_box *box, char **errstr);
+static int ltk_box_remove(ltk_window *window, ltk_widget *widget, ltk_widget *self, char **errstr);
/* static int ltk_box_clear(ltk_window *window, ltk_box *box, int shallow, char **errstr); */
static void ltk_box_scroll(ltk_box *box);
static int ltk_box_mouse_event(ltk_box *box, XEvent event, void (*handler)(ltk_widget *, XEvent));
-static int ltk_box_mouse_press(ltk_box *box, XEvent event);
-static int ltk_box_mouse_release(ltk_box *box, XEvent event);
-static int ltk_box_motion_notify(ltk_box *box, XEvent event);
+static int ltk_box_mouse_press(ltk_widget *self, XEvent event);
+static int ltk_box_mouse_release(ltk_widget *self, XEvent event);
+static int ltk_box_motion_notify(ltk_widget *self, XEvent event);
static int ltk_box_cmd_add(
ltk_window *window,
@@ -75,7 +75,8 @@ static int ltk_box_cmd_create(
char **errstr);
static void
-ltk_box_draw(ltk_box *box, ltk_rect clip) {
+ltk_box_draw(ltk_widget *self, ltk_rect clip) {
+ ltk_box *box = self;
ltk_widget *ptr;
ltk_rect real_clip = ltk_rect_intersect(box->widget.rect, clip);
for (size_t i = 0; i < box->num_widgets; i++) {
@@ -110,7 +111,8 @@ ltk_box_create(ltk_window *window, const char *id, ltk_orientation orient) {
}
static void
-ltk_box_destroy(ltk_box *box, int shallow) {
+ltk_box_destroy(ltk_widget *self, int shallow) {
+ ltk_box *box = self;
ltk_widget *ptr;
if (!shallow) {
for (size_t i = 0; i < box->num_widgets; i++) {
@@ -119,7 +121,7 @@ ltk_box_destroy(ltk_box *box, int shallow) {
}
}
ltk_free(box->widgets);
- ltk_remove_widget(box->widget.window, box->widget.id);
+ ltk_remove_widget(box->widget.id);
ltk_free(box->widget.id);
box->sc->widget.destroy(box->sc, 0);
ltk_free(box);
@@ -130,7 +132,8 @@ ltk_box_destroy(ltk_box *box, int shallow) {
virtual_size is set - this can cause problems when a widget changes its size
(in the scrolled direction) when resized. */
static void
-ltk_recalculate_box(ltk_box *box) {
+ltk_recalculate_box(ltk_widget *self) {
+ ltk_box *box = self;
ltk_widget *ptr;
ltk_rect *sc_rect = &box->sc->widget.rect;
int offset = box->orient == LTK_HORIZONTAL ? box->widget.rect.x : box->widget.rect.y;
@@ -185,7 +188,8 @@ ltk_recalculate_box(ltk_box *box) {
actually give it more space if it knew that it needed it. */
static void
-ltk_box_child_size_change(ltk_box *box, ltk_widget *widget) {
+ltk_box_child_size_change(ltk_widget *self, ltk_widget *widget) {
+ ltk_box *box = self;
short size_changed = 0;
/* This is always reset here - if it needs to be changed,
the resize function called by the last child_size_change
@@ -250,7 +254,8 @@ ltk_box_add(ltk_window *window, ltk_widget *widget, ltk_box *box, unsigned short
}
static int
-ltk_box_remove(ltk_window *window, ltk_widget *widget, ltk_box *box, char **errstr) {
+ltk_box_remove(ltk_window *window, ltk_widget *widget, ltk_widget *self, char **errstr) {
+ ltk_box *box = self;
int sc_w = box->sc->widget.rect.w;
int sc_h = box->sc->widget.rect.h;
if (widget->parent != box) {
@@ -321,17 +326,20 @@ ltk_box_mouse_event(ltk_box *box, XEvent event, void (*handler)(ltk_widget *, XE
}
static int
-ltk_box_mouse_press(ltk_box *box, XEvent event) {
+ltk_box_mouse_press(ltk_widget *self, XEvent event) {
+ ltk_box *box = self;
return ltk_box_mouse_event(box, event, <k_widget_mouse_press_event);
}
static int
-ltk_box_mouse_release(ltk_box *box, XEvent event) {
+ltk_box_mouse_release(ltk_widget *self, XEvent event) {
+ ltk_box *box = self;
return ltk_box_mouse_event(box, event, <k_widget_mouse_release_event);
}
static int
-ltk_box_motion_notify(ltk_box *box, XEvent event) {
+ltk_box_motion_notify(ltk_widget *self, XEvent event) {
+ ltk_box *box = self;
return ltk_box_mouse_event(box, event, <k_widget_motion_notify_event);
}
diff --git a/button.c b/button.c
@@ -37,11 +37,11 @@
#include "text.h"
#include "button.h"
-static void ltk_button_draw(ltk_button *button, ltk_rect clip);
-static int ltk_button_mouse_release(ltk_button *button, XEvent event);
+static void ltk_button_draw(ltk_widget *self, ltk_rect clip);
+static int ltk_button_mouse_release(ltk_widget *self, XEvent event);
static ltk_button *ltk_button_create(ltk_window *window,
const char *id, const char *text);
-static void ltk_button_destroy(ltk_button *button, int shallow);
+static void ltk_button_destroy(ltk_widget *self, int shallow);
static struct {
int border_width;
@@ -126,7 +126,8 @@ ltk_button_ini_handler(ltk_window *window, const char *prop, const char *value)
}
static void
-ltk_button_draw(ltk_button *button, ltk_rect clip) {
+ltk_button_draw(ltk_widget *self, ltk_rect clip) {
+ ltk_button *button = self;
ltk_window *window = button->widget.window;
ltk_rect rect = button->widget.rect;
ltk_rect clip_final = ltk_rect_intersect(clip, rect);
@@ -186,7 +187,8 @@ ltk_button_redraw_pixmap(ltk_button *button) {
/* FIXME: Make this amortised constant; make it generic for all widgets */
static void
-ltk_button_resize(ltk_button *button) {
+ltk_button_resize(ltk_widget *self) {
+ ltk_button *button = self;
Window win;
int x, y, w, h, bw, d;
int new_w, new_h;
@@ -205,7 +207,8 @@ ltk_button_resize(ltk_button *button) {
}
static void
-ltk_button_change_state(ltk_button *button) {
+ltk_button_change_state(ltk_widget *self) {
+ ltk_button *button = self;
ltk_window *window = button->widget.window;
LtkColor *fill;
switch (button->widget.state) {
@@ -229,7 +232,8 @@ ltk_button_change_state(ltk_button *button) {
}
static int
-ltk_button_mouse_release(ltk_button *button, XEvent event) {
+ltk_button_mouse_release(ltk_widget *self, XEvent event) {
+ ltk_button *button = self;
ltk_queue_event(button->widget.window, LTK_EVENT_BUTTON, button->widget.id, "button_click");
return 1;
}
@@ -259,13 +263,14 @@ ltk_button_create(ltk_window *window, const char *id, const char *text) {
}
static void
-ltk_button_destroy(ltk_button *button, int shallow) {
+ltk_button_destroy(ltk_widget *self, int shallow) {
+ ltk_button *button = self;
if (!button) {
ltk_warn("Tried to destroy NULL button.\n");
return;
}
ltk_text_line_destroy(button->tl);
- ltk_remove_widget(button->widget.window, button->widget.id);
+ ltk_remove_widget(button->widget.id);
ltk_free(button->widget.id);
ltk_free(button);
}
diff --git a/draw.c b/draw.c
@@ -36,11 +36,11 @@
#include "util.h"
#include "draw.h"
-static void ltk_draw_draw(ltk_draw *draw);
+static void ltk_draw_draw(ltk_widget *self);
static ltk_draw *ltk_draw_create(ltk_window *window,
const char *id, int w, int h, const char *color);
-static void ltk_draw_resize(ltk_draw *draw);
-static void ltk_draw_destroy(ltk_draw *draw, int shallow);
+static void ltk_draw_resize(ltk_widget *self);
+static void ltk_draw_destroy(ltk_widget *self, int shallow);
static void ltk_draw_clear(ltk_window *window, ltk_draw *draw);
static void ltk_draw_set_color(ltk_window *window, ltk_draw *draw, const char *color);
static void ltk_draw_line(ltk_window *window, ltk_draw *draw, int x1, int y1, int x2, int y2);
@@ -72,7 +72,8 @@ static int ltk_draw_cmd_create(
char **errstr);
static void
-ltk_draw_draw(ltk_draw *draw) {
+ltk_draw_draw(ltk_widget *self) {
+ ltk_draw *draw = self;
ltk_window *window = draw->widget.window;
ltk_rect rect = draw->widget.rect;
XCopyArea(window->dpy, draw->pix, window->xwindow, window->gc, 0, 0, rect.w, rect.h, rect.x, rect.y);
@@ -101,7 +102,8 @@ ltk_draw_create(ltk_window *window, const char *id, int w, int h, const char *co
}
static void
-ltk_draw_resize(ltk_draw *draw) {
+ltk_draw_resize(ltk_widget *self) {
+ ltk_draw *draw = self;
Window win;
int x, y, w, h, bw, d;
int new_w, new_h;
@@ -124,12 +126,13 @@ ltk_draw_resize(ltk_draw *draw) {
}
static void
-ltk_draw_destroy(ltk_draw *draw, int shallow) {
+ltk_draw_destroy(ltk_widget *self, int shallow) {
+ ltk_draw *draw = self;
if (!draw) {
ltk_warn("Tried to destroy NULL draw.\n");
return;
}
- ltk_remove_widget(draw->widget.window, draw->widget.id);
+ ltk_remove_widget(draw->widget.id);
ltk_free(draw->widget.id);
XFreePixmap(draw->widget.window->dpy, draw->pix);
ltk_free(draw);
diff --git a/grid.c b/grid.c
@@ -30,6 +30,7 @@
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include <stdarg.h>
#include <stdint.h>
@@ -44,20 +45,20 @@
static void ltk_grid_set_row_weight(ltk_grid *grid, int row, int weight);
static void ltk_grid_set_column_weight(ltk_grid *grid, int column, int weight);
-static void ltk_grid_draw(ltk_grid *grid, ltk_rect clip);
+static void ltk_grid_draw(ltk_widget *self, ltk_rect clip);
static ltk_grid *ltk_grid_create(ltk_window *window, const char *id,
int rows, int columns);
-static void ltk_grid_destroy(ltk_grid *grid, int shallow);
-static void ltk_recalculate_grid(ltk_grid *grid);
-static void ltk_grid_child_size_change(ltk_grid *grid, ltk_widget *widget);
+static void ltk_grid_destroy(ltk_widget *self, int shallow);
+static void ltk_recalculate_grid(ltk_widget *self);
+static void ltk_grid_child_size_change(ltk_widget *self, ltk_widget *widget);
static int ltk_grid_add(ltk_window *window, ltk_widget *widget, ltk_grid *grid,
int row, int column, int row_span, int column_span, unsigned short sticky, char **errstr);
-static int ltk_grid_ungrid(ltk_window *window, ltk_widget *widget, ltk_grid *grid, char **errstr);
+static int ltk_grid_ungrid(ltk_window *window, ltk_widget *widget, ltk_widget *self, char **errstr);
static int ltk_grid_find_nearest_column(ltk_grid *grid, int x);
static int ltk_grid_find_nearest_row(ltk_grid *grid, int y);
-static int ltk_grid_mouse_press(ltk_grid *grid, XEvent event);
-static int ltk_grid_mouse_release(ltk_grid *grid, XEvent event);
-static int ltk_grid_motion_notify(ltk_grid *grid, XEvent event);
+static int ltk_grid_mouse_press(ltk_widget *self, XEvent event);
+static int ltk_grid_mouse_release(ltk_widget *self, XEvent event);
+static int ltk_grid_motion_notify(ltk_widget *self, XEvent event);
static int ltk_grid_cmd_add(
ltk_window *window,
@@ -98,7 +99,8 @@ ltk_grid_set_column_weight(ltk_grid *grid, int column, int weight) {
}
static void
-ltk_grid_draw(ltk_grid *grid, ltk_rect clip) {
+ltk_grid_draw(ltk_widget *self, ltk_rect clip) {
+ ltk_grid *grid = self;
int i;
for (i = 0; i < grid->rows * grid->columns; i++) {
if (!grid->widget_grid[i])
@@ -154,7 +156,8 @@ ltk_grid_create(ltk_window *window, const char *id, int rows, int columns) {
}
static void
-ltk_grid_destroy(ltk_grid *grid, int shallow) {
+ltk_grid_destroy(ltk_widget *self, int shallow) {
+ ltk_grid *grid = self;
ltk_widget *ptr;
if (!shallow) {
for (int i = 0; i < grid->rows * grid->columns; i++) {
@@ -178,13 +181,14 @@ ltk_grid_destroy(ltk_grid *grid, int shallow) {
ltk_free(grid->column_weights);
ltk_free(grid->row_pos);
ltk_free(grid->column_pos);
- ltk_remove_widget(grid->widget.window, grid->widget.id);
+ ltk_remove_widget(grid->widget.id);
ltk_free(grid->widget.id);
ltk_free(grid);
}
static void
-ltk_recalculate_grid(ltk_grid *grid) {
+ltk_recalculate_grid(ltk_widget *self) {
+ ltk_grid *grid = self;
unsigned int height_static = 0, width_static = 0;
unsigned int total_row_weight = 0, total_column_weight = 0;
float height_unit = 0, width_unit = 0;
@@ -270,7 +274,8 @@ ltk_recalculate_grid(ltk_grid *grid) {
/* FIXME: Maybe add debug stuff to check that grid is actually parent of widget */
static void
-ltk_grid_child_size_change(ltk_grid *grid, ltk_widget *widget) {
+ltk_grid_child_size_change(ltk_widget *self, ltk_widget *widget) {
+ ltk_grid *grid = self;
short size_changed = 0;
widget->rect.w = widget->ideal_w;
widget->rect.h = widget->ideal_h;
@@ -318,7 +323,8 @@ ltk_grid_add(ltk_window *window, ltk_widget *widget, ltk_grid *grid,
}
static int
-ltk_grid_ungrid(ltk_window *window, ltk_widget *widget, ltk_grid *grid, char **errstr) {
+ltk_grid_ungrid(ltk_window *window, ltk_widget *widget, ltk_widget *self, char **errstr) {
+ ltk_grid *grid = self;
if (widget->parent != grid) {
*errstr = "Widget isn't gridded in given grid.\n";
return 1;
@@ -357,7 +363,8 @@ ltk_grid_find_nearest_row(ltk_grid *grid, int y) {
}
static int
-ltk_grid_mouse_press(ltk_grid *grid, XEvent event) {
+ltk_grid_mouse_press(ltk_widget *self, XEvent event) {
+ ltk_grid *grid = self;
int x = event.xbutton.x;
int y = event.xbutton.y;
int row = ltk_grid_find_nearest_row(grid, y);
@@ -373,7 +380,8 @@ ltk_grid_mouse_press(ltk_grid *grid, XEvent event) {
}
static int
-ltk_grid_mouse_release(ltk_grid *grid, XEvent event) {
+ltk_grid_mouse_release(ltk_widget *self, XEvent event) {
+ ltk_grid *grid = self;
int x = event.xbutton.x;
int y = event.xbutton.y;
int row = ltk_grid_find_nearest_row(grid, y);
@@ -389,7 +397,8 @@ ltk_grid_mouse_release(ltk_grid *grid, XEvent event) {
}
static int
-ltk_grid_motion_notify(ltk_grid *grid, XEvent event) {
+ltk_grid_motion_notify(ltk_widget *self, XEvent event) {
+ ltk_grid *grid = self;
/* FIXME: Why does it check this? */
short pressed = (event.xmotion.state & Button1Mask) == Button1Mask;
if (pressed)
diff --git a/label.c b/label.c
@@ -37,10 +37,10 @@
#include "text.h"
#include "label.h"
-static void ltk_label_draw(ltk_label *label, ltk_rect clip);
+static void ltk_label_draw(ltk_widget *self, ltk_rect clip);
static ltk_label *ltk_label_create(ltk_window *window,
const char *id, const char *text);
-static void ltk_label_destroy(ltk_label *label, int shallow);
+static void ltk_label_destroy(ltk_widget *self, int shallow);
static struct {
LtkColor text_color;
@@ -73,7 +73,8 @@ ltk_label_ini_handler(ltk_window *window, const char *prop, const char *value) {
}
static void
-ltk_label_draw(ltk_label *label, ltk_rect clip) {
+ltk_label_draw(ltk_widget *self, ltk_rect clip) {
+ ltk_label *label = self;
ltk_window *window = label->widget.window;
ltk_rect rect = label->widget.rect;
ltk_rect clip_final = ltk_rect_intersect(clip, rect);
@@ -117,13 +118,14 @@ ltk_label_create(ltk_window *window, const char *id, const char *text) {
}
static void
-ltk_label_destroy(ltk_label *label, int shallow) {
+ltk_label_destroy(ltk_widget *self, int shallow) {
+ ltk_label *label = self;
if (!label) {
ltk_warn("Tried to destroy NULL label.\n");
return;
}
ltk_text_line_destroy(label->tl);
- ltk_remove_widget(label->widget.window, label->widget.id);
+ ltk_remove_widget(label->widget.id);
ltk_free(label->widget.id);
ltk_free(label);
}
diff --git a/ltk.h b/ltk.h
@@ -69,10 +69,10 @@ typedef enum {
LTK_BOX
} ltk_widget_type;
-typedef struct ltk_window ltk_window;
+struct ltk_window;
typedef struct ltk_widget {
- ltk_window *window;
+ struct ltk_window *window;
struct ltk_widget *active_widget;
struct ltk_widget *parent;
char *id;
@@ -81,21 +81,21 @@ typedef struct ltk_widget {
unsigned int ideal_w;
unsigned int ideal_h;
- void (*key_press) (void *, XEvent);
- void (*key_release) (void *, XEvent);
- int (*mouse_press) (void *, XEvent);
- int (*mouse_release) (void *, XEvent);
- int (*motion_notify) (void *, XEvent);
- void (*mouse_leave) (void *, XEvent);
- void (*mouse_enter) (void *, XEvent);
+ void (*key_press) (struct ltk_widget *, XEvent);
+ void (*key_release) (struct ltk_widget *, XEvent);
+ int (*mouse_press) (struct ltk_widget *, XEvent);
+ int (*mouse_release) (struct ltk_widget *, XEvent);
+ int (*motion_notify) (struct ltk_widget *, XEvent);
+ void (*mouse_leave) (struct ltk_widget *, XEvent);
+ void (*mouse_enter) (struct ltk_widget *, XEvent);
- void (*resize) (void *);
- void (*draw) (void *, ltk_rect);
- void (*change_state) (void *);
- void (*destroy) (void *, int);
+ void (*resize) (struct ltk_widget *);
+ void (*draw) (struct ltk_widget *, ltk_rect);
+ void (*change_state) (struct ltk_widget *);
+ void (*destroy) (struct ltk_widget *, int);
void (*child_size_change) (struct ltk_widget *, struct ltk_widget *);
- int (*remove_child) (ltk_window *, void *, void *, char **);
+ int (*remove_child) (struct ltk_window *, struct ltk_widget *, struct ltk_widget *, char **);
ltk_widget_type type;
ltk_widget_state state;
@@ -143,7 +143,7 @@ typedef struct ltk_window {
ltk_widget *root_widget;
ltk_widget *active_widget;
ltk_widget *pressed_widget;
- void (*other_event) (ltk_window *, XEvent event);
+ void (*other_event) (struct ltk_window *, XEvent event);
ltk_rect rect;
ltk_window_theme theme;
ltk_rect dirty_rect;
@@ -160,14 +160,15 @@ int ltk_collide_rect(ltk_rect rect, int x, int y);
void ltk_window_set_active_widget(ltk_window *window, ltk_widget *widget);
void ltk_window_set_pressed_widget(ltk_window *window, ltk_widget *widget);
void ltk_fill_widget_defaults(ltk_widget *widget, const char *id, ltk_window * window,
- void (*draw) (void *, ltk_rect), void (*change_state) (void *),
- void (*destroy) (void *, int), unsigned int needs_redraw,
+ void (*draw) (ltk_widget *, ltk_rect), void (*change_state) (ltk_widget *),
+ void (*destroy) (ltk_widget *, int), unsigned int needs_redraw,
ltk_widget_type type);
void ltk_widget_mouse_press_event(ltk_widget *widget, XEvent event);
void ltk_widget_mouse_release_event(ltk_widget *widget, XEvent event);
void ltk_widget_motion_notify_event(ltk_widget *widget, XEvent event);
-int ltk_check_widget_id_free(const char *id);
+int ltk_widget_id_free(const char *id);
ltk_widget *ltk_get_widget(const char *id, ltk_widget_type type, char **errstr);
void ltk_set_widget(ltk_widget *widget, const char *id);
+void ltk_remove_widget(const char *id);
#endif
diff --git a/ltkd.c b/ltkd.c
@@ -685,8 +685,8 @@ ltk_collide_rect(ltk_rect rect, int x, int y) {
void
ltk_fill_widget_defaults(ltk_widget *widget, const char *id, ltk_window *window,
- void (*draw) (void *, ltk_rect), void (*change_state) (void *),
- void (*destroy) (void *, int), unsigned int needs_redraw,
+ void (*draw) (ltk_widget *, ltk_rect), void (*change_state) (ltk_widget *),
+ void (*destroy) (ltk_widget *, int), unsigned int needs_redraw,
ltk_widget_type type) {
if (id) {
widget->id = ltk_strdup(id);
@@ -1208,7 +1208,7 @@ ltk_widget_destroy(
return 1;
}
ltk_remove_widget(tokens[1]);
- /* widget->parent->remove_child should never be NULl because of the fact that
+ /* widget->parent->remove_child should never be NULL because of the fact that
the widget is set as parent, but let's just check anyways... */
if (widget->parent && widget->parent->remove_child) {
err = widget->parent->remove_child(
diff --git a/scrollbar.c b/scrollbar.c
@@ -36,10 +36,10 @@
#include "util.h"
#include "scrollbar.h"
-static void ltk_scrollbar_draw(ltk_scrollbar *scrollbar, ltk_rect clip);
-static int ltk_scrollbar_mouse_press(ltk_scrollbar *scrollbar, XEvent event);
-static int ltk_scrollbar_motion_notify(ltk_scrollbar *scrollbar, XEvent event);
-static void ltk_scrollbar_destroy(ltk_scrollbar *scrollbar, int shallow);
+static void ltk_scrollbar_draw(ltk_widget *self, ltk_rect clip);
+static int ltk_scrollbar_mouse_press(ltk_widget *self, XEvent event);
+static int ltk_scrollbar_motion_notify(ltk_widget *self, XEvent event);
+static void ltk_scrollbar_destroy(ltk_widget *self, int shallow);
static struct {
int size; /* width or height, depending on orientation */
@@ -105,7 +105,8 @@ ltk_scrollbar_set_virtual_size(ltk_scrollbar *scrollbar, int virtual_size) {
}
static void
-ltk_scrollbar_draw(ltk_scrollbar *scrollbar, ltk_rect clip) {
+ltk_scrollbar_draw(ltk_widget *self, ltk_rect clip) {
+ ltk_scrollbar *scrollbar = self;
LtkColor *bg, *fg;
int handle_x, handle_y, handle_w, handle_h;
ltk_window *window = scrollbar->widget.window;
@@ -160,7 +161,8 @@ ltk_scrollbar_draw(ltk_scrollbar *scrollbar, ltk_rect clip) {
}
static int
-ltk_scrollbar_mouse_press(ltk_scrollbar *sc, XEvent event) {
+ltk_scrollbar_mouse_press(ltk_widget *self, XEvent event) {
+ ltk_scrollbar *sc = self;
int max_pos;
double rel_pos;
if (event.xbutton.button != 1 && event.xbutton.button != 3)
@@ -192,7 +194,8 @@ ltk_scrollbar_mouse_press(ltk_scrollbar *sc, XEvent event) {
/* FIXME: Make this scrollbar more "traditional" */
static int
-ltk_scrollbar_motion_notify(ltk_scrollbar *sc, XEvent event) {
+ltk_scrollbar_motion_notify(ltk_widget *self, XEvent event) {
+ ltk_scrollbar *sc = self;
/*
double scale;
int delta, max_pos;
@@ -243,6 +246,7 @@ ltk_scrollbar_create(ltk_window *window, ltk_orientation orient, void (*callback
}
static void
-ltk_scrollbar_destroy(ltk_scrollbar *scrollbar, int shallow) {
+ltk_scrollbar_destroy(ltk_widget *self, int shallow) {
+ ltk_scrollbar *scrollbar = self;
ltk_free(scrollbar);
}
diff --git a/text_stb.c b/text_stb.c
@@ -112,7 +112,7 @@ static khash_t(glyphinfo) *ltk_get_glyph_cache(uint16_t font_id,
uint16_t font_size);
static khint_t ltk_create_glyph_cache(uint16_t font_id, uint16_t font_size);
static void ltk_destroy_glyph_cache(khash_t(glyphinfo) *cache);
-static void ltk_load_default_font(char *name);
+static void ltk_load_default_font(const char *name);
static LtkFont *ltk_create_font(char *path, uint16_t id, int index);
static void ltk_destroy_font(LtkFont *font);
static LtkFont *ltk_load_font(char *path, int index);
@@ -263,7 +263,7 @@ ltk_get_glyph_info(LtkFont *font, int id, float scale, khash_t(glyphinfo) *cache
static khash_t(glyphinfo) *
ltk_get_glyph_cache(uint16_t font_id, uint16_t font_size) {
khint_t k;
- uint32_t attr = (uint32_t)font_id << 16 + font_size;
+ uint32_t attr = ((uint32_t)font_id << 16) + font_size;
k = kh_get(glyphcache, tm.glyph_cache, attr);
if (k == kh_end(tm.glyph_cache)) {
k = ltk_create_glyph_cache(font_id, font_size);
@@ -277,7 +277,7 @@ ltk_create_glyph_cache(uint16_t font_id, uint16_t font_size) {
int ret;
khint_t k;
/* I guess I can just ignore ret for now */
- k = kh_put(glyphcache, tm.glyph_cache, font_id << 16 + font_size, &ret);
+ k = kh_put(glyphcache, tm.glyph_cache, ((uint32_t)font_id << 16) + font_size, &ret);
kh_value(tm.glyph_cache, k) = cache;
return k;
@@ -295,7 +295,7 @@ ltk_destroy_glyph_cache(khash_t(glyphinfo) *cache) {
}
static void
-ltk_load_default_font(char *name) {
+ltk_load_default_font(const char *name) {
FcPattern *match;
FcResult result;
char *file;
@@ -345,7 +345,7 @@ static LtkFont *
ltk_load_font(char *path, int index) {
LtkFont *font = ltk_create_font(path, tm.font_id_cur++, index);
if (tm.num_fonts == tm.fonts_bufsize) {
- LtkFont *new = ltk_realloc(tm.fonts, tm.fonts_bufsize * 2 * sizeof(LtkFont *));
+ LtkFont **new = ltk_realloc(tm.fonts, tm.fonts_bufsize * 2 * sizeof(LtkFont *));
tm.fonts = new;
tm.fonts_bufsize *= 2;
}
@@ -360,7 +360,7 @@ ltk_get_font(char *path, int index) {
for (int i = 0; i < tm.num_fonts; i++) {
if (tm.fonts[i]->index == index &&
strcmp(tm.fonts[i]->path, path) == 0) {
- font = &tm.fonts[i];
+ font = tm.fonts[i];
break;
}
}
@@ -375,7 +375,7 @@ ltk_text_to_glyphs(LtkGlyph *glyphs, int num_glyphs, char *text, uint16_t font_s
uint32_t c1, c2 = 0;
int gid;
int index;
- char *file;
+ FcChar8 *file;
size_t inc = 0;
int x = 0, y, kern_advance, ax;
int x1_abs, x2_abs;
diff --git a/util.c b/util.c
@@ -27,6 +27,8 @@
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
+#include <unistd.h>
+#include <sys/stat.h>
#include "util.h"
#include "memory.h"