Skip to content

Commit

Permalink
Merge pull request #32 from william8000/set-isize-9oct24
Browse files Browse the repository at this point in the history
Add -isize option and XV_OPTIONS environment variable.
  • Loading branch information
mdadams authored Oct 15, 2024
2 parents a1e2dc8 + f09aa9f commit e87f556
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 10 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ cmake_minimum_required(VERSION 3.12)
# The major, minor, and micro version numbers of the project.
set(XV_VERSION_MAJOR 6)
set(XV_VERSION_MINOR 0)
set(XV_VERSION_PATCH 1)
set(XV_VERSION_DATE "20240901")
set(XV_VERSION_PATCH 2)
set(XV_VERSION_DATE "20241015")

# Generate the project version.
set(XV_VERSION "${XV_VERSION_MAJOR}.${XV_VERSION_MINOR}.${XV_VERSION_PATCH}")
Expand Down
11 changes: 11 additions & 0 deletions NEWS.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
6.0.2 (2024-10-15)
==================

* Added -isize option to control the icon size in the browser.
The syntax is -isize <width> or -isize <width>x<height>
If the height is omitted, it defaults to the width * 3/4.

* xv now checks the XV_OPTIONS environment variable before reading the
command line. xv splits it into words and parses it like command line
options. Use XV_OPTIONS to set default options.

6.0.1 (2024-09-01)
==================

Expand Down
118 changes: 113 additions & 5 deletions src/xv.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ static int highbit PARM((unsigned long));
static void makeDirectCmap PARM((void));
static void useOtherVisual PARM((XVisualInfo *, int));
static void parseResources PARM((int, char **));
static void parseCmdLine PARM((int, char **));
static void parseOptions PARM((const char *));
static void parseCmdLine PARM((int, char **, int));
static void verifyArgs PARM((void));
static void printoption PARM((const char *));
static void cmdSyntax PARM((int));
Expand Down Expand Up @@ -295,6 +296,7 @@ int main(int argc, char **argv)
preset = 0;
viewonly = 0;
dpiMult = 1;
isize_wide = isize_high = 0;

#ifdef ENABLE_FIXPIX_SMOOTH
do_fixpix_smooth = 0;
Expand Down Expand Up @@ -376,7 +378,8 @@ int main(int argc, char **argv)

/* handle user-specified resources and cmd-line arguments */
parseResources(argc,argv);
parseCmdLine(argc, argv);
parseOptions( getenv("XV_OPTIONS") );
parseCmdLine(argc, argv, 1);
verifyArgs();
#ifdef AUTO_EXPAND
Vdinit();
Expand Down Expand Up @@ -1487,7 +1490,7 @@ static void parseResources(int argc, char **argv)


