Skip to content
Snippets Groups Projects
Commit cdc21fb0 authored by Deucе's avatar Deucе :ok_hand_tone4:
Browse files

Add fill and aliases...

I think this is ready to start drawing things soon now.
parent 35cf3602
Branches
Tags
No related merge requests found
Pipeline #5450 passed
#include <fcntl.h> #include <fcntl.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
enum ni_type { enum ni_type {
ni_bool, ni_bool,
...@@ -21,6 +22,8 @@ objtypes[] = { ...@@ -21,6 +22,8 @@ objtypes[] = {
enum attribute_types { enum attribute_types {
NI_attr_type_NewIfcObj, NI_attr_type_NewIfcObj,
NI_attr_type_uint16_t, NI_attr_type_uint16_t,
NI_attr_type_uint8_t,
NI_attr_type_uint32_t,
NI_attr_type_NI_err, NI_attr_type_NI_err,
NI_attr_type_bool, NI_attr_type_bool,
NI_attr_type_charptr, NI_attr_type_charptr,
...@@ -35,6 +38,8 @@ struct type_str_values { ...@@ -35,6 +38,8 @@ struct type_str_values {
struct type_str_values type_str[] = { struct type_str_values type_str[] = {
{"NewIfcObj", "obj"}, {"NewIfcObj", "obj"},
{"uint16_t", "uint16"}, {"uint16_t", "uint16"},
{"uint8_t", "uint8"},
{"uint32_t", "uint32"},
{"NI_err", "NI_err"}, {"NI_err", "NI_err"},
{"bool", "bool"}, {"bool", "bool"},
{"const char *", "const_char_ptr"}, {"const char *", "const_char_ptr"},
...@@ -63,6 +68,10 @@ attributes[] = { ...@@ -63,6 +68,10 @@ attributes[] = {
{"child_xpos", NI_attr_type_uint16_t, attr_impl_global, 1}, {"child_xpos", NI_attr_type_uint16_t, attr_impl_global, 1},
{"child_ypos", NI_attr_type_uint16_t, attr_impl_global, 1}, {"child_ypos", NI_attr_type_uint16_t, attr_impl_global, 1},
{"dirty", NI_attr_type_bool, attr_impl_root, 1}, {"dirty", NI_attr_type_bool, attr_impl_root, 1},
{"fill_character", NI_attr_type_uint32_t, attr_impl_global, 0},
{"fill_character_colour", NI_attr_type_uint32_t, attr_impl_global, 0},
{"fill_colour", NI_attr_type_uint32_t, attr_impl_global, 0},
{"fill_font", NI_attr_type_uint8_t, attr_impl_global, 0},
{"focus", NI_attr_type_bool, attr_impl_global_custom_setter, 0}, {"focus", NI_attr_type_bool, attr_impl_global_custom_setter, 0},
{"height", NI_attr_type_uint16_t, attr_impl_global, 0}, {"height", NI_attr_type_uint16_t, attr_impl_global, 0},
{"hidden", NI_attr_type_bool, attr_impl_global, 1}, {"hidden", NI_attr_type_bool, attr_impl_global, 1},
...@@ -85,6 +94,16 @@ attributes[] = { ...@@ -85,6 +94,16 @@ attributes[] = {
{"ypos", NI_attr_type_uint16_t, attr_impl_global, 0}, {"ypos", NI_attr_type_uint16_t, attr_impl_global, 0},
}; };
struct attribute_alias {
const char *attribute_name;
const char *alias_name;
};
const struct attribute_alias aliases[] = {
{"fill_colour", "fill_color"},
{"fill_character_colour", "fill_character_color"},
};
struct error_info { struct error_info {
const char *name; const char *name;
int value; int value;
...@@ -115,6 +134,148 @@ extra_handlers[] = { ...@@ -115,6 +134,148 @@ extra_handlers[] = {
{"on_destroy", "NI_err (*on_destroy)(NewIfcObj obj, void *cbdata)"}, {"on_destroy", "NI_err (*on_destroy)(NewIfcObj obj, void *cbdata)"},
}; };
size_t
find_attribute(const char *name)
{
size_t nitems = sizeof(attributes) / sizeof(attributes[0]);
// Linear search in case they're not alphabetical
for (size_t i = 0; i < nitems; i++) {
if (strcmp(attributes[i].name, name) == 0)
return i;
}
return -1;
}
void
attribute_functions(size_t i, FILE *c_code, const char *alias)
{
switch (attributes[i].impl) {
case attr_impl_object:
if (!attributes[i].read_only) {
fprintf(c_code, "NI_err\n"
"NI_set_%s(NewIfcObj obj, %s value) {\n"
" NI_err ret;\n"
" if (obj == NULL)\n"
" return NewIfc_error_invalid_arg;\n"
" if (NI_set_locked(obj, true)) {\n"
" ret = call_%s_change_handlers(obj, NewIfc_%s, value);\n"
" if (ret != NewIfc_error_none)\n"
" return ret;\n"
" ret = obj->set(obj, NewIfc_%s, value);\n"
" NI_set_locked(obj, false);\n"
" }\n"
" else\n"
" ret = NewIfc_error_lock_failed;\n"
" return ret;\n"
"}\n\n", alias, type_str[attributes[i].type].type, type_str[attributes[i].type].var_name, attributes[i].name, attributes[i].name);
}
fprintf(c_code, "NI_err\n"
"NI_get_%s(NewIfcObj obj, %s* value) {\n"
" NI_err ret;\n"
" if (obj == NULL)\n"
" return NewIfc_error_invalid_arg;\n"
" if (value == NULL)\n"
" return NewIfc_error_invalid_arg;\n"
" if (NI_set_locked(obj, true)) {\n"
" ret = obj->get(obj, NewIfc_%s, value);\n"
" NI_set_locked(obj, false);\n"
" }\n"
" else\n"
" ret = NewIfc_error_lock_failed;\n"
" return ret;\n"
"}\n\n", alias, type_str[attributes[i].type].type, attributes[i].name);
break;
case attr_impl_global:
if (!attributes[i].read_only) {
fprintf(c_code, "NI_err\n"
"NI_set_%s(NewIfcObj obj, %s value) {\n"
" NI_err ret;\n"
" if (obj == NULL)\n"
" return NewIfc_error_invalid_arg;\n"
" if (NI_set_locked(obj, true)) {\n"
" ret = obj->set(obj, NewIfc_%s, value);\n"
" if (ret != NewIfc_error_none && obj->last_error != NewIfc_error_not_implemented) {\n"
" obj->%s = value;\n"
" obj->last_error = NewIfc_error_none;\n"
" }\n"
" NI_set_locked(obj, false);\n"
" }\n"
" else\n"
" ret = NewIfc_error_lock_failed;\n"
" return ret;\n"
"}\n\n", alias, type_str[attributes[i].type].type, attributes[i].name, attributes[i].name);
}
// Fall-through
case attr_impl_global_custom_setter:
fprintf(c_code, "NI_err\n"
"NI_get_%s(NewIfcObj obj, %s* value) {\n"
" NI_err ret;\n"
" if (obj == NULL)\n"
" return NewIfc_error_invalid_arg;\n"
" if (value == NULL)\n"
" return NewIfc_error_invalid_arg;\n"
" if (NI_set_locked(obj, true)) {\n"
" ret = obj->get(obj, NewIfc_%s, value);\n"
" if ((ret != NewIfc_error_none) && obj->last_error != NewIfc_error_not_implemented) {\n"
" *value = obj->%s;\n"
" obj->last_error = NewIfc_error_none;\n"
" }\n"
" NI_set_locked(obj, false);\n"
" }\n"
" else\n"
" ret = NewIfc_error_lock_failed;\n"
" return ret;\n"
"}\n\n", alias, type_str[attributes[i].type].type, attributes[i].name, attributes[i].name);
break;
case attr_impl_root:
if (!attributes[i].read_only) {
fprintf(c_code, "NI_err\n"
"NI_set_%s(NewIfcObj obj, %s value) {\n"
" if (obj == NULL)\n"
" return NewIfc_error_invalid_arg;\n"
" NI_err ret = obj->root->set(obj, NewIfc_%s, value);\n"
" obj->last_error = obj->root->last_error;\n"
" return ret;\n"
"}\n\n", alias, type_str[attributes[i].type].type, attributes[i].name);
}
fprintf(c_code, "NI_err\n"
"NI_get_%s(NewIfcObj obj, %s* value) {\n"
" if (obj == NULL)\n"
" return NewIfc_error_invalid_arg;\n"
" if (value == NULL)\n"
" return NewIfc_error_invalid_arg;\n"
" NI_err ret = obj->root->get(obj, NewIfc_%s, value);\n"
" obj->last_error = obj->root->last_error;\n"
" return ret;\n"
"}\n\n", alias, type_str[attributes[i].type].type, attributes[i].name);
break;
}
fprintf(c_code, "NI_err\n"
"NI_add_%s_handler(NewIfcObj obj, NI_err (*handler)(NewIfcObj obj, %s newval, void *cbdata), void *cbdata)\n"
"{\n"
" NI_err ret;\n"
" if (obj == NULL || handler == NULL)\n"
" return NewIfc_error_invalid_arg;\n"
" if (NI_set_locked(obj, true)) {\n"
" struct NewIfc_handler *h = malloc(sizeof(struct NewIfc_handler));\n"
" if (h == NULL)\n"
" return NewIfc_error_allocation_failure;\n"
" h->on_%s_change = handler;\n"
" h->cbdata = cbdata;\n"
" h->event = NewIfc_on_%s_change;\n"
" h->next = NULL;\n"
" ret = NI_install_handler(obj, h);\n"
" NI_set_locked(obj, false);\n"
" }\n"
" else\n"
" ret = NewIfc_error_lock_failed;\n"
" return ret;\n"
"}\n\n", alias, type_str[attributes[i].type].type, type_str[attributes[i].type].var_name, attributes[i].name);
}
int int
main(int argc, char **argv) main(int argc, char **argv)
{ {
...@@ -158,6 +319,8 @@ main(int argc, char **argv) ...@@ -158,6 +319,8 @@ main(int argc, char **argv)
} }
fputs("};\n\n", header); fputs("};\n\n", header);
fputs("#define NI_TRANSPARENT UINT32_MAX\n\n", header);
fputs("NI_err NI_copy(NewIfcObj obj, NewIfcObj *newobj);\n", header); fputs("NI_err NI_copy(NewIfcObj obj, NewIfcObj *newobj);\n", header);
fputs("NI_err NI_create(enum NewIfc_object obj, NewIfcObj parent, NewIfcObj *newobj);\n", header); fputs("NI_err NI_create(enum NewIfc_object obj, NewIfcObj parent, NewIfcObj *newobj);\n", header);
fputs("NI_err NI_error(NewIfcObj obj);\n", header); fputs("NI_err NI_error(NewIfcObj obj);\n", header);
...@@ -171,6 +334,15 @@ main(int argc, char **argv) ...@@ -171,6 +334,15 @@ main(int argc, char **argv)
} }
fprintf(header, "NI_err NI_get_%s(NewIfcObj obj, %s* value);\n", attributes[i].name, type_str[attributes[i].type].type); fprintf(header, "NI_err NI_get_%s(NewIfcObj obj, %s* value);\n", attributes[i].name, type_str[attributes[i].type].type);
} }
nitems = sizeof(aliases) / sizeof(aliases[0]);
for (i = 0; i < nitems; i++) {
size_t a = find_attribute(aliases[i].attribute_name);
if (!attributes[a].read_only) {
fprintf(header, "NI_err NI_set_%s(NewIfcObj obj, %s value);\n", aliases[i].alias_name, type_str[attributes[a].type].type);
}
fprintf(header, "NI_err NI_add_%s_handler(NewIfcObj obj, NI_err (*handler)(NewIfcObj obj, %s newval, void *cbdata), void *cbdata);\n", aliases[i].alias_name, type_str[attributes[a].type].type);
fprintf(header, "NI_err NI_get_%s(NewIfcObj obj, %s* value);\n", aliases[i].alias_name, type_str[attributes[a].type].type);
}
fputs("\n#endif\n", header); fputs("\n#endif\n", header);
fclose(header); fclose(header);
...@@ -219,13 +391,15 @@ main(int argc, char **argv) ...@@ -219,13 +391,15 @@ main(int argc, char **argv)
" NI_err (*get)(NewIfcObj niobj, const int attr, ...);\n" " NI_err (*get)(NewIfcObj niobj, const int attr, ...);\n"
" NI_err (*copy)(NewIfcObj obj, NewIfcObj *newobj);\n" " NI_err (*copy)(NewIfcObj obj, NewIfcObj *newobj);\n"
" struct NewIfc_handler **handlers;\n" " struct NewIfc_handler **handlers;\n"
" size_t handlers_sz;\n"
" NewIfcObj root;\n" " NewIfcObj root;\n"
" NewIfcObj parent;\n" " NewIfcObj parent;\n"
" NewIfcObj higherpeer;\n" " NewIfcObj higherpeer;\n"
" NewIfcObj lowerpeer;\n" " NewIfcObj lowerpeer;\n"
" NewIfcObj topchild;\n" " NewIfcObj topchild;\n"
" NewIfcObj bottomchild;\n" " NewIfcObj bottomchild;\n"
" size_t handlers_sz;\n"
" uint32_t fill_character_colour;\n"
" uint32_t fill_colour;\n"
" enum NewIfc_object type;\n" " enum NewIfc_object type;\n"
" NI_err last_error;\n" " NI_err last_error;\n"
" uint16_t height;\n" " uint16_t height;\n"
...@@ -238,6 +412,8 @@ main(int argc, char **argv) ...@@ -238,6 +412,8 @@ main(int argc, char **argv)
" uint16_t child_width;\n" " uint16_t child_width;\n"
" uint16_t child_xpos;\n" " uint16_t child_xpos;\n"
" uint16_t child_ypos;\n" " uint16_t child_ypos;\n"
" uint8_t fill_character;\n"
" uint8_t fill_font;\n"
" unsigned focus:1;\n" " unsigned focus:1;\n"
" unsigned hidden:1;\n" " unsigned hidden:1;\n"
"};\n\n", internal_header); "};\n\n", internal_header);
...@@ -272,7 +448,8 @@ main(int argc, char **argv) ...@@ -272,7 +448,8 @@ main(int argc, char **argv)
fputs("\n", c_code); fputs("\n", c_code);
fputs("NI_err\n" fputs("NI_err\n"
"NI_create(enum NewIfc_object obj, NewIfcObj parent, NewIfcObj *newobj) {\n" "NI_create(enum NewIfc_object obj, NewIfcObj parent, NewIfcObj *newobj)\n"
"{\n"
" NI_err ret = NewIfc_error_none;\n" " NI_err ret = NewIfc_error_none;\n"
"\n" "\n"
" if (newobj == NULL)\n" " if (newobj == NULL)\n"
...@@ -349,131 +526,12 @@ main(int argc, char **argv) ...@@ -349,131 +526,12 @@ main(int argc, char **argv)
nitems = sizeof(attributes) / sizeof(attributes[0]); nitems = sizeof(attributes) / sizeof(attributes[0]);
for (i = 0; i < nitems; i++) { for (i = 0; i < nitems; i++) {
switch (attributes[i].impl) { attribute_functions(i, c_code, attributes[i].name);
case attr_impl_object: }
if (!attributes[i].read_only) { nitems = sizeof(aliases) / sizeof(aliases[0]);
fprintf(c_code, "NI_err\n" for (i = 0; i < nitems; i++) {
"NI_set_%s(NewIfcObj obj, %s value) {\n" size_t a = find_attribute(aliases[i].attribute_name);
" NI_err ret;\n" attribute_functions(a, c_code, aliases[i].alias_name);
" if (obj == NULL)\n"
" return NewIfc_error_invalid_arg;\n"
" if (NI_set_locked(obj, true)) {\n"
" ret = call_%s_change_handlers(obj, NewIfc_%s, value);\n"
" if (ret != NewIfc_error_none)\n"
" return ret;\n"
" ret = obj->set(obj, NewIfc_%s, value);\n"
" NI_set_locked(obj, false);\n"
" }\n"
" else\n"
" ret = NewIfc_error_lock_failed;\n"
" return ret;\n"
"}\n\n", attributes[i].name, type_str[attributes[i].type].type, type_str[attributes[i].type].var_name, attributes[i].name, attributes[i].name);
}
fprintf(c_code, "NI_err\n"
"NI_get_%s(NewIfcObj obj, %s* value) {\n"
" NI_err ret;\n"
" if (obj == NULL)\n"
" return NewIfc_error_invalid_arg;\n"
" if (value == NULL)\n"
" return NewIfc_error_invalid_arg;\n"
" if (NI_set_locked(obj, true)) {\n"
" ret = obj->get(obj, NewIfc_%s, value);\n"
" NI_set_locked(obj, false);\n"
" }\n"
" else\n"
" ret = NewIfc_error_lock_failed;\n"
" return ret;\n"
"}\n\n", attributes[i].name, type_str[attributes[i].type].type, attributes[i].name);
break;
case attr_impl_global:
if (!attributes[i].read_only) {
fprintf(c_code, "NI_err\n"
"NI_set_%s(NewIfcObj obj, %s value) {\n"
" NI_err ret;\n"
" if (obj == NULL)\n"
" return NewIfc_error_invalid_arg;\n"
" if (NI_set_locked(obj, true)) {\n"
" ret = obj->set(obj, NewIfc_%s, value);\n"
" if (ret != NewIfc_error_none && obj->last_error != NewIfc_error_not_implemented) {\n"
" obj->%s = value;\n"
" obj->last_error = NewIfc_error_none;\n"
" }\n"
" NI_set_locked(obj, false);\n"
" }\n"
" else\n"
" ret = NewIfc_error_lock_failed;\n"
" return ret;\n"
"}\n\n", attributes[i].name, type_str[attributes[i].type].type, attributes[i].name, attributes[i].name);
}
// Fall-through
case attr_impl_global_custom_setter:
fprintf(c_code, "NI_err\n"
"NI_get_%s(NewIfcObj obj, %s* value) {\n"
" NI_err ret;\n"
" if (obj == NULL)\n"
" return NewIfc_error_invalid_arg;\n"
" if (value == NULL)\n"
" return NewIfc_error_invalid_arg;\n"
" if (NI_set_locked(obj, true)) {\n"
" ret = obj->get(obj, NewIfc_%s, value);\n"
" if ((ret != NewIfc_error_none) && obj->last_error != NewIfc_error_not_implemented) {\n"
" *value = obj->%s;\n"
" obj->last_error = NewIfc_error_none;\n"
" }\n"
" NI_set_locked(obj, false);\n"
" }\n"
" else\n"
" ret = NewIfc_error_lock_failed;\n"
" return ret;\n"
"}\n\n", attributes[i].name, type_str[attributes[i].type].type, attributes[i].name, attributes[i].name);
break;
case attr_impl_root:
if (!attributes[i].read_only) {
fprintf(c_code, "NI_err\n"
"NI_set_%s(NewIfcObj obj, %s value) {\n"
" if (obj == NULL)\n"
" return NewIfc_error_invalid_arg;\n"
" NI_err ret = obj->root->set(obj, NewIfc_%s, value);\n"
" obj->last_error = obj->root->last_error;\n"
" return ret;\n"
"}\n\n", attributes[i].name, type_str[attributes[i].type].type, attributes[i].name);
}
fprintf(c_code, "NI_err\n"
"NI_get_%s(NewIfcObj obj, %s* value) {\n"
" if (obj == NULL)\n"
" return NewIfc_error_invalid_arg;\n"
" if (value == NULL)\n"
" return NewIfc_error_invalid_arg;\n"
" NI_err ret = obj->root->get(obj, NewIfc_%s, value);\n"
" obj->last_error = obj->root->last_error;\n"
" return ret;\n"
"}\n\n", attributes[i].name, type_str[attributes[i].type].type, attributes[i].name);
break;
}
fprintf(c_code, "NI_err\n"
"NI_add_%s_handler(NewIfcObj obj, NI_err (*handler)(NewIfcObj obj, %s newval, void *cbdata), void *cbdata)\n"
"{\n"
" NI_err ret;\n"
" if (obj == NULL || handler == NULL)\n"
" return NewIfc_error_invalid_arg;\n"
" if (NI_set_locked(obj, true)) {\n"
" struct NewIfc_handler *h = malloc(sizeof(struct NewIfc_handler));\n"
" if (h == NULL)\n"
" return NewIfc_error_allocation_failure;\n"
" h->on_%s_change = handler;\n"
" h->cbdata = cbdata;\n"
" h->event = NewIfc_on_%s_change;\n"
" h->next = NULL;\n"
" ret = NI_install_handler(obj, h);\n"
" NI_set_locked(obj, false);\n"
" }\n"
" else\n"
" ret = NewIfc_error_lock_failed;\n"
" return ret;\n"
"}\n\n", attributes[i].name, type_str[attributes[i].type].type, type_str[attributes[i].type].var_name, attributes[i].name);
} }
fputs("#include \"newifc_nongen_after.c\"\n\n", c_code); fputs("#include \"newifc_nongen_after.c\"\n\n", c_code);
......
...@@ -136,3 +136,16 @@ remove_focus_cb(NewIfcObj obj, void *cbdata) ...@@ -136,3 +136,16 @@ remove_focus_cb(NewIfcObj obj, void *cbdata)
obj->set(obj, NewIfc_focus, false); obj->set(obj, NewIfc_focus, false);
return NewIfc_error_none; return NewIfc_error_none;
} }
static NI_err
NI_resize(NewIfcObj obj, uint16_t width, uint16_t height)
{
/* First, make sure all children will fit in new size...
* walk through them and check that the minsize is smaller than
* or equal to the updated client size accounting for X/Y position */
/* Now walk through them again actually setting the size...
* This is where sizers will need to get beefy */
return NewIfc_error_none;
}
...@@ -33,45 +33,6 @@ struct rw_recalc_child_cb_params { ...@@ -33,45 +33,6 @@ struct rw_recalc_child_cb_params {
uint16_t width; uint16_t width;
}; };
static NI_err
rw_recalc_child_cb(NewIfcObj obj, void *cbdata)
{
struct rw_recalc_child_cb_params *nsz = cbdata;
if (obj->height > nsz->height)
return NewIfc_error_wont_fit;
if (obj->width > nsz->width)
return NewIfc_error_wont_fit;
return NewIfc_error_none;
}
static void
rw_recalc_child(struct root_window *rw, uint16_t height, uint16_t width)
{
uint16_t losty = 0;
struct rw_recalc_child_cb_params nsz = {height, width};
if (rw->show_title) {
nsz.height--;
losty++;
}
if (rw->help) {
nsz.height--;
losty++;
}
if (losty > height) {
rw->api.last_error = NewIfc_error_wont_fit;
return;
}
if (NI_walk_children((NewIfcObj)rw, false, rw_recalc_child_cb, &nsz) != NewIfc_error_none) {
rw->api.last_error = NewIfc_error_wont_fit;
return;
}
rw->api.child_height = nsz.height;
rw->api.child_ypos = rw->show_title ? 1 : 0;
return;
}
static NI_err static NI_err
rw_set(NewIfcObj obj, int attr, ...) rw_set(NewIfcObj obj, int attr, ...)
{ {
...@@ -81,23 +42,6 @@ rw_set(NewIfcObj obj, int attr, ...) ...@@ -81,23 +42,6 @@ rw_set(NewIfcObj obj, int attr, ...)
rw->api.last_error = NewIfc_error_none; rw->api.last_error = NewIfc_error_none;
va_start(ap, attr); va_start(ap, attr);
switch (attr) { switch (attr) {
case NewIfc_show_title:
SET_BOOL(rw, show_title);
break;
case NewIfc_show_help:
SET_BOOL(rw, help);
rw_recalc_child(rw, rw->api.height, rw->api.width);
break;
case NewIfc_title:
SET_STRING(rw, title, title_sz);
rw_recalc_child(rw, rw->api.height, rw->api.width);
break;
case NewIfc_height:
rw_recalc_child(rw, va_arg(ap, int), rw->api.width);
break;
case NewIfc_width:
rw_recalc_child(rw, rw->api.height, va_arg(ap, int));
break;
case NewIfc_locked: case NewIfc_locked:
if (va_arg(ap, int)) { if (va_arg(ap, int)) {
if (pthread_mutex_lock(&rw->mtx) != 0) { if (pthread_mutex_lock(&rw->mtx) != 0) {
...@@ -151,15 +95,6 @@ rw_get(NewIfcObj obj, int attr, ...) ...@@ -151,15 +95,6 @@ rw_get(NewIfcObj obj, int attr, ...)
rw->api.last_error = NewIfc_error_none; rw->api.last_error = NewIfc_error_none;
va_start(ap, attr); va_start(ap, attr);
switch (attr) { switch (attr) {
case NewIfc_show_title:
GET_BOOL(rw, show_title);
break;
case NewIfc_show_help:
GET_BOOL(rw, help);
break;
case NewIfc_title:
GET_STRING(rw, title);
break;
case NewIfc_locked: case NewIfc_locked:
if (pthread_mutex_trylock(&rw->mtx) != 0) if (pthread_mutex_trylock(&rw->mtx) != 0)
*(va_arg(ap, bool *)) = true; *(va_arg(ap, bool *)) = true;
...@@ -207,11 +142,6 @@ rw_copy(NewIfcObj old, NewIfcObj *newobj) ...@@ -207,11 +142,6 @@ rw_copy(NewIfcObj old, NewIfcObj *newobj)
return NewIfc_error_allocation_failure; return NewIfc_error_allocation_failure;
} }
memcpy(*newrw, old, sizeof(struct root_window)); memcpy(*newrw, old, sizeof(struct root_window));
(*newrw)->title = strdup(oldrw->title);
if ((*newrw)->title == NULL) {
free(*newrw);
return NewIfc_error_allocation_failure;
}
return NewIfc_error_none; return NewIfc_error_none;
} }
...@@ -232,26 +162,18 @@ NewIFC_root_window(NewIfcObj *newobj) ...@@ -232,26 +162,18 @@ NewIFC_root_window(NewIfcObj *newobj)
(*newrw)->api.last_error = NewIfc_error_none; (*newrw)->api.last_error = NewIfc_error_none;
(*newrw)->api.width = 80; (*newrw)->api.width = 80;
(*newrw)->api.height = 25; (*newrw)->api.height = 25;
(*newrw)->api.child_width = 80;
(*newrw)->api.child_height = 25;
(*newrw)->api.xpos = 0; (*newrw)->api.xpos = 0;
(*newrw)->api.ypos = 0; (*newrw)->api.ypos = 0;
(*newrw)->api.child_xpos = 0; (*newrw)->api.child_xpos = 0;
(*newrw)->api.child_ypos = 1; (*newrw)->api.child_ypos = 1;
(*newrw)->api.child_width = 80;
(*newrw)->api.child_height = 23;
(*newrw)->api.min_height = 2; (*newrw)->api.min_height = 2;
(*newrw)->api.min_width = 40; (*newrw)->api.min_width = 40;
// TODO: This is only needed by the unit tests... // TODO: This is only needed by the unit tests...
(*newrw)->api.root = *newobj; (*newrw)->api.root = *newobj;
(*newrw)->api.focus = true; (*newrw)->api.focus = true;
(*newrw)->show_title = true;
(*newrw)->help = true;
(*newrw)->title_sz = 0;
(*newrw)->title = strdup(default_title);
(*newrw)->locks = 0; (*newrw)->locks = 0;
if ((*newrw)->title == NULL) {
free(*newrw);
return NewIfc_error_allocation_failure;
}
(*newrw)->mtx = pthread_mutex_initializer_np(true); (*newrw)->mtx = pthread_mutex_initializer_np(true);
return NewIfc_error_none; return NewIfc_error_none;
...@@ -278,24 +200,11 @@ void test_root_window(CuTest *ct) ...@@ -278,24 +200,11 @@ void test_root_window(CuTest *ct)
CuAssertTrue(ct, obj->min_height == 2); CuAssertTrue(ct, obj->min_height == 2);
CuAssertTrue(ct, obj->last_error == NewIfc_error_none); CuAssertTrue(ct, obj->last_error == NewIfc_error_none);
CuAssertTrue(ct, obj->focus == true); CuAssertTrue(ct, obj->focus == true);
CuAssertTrue(ct, obj->get(obj, NewIfc_show_title, &b) == NewIfc_error_none && b);
CuAssertTrue(ct, obj->last_error == NewIfc_error_none);
CuAssertTrue(ct, obj->get(obj, NewIfc_show_help, &b) == NewIfc_error_none && b);
CuAssertTrue(ct, obj->last_error == NewIfc_error_none);
CuAssertTrue(ct, obj->get(obj, NewIfc_title, &s) == NewIfc_error_none);
CuAssertStrEquals(ct, s, default_title);
CuAssertTrue(ct, obj->last_error == NewIfc_error_none);
CuAssertTrue(ct, obj->get(obj, NewIfc_locked, &b) == NewIfc_error_none && !b); CuAssertTrue(ct, obj->get(obj, NewIfc_locked, &b) == NewIfc_error_none && !b);
CuAssertTrue(ct, obj->last_error == NewIfc_error_none); CuAssertTrue(ct, obj->last_error == NewIfc_error_none);
CuAssertTrue(ct, obj->get(obj, NewIfc_locked_by_me, &b) == NewIfc_error_none && !b); CuAssertTrue(ct, obj->get(obj, NewIfc_locked_by_me, &b) == NewIfc_error_none && !b);
CuAssertTrue(ct, obj->last_error == NewIfc_error_none); CuAssertTrue(ct, obj->last_error == NewIfc_error_none);
CuAssertTrue(ct, obj->last_error == NewIfc_error_none);
CuAssertTrue(ct, obj->set(obj, NewIfc_show_title, false) == NewIfc_error_none);
CuAssertTrue(ct, obj->last_error == NewIfc_error_none);
CuAssertTrue(ct, obj->set(obj, NewIfc_show_help, false) == NewIfc_error_none);
CuAssertTrue(ct, obj->last_error == NewIfc_error_none);
CuAssertTrue(ct, obj->set(obj, NewIfc_title, new_title) == NewIfc_error_none);
CuAssertTrue(ct, obj->last_error == NewIfc_error_none); CuAssertTrue(ct, obj->last_error == NewIfc_error_none);
CuAssertTrue(ct, obj->set(obj, NewIfc_locked, false) == NewIfc_error_lock_failed); CuAssertTrue(ct, obj->set(obj, NewIfc_locked, false) == NewIfc_error_lock_failed);
CuAssertTrue(ct, obj->last_error == NewIfc_error_lock_failed); CuAssertTrue(ct, obj->last_error == NewIfc_error_lock_failed);
...@@ -304,13 +213,6 @@ void test_root_window(CuTest *ct) ...@@ -304,13 +213,6 @@ void test_root_window(CuTest *ct)
CuAssertTrue(ct, obj->set(obj, NewIfc_locked_by_me, &b) == NewIfc_error_not_implemented); CuAssertTrue(ct, obj->set(obj, NewIfc_locked_by_me, &b) == NewIfc_error_not_implemented);
CuAssertTrue(ct, obj->last_error == NewIfc_error_not_implemented); CuAssertTrue(ct, obj->last_error == NewIfc_error_not_implemented);
CuAssertTrue(ct, obj->get(obj, NewIfc_show_title, &b) == NewIfc_error_none && !b);
CuAssertTrue(ct, obj->last_error == NewIfc_error_none);
CuAssertTrue(ct, obj->get(obj, NewIfc_show_help, &b) == NewIfc_error_none && !b);
CuAssertTrue(ct, obj->last_error == NewIfc_error_none);
CuAssertTrue(ct, obj->get(obj, NewIfc_title, &s) == NewIfc_error_none);
CuAssertStrEquals(ct, s, new_title);
CuAssertTrue(ct, obj->last_error == NewIfc_error_none);
CuAssertTrue(ct, obj->get(obj, NewIfc_locked, &b) == NewIfc_error_none && b); CuAssertTrue(ct, obj->get(obj, NewIfc_locked, &b) == NewIfc_error_none && b);
CuAssertTrue(ct, obj->last_error == NewIfc_error_none); CuAssertTrue(ct, obj->last_error == NewIfc_error_none);
CuAssertTrue(ct, obj->get(obj, NewIfc_locked_by_me, &b) == NewIfc_error_none && b); CuAssertTrue(ct, obj->get(obj, NewIfc_locked_by_me, &b) == NewIfc_error_none && b);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment