-fg -foreground {color} foreground color
-bg -background {color} background color
+If using the GTK4 GUI, then only the following are supported:
+ -fn or -font
+ -geom or -geometry (window positioning is NOT supported)
+ -fg -foreground {color}
+ -bg -background {color}
+
+Command line arguments specific to GTK4:
+ command line argument meaning ~
+ --prg-name {name} Argument passed to g_set_prgname(), otherwise
+ "gvim" is used. On Wayland this will set the app
+ id, which is equivalent to the X11 WM_CLASS
+
To set the font, see 'guifont'. For GTK, there's also a menu option that does
this.
Additionally, there are these command line arguments, which are handled by GTK
-internally. Look in the GTK documentation for how they are used:
+internally (except GTK4, see below). Look in the GTK documentation for how
+they are used:
--sync
--gdk-debug
--gdk-no-debug
-xrm
-mf
+If using the GTK4 GUI, then no GTK specific command line arguments are
+supported. Instead configure GTK via environment variables:
+https://docs.gtk.org/gtk4/running.html
+
As for colors, Vim's color settings (for syntax highlighting) is still
done the traditional Vim way. See |:highlight| for more help.
* Format: [WIDTHxHEIGHT][{+-}XOFF{+-}YOFF]
*/
#define NoValue 0x0000
-#define XValue 0x0001
-#define YValue 0x0002
#define WidthValue 0x0004
#define HeightValue 0x0008
-#define XNegative 0x0010
-#define YNegative 0x0020
static int
-vim_parse_geometry(const char *str, int *x, int *y,
- unsigned int *width, unsigned int *height)
+vim_parse_geometry(const char *str, unsigned int *width, unsigned int *height)
{
int mask = NoValue;
char *end;
}
}
- // Parse x offset
- if (*str == '+' || *str == '-')
- {
- int negative = (*str == '-');
- str++;
- val = strtol(str, &end, 10);
- if (end != str)
- {
- *x = negative ? -(int)val : (int)val;
- mask |= XValue;
- if (negative)
- mask |= XNegative;
- str = end;
- }
- }
-
- // Parse y offset
- if (*str == '+' || *str == '-')
- {
- int negative = (*str == '-');
- str++;
- val = strtol(str, &end, 10);
- if (end != str)
- {
- *y = negative ? -(int)val : (int)val;
- mask |= YValue;
- if (negative)
- mask |= YNegative;
- }
- }
-
return mask;
}
static void show_menubar_popover(void);
#endif
+static const char *prgname = NULL;
+
+/*
+ * Check if "s" is the option "name" (which includes the leading dash(es)).
+ * "value" is set to the value if the option uses 'opt=val' format.
+ */
+ static gboolean
+arg_match(const char *s, const char *name, char **value)
+{
+ size_t len = strlen(name);
+
+ if (strncmp(s, name, len) != 0)
+ return FALSE;
+ if (s[len] == '=')
+ *value = (char *)s + len + 1;
+ else if (s[len] != NUL)
+ // Something follows the option name that isn't "=": this is a
+ // different, longer option (e.g. "-fnord" while matching "-fn").
+ return FALSE;
+ return TRUE;
+}
+
/*
* Parse the GUI related command-line arguments. Any arguments used are
* deleted from argv, and *argc is decremented accordingly. This is called
// gui_mch_init_check() after the fork. Calling it before fork
// breaks the display connection in the child process, causing gvim
// to fail to start without --nofork.
+
+ int i = 0;
+
+ while (i < *argc)
+ {
+ char *s = argv[i];
+ char *value = NULL;
+ int has_inline_value = FALSE;
+ int n_strip;
+
+ if (s[0] != '-' && s[0] != '+')
+ {
+ ++i;
+ continue;
+ }
+
+ if (strchr(s, '=') != NULL)
+ has_inline_value = TRUE;
+
+ // If the value was not given inline (no "="), it would come from the
+ // next argv element. Do not treat that next element as this option's
+ // value if it is "--" (end-of-options marker) or is another option.
+ if (!has_inline_value)
+ {
+ if (i + 1 < *argc
+ && strcmp(argv[i + 1], "--") != 0
+ && !((argv[i + 1][0] == '-' || argv[i + 1][0] == '+')
+ && !vim_isdigit(argv[i + 1][1])))
+ value = argv[i + 1];
+ else
+ value = NULL;
+ }
+
+ if (arg_match(s, "-fn", &value) || arg_match(s, "-font", &value))
+ font_argument = value;
+ else if (arg_match(s, "-geom", &value)
+ || arg_match(s, "-geometry", &value))
+ {
+ if (value != NULL)
+ gui.geom = vim_strsave((char_u *)value);
+ }
+ else if (arg_match(s, "-bg", &value)
+ || arg_match(s, "-background", &value))
+ background_argument = value;
+ else if (arg_match(s, "-fg", &value)
+ || arg_match(s, "-foreground", &value))
+ foreground_argument = value;
+ else if (strncmp(s, "-nb", 3) == 0)
+ {
+ gui.dofork = false; // don't fork() when starting GUI
+ netbeansArg = argv[i];
+ has_inline_value = TRUE; // -nb uses non standard syntax, just
+ // remove the flag.
+ }
+ else if (arg_match(s, "--prg-name", &value))
+ // GTK4 specific
+ prgname = value;
+ else
+ {
+ i++;
+ continue;
+ }
+
+ // Remove the flag from the argument vector.
+ n_strip = 1;
+ // Move the argument's value as well, but only if it was consumed
+ // from a separate argv element (the "-opt=value" form lives inside
+ // the flag's own element and is stripped along with it already).
+ if (value != NULL && !has_inline_value)
+ n_strip = 2;
+
+ if (*argc - n_strip >= i)
+ {
+ *argc -= n_strip;
+ if (*argc > i)
+ mch_memmove(&argv[i], &argv[i + n_strip],
+ (*argc - i) * sizeof(char *));
+ argv[*argc] = NULL;
+ }
+ }
}
/*
{
// This defaults to argv[0], but we want it to match the name of the
// shipped gvim.desktop so that Vim's windows can be associated with this
- // file. Also sets WM_CLASS on X11.
- g_set_prgname("gvim");
+ // file. Also sets WM_CLASS on X11. If "--prg-name" is specified, then use
+ // that.
+ g_set_prgname(prgname == NULL ? "gvim" : prgname);
// Suppress noisy EGL warnings when GL is not available. Only set
// this when actually starting the GUI, so non-GUI invocations are
{
int mask;
unsigned int w, h;
- int x = 0;
- int y = 0;
- mask = vim_parse_geometry((char *)gui.geom, &x, &y, &w, &h);
+ mask = vim_parse_geometry((char *)gui.geom, &w, &h);
if (mask & WidthValue)
Columns = w;
VIM_CLEAR(gui.geom);
}
+ else
+ {
+ // Use 80x24 as the default GUI size, unless geometry was specified.
+ if (Columns > 80)
+ Columns = 80;
+ if (Rows > 24)
+ Rows = 24;
+ }
- // Use 80x24 as the default GUI size, unless geometry was specified.
- if (Columns > 80 && gui.geom == NULL)
- Columns = 80;
- if (Rows > 24 && gui.geom == NULL)
- Rows = 24;
pixel_width = (guint)(gui_get_base_width() + Columns * gui.char_width);
pixel_height = (guint)(gui_get_base_height() + Rows * gui.char_height);
gtk_window_set_default_size(GTK_WINDOW(gui.mainwin),
G_CALLBACK(mainwin_destroy_cb), NULL);
// Resize is handled by GtkForm's size_allocate callback.
+ // Not sure if this needed but still do it I guess?
gtk_widget_set_visible(gui.mainwin, TRUE);
// Make sure the drawing area gets keyboard focus.