From: Christophe CURIS <christophe.cu...@free.fr> Because the macro wlengthof preforms a check of validity of its argument with static_assert, there is a use case where it fails with a compiler error. This patch introduces an alternate macro without the check, to be used only for this specific case.
To be able to use the size of the array, a few of those array declaration have to be moved before the structure in which their size is used. Signed-off-by: Christophe CURIS <christophe.cu...@free.fr> --- WPrefs.app/Appearance.c | 111 +++++++++++++++++++++++++----------------------- WPrefs.app/Docks.c | 54 +++++++++++------------ WPrefs.app/Expert.c | 2 +- WPrefs.app/WPrefs.h | 14 ++++++ 4 files changed, 99 insertions(+), 82 deletions(-) diff --git a/WPrefs.app/Appearance.c b/WPrefs.app/Appearance.c index d5786e5..ac5aed7 100644 --- a/WPrefs.app/Appearance.c +++ b/WPrefs.app/Appearance.c @@ -31,6 +31,62 @@ #include "TexturePanel.h" + +static const struct { + const char *key; + const char *default_value; + const char *label; + WMRect preview; /* The rectangle where the corresponding object is displayed */ + WMPoint hand; /* The coordinate where the hand is drawn when pointing this item */ +} colorOptions[] = { + /* Related to Window titles */ + { "FTitleColor", "white", N_("Focused Window Title"), + { { 30, 10 }, { 190, 20 } }, { 5, 10 } }, + { "UTitleColor", "black", N_("Unfocused Window Title"), + { { 30, 40 }, { 190, 20 } }, { 5, 40 } }, + { "PTitleColor", "white", N_("Owner of Focused Window Title"), + { { 30, 70 }, { 190, 20 } }, { 5, 70 } }, + + /* Related to Menus */ + { "MenuTitleColor", "white", N_("Menu Title") , + { { 30, 120 }, { 90, 20 } }, { 5, 120 } }, + { "MenuTextColor", "black", N_("Menu Item Text") , + { { 30, 140 }, { 90, 20 } }, { 5, 140 } }, + { "MenuDisabledColor", "#616161", N_("Disabled Menu Item Text") , + { { 30, 160 }, { 90, 20 } }, { 5, 160 } }, + { "HighlightColor", "white", N_("Menu Highlight Color") , + { { 30, 180 }, { 90, 20 } }, { 5, 180 } }, + { "HighlightTextColor", "black", N_("Highlighted Menu Text Color") , + { { 30, 200 }, { 90, 20 } }, { 5, 180 } }, + /* + * yuck kluge: the coordinate for HighlightTextColor are actually those of the last "Normal item" + * at the bottom when user clicks it, the "yuck kluge" in the function 'previewClick' will swap it + * for the MenuTextColor selection as user would expect + * + * Note that the entries are reffered by their index for performance + */ + + /* Related to Window's border */ + { "FrameFocusedBorderColor", "black", N_("Focused Window Border Color") , + { { 0, 0 }, { 0, 0 } }, { -22, -21 } }, + { "FrameBorderColor", "black", N_("Window Border Color") , + { { 0, 0 }, { 0, 0 } }, { -22, -21 } }, + { "FrameSelectedBorderColor", "white", N_("Selected Window Border Color") , + { { 0, 0 }, { 0, 0 } }, { -22, -21 } }, + + /* Related to Icons and Clip */ + { "IconTitleColor", "white", N_("Miniwindow Title") , + { { 155, 130 }, { 64, 64 } }, { 130, 132 } }, + { "IconTitleBack", "black", N_("Miniwindow Title Back") , + { { 155, 130 }, { 64, 64 } }, { 130, 132 } }, + { "ClipTitleColor", "black", N_("Clip Title") , + { { 155, 130 }, { 64, 64 } }, { 130, 132 } }, + { "CClipTitleColor", "#454045", N_("Collapsed Clip Title") , + { { 155, 130 }, { 64, 64 } }, { 130, 132 } } +}; + + +/********************************************************************/ typedef struct _Panel { WMBox *box; char *sectionName; @@ -60,7 +116,7 @@ typedef struct _Panel { WMFrame *colF; WMPopUpButton *colP; - WMColor *colors[15]; + WMColor *colors[wlengthof_nocheck(colorOptions)]; WMColorWell *colW; @@ -369,59 +425,6 @@ enum { CCLIP_COL }; -static const struct { - const char *key; - const char *default_value; - const char *label; - WMRect preview; /* The rectangle where the corresponding object is displayed */ - WMPoint hand; /* The coordinate where the hand is drawn when pointing this item */ -} colorOptions[] = { - /* Related to Window titles */ - { "FTitleColor", "white", N_("Focused Window Title"), - { { 30, 10 }, { 190, 20 } }, { 5, 10 } }, - { "UTitleColor", "black", N_("Unfocused Window Title"), - { { 30, 40 }, { 190, 20 } }, { 5, 40 } }, - { "PTitleColor", "white", N_("Owner of Focused Window Title"), - { { 30, 70 }, { 190, 20 } }, { 5, 70 } }, - - /* Related to Menus */ - { "MenuTitleColor", "white", N_("Menu Title") , - { { 30, 120 }, { 90, 20 } }, { 5, 120 } }, - { "MenuTextColor", "black", N_("Menu Item Text") , - { { 30, 140 }, { 90, 20 } }, { 5, 140 } }, - { "MenuDisabledColor", "#616161", N_("Disabled Menu Item Text") , - { { 30, 160 }, { 90, 20 } }, { 5, 160 } }, - { "HighlightColor", "white", N_("Menu Highlight Color") , - { { 30, 180 }, { 90, 20 } }, { 5, 180 } }, - { "HighlightTextColor", "black", N_("Highlighted Menu Text Color") , - { { 30, 200 }, { 90, 20 } }, { 5, 180 } }, - /* - * yuck kluge: the coordinate for HighlightTextColor are actually those of the last "Normal item" - * at the bottom when user clicks it, the "yuck kluge" in the function 'previewClick' will swap it - * for the MenuTextColor selection as user would expect - * - * Note that the entries are reffered by their index for performance - */ - - /* Related to Window's border */ - { "FrameFocusedBorderColor", "black", N_("Focused Window Border Color") , - { { 0, 0 }, { 0, 0 } }, { -22, -21 } }, - { "FrameBorderColor", "black", N_("Window Border Color") , - { { 0, 0 }, { 0, 0 } }, { -22, -21 } }, - { "FrameSelectedBorderColor", "white", N_("Selected Window Border Color") , - { { 0, 0 }, { 0, 0 } }, { -22, -21 } }, - - /* Related to Icons and Clip */ - { "IconTitleColor", "white", N_("Miniwindow Title") , - { { 155, 130 }, { 64, 64 } }, { 130, 132 } }, - { "IconTitleBack", "black", N_("Miniwindow Title Back") , - { { 155, 130 }, { 64, 64 } }, { 130, 132 } }, - { "ClipTitleColor", "black", N_("Clip Title") , - { { 155, 130 }, { 64, 64 } }, { 130, 132 } }, - { "CClipTitleColor", "#454045", N_("Collapsed Clip Title") , - { { 155, 130 }, { 64, 64 } }, { 130, 132 } } -}; - static void str2rcolor(RContext * rc, const char *name, RColor * color) { diff --git a/WPrefs.app/Docks.c b/WPrefs.app/Docks.c index 8404941..c7f1130 100644 --- a/WPrefs.app/Docks.c +++ b/WPrefs.app/Docks.c @@ -21,6 +21,28 @@ #include "WPrefs.h" + +static const struct { + const char *key; + const char *string; +} auto_delay[] = { + { "ClipAutoexpandDelay", N_("Before auto-expansion") }, + { "ClipAutocollapseDelay", N_("Before auto-collapsing") }, + { "ClipAutoraiseDelay", N_("Before auto-raise") }, + { "ClipAutolowerDelay", N_("Before auto-lowering") } +}; + +static char *autoDelayPresetValues[5] = { "0", "100", "250", "600", "1000" }; + +static const struct { + const char *disable_key; + const char *icon_file; +} dock_config[] = { + { "DisableDock", "dock" }, + { "DisableClip", "clip" }, + { "DisableDrawers", "drawer" } +}; + typedef struct _Panel { WMBox *box; @@ -33,13 +55,13 @@ typedef struct _Panel { WMWidget *parent; WMFrame *autoDelayF[2]; - WMLabel *autoDelayL[4]; - WMButton *autoDelayB[4][5]; - WMTextField *autoDelayT[4]; - WMLabel *autoDelayMsL[4]; + WMLabel *autoDelayL[wlengthof_nocheck(auto_delay)]; + WMButton *autoDelayB[wlengthof_nocheck(auto_delay)][wlengthof_nocheck(autoDelayPresetValues)]; + WMTextField *autoDelayT[wlengthof_nocheck(auto_delay)]; + WMLabel *autoDelayMsL[wlengthof_nocheck(auto_delay)]; WMFrame *dockF; - WMButton *docksB[3]; + WMButton *docksB[wlengthof_nocheck(dock_config)]; } _Panel; #define ICON_FILE "dockclipdrawersection" @@ -48,28 +70,6 @@ typedef struct _Panel { #define DELAY_ICON "timer%i" #define DELAY_ICON_S "timer%is" -static const struct { - const char *key; - const char *string; -} auto_delay[] = { - { "ClipAutoexpandDelay", N_("Before auto-expansion") }, - { "ClipAutocollapseDelay", N_("Before auto-collapsing") }, - { "ClipAutoraiseDelay", N_("Before auto-raise") }, - { "ClipAutolowerDelay", N_("Before auto-lowering") } -}; - - -static char *autoDelayPresetValues[5] = { "0", "100", "250", "600", "1000" }; - -static const struct { - const char *disable_key; - const char *icon_file; -} dock_config[] = { - { "DisableDock", "dock" }, - { "DisableClip", "clip" }, - { "DisableDrawers", "drawer" } -}; - static void showData(_Panel *panel); static void storeData(_Panel *panel); diff --git a/WPrefs.app/Expert.c b/WPrefs.app/Expert.c index 2f6cb7f..84e4eb4 100644 --- a/WPrefs.app/Expert.c +++ b/WPrefs.app/Expert.c @@ -100,7 +100,7 @@ typedef struct _Panel { WMWidget *parent; - WMButton *swi[sizeof(expert_options) / sizeof(expert_options[0])]; + WMButton *swi[wlengthof_nocheck(expert_options)]; } _Panel; diff --git a/WPrefs.app/WPrefs.h b/WPrefs.app/WPrefs.h index 4fbd8ee..0373414 100644 --- a/WPrefs.app/WPrefs.h +++ b/WPrefs.app/WPrefs.h @@ -37,6 +37,20 @@ /* Needed for HAVE_LIBINTL_H and EXTENDED_WINDOWSHORTCUT */ #include "../src/wconfig.h" +/* + * The macro 'wlengthof' should be used as much as possible, this macro + * is reserved for the cases where wlengthof cannot be used because the + * static_assert. Typical symptom is this compiler error (gcc): + * + * error: braced-group within expression allowed only inside a function + * + * which appears when you try to create an array whose size is determined using + * wlengthof on some other array. + */ +#define wlengthof_nocheck(array) \ + (sizeof(array) / sizeof(array[0])) + + /****/ extern char *NOptionValueChanged; -- 2.1.1 -- To unsubscribe, send mail to wmaker-dev-unsubscr...@lists.windowmaker.org.