Get to the point where we are fairly happy with our uncrustify config. Fixes #6.

This commit is contained in:
Joshua Strobl 2021-05-11 20:05:04 +03:00
parent d07d3dfe50
commit 62de9c2032
58 changed files with 4811 additions and 1946 deletions

View file

@ -26,7 +26,7 @@ struct _PixbufSize {
typedef struct _PixbufSize PixbufSize;
static PixbufSize *pixbuf_sizes = NULL;
static PixbufSize * pixbuf_sizes = NULL;
static guint pixbuf_sizes_allocated = 0;
static void init_pixbuf_sizes() {
@ -62,24 +62,26 @@ enum {
N_BTN_PROPERTIES
};
static GParamSpec *btn_props[N_BTN_PROPERTIES] = { NULL, };
static GParamSpec * btn_props[N_BTN_PROPERTIES] = {
NULL,
};
struct _KotoButton {
GtkBox parent_instance;
guint pix_size;
GtkWidget *button_pic;
GtkWidget *badge_label;
GtkWidget *button_label;
GtkWidget * button_pic;
GtkWidget * badge_label;
GtkWidget * button_label;
GtkGesture *left_click_gesture;
GtkGesture *right_click_gesture;
GtkGesture * left_click_gesture;
GtkGesture * right_click_gesture;
gchar *image_file_path;
gchar *badge_text;
gchar *icon_name;
gchar *alt_icon_name;
gchar *text;
gchar * image_file_path;
gchar * badge_text;
gchar * icon_name;
gchar * alt_icon_name;
gchar * text;
KotoButtonImagePosition image_position;
gboolean use_from_file;
@ -92,12 +94,26 @@ struct _KotoButtonClass {
G_DEFINE_TYPE(KotoButton, koto_button, GTK_TYPE_BOX);
static void koto_button_constructed(GObject *obj);
static void koto_button_get_property(GObject *obj, guint prop_id, GValue *val, GParamSpec *spec);
static void koto_button_set_property(GObject *obj, guint prop_id, const GValue *val, GParamSpec *spec);
static void koto_button_constructed(GObject * obj);
static void koto_button_get_property(
GObject * obj,
guint prop_id,
GValue * val,
GParamSpec * spec
);
static void koto_button_set_property(
GObject * obj,
guint prop_id,
const GValue * val,
GParamSpec * spec
);
static void koto_button_class_init(KotoButtonClass * c) {
GObjectClass * gobject_class;
static void koto_button_class_init(KotoButtonClass *c) {
GObjectClass *gobject_class;
gobject_class = G_OBJECT_CLASS(c);
gobject_class->constructed = koto_button_constructed;
gobject_class->set_property = koto_button_set_property;
@ -110,7 +126,7 @@ static void koto_button_class_init(KotoButtonClass *c) {
koto_get_pixbuf_size(KOTO_BUTTON_PIXBUF_SIZE_TINY),
koto_get_pixbuf_size(KOTO_BUTTON_PIXBUF_SIZE_GODLIKE),
koto_get_pixbuf_size(KOTO_BUTTON_PIXBUF_SIZE_SMALL),
G_PARAM_CONSTRUCT|G_PARAM_EXPLICIT_NOTIFY|G_PARAM_READWRITE
G_PARAM_CONSTRUCT | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_READWRITE
);
btn_props[PROP_TEXT] = g_param_spec_string(
@ -118,7 +134,7 @@ static void koto_button_class_init(KotoButtonClass *c) {
"Button Text",
"Text of Button",
NULL,
G_PARAM_CONSTRUCT|G_PARAM_EXPLICIT_NOTIFY|G_PARAM_READWRITE
G_PARAM_CONSTRUCT | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_READWRITE
);
btn_props[PROP_BADGE_TEXT] = g_param_spec_string(
@ -126,7 +142,7 @@ static void koto_button_class_init(KotoButtonClass *c) {
"Badge Text",
"Text of Badge",
NULL,
G_PARAM_CONSTRUCT|G_PARAM_EXPLICIT_NOTIFY|G_PARAM_READWRITE
G_PARAM_CONSTRUCT | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_READWRITE
);
btn_props[PROP_USE_FROM_FILE] = g_param_spec_boolean(
@ -134,7 +150,7 @@ static void koto_button_class_init(KotoButtonClass *c) {
"Use from a file / file name",
"Use from a file / file name",
FALSE,
G_PARAM_CONSTRUCT|G_PARAM_EXPLICIT_NOTIFY|G_PARAM_READWRITE
G_PARAM_CONSTRUCT | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_READWRITE
);
btn_props[PROP_IMAGE_FILE_PATH] = g_param_spec_string(
@ -142,7 +158,7 @@ static void koto_button_class_init(KotoButtonClass *c) {
"File path to image",
"File path to image",
NULL,
G_PARAM_CONSTRUCT|G_PARAM_EXPLICIT_NOTIFY|G_PARAM_READWRITE
G_PARAM_CONSTRUCT | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_READWRITE
);
btn_props[PROP_ICON_NAME] = g_param_spec_string(
@ -150,7 +166,7 @@ static void koto_button_class_init(KotoButtonClass *c) {
"Icon Name",
"Name of Icon",
NULL,
G_PARAM_CONSTRUCT|G_PARAM_EXPLICIT_NOTIFY|G_PARAM_READWRITE
G_PARAM_CONSTRUCT | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_READWRITE
);
btn_props[PROP_ALT_ICON_NAME] = g_param_spec_string(
@ -158,13 +174,13 @@ static void koto_button_class_init(KotoButtonClass *c) {
"Name of an Alternate Icon",
"Name of an Alternate Icon",
NULL,
G_PARAM_CONSTRUCT|G_PARAM_EXPLICIT_NOTIFY|G_PARAM_READWRITE
G_PARAM_CONSTRUCT | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_READWRITE
);
g_object_class_install_properties(gobject_class, N_BTN_PROPERTIES, btn_props);
}
static void koto_button_init(KotoButton *self) {
static void koto_button_init(KotoButton * self) {
self->currently_showing_alt = FALSE;
self->image_position = KOTO_BUTTON_IMAGE_POS_LEFT;
@ -178,16 +194,24 @@ static void koto_button_init(KotoButton *self) {
gtk_widget_add_controller(GTK_WIDGET(self), GTK_EVENT_CONTROLLER(self->right_click_gesture)); // Add our right click gesture
}
static void koto_button_constructed(GObject *obj) {
KotoButton *self = KOTO_BUTTON(obj);
GtkStyleContext *style = gtk_widget_get_style_context(GTK_WIDGET(self));
static void koto_button_constructed(GObject * obj) {
KotoButton * self = KOTO_BUTTON(obj);
GtkStyleContext * style = gtk_widget_get_style_context(GTK_WIDGET(self));
gtk_style_context_add_class(style, "koto-button");
G_OBJECT_CLASS (koto_button_parent_class)->constructed (obj);
G_OBJECT_CLASS(koto_button_parent_class)->constructed(obj);
}
static void koto_button_get_property(GObject *obj, guint prop_id, GValue *val, GParamSpec *spec) {
KotoButton *self = KOTO_BUTTON(obj);
static void koto_button_get_property(
GObject * obj,
guint prop_id,
GValue * val,
GParamSpec * spec
) {
KotoButton * self = KOTO_BUTTON(obj);
switch (prop_id) {
case PROP_IMAGE_FILE_PATH:
@ -217,8 +241,14 @@ static void koto_button_get_property(GObject *obj, guint prop_id, GValue *val, G
}
}
static void koto_button_set_property(GObject *obj, guint prop_id, const GValue *val, GParamSpec *spec) {
KotoButton *self = KOTO_BUTTON(obj);
static void koto_button_set_property(
GObject * obj,
guint prop_id,
const GValue * val,
GParamSpec * spec
) {
KotoButton * self = KOTO_BUTTON(obj);
switch (prop_id) {
case PROP_PIX_SIZE:
@ -257,7 +287,12 @@ static void koto_button_set_property(GObject *obj, guint prop_id, const GValue *
}
}
void koto_button_add_click_handler(KotoButton *self, KotoButtonClickType button, GCallback handler, gpointer user_data) {
void koto_button_add_click_handler(
KotoButton * self,
KotoButtonClickType button,
GCallback handler,
gpointer user_data
) {
if (!KOTO_IS_BUTTON(self)) {
return;
}
@ -269,7 +304,7 @@ void koto_button_add_click_handler(KotoButton *self, KotoButtonClickType button,
g_signal_connect((button == KOTO_BUTTON_CLICK_TYPE_PRIMARY) ? self->left_click_gesture : self->right_click_gesture, "pressed", handler, user_data);
}
void koto_button_flip(KotoButton *self) {
void koto_button_flip(KotoButton * self) {
if (!KOTO_IS_BUTTON(self)) {
return;
}
@ -277,13 +312,16 @@ void koto_button_flip(KotoButton *self) {
koto_button_show_image(self, !self->currently_showing_alt);
}
void koto_button_hide_image(KotoButton *self) {
void koto_button_hide_image(KotoButton * self) {
if (GTK_IS_WIDGET(self->button_pic)) { // Is a widget
gtk_widget_hide(self->button_pic);
}
}
void koto_button_set_badge_text(KotoButton *self, gchar *text) {
void koto_button_set_badge_text(
KotoButton * self,
gchar * text
) {
if ((text == NULL) || (strcmp(text, "") == 0)) { // If the text is empty
self->badge_text = g_strdup("");
} else {
@ -307,7 +345,10 @@ void koto_button_set_badge_text(KotoButton *self, gchar *text) {
g_object_notify_by_pspec(G_OBJECT(self), btn_props[PROP_BADGE_TEXT]);
}
void koto_button_set_file_path(KotoButton *self, gchar *file_path) {
void koto_button_set_file_path(
KotoButton * self,
gchar * file_path
) {
if (!KOTO_IS_BUTTON(self)) { // Not a button
return;
}
@ -324,8 +365,13 @@ void koto_button_set_file_path(KotoButton *self, gchar *file_path) {
koto_button_show_image(self, FALSE);
}
void koto_button_set_icon_name(KotoButton *self, gchar *icon_name, gboolean for_alt) {
gchar *copied_icon_name = g_strdup(icon_name);
void koto_button_set_icon_name(
KotoButton * self,
gchar * icon_name,
gboolean for_alt
) {
gchar * copied_icon_name = g_strdup(icon_name);
if (for_alt) { // Is for the alternate icon
if ((self->alt_icon_name != NULL) && strcmp(icon_name, self->alt_icon_name) != 0) { // If the icons are different
@ -342,9 +388,11 @@ void koto_button_set_icon_name(KotoButton *self, gchar *icon_name, gboolean for_
}
gboolean hide_image = FALSE;
if (for_alt && self->currently_showing_alt && ((self->alt_icon_name == NULL) || strcmp(self->alt_icon_name, "") == 0)) { // For alt, alt is currently showing, and no longer have alt
hide_image = TRUE;
} else if (!for_alt && ((self->icon_name == NULL) || (strcmp(self->icon_name,"") == 0))) { // Not for alt, no icon
} else if (!for_alt && ((self->icon_name == NULL) || (strcmp(self->icon_name, "") == 0))) { // Not for alt, no icon
hide_image = TRUE;
}
@ -359,7 +407,10 @@ void koto_button_set_icon_name(KotoButton *self, gchar *icon_name, gboolean for_
g_object_notify_by_pspec(G_OBJECT(self), for_alt ? btn_props[PROP_ALT_ICON_NAME] : btn_props[PROP_ICON_NAME]);
}
void koto_button_set_image_position(KotoButton *self, KotoButtonImagePosition pos) {
void koto_button_set_image_position(
KotoButton * self,
KotoButtonImagePosition pos
) {
if (self->image_position == pos) { // Is a different position that currently
return;
}
@ -375,7 +426,10 @@ void koto_button_set_image_position(KotoButton *self, KotoButtonImagePosition po
self->image_position = pos;
}
void koto_button_set_pixbuf_size(KotoButton *self, guint size) {
void koto_button_set_pixbuf_size(
KotoButton * self,
guint size
) {
if (size == self->pix_size) {
return;
}
@ -386,7 +440,10 @@ void koto_button_set_pixbuf_size(KotoButton *self, guint size) {
g_object_notify_by_pspec(G_OBJECT(self), btn_props[PROP_PIX_SIZE]);
}
void koto_button_set_text(KotoButton *self, gchar *text) {
void koto_button_set_text(
KotoButton * self,
gchar * text
) {
if (text == NULL) {
return;
}
@ -421,7 +478,10 @@ void koto_button_set_text(KotoButton *self, gchar *text) {
g_object_notify_by_pspec(G_OBJECT(self), btn_props[PROP_TEXT]);
}
void koto_button_show_image(KotoButton *self, gboolean use_alt) {
void koto_button_show_image(
KotoButton * self,
gboolean use_alt
) {
if (!KOTO_IS_BUTTON(self)) {
return;
}
@ -446,7 +506,7 @@ void koto_button_show_image(KotoButton *self, gboolean use_alt) {
}
self->currently_showing_alt = use_alt;
gchar *name = use_alt ? self->alt_icon_name : self->icon_name;
gchar * name = use_alt ? self->alt_icon_name : self->icon_name;
if (GTK_IS_IMAGE(self->button_pic)) {
gtk_image_set_from_icon_name(GTK_IMAGE(self->button_pic), name); // Just update the existing iamge
@ -461,7 +521,7 @@ void koto_button_show_image(KotoButton *self, gboolean use_alt) {
gtk_widget_show(self->button_pic); // Ensure we actually are showing the image
}
void koto_button_unflatten(KotoButton *self) {
void koto_button_unflatten(KotoButton * self) {
if (!KOTO_IS_BUTTON(self)) {
return;
}
@ -469,26 +529,44 @@ void koto_button_unflatten(KotoButton *self) {
gtk_widget_remove_css_class(GTK_WIDGET(self), "flat");
}
KotoButton* koto_button_new_plain(gchar *label) {
return g_object_new(KOTO_TYPE_BUTTON,
"button-text", label,
KotoButton * koto_button_new_plain(gchar * label) {
return g_object_new(
KOTO_TYPE_BUTTON,
"button-text",
label,
NULL
);
}
KotoButton* koto_button_new_with_icon(gchar *label, gchar *icon_name, gchar *alt_icon_name, KotoButtonPixbufSize size) {
return g_object_new(KOTO_TYPE_BUTTON,
"button-text", label,
"icon-name", icon_name,
"alt-icon-name", alt_icon_name,
"pixbuf-size", koto_get_pixbuf_size(size),
KotoButton * koto_button_new_with_icon(
gchar * label,
gchar * icon_name,
gchar * alt_icon_name,
KotoButtonPixbufSize size
) {
return g_object_new(
KOTO_TYPE_BUTTON,
"button-text",
label,
"icon-name",
icon_name,
"alt-icon-name",
alt_icon_name,
"pixbuf-size",
koto_get_pixbuf_size(size),
NULL
);
}
KotoButton *koto_button_new_with_file(gchar *label, gchar *file_path, KotoButtonPixbufSize size) {
return g_object_new(KOTO_TYPE_BUTTON,
"button-text", label,
KotoButton * koto_button_new_with_file(
gchar * label,
gchar * file_path,
KotoButtonPixbufSize size
) {
return g_object_new(
KOTO_TYPE_BUTTON,
"button-text",
label,
"use-from-file",
TRUE,
"image-file-path",