1
0
mirror of https://github.com/gryf/wmaker.git synced 2026-07-09 20:26:37 +02:00

Compare commits

...

30 Commits

Author SHA1 Message Date
David Maciejak a383074c99 WPrefs: sort alphabetically the key shortcut actions and expert options
There are too many entries now in key shortcut actions and expert options,
better to sort them dynamically.
2023-03-03 14:15:19 +00:00
David Maciejak 52a623729d Coverity: fix WRaster convert uninitialized scalar variable 2023-03-03 14:15:19 +00:00
David Maciejak d4ee17f0b5 Coverity: fix WPrefs workspace negative array index read 2023-03-03 14:15:19 +00:00
David Maciejak 7475bc5d0a Coverity: fix util wmsetbg resource leak 2023-03-03 14:15:19 +00:00
David Maciejak 35f87b5592 WRaster: add new file references for translation
This patch is adding the references for the two newly added files
save_jpeg.c and save_png.c for translation (even if those new
files are not adding any new strings to be translated).
2023-03-03 09:51:24 +00:00
David Maciejak 5e37d13eb6 Coverity: fix wmgenmenu resource leak 2023-03-02 17:04:48 +00:00
David Maciejak 4b1aee3e79 Coverity: fix wmmenugen resource leak 2023-03-02 17:04:48 +00:00
David Maciejak 0ccc5bbde7 Coverity: fix wmspec dereference after null check 2023-03-02 17:04:48 +00:00
David Maciejak 59a686d22e Coverity: fix WPrefs appearance negative array index read 2023-03-02 17:04:48 +00:00
David Maciejak 26d46f6e16 Coverity: fix WPrefs menu negative array index read 2023-03-02 17:04:48 +00:00
David Maciejak ceafbf0629 Coverity: fix WPrefs mousesettings menu negative array index read 2023-03-02 17:04:48 +00:00
David Maciejak cf178d011b Coverity: fix WPrefs preference negative array index read 2023-03-02 17:04:48 +00:00
David Maciejak 682c2767c2 Coverity: fix WPrefs texturepanel negative array index read 2023-03-02 17:04:48 +00:00
David Maciejak 0e00c6b605 Coverity: fix dialog dereference null return value
This patch is making sure defaultPath returns from FindImage() is not null
and freeing the variables.
2023-03-02 17:04:48 +00:00
David Maciejak e9717ed719 Coverity: fix WPrefs appearance time of check time of use 2023-03-02 17:04:48 +00:00
David Maciejak 9e59d19507 Coverity: fix WPrefs editmenu uninitialized scalar variables 2023-03-02 17:04:48 +00:00
David Maciejak 94f98dcd25 Coverity: fix WRaster convert uninitialized scalar variable 2023-03-02 17:04:48 +00:00
David Maciejak 6c7266c338 Coverity: fix session resource leak 2023-03-02 17:04:48 +00:00
David Maciejak b4bd6d0cad Coverity: fix xmodifier uninitialized scalar variable 2023-03-02 17:04:48 +00:00
David Maciejak c7f7c10d7c Coverity: fix wmsetbg string not null terminated 2023-03-02 17:04:48 +00:00
David Maciejak d831766572 Coverity: fix rootmenu structurally dead code 2023-03-02 17:04:48 +00:00
David Maciejak e2ecfbfd54 Coverity: fix wcolorpanel uninitialized scalar value 2023-03-02 17:04:48 +00:00
David Maciejak a8ec32d41a Coverity: fix setstyle resource leak 2023-03-02 17:04:48 +00:00
David Maciejak 1215680b6d Coverity: fix misc resource leak 2023-03-02 17:04:48 +00:00
David Maciejak 77df89396c Coverity: fix menuparser_macro uninitialized pointer read 2023-03-02 17:04:48 +00:00
David Maciejak c8883fdbb0 WRaster: add functions to save image on disk
This patch adds the RSaveTitledImage() function to the WRaster lib
to be able to save file on disk either as a PNG or a JPEG file.
Those two formats depends on optional external libs.
The function can take an optional title/comment which will
be save inside the file.

