Skip to content

Commit e87f556

Browse files
authored
Merge pull request #32 from william8000/set-isize-9oct24
Add -isize option and XV_OPTIONS environment variable.
2 parents a1e2dc8 + f09aa9f commit e87f556

File tree

6 files changed

+132
-10
lines changed

6 files changed

+132
-10
lines changed

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ cmake_minimum_required(VERSION 3.12)
77
# The major, minor, and micro version numbers of the project.
88
set(XV_VERSION_MAJOR 6)
99
set(XV_VERSION_MINOR 0)
10-
set(XV_VERSION_PATCH 1)
11-
set(XV_VERSION_DATE "20240901")
10+
set(XV_VERSION_PATCH 2)
11+
set(XV_VERSION_DATE "20241015")
1212

1313
# Generate the project version.
1414
set(XV_VERSION "${XV_VERSION_MAJOR}.${XV_VERSION_MINOR}.${XV_VERSION_PATCH}")

NEWS.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
6.0.2 (2024-10-15)
2+
==================
3+
4+
* Added -isize option to control the icon size in the browser.
5+
The syntax is -isize <width> or -isize <width>x<height>
6+
If the height is omitted, it defaults to the width * 3/4.
7+
8+
* xv now checks the XV_OPTIONS environment variable before reading the
9+
command line. xv splits it into words and parses it like command line
10+
options. Use XV_OPTIONS to set default options.
11+
112
6.0.1 (2024-09-01)
213
==================
314

src/xv.c

Lines changed: 113 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ static int highbit PARM((unsigned long));
104104
static void makeDirectCmap PARM((void));
105105
static void useOtherVisual PARM((XVisualInfo *, int));
106106
static void parseResources PARM((int, char **));
107-
static void parseCmdLine PARM((int, char **));
107+
static void parseOptions PARM((const char *));
108+
static void parseCmdLine PARM((int, char **, int));
108109
static void verifyArgs PARM((void));
109110
static void printoption PARM((const char *));
110111
static void cmdSyntax PARM((int));
@@ -295,6 +296,7 @@ int main(int argc, char **argv)
295296
preset = 0;
296297
viewonly = 0;
297298
dpiMult = 1;
299+
isize_wide = isize_high = 0;
298300

299301
#ifdef ENABLE_FIXPIX_SMOOTH
300302
do_fixpix_smooth = 0;
@@ -376,7 +378,8 @@ int main(int argc, char **argv)
376378

377379
/* handle user-specified resources and cmd-line arguments */
378380
parseResources(argc,argv);
379-
parseCmdLine(argc, argv);
381+
parseOptions( getenv("XV_OPTIONS") );
382+
parseCmdLine(argc, argv, 1);
380383
verifyArgs();
381384
#ifdef AUTO_EXPAND
382385
Vdinit();
@@ -1487,7 +1490,7 @@ static void parseResources(int argc, char **argv)
14871490

14881491