/*****************************************************/
static void parseCmdLine(int argc, char **argv)
static void parseCmdLine(int argc, char **argv, int allow_file_names)
{
int i, oldi, not_in_first_half, pm;
int hidpi;
Expand All @@ -1501,6 +1504,12 @@ static void parseCmdLine(int argc, char **argv)
not_in_first_half = 0;

if (argv[i][0] != '-' && argv[i][0] != '+') {

if (!allow_file_names) {
fprintf(stderr, "Unexpected option '%s'\n", argv[i]);
cmdSyntax(1);
}

/* a file name. put it in list */

if (!nostat) {
Expand Down Expand Up @@ -1708,6 +1717,31 @@ static void parseCmdLine(int argc, char **argv)
else if (!argcmp(argv[i],"-ibg",3,0,&pm)) /* image bkgd color */
{ if (++i<argc) imagebgstr = argv[i]; }

else if (!argcmp(argv[i],"-isize",4,0,&pm)) /* isize width x high */
{ if (++i<argc) {
int parse_flags, parse_x, parse_y;
unsigned parse_w, parse_h;
parse_x = parse_y = 0;
parse_w = parse_h = 0;
parse_flags = XParseGeometry(argv[i], &parse_x, &parse_y, &parse_w, &parse_h);
if ((parse_flags & WidthValue) != 0) {
if (parse_w > 1000) {
parse_w = 1000;
fprintf(stderr, "Warning: reduced large -isize width\n");
}
isize_wide = parse_w;
if ((parse_flags & HeightValue) != 0) {
if (parse_h > 1000) {
parse_h = 1000;
fprintf(stderr, "Warning: reduced large -isize height\n");
}
isize_high = parse_h;
}
if (isize_high == 0) isize_high = (isize_wide * 3) / 4;
}
}
}

else if (!argcmp(argv[i],"-lbrowse",3,1,&browseMode)); /* browse mode */

else if (!argcmp(argv[i],"-lo",3,0,&pm)) /* lowlight */
Expand Down Expand Up @@ -1862,11 +1896,82 @@ static void parseCmdLine(int argc, char **argv)

/* build origlist[], a copy of namelist that remains unmodified, for
use with the 'autoDelete' option */
orignumnames = numnames;
xvbcopy((char *) namelist, (char *) origlist, sizeof(origlist));
if (allow_file_names) {
orignumnames = numnames;
xvbcopy((char *) namelist, (char *) origlist, sizeof(origlist));
}
}


/*****************************************************/
static void parseOptions(const char *options)
{
#define MAX_OPTIONS 1000
char *option_list[ MAX_OPTIONS ];
char *option_ptr, *out_ptr;
int option_len;
int num_options;
char quote;
static char *option_buf; /* so asan doesn't warn about lost memory */

if (options == NULL || *options == '\0') {
return;
}

/* fprintf(stderr, "options '%s'\n", options); */

option_len = strlen(options);
option_buf = (char *) malloc(option_len + 1);
if (!option_buf) {
FatalError("can't malloc option buf\n");
}
memcpy(option_buf, options, option_len+1);
num_options = 0;
option_list[ num_options++ ] = NULL;
option_ptr = option_buf;
while (*option_ptr != '\0' && num_options < MAX_OPTIONS - 1) {
while (*option_ptr == ' ' || *option_ptr == '\t') {
option_ptr++;
}
quote = *option_ptr;
if (quote == '\'' || quote == '"') {
/* quoted option */
/* very simple quoting to allow embedded spaces */
option_ptr++;
option_list[ num_options++ ] = option_ptr;
out_ptr = option_ptr;
while (*option_ptr != quote && *option_ptr != '\0') {
if (*option_ptr == '\\') {
option_ptr++;
if (*option_ptr == '\0') break;
}
*out_ptr++ = *option_ptr++;
}
if (*option_ptr != '\0') {
option_ptr++;
}
*out_ptr = '\0';
} else {
/* unquoted option */
option_list[ num_options++ ] = option_ptr;
while (*option_ptr != ' ' && *option_ptr != '\t' && *option_ptr != '\0') {
option_ptr++;
}
if (*option_ptr != '\0') {
*option_ptr = '\0';
option_ptr++;
}
}
/* fprintf(stderr, "option %d '%s'\n", num_options-1, option_list[ num_options-1 ]); */
}

option_list[ num_options ] = NULL;

parseCmdLine(num_options, option_list, /* allow_file_names */ 0);

/* option_buf can't be freed because parseCmdLine copies pointers to some arguments */
}

/*****************************************************************/
static void verifyArgs(void)
{
Expand Down Expand Up @@ -2017,6 +2122,7 @@ static void cmdSyntax(int i)
printoption("[-dir directory]");
printoption("[-display disp]");
printoption("[-/+dither]");
printoption("[-dpimult val]");
printoption("[-drift dx dy]");
printoption("[-expand exp | hexp:vexp]");
printoption("[-fg color]");
Expand All @@ -2034,13 +2140,15 @@ static void cmdSyntax(int i)
printoption("[-help]");
printoption("[-/+hflip]");
printoption("[-hi color]");
printoption("[-/+hidpi]");
printoption("[-/+hist]");
printoption("[-/+hsv]");
printoption("[-ibg color]"); /* GRR 19980314 */
printoption("[-icgeometry geom]");
printoption("[-/+iconic]");
printoption("[-igeometry geom]");
printoption("[-/+imap]");
printoption("[-isize geom]");
printoption("[-/+lbrowse]");
printoption("[-lo color]");
printoption("[-/+loadclear]");
Expand Down
1 change: 1 addition & 0 deletions src/xv.h
Original file line number Diff line number Diff line change
Expand Up @@ -1206,6 +1206,7 @@ WHERE unsigned int ncells, dispDEEP; /* root color sizes */
WHERE unsigned int dispWIDE, dispHIGH; /* screen sizes */
WHERE unsigned int vrWIDE, vrHIGH, maxWIDE, maxHIGH; /* virtual root and max image sizes */
WHERE int dpiMult; /* multiplier for hidpi displays */
WHERE int isize_wide, isize_high; /* ISIZE icon size for xvbrowse */
WHERE Colormap theCmap, LocalCmap;
WHERE Window spec_window, rootW, mainW, vrootW;
WHERE GC theGC;
Expand Down
4 changes: 2 additions & 2 deletions src/xvbrowse.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,10 @@ typedef unsigned int mode_t; /* file mode bits */
/* some people like bigger icons; 4:3 aspect ratio is recommended
* (NOTE: standard XV binaries will not be able to read larger icons!) */
#ifndef ISIZE_WIDE
# define ISIZE_WIDE (80 * dpiMult) /* maximum size of an icon */
# define ISIZE_WIDE (isize_wide > 0? isize_wide: (80 * dpiMult)) /* maximum size of an icon */
#endif
#ifndef ISIZE_HIGH
# define ISIZE_HIGH (60 /* * dpiMult */)
# define ISIZE_HIGH (isize_high > 0? isize_high: (60 /* * dpiMult */))
#endif

#ifndef ISIZE_WPAD
Expand Down
4 changes: 3 additions & 1 deletion src/xvevent.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,9 @@ int EventLoop(void)
sleep(1);
else {
/* less than one second remaining: do delay in msec, then return */
Timer((remaining_interval * 1000L) / clock_ticks); /* can't overflow */
if (remaining_interval > 0) {
Timer((remaining_interval * 1000L) / clock_ticks); /* can't overflow */
}
return waitloop? NEXTLOOP : NEXTQUIT;
}
#else
Expand Down

0 comments on commit e87f556

Please sign in to comment.