The WRaster lib and header versions are bumped.
2023-03-02 10:23:47 +00:00
David Maciejak 3cc5808dcd Coverity: fix wmspec uninitialized layer variable 2023-02-28 13:40:48 +00:00
David Maciejak 8ca89f0141 Coverity: fix RContextAttributes uninitialized variable 2023-02-28 13:33:11 +00:00
David Maciejak 76fa91d21e Coverity: fix wmiv resource leak 2023-02-28 13:33:11 +00:00
David Maciejak d2d5297a1e Coverity: fix potential buffer overflow 2023-02-28 13:33:11 +00:00
36 changed files with 426 additions and 73 deletions
+1 -1
View File
@@ -615,7 +615,7 @@ static void menu_parser_condition_ifmacro(WMenuParser parser, Bool check_exists)
((!check_exists) && (macro != NULL));
}
strcpy(parser->cond.stack[0].name, cmd_name);
strncpy(parser->cond.stack[0].name, cmd_name, sizeof(parser->cond.stack[0].name) - 1);
parser->cond.stack[0].line = parser->line_number;
}
+4 -1
View File
@@ -167,6 +167,7 @@ void menu_parser_define_macro(WMenuParser parser)
return;
}
macro = wmalloc(sizeof(*macro));
memset(arg_name, 0, MAX_MACRO_ARG_COUNT * sizeof(char *));
/* Isolate name of macro */
idx = 0;
@@ -392,6 +393,8 @@ void menu_parser_expand_macro(WMenuParser parser, WParserMacro *macro)
unsigned int size;
int i, space_left;
memset(arg_value, 0, MAX_MACRO_ARG_COUNT * sizeof(char *));
/* Skip the name of the macro, this was not done by caller */
for (i = 0; macro->name[i] != '\0'; i++)
parser->rd++;
@@ -693,7 +696,7 @@ static void w_create_macro(WMenuParser parser, const char *name, WParserMacroFun
WParserMacro *macro;
macro = wmalloc(sizeof(*macro));
strcpy(macro->name, name);
strncpy(macro->name, name, sizeof(macro->name) - 1);
macro->function = handler;
macro->arg_count = -1;
macro->next = parser->macros;
+3 -3
View File
@@ -2259,7 +2259,7 @@ static void wheelPositionSelectionOutBounds(W_ColorPanel * panel, int x, int y)
static void wheelUpdateBrightnessGradientFromLocation(W_ColorPanel * panel)
{
CPColor from;
CPColor from = {};
unsigned long ofs;
ofs = panel->coly * panel->wheelMtrx->width + panel->colx;
@@ -2604,7 +2604,7 @@ static void cmykTextFieldCallback(void *observerData, WMNotification * notificat
static void hsbSliderCallback(WMWidget * w, void *data)
{
CPColor cpColor;
CPColor cpColor = {};
int value[3];
char tmp[4];
W_ColorPanel *panel = (W_ColorPanel *) data;
@@ -2640,7 +2640,7 @@ static void hsbSliderCallback(WMWidget * w, void *data)
static void hsbTextFieldCallback(void *observerData, WMNotification * notification)
{
CPColor cpColor;
CPColor cpColor = {};
int value[3];
char tmp[12]; /* We only 4 bytes needed, but compilers cannot know that */
int n;
+17 -5
View File
@@ -1076,6 +1076,8 @@ static void deleteTexture(WMWidget * w, void *data)
(void) w;
section = WMGetPopUpButtonSelectedItem(panel->secP);
if (section < 0)
return;
row = WMGetListSelectedItemRow(panel->texLs);
item = WMGetListItem(panel->texLs, row);
titem = (TextureListItem *) item->clientData;
@@ -1134,6 +1136,8 @@ static void changePage(WMWidget * w, void *data)
if (w) {
section = WMGetPopUpButtonSelectedItem(panel->secP);
if (section < 0)
return;
WMSelectListItem(panel->texLs, panel->textureIndex[section]);
@@ -1233,6 +1237,8 @@ static void textureDoubleClick(WMWidget * w, void *data)
/* unselect old texture */
section = WMGetPopUpButtonSelectedItem(panel->secP);
if (section < 0)
return;
item = WMGetListItem(panel->texLs, panel->textureIndex[section]);
titem = (TextureListItem *) item->clientData;
@@ -1261,7 +1267,7 @@ static void paintListItem(WMList * lPtr, int index, Drawable d, char *text, int
{
_Panel *panel = (_Panel *) WMGetHangedData(lPtr);
WMScreen *scr = WMWidgetScreen(lPtr);
int width, height, x, y;
int width, height, x, y, tmp;
Display *dpy = WMScreenDisplay(scr);
WMColor *back = (state & WLDSSelected) ? WMWhiteColor(scr) : WMGrayColor(scr);
WMListItem *item;
@@ -1290,7 +1296,8 @@ static void paintListItem(WMList * lPtr, int index, Drawable d, char *text, int
XCopyArea(dpy, titem->preview, d, WMColorGC(black), 0, 0,
TEXPREV_WIDTH, TEXPREV_HEIGHT, x + 5, y + 5);
if ((1 << WMGetPopUpButtonSelectedItem(panel->secP)) & titem->selectedFor)
tmp = WMGetPopUpButtonSelectedItem(panel->secP);
if ((tmp >= 0) && ((1 << tmp) & titem->selectedFor))
WMDrawPixmap(panel->onLed, d, x + TEXPREV_WIDTH + 10, y + 6);
else if (titem->selectedFor)
WMDrawPixmap(panel->offLed, d, x + TEXPREV_WIDTH + 10, y + 6);
@@ -1425,6 +1432,10 @@ static void changeColorPage(WMWidget * w, void *data)
WMScreen *scr = WMWidgetScreen(panel->box);
RContext *rc = WMScreenRContext(scr);
section = WMGetPopUpButtonSelectedItem(panel->colP);
if (section < 0)
return;
if (panel->preview) {
GC gc;
@@ -1436,7 +1447,6 @@ static void changeColorPage(WMWidget * w, void *data)
colorOptions[panel->oldcsection].hand.y);
}
if (w) {
section = WMGetPopUpButtonSelectedItem(panel->colP);
panel->oldcsection = section;
if (panel->preview)
@@ -1737,6 +1747,8 @@ static void colorWellObserver(void *self, WMNotification * n)
(void) n;
p = WMGetPopUpButtonSelectedItem(panel->colP);
if (p < 0)
return;
WMReleaseColor(panel->colors[p]);
@@ -1831,7 +1843,7 @@ static void createPanel(Panel * p)
panel->fprefix = wstrconcat(wuserdatapath(), "/" PACKAGE_TARNAME);
if (access(panel->fprefix, F_OK) != 0) {
if (mkdir(panel->fprefix, 0755) < 0) {
if (-1 == mkdir(panel->fprefix, 0755) && errno != EEXIST) {
werror("%s", panel->fprefix);
ok = False;
}
@@ -1841,7 +1853,7 @@ static void createPanel(Panel * p)
wfree(panel->fprefix);
panel->fprefix = tmp;
if (access(panel->fprefix, F_OK) != 0) {
if (mkdir(panel->fprefix, 0755) < 0) {
if (-1 == mkdir(panel->fprefix, 0755) && errno != EEXIST) {
werror("%s", panel->fprefix);
}
}
+15 -1
View File
@@ -25,7 +25,7 @@
/* This structure containts the list of all the check-buttons to display in the
* expert tab of the window with the corresponding information for effect
*/
static const struct {
static struct expert_option {
const char *label; /* Text displayed to user */
int def_state; /* True/False: the default value, if not defined in current config */
@@ -172,6 +172,19 @@ static void upButtonCallback(WMWidget *self, void *data)
changeIntTextfield(data, 1);
}
static int cmpExpertOptions(const void *v1, const void *v2)
{
int rc;
const struct expert_option *opt1 = (struct expert_option *)v1;
const struct expert_option *opt2 = (struct expert_option *)v2;
if ((rc = strcmp(opt1->label, opt2->label)) < 0)
return -1;
else if (rc > 0)
return 1;
return 0;
}
static void createPanel(Panel *p)
{
_Panel *panel = (_Panel *) p;
@@ -195,6 +208,7 @@ static void createPanel(Panel *p)
WMSetFrameRelief(f, WRFlat);
udb = WMGetStandardUserDefaults();
qsort(expert_options, wlengthof(expert_options), sizeof(expert_options[0]), cmpExpertOptions);
for (i = 0; i < wlengthof(expert_options); i++) {
if (expert_options[i].class != OPTION_WMAKER_INT) {
panel->swi[i] = WMCreateSwitchButton(f);
+16 -1
View File
@@ -65,7 +65,7 @@ typedef struct _Panel {
* First parameter is the internal keyword known by WMaker
* Second is the text displayed to the user
*/
static const struct {
static struct keyOption {
const char *key;
const char *title;
} keyOptions[] = {
@@ -541,6 +541,20 @@ static void paintItem(WMList * lPtr, int index, Drawable d, char *text, int stat
WMDrawString(scr, d, panel->black, panel->font, x + 20, y, text, strlen(text));
}
static int cmpKeyOptions(const void *v1, const void *v2)
{
int rc;
const struct keyOption *opt1 = (struct keyOption *)v1;
const struct keyOption *opt2 = (struct keyOption *)v2;
if ((rc = strcmp(opt1->title, opt2->title)) < 0)
return -1;
else if (rc > 0)
return 1;
return 0;
}
static void createPanel(Panel * p)
{
_Panel *panel = (_Panel *) p;
@@ -580,6 +594,7 @@ static void createPanel(Panel * p)
WMSetListUserDrawProc(panel->actLs, paintItem);
WMHangData(panel->actLs, panel);
qsort(keyOptions, wlengthof(keyOptions), sizeof(keyOptions[0]), cmpKeyOptions);
for (i = 0; i < wlengthof(keyOptions); i++) {
WMAddListItem(panel->actLs, _(keyOptions[i].title));
}
+2
View File
@@ -291,6 +291,8 @@ static void changedItemPad(WMWidget * w, void *data)
_Panel *panel = (_Panel *) data;
int padn = WMGetPopUpButtonSelectedItem(w);
if (padn < 0)
return;
WMUnmapWidget(panel->itemPad[panel->currentPad]);
WMMapWidget(panel->itemPad[padn]);
+2
View File
@@ -748,6 +748,8 @@ static void storeData(_Panel * panel)
int action;
action = WMGetPopUpButtonSelectedItem(panel->mouse_action[i].popup);
if (action < 0)
continue;
if (button_list[i].type == T_BUTTON)
db_value = button_actions[action].db_value;
else
+4
View File
@@ -196,9 +196,13 @@ static void storeData(_Panel * panel)
int i;
i = WMGetPopUpButtonSelectedItem(panel->sizeP);
if (i < 0)
return;
SetStringForKey(resize_display[i].db_value, "ResizeDisplay");
i = WMGetPopUpButtonSelectedItem(panel->posiP);
if (i < 0)
return;
SetStringForKey(move_display[i].db_value, "MoveDisplay");
lr = WMGetButtonSelected(panel->lrB);
+1 -1
View File
@@ -689,7 +689,7 @@ static void changeTypeCallback(WMWidget *w, void *data)
int i;
newType = WMGetPopUpButtonSelectedItem(w);
if (newType == panel->currentType)
if (newType < 0 || newType == panel->currentType)
return;
if (panel->currentType >= 0) {
+5 -2
View File
@@ -207,12 +207,15 @@ static void createPanel(Panel * p)
static void storeData(_Panel * panel)
{
int tmp = WMGetPopUpButtonSelectedItem(panel->posP);
if (tmp < 0)
return;
SetBoolForKey(!WMGetButtonSelected(panel->linkB), "DontLinkWorkspaces");
SetBoolForKey(WMGetButtonSelected(panel->cyclB), "CycleWorkspaces");
SetBoolForKey(WMGetButtonSelected(panel->newB), "AdvanceToNewWorkspace");
SetStringForKey(WSNamePositions[WMGetPopUpButtonSelectedItem(panel->posP)],
"WorkspaceNameDisplayPosition");
SetStringForKey(WSNamePositions[tmp], "WorkspaceNameDisplayPosition");
}
Panel *InitWorkspace(WMWidget *parent)
+1 -1
View File
@@ -1150,7 +1150,7 @@ static void dragItem(WEditMenu * menu, WEditMenuItem * item, Bool copy)
static XColor back = { 0, 0xffff, 0xffff, 0xffff, DoRed | DoGreen | DoBlue, 0 };
Display *dpy = W_VIEW_DISPLAY(menu->view);
WMScreen *scr = W_VIEW_SCREEN(menu->view);
int x, y;
int x = 0, y = 0;
int dx, dy;
Bool done = False;
Window blaw;
+2 -2
View File
@@ -71,9 +71,9 @@ dnl 6. If any interfaces have been removed or changed since the last
dnl public release, then set age to 0.
dnl
dnl libwraster
WRASTER_CURRENT=6
WRASTER_CURRENT=7
WRASTER_REVISION=0
WRASTER_AGE=0
WRASTER_AGE=1
WRASTER_VERSION=$WRASTER_CURRENT:$WRASTER_REVISION:$WRASTER_AGE
AC_SUBST(WRASTER_VERSION)
dnl
+9 -7
View File
@@ -1103,14 +1103,16 @@ Bool wIconChooserDialog(WScreen *scr, char **file, const char *instance, const c
} else {
defaultPath = FindImage(wPreferences.icon_path, *file);
wantedPath = WMGetTextFieldText(panel->fileField);
/* if the file is not the default, use full path */
if (strcmp(wantedPath, defaultPath) != 0) {
*file = wantedPath;
} else {
*file = wstrdup(*file);
wfree(wantedPath);
if (defaultPath) {
/* if the file is not the default, use full path */
if (strcmp(wantedPath, defaultPath) != 0) {
*file = wstrdup(wantedPath);
} else {
*file = wstrdup(*file);
}
wfree(defaultPath);
}
wfree(defaultPath);
wfree(wantedPath);
}
} else {
*file = NULL;
+1
View File
@@ -799,6 +799,7 @@ char *GetShortcutString(const char *shortcut)
*k = 0;
mod = wXModifierFromKey(text);
if (mod < 0) {
wfree(buffer);
return wstrdup("bug");
}
lbl = wXModifierToShortcutLabel(mod);
-2
View File
@@ -1038,8 +1038,6 @@ static WMenu *readMenu(WScreen *scr, const char *flat_file, FILE *file)
freeline(title, command, params, shortcut);
break;
}
freeline(title, command, params, shortcut);
}
WMenuParserDelete(parser);
+1 -1
View File
@@ -617,7 +617,7 @@ WScreen *wScreenInit(int screen_number)
{
WScreen *scr;
XIconSize icon_size[1];
RContextAttributes rattr;
RContextAttributes rattr = {};
long event_mask;
XErrorHandler oldHandler;
int i;
+2 -1
View File
@@ -203,7 +203,7 @@ static WMPropList *makeWindowState(WWindow * wwin, WApplication * wapp)
command = GetCommandForWindow(win);
if (!command) {
if (wapp->app_icon && wapp->app_icon->command) {
command = wmalloc(strlen(wapp->app_icon->command));
command = wmalloc(strlen(wapp->app_icon->command) + 1);
strcpy(command, wapp->app_icon->command);
} else
return NULL;
@@ -371,6 +371,7 @@ static pid_t execCommand(WScreen *scr, char *command)
wtokensplit(command, &argv, &argc);
if (!argc) {
wfree(argv);
return 0;
}
+6 -4
View File
@@ -997,7 +997,7 @@ static void updateWorkspaceNames(WScreen *scr)
len = 0;
for (i = 0; i < scr->workspace_count; i++) {
curr_size = strlen(scr->workspaces[i]->name);
strcpy(pos, scr->workspaces[i]->name);
strncpy(pos, scr->workspaces[i]->name, sizeof(pos) - 1);
pos += (curr_size + 1);
len += (curr_size + 1);
}
@@ -1483,7 +1483,8 @@ void wNETWMPositionSplash(WWindow *wwin, int *x, int *y, int width, int height)
static void updateWindowType(WWindow *wwin)
{
Atom type_ret;
int fmt_ret, layer;
int fmt_ret;
int layer = INT_MIN; //illegal level
unsigned long nitems_ret, bytes_after_ret;
long *data = NULL;
@@ -1501,7 +1502,8 @@ static void updateWindowType(WWindow *wwin)
}
if (wwin->frame != NULL) {
ChangeStackingLevel(wwin->frame->core, layer);
if (layer != INT_MIN)
ChangeStackingLevel(wwin->frame->core, layer);
wwin->frame->flags.need_texture_change = 1;
wWindowConfigureBorders(wwin);
wFrameWindowPaint(wwin->frame);
@@ -1734,7 +1736,7 @@ Bool wNETWMProcessClientMessage(XClientMessageEvent *event)
if (wwin->frame->workspace == wwin->screen_ptr->current_workspace /* No workspace change */
|| event->data.l[0] == 2 /* Requested by pager */
|| WFLAGP(wwin, focus_across_wksp) /* Explicitly allowed */) {
wNETWMShowingDesktop(scr, False);
wNETWMShowingDesktop(wwin->screen_ptr, False);
wMakeWindowVisible(wwin);
}
return True;
+1 -1
View File
@@ -175,7 +175,7 @@ static void x_reset_modifier_mapping(Display * display)
}
code = x_modifier_keymap->modifiermap[modifier_index * mkpm + modifier_key];
sym = (code ? W_KeycodeToKeysym(display, code, column) : NoSymbol);
sym = W_KeycodeToKeysym(display, code, column);
if (sym == last_sym)
continue;
+1
View File
@@ -349,6 +349,7 @@ static void hackStyle(WMPropList * style)
t = WMCreatePLArray(WMCreatePLString("solid"), value, NULL);
WMPutInPLDictionary(style, WMCreatePLString("ResizebarBack"), t);
WMReleasePropList(value);
}
}
}
+1
View File
@@ -451,6 +451,7 @@ static void find_and_write(const char *group, char *list[][2], int this_is_termi
WMAddToPLArray(L2Menu, L3Menu);
wfree(t);
}
wfree(argv);
i++;
}
if (L2Menu)
+3 -1
View File
@@ -435,6 +435,7 @@ int zoom_in_out(int z)
tmp->height + (int)(tmp->height * zoom_factor));
if (!img) {
img = old_img;
RReleaseImage(tmp);
return EXIT_FAILURE;
}
} else {
@@ -449,6 +450,7 @@ int zoom_in_out(int z)
img = RScaleImage(tmp, new_width, new_height);
if (!img) {
img = old_img;
RReleaseImage(tmp);
return EXIT_FAILURE;
}
}
@@ -678,7 +680,7 @@ link_t *connect_dir(char *dirpath, linked_list_t *li)
int main(int argc, char **argv)
{
int option = -1;
RContextAttributes attr;
RContextAttributes attr = {};
XEvent e;
KeySym keysym;
char *reading_filename = "";
+24 -23
View File
@@ -275,45 +275,46 @@ static void assemblePLMenuFunc(WMTreeNode *aNode, void *data)
if (!wm->CmdLine) { /* new submenu */
WMAddToArray(plMenuNodes, WMCreatePLArray(WMCreatePLString(wm->Name), NULL));
} else { /* new menu item */
WMPropList *tmp1, *tmp2;
pl = WMPopFromArray(plMenuNodes);
if (wm->Flags & F_RESTART_OTHER) { /* RESTART, somewm */
char buf[1024];
WMPropList *tmp3;
memset(buf, 0, sizeof(buf));
snprintf(buf, sizeof(buf), "%s %s", _("Restart"), wm->Name);
WMAddToPLArray(pl, WMCreatePLArray(
WMCreatePLString(buf),
WMCreatePLString("RESTART"),
WMCreatePLString(wm->CmdLine),
NULL)
);
tmp1 = WMCreatePLString(buf);
tmp2 = WMCreatePLString("RESTART");
tmp3 = WMCreatePLString(wm->CmdLine);
WMAddToPLArray(pl, WMCreatePLArray(tmp1, tmp2, tmp3, NULL));
WMReleasePropList(tmp3);
} else if (wm->Flags & F_RESTART_SELF) {/* RESTART */
WMAddToPLArray(pl, WMCreatePLArray(
WMCreatePLString(_("Restart Window Maker")),
WMCreatePLString("RESTART"),
NULL)
);
tmp1 = WMCreatePLString(_("Restart Window Maker"));
tmp2 = WMCreatePLString("RESTART");
WMAddToPLArray(pl, WMCreatePLArray(tmp1, tmp2, NULL));
} else if (wm->Flags & F_QUIT) { /* EXIT */
WMAddToPLArray(pl, WMCreatePLArray(
WMCreatePLString(_("Exit Window Maker")),
WMCreatePLString("EXIT"),
NULL)
);
tmp1 = WMCreatePLString(_("Exit Window Maker"));
tmp2 = WMCreatePLString("EXIT");
WMAddToPLArray(pl, WMCreatePLArray(tmp1, tmp2, NULL));
} else { /* plain simple command */
char buf[1024];
WMPropList *tmp3;
memset(buf, 0, sizeof(buf));
if (wm->Flags & F_TERMINAL) /* XXX: quoting! */
snprintf(buf, sizeof(buf), "%s -e \"%s\"", terminal, wm->CmdLine);
else
snprintf(buf, sizeof(buf), "%s", wm->CmdLine);
WMAddToPLArray(pl, WMCreatePLArray(
WMCreatePLString(wm->Name),
WMCreatePLString("SHEXEC"),
WMCreatePLString(buf),
NULL)
);
tmp1 = WMCreatePLString(wm->Name);
tmp2 = WMCreatePLString("SHEXEC");
tmp3 = WMCreatePLString(buf);
WMAddToPLArray(pl, WMCreatePLArray(tmp1, tmp2, tmp3, NULL));
WMReleasePropList(tmp3);
}
WMReleasePropList(tmp1);
WMReleasePropList(tmp2);
WMAddToArray(plMenuNodes, pl);
}
+10 -1
View File
@@ -505,7 +505,15 @@ static BackgroundTexture *parseTexture(RContext * rc, char *text)
iheight = image->height;
}
GETSTRORGOTO(val, tmp, 2, error);
/* cannot use GETSTRORGOTO() here
* as we have to free image in case of error */
val = WMGetFromPLArray(texarray, 2);
if (!WMIsPLString(val)) {
wwarning("could not parse texture %s", text);
RReleaseImage(image);
goto error;
}
tmp = WMGetFromPLString(val);
if (!XParseColor(dpy, DefaultColormap(dpy, scr), tmp, &color)) {
wwarning("could not parse color %s in texture %s", tmp, text);
@@ -898,6 +906,7 @@ static noreturn void helperLoop(RContext * rc)
int errcount = 4;
memset(textures, 0, WORKSPACE_COUNT * sizeof(BackgroundTexture *));
memset(buffer, 0, sizeof(buffer));
while (1) {
int workspace = -1;
+2
View File
@@ -1,3 +1,5 @@
- added RSaveTitledImage()
- removed obsoleted RDestroyImage()
- removed Hermes code.
- Put back asm/mmx optimized code.
+2
View File
@@ -55,10 +55,12 @@ endif
if USE_JPEG
libwraster_la_SOURCES += load_jpeg.c
libwraster_la_SOURCES += save_jpeg.c
endif
if USE_PNG
libwraster_la_SOURCES += load_png.c
libwraster_la_SOURCES += save_png.c
endif
if USE_TIFF
+13 -2
View File
@@ -1,8 +1,19 @@
** API and ABI modifications since wmaker 0.92.0
** API and ABI modifications
----------------------------------------------------
Sat 25 Feb 2023
RSaveImage: Improved
Able to save image on disk as PNG or JPEG file
RSaveTitledImage: Added
Image title can be set on the image to be saved
----------------------------------------------------
Since wmaker 0.92.0
RLightImage: ADDED
----------------------------------------------------
Sat Apr 21 09:12:09 EEST 2001 -Dan
+8
View File
@@ -627,6 +627,10 @@ static RXImage *image2StandardPseudoColor(RContext * ctx, RImage * image)
RDestroyXImage(ctx, ximg);
return NULL;
}
memset(err, 0, 3 * (image->width + 2) * sizeof(short));
memset(nerr, 0, 3 * (image->width + 2) * sizeof(short));
for (x = 0, x1 = 0; x < image->width * 3; x1 += channels - 3) {
err[x++] = ptr[x1++];
err[x++] = ptr[x1++];
@@ -778,6 +782,10 @@ static RXImage *image2GrayScale(RContext * ctx, RImage * image)
RDestroyXImage(ctx, ximg);
return NULL;
}
memset(gerr, 0, (image->width + 2) * sizeof(short));
memset(ngerr, 0, (image->width + 2) * sizeof(short));
for (x = 0, y = 0; x < image->width; x++, y += channels) {
gerr[x] = (ptr[y] * 30 + ptr[y + 1] * 59 + ptr[y + 2] * 11) / 100;
}
+8 -2
View File
@@ -29,7 +29,6 @@
#ifndef IMGFORMAT_INTERNAL_H
#define IMGFORMAT_INTERNAL_H
typedef enum {
IM_ERROR = -1,
IM_UNKNOWN = 0,
@@ -82,8 +81,15 @@ void RReleaseMagick(void);
/*
* Function for Saving in a specific format
*/
Bool RSaveXPM(RImage *image, const char *file);
Bool RSaveXPM(RImage *image, const char *filename);
#ifdef USE_PNG
Bool RSavePNG(RImage *image, const char *filename, char *title);
#endif
#ifdef USE_JPEG
Bool RSaveJPEG(RImage *image, const char *filename, char *title);
#endif
/*
* Function to terminate properly
+2
View File
@@ -22,6 +22,8 @@ POTFILES = \
$(top_srcdir)/wrlib/rotate.c \
$(top_srcdir)/wrlib/flip.c \
$(top_srcdir)/wrlib/convolve.c \
$(top_srcdir)/wrlib/save_jpeg.c \
$(top_srcdir)/wrlib/save_png.c \
$(top_srcdir)/wrlib/save_xpm.c \
$(top_srcdir)/wrlib/xutil.c \
$(top_srcdir)/wrlib/load_ppm.c \
+23 -8
View File
@@ -3,6 +3,7 @@
* Raster graphics library
*
* Copyright (c) 1998-2003 Alfredo K. Kojima
* Copyright (c) 2013-2023 Window Maker Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@@ -29,18 +30,32 @@
#include <fcntl.h>
#include <sys/stat.h>
#include <string.h>
#include <time.h>
#include "wraster.h"
#include "imgformat.h"
#include "wr_i18n.h"
Bool RSaveImage(RImage * image, const char *filename, const char *format)
Bool RSaveImage(RImage *image, const char *filename, const char *format)
{
if (strcmp(format, "XPM") != 0) {
RErrorCode = RERR_BADFORMAT;
return False;
}
return RSaveXPM(image, filename);
return RSaveTitledImage(image, filename, format, NULL);
}
Bool RSaveTitledImage(RImage *image, const char *filename, const char *format, char *title)
{
#ifdef USE_PNG
if (strcasecmp(format, "PNG") == 0)
return RSavePNG(image, filename, title);
#endif
#ifdef USE_JPEG
if (strcasecmp(format, "JPG") == 0)
return RSaveJPEG(image, filename, title);
if (strcasecmp(format, "JPEG") == 0)
return RSaveJPEG(image, filename, title);
#endif
if (strcasecmp(format, "XPM") == 0)
return RSaveXPM(image, filename);
RErrorCode = RERR_BADFORMAT;
return False;
}
+104
View File
@@ -0,0 +1,104 @@
/* save_jpeg.c - save JPEG image
*
* Raster graphics library
*
* Copyright (c) 2023 Window Maker Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
#include <config.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <errno.h>
#include <jpeglib.h>
#include "wraster.h"
#include "imgformat.h"
#include "wr_i18n.h"
/*
* Save RImage to JPEG image
*/
Bool RSaveJPEG(RImage *img, const char *filename, char *title)
{
FILE *file;
int x, y, img_depth;
char *buffer;
RColor pixel;
struct jpeg_compress_struct cinfo;
struct jpeg_error_mgr jerr;
JSAMPROW row_pointer;
file = fopen(filename, "wb");
if (!file) {
RErrorCode = RERR_OPEN;
return False;
}
if (img->format == RRGBAFormat)
img_depth = 4;
else
img_depth = 3;
/* collect separate RGB values to a buffer */
buffer = malloc(sizeof(char) * 3 * img->width * img->height);
for (y = 0; y < img->height; y++) {
for (x = 0; x < img->width; x++) {
RGetPixel(img, x, y, &pixel);
buffer[y*img->width*3+x*3+0] = (char)(pixel.red);
buffer[y*img->width*3+x*3+1] = (char)(pixel.green);
buffer[y*img->width*3+x*3+2] = (char)(pixel.blue);
}
}
/* Setup Exception handling */
cinfo.err = jpeg_std_error(&jerr);
/* Initialize cinfo structure */
jpeg_create_compress(&cinfo);
jpeg_stdio_dest(&cinfo, file);
cinfo.image_width = img->width;
cinfo.image_height = img->height;
cinfo.input_components = 3;
cinfo.in_color_space = JCS_RGB;
jpeg_set_defaults(&cinfo);
jpeg_set_quality(&cinfo, 85, TRUE);
jpeg_start_compress(&cinfo, TRUE);
/* Set title if any */
if (title)
jpeg_write_marker(&cinfo, JPEG_COM, (const JOCTET*)title, strlen(title));
while (cinfo.next_scanline < cinfo.image_height) {
row_pointer = (JSAMPROW) &buffer[cinfo.next_scanline * img_depth * img->width];
jpeg_write_scanlines(&cinfo, &row_pointer, 1);
}
jpeg_finish_compress(&cinfo);
/* Clean */
free(buffer);
fclose(file);
return True;
}
+127
View File
@@ -0,0 +1,127 @@
/* save_png.c - save PNG image
*
* Raster graphics library
*
* Copyright (c) 2023 Window Maker Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
#include <config.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <errno.h>
#include <png.h>
#include "wraster.h"
#include "imgformat.h"
#include "wr_i18n.h"
/*
* Save RImage to PNG image
*/
Bool RSavePNG(RImage *img, const char *filename, char *title)
{
FILE *file;
png_structp png_ptr;
png_infop png_info_ptr;
png_bytep png_row;
RColor pixel;
int x, y;
int width = img->width;
int height = img->height;
file = fopen(filename, "wb");
if (file == NULL) {
RErrorCode = RERR_OPEN;
return False;
}
/* Initialize write structure */
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (png_ptr == NULL) {
fclose(file);
RErrorCode = RERR_NOMEMORY;
return False;
}
/* Initialize info structure */
png_info_ptr = png_create_info_struct(png_ptr);
if (png_info_ptr == NULL) {
fclose(file);
RErrorCode = RERR_NOMEMORY;
return False;
}
/* Setup Exception handling */
if (setjmp(png_jmpbuf (png_ptr))) {
fclose(file);
RErrorCode = RERR_INTERNAL;
return False;
}
png_init_io(png_ptr, file);
/* Write header (8 bit colour depth) */
png_set_IHDR(png_ptr, png_info_ptr, width, height, 8, PNG_COLOR_TYPE_RGB,
PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE,
PNG_FILTER_TYPE_BASE);
/* Set title if any */
if (title) {
png_text title_text;
title_text.compression = PNG_TEXT_COMPRESSION_NONE;
title_text.key = "Title";
title_text.text = title;
png_set_text(png_ptr, png_info_ptr, &title_text, 1);
}
png_write_info(png_ptr, png_info_ptr);
/* Allocate memory for one row (3 bytes per pixel - RGB) */
png_row = (png_bytep) malloc(3 * width * sizeof(png_byte));
/* Write image data */
for (y = 0; y < height; y++) {
for (x = 0; x < width; x++) {
png_byte *ptr;
RGetPixel(img, x, y, &pixel);
ptr = &(png_row[x * 3]);
ptr[0] = pixel.red;
ptr[1] = pixel.green;
ptr[2] = pixel.blue;
}
png_write_row(png_ptr, png_row);
}
/* End write */
png_write_end(png_ptr, NULL);
/* Clean */
fclose(file);
if (png_info_ptr != NULL)
png_free_data(png_ptr, png_info_ptr, PNG_FREE_ALL, -1);
if (png_ptr != NULL)
png_destroy_write_struct(&png_ptr, (png_infopp) NULL);
if (png_row != NULL)
free(png_row);
return True;
}
+1 -1
View File
@@ -1,4 +1,4 @@
/* nxpm.c - load "normalized" XPM image
/* save_xpm.c - save "normalized" XPM image
*
* Raster graphics library
*
+4 -1
View File
@@ -41,7 +41,7 @@
/* version of the header for the library */
#define WRASTER_HEADER_VERSION 24
#define WRASTER_HEADER_VERSION 25
#include <X11/Xlib.h>
@@ -391,6 +391,9 @@ RImage *RGetImageFromXPMData(RContext *context, char **xpmData)
Bool RSaveImage(RImage *image, const char *filename, const char *format)
__wrlib_nonnull(1, 2, 3);
Bool RSaveTitledImage(RImage *image, const char *filename, const char *format, char *title)
__wrlib_nonnull(1, 2, 3);
/*
* Area manipulation
*/