14891492
/*****************************************************/
1490-
static void parseCmdLine(int argc, char **argv)
1493+
static void parseCmdLine(int argc, char **argv, int allow_file_names)
14911494
{
14921495
int i, oldi, not_in_first_half, pm;
14931496
int hidpi;
@@ -1501,6 +1504,12 @@ static void parseCmdLine(int argc, char **argv)
15011504
not_in_first_half = 0;
15021505

15031506
if (argv[i][0] != '-' && argv[i][0] != '+') {
1507+
1508+
if (!allow_file_names) {
1509+
fprintf(stderr, "Unexpected option '%s'\n", argv[i]);
1510+
cmdSyntax(1);
1511+
}
1512+
15041513
/* a file name. put it in list */
15051514

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

1720+
else if (!argcmp(argv[i],"-isize",4,0,&pm)) /* isize width x high */
1721+
{ if (++i<argc) {
1722+
int parse_flags, parse_x, parse_y;
1723+
unsigned parse_w, parse_h;
1724+
parse_x = parse_y = 0;
1725+
parse_w = parse_h = 0;
1726+
parse_flags = XParseGeometry(argv[i], &parse_x, &parse_y, &parse_w, &parse_h);
1727+
if ((parse_flags & WidthValue) != 0) {
1728+
if (parse_w > 1000) {
1729+
parse_w = 1000;
1730+
fprintf(stderr, "Warning: reduced large -isize width\n");
1731+
}
1732+
isize_wide = parse_w;
1733+
if ((parse_flags & HeightValue) != 0) {
1734+
if (parse_h > 1000) {
1735+
parse_h = 1000;
1736+
fprintf(stderr, "Warning: reduced large -isize height\n");
1737+
}
1738+
isize_high = parse_h;
1739+
}
1740+
if (isize_high == 0) isize_high = (isize_wide * 3) / 4;
1741+
}
1742+
}
1743+
}
1744+
17111745
else if (!argcmp(argv[i],"-lbrowse",3,1,&browseMode)); /* browse mode */
17121746

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

18631897
/* build origlist[], a copy of namelist that remains unmodified, for
18641898
use with the 'autoDelete' option */
1865-
orignumnames = numnames;
1866-
xvbcopy((char *) namelist, (char *) origlist, sizeof(origlist));
1899+
if (allow_file_names) {
1900+
orignumnames = numnames;
1901+
xvbcopy((char *) namelist, (char *) origlist, sizeof(origlist));
1902+
}
18671903
}
18681904

18691905

1906+
/*****************************************************/
1907+
static void parseOptions(const char *options)
1908+
{
1909+
#define MAX_OPTIONS 1000
1910+
char *option_list[ MAX_OPTIONS ];
1911+
char *option_ptr, *out_ptr;
1912+
int option_len;
1913+
int num_options;
1914+
char quote;
1915+
static char *option_buf; /* so asan doesn't warn about lost memory */
1916+
1917+
if (options == NULL || *options == '\0') {
1918+
return;
1919+
}
1920+
1921+
/* fprintf(stderr, "options '%s'\n", options); */
1922+
1923+
option_len = strlen(options);
1924+
option_buf = (char *) malloc(option_len + 1);
1925+
if (!option_buf) {
1926+
FatalError("can't malloc option buf\n");
1927+
}
1928+
memcpy(option_buf, options, option_len+1);
1929+
num_options = 0;
1930+
option_list[ num_options++ ] = NULL;
1931+
option_ptr = option_buf;
1932+
while (*option_ptr != '\0' && num_options < MAX_OPTIONS - 1) {
1933+
while (*option_ptr == ' ' || *option_ptr == '\t') {
1934+
option_ptr++;
1935+
}
1936+
quote = *option_ptr;
1937+
if (quote == '\'' || quote == '"') {
1938+
/* quoted option */
1939+
/* very simple quoting to allow embedded spaces */
1940+
option_ptr++;
1941+
option_list[ num_options++ ] = option_ptr;
1942+
out_ptr = option_ptr;
1943+
while (*option_ptr != quote && *option_ptr != '\0') {
1944+
if (*option_ptr == '\\') {
1945+
option_ptr++;
1946+
if (*option_ptr == '\0') break;
1947+
}
1948+
*out_ptr++ = *option_ptr++;
1949+
}
1950+
if (*option_ptr != '\0') {
1951+
option_ptr++;
1952+
}
1953+
*out_ptr = '\0';
1954+
} else {
1955+
/* unquoted option */
1956+
option_list[ num_options++ ] = option_ptr;
1957+
while (*option_ptr != ' ' && *option_ptr != '\t' && *option_ptr != '\0') {
1958+
option_ptr++;
1959+
}
1960+
if (*option_ptr != '\0') {
1961+
*option_ptr = '\0';
1962+
option_ptr++;
1963+
}
1964+
}
1965+
/* fprintf(stderr, "option %d '%s'\n", num_options-1, option_list[ num_options-1 ]); */
1966+
}
1967+
1968+
option_list[ num_options ] = NULL;
1969+
1970+
parseCmdLine(num_options, option_list, /* allow_file_names */ 0);
1971+
1972+
/* option_buf can't be freed because parseCmdLine copies pointers to some arguments */
1973+
}
1974+
18701975
/*****************************************************************/
18711976
static void verifyArgs(void)
18721977
{
@@ -2017,6 +2122,7 @@ static void cmdSyntax(int i)
20172122
printoption("[-dir directory]");
20182123
printoption("[-display disp]");
20192124
printoption("[-/+dither]");
2125+
printoption("[-dpimult val]");
20202126
printoption("[-drift dx dy]");
20212127
printoption("[-expand exp | hexp:vexp]");
20222128
printoption("[-fg color]");
@@ -2034,13 +2140,15 @@ static void cmdSyntax(int i)
20342140
printoption("[-help]");
20352141
printoption("[-/+hflip]");
20362142
printoption("[-hi color]");
2143+
printoption("[-/+hidpi]");
20372144
printoption("[-/+hist]");
20382145
printoption("[-/+hsv]");
20392146
printoption("[-ibg color]"); /* GRR 19980314 */
20402147
printoption("[-icgeometry geom]");
20412148
printoption("[-/+iconic]");
20422149
printoption("[-igeometry geom]");
20432150
printoption("[-/+imap]");
2151+
printoption("[-isize geom]");
20442152
printoption("[-/+lbrowse]");
20452153
printoption("[-lo color]");
20462154
printoption("[-/+loadclear]");

src/xv.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,6 +1206,7 @@ WHERE unsigned int ncells, dispDEEP; /* root color sizes */
12061206
WHERE unsigned int dispWIDE, dispHIGH; /* screen sizes */
12071207
WHERE unsigned int vrWIDE, vrHIGH, maxWIDE, maxHIGH; /* virtual root and max image sizes */
12081208
WHERE int dpiMult; /* multiplier for hidpi displays */
1209+
WHERE int isize_wide, isize_high; /* ISIZE icon size for xvbrowse */
12091210
WHERE Colormap theCmap, LocalCmap;
12101211
WHERE Window spec_window, rootW, mainW, vrootW;
12111212
WHERE GC theGC;

src/xvbrowse.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,10 @@ typedef unsigned int mode_t; /* file mode bits */
146146
/* some people like bigger icons; 4:3 aspect ratio is recommended
147147
* (NOTE: standard XV binaries will not be able to read larger icons!) */
148148
#ifndef ISIZE_WIDE
149-
# define ISIZE_WIDE (80 * dpiMult) /* maximum size of an icon */
149+
# define ISIZE_WIDE (isize_wide > 0? isize_wide: (80 * dpiMult)) /* maximum size of an icon */
150150
#endif
151151
#ifndef ISIZE_HIGH
152-
# define ISIZE_HIGH (60 /* * dpiMult */)
152+
# define ISIZE_HIGH (isize_high > 0? isize_high: (60 /* * dpiMult */))
153153
#endif
154154

155155
#ifndef ISIZE_WPAD

src/xvevent.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,9 @@ int EventLoop(void)
190190
sleep(1);
191191
else {
192192
/* less than one second remaining: do delay in msec, then return */
193-
Timer((remaining_interval * 1000L) / clock_ticks); /* can't overflow */
193+
if (remaining_interval > 0) {
194+
Timer((remaining_interval * 1000L) / clock_ticks); /* can't overflow */
195+
}
194196
return waitloop? NEXTLOOP : NEXTQUIT;
195197
}
196198
#else

0 commit comments

Comments
 (0)