1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357
|
/*-F
* Copyright (c) 2004-2007 os-cillation e.K.
*
* Written by Benedikt Meurer <benny@xfce.org>.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program 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 General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#ifdef HAVE_SIGNAL_H
#include <signal.h>
#endif
#ifdef HAVE_LOCALE_H
#include <locale.h>
#endif
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#include <terminal/terminal-app.h>
#include <terminal/terminal-private.h>
#include <terminal/terminal-gdbus.h>
#include <terminal/terminal-preferences-dialog.h>
#include <terminal/terminal-window.h>
#include <terminal/terminal-widget.h>
static void
colortable_sub (const gchar *bright,
guint start)
{
guint n;
guint fg;
guint bg;
for (n = start; n <= 37; n++)
{
if (n == 28)
fg = 0;
else if (n == 29)
fg = 1;
else
fg = n;
/* blank */
g_print (" %*s%2dm |",
2, bright, fg);
/* without background color */
g_print ("\e[%s%dm %*s%2dm ",
bright, fg, 2, bright, fg);
/* with background color */
for (bg = 40; bg <= 47; bg++)
{
g_print ("\e[%s%d;%dm %*s%2dm ",
bright, fg, bg, 2, bright, fg);
}
g_print ("\e[0m\n");
}
}
static void
colortable (void)
{
guint bg;
/* header */
g_print ("%*s|%*s", 7, "", 7, "");
for (bg = 40; bg <= 47; bg++)
g_print (" %dm ", bg);
g_print ("\n");
/* normal */
colortable_sub ("", 28);
/* bright */
colortable_sub ("1;", 30);
}
static void
usage (void)
{
g_print ("%s\n"
" %s [%s...]\n\n",
_("Usage:"), PACKAGE_NAME, _("OPTION"));
g_print ("%s:\n"
" -h, --help; -V, --version; --disable-server; --color-table; --preferences;\n"
" --default-display=%s; --default-working-directory=%s\n\n",
_("General Options"),
/* parameter of --default-display */
_("display"),
/* parameter of --default-working-directory */
_("directory"));
g_print ("%s:\n"
" --tab; --window\n\n",
_("Window or Tab Separators"));
g_print ("%s:\n"
" -x, --execute; -e, --command=%s; -T, --title=%s;\n"
" --dynamic-title-mode=%s ('replace', 'before', 'after', 'none');\n"
" --initial-title=%s; --working-directory=%s; -H, --hold;\n"
" --active-tab; --color-text=%s; --color-bg=%s\n\n",
_("Tab Options"),
/* parameter of --command */
_("command"),
/* parameter of --title */
_("title"),
/* parameter of --dynamic-title-mode */
_("mode"),
/* parameter of --initial-title */
_("title"),
/* parameter of --working-directory */
_("directory"),
/* parameter of --color-text */
_("color"),
/* parameter of --color-bg */
_("color"));
g_print ("%s:\n"
" --display=%s; --geometry=%s; --role=%s; --drop-down;\n"
" --startup-id=%s; -I, --icon=%s; --fullscreen; --maximize; --minimize;\n"
" --show-menubar, --hide-menubar; --show-borders, --hide-borders;\n"
" --show-toolbar, --hide-toolbar; --show-scrollbar, --hide-scrollbar;\n"
" --font=%s; --zoom=%s; --class=%s\n\n",
_("Window Options"),
/* parameter of --display */
_("display"),
/* parameter of --geometry */
_("geometry"),
/* parameter of --role */
_("role"),
/* parameter of --startup-id */
_("string"),
/* parameter of --icon */
_("icon"),
/* parameter of --font */
_("font"),
/* parameter of --zoom */
_("zoom"),
/* parameter of --class */
_("class"));
g_print (_("See the %s man page for full explanation of the options above."),
PACKAGE_NAME);
g_print ("\n\n");
}
int
main (int argc, char **argv)
{
TerminalOptions options;
TerminalApp *app;
const gchar *startup_id;
GdkDisplay *display;
GError *error = NULL;
gchar **nargv;
gint nargc;
gint n;
const gchar *msg;
/* initialize options */
options.disable_server = options.show_version = options.show_colors = options.show_help =
options.show_preferences = 0;
/* install required signal handlers */
signal (SIGPIPE, SIG_IGN);
xfce_textdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8");
/* initializes internationalization support */
if (setlocale (LC_ALL, "") == NULL)
g_warning ("Locale not supported by C library.");
g_set_application_name (_("Xfce Terminal"));
/* initialize GTK: do this before our parsing so GTK parses its options first */
gtk_init (&argc, &argv);
/* parse some options we need in main, not the windows attrs */
terminal_options_parse (argc, argv, &options);
if (G_UNLIKELY (options.show_version))
{
g_print ("%s %s (Xfce %s)\n\n", PACKAGE_NAME, PACKAGE_VERSION, xfce_version_string ());
g_print ("%s\n", "Copyright (c) 2003-2024");
g_print ("\t%s\n\n", _("The Xfce development team. All rights reserved."));
g_print ("%s\n", _("Written by Benedikt Meurer <benny@xfce.org>,"));
g_print ("%s\n", _("Nick Schermer <nick@xfce.org>,"));
g_print ("%s\n", _("Igor Zakharov <f2404@yandex.ru>,"));
g_print ("%s\n\n", _("Sergios - Anestis Kefalidis <sergioskefalidis@gmail.com>."));
g_print (_("Please report bugs to <%s>."), PACKAGE_BUGREPORT);
g_print ("\n");
return EXIT_SUCCESS;
}
else if (G_UNLIKELY (options.show_colors))
{
colortable ();
return EXIT_SUCCESS;
}
else if (G_UNLIKELY (options.show_help))
{
usage ();
return EXIT_SUCCESS;
}
else if (G_UNLIKELY (options.show_preferences))
{
GtkWidget *dialog;
/* load the AccelMap for the XfceShortcutsEditor */
app = g_object_new (TERMINAL_TYPE_APP, NULL);
xfce_gtk_translate_action_entries (terminal_window_get_action_entries (), TERMINAL_WINDOW_ACTION_N);
xfce_gtk_translate_action_entries (terminal_widget_get_action_entries (), TERMINAL_WIDGET_ACTION_N);
xfce_gtk_accel_map_add_entries (terminal_window_get_action_entries (), TERMINAL_WINDOW_ACTION_N);
xfce_gtk_accel_map_add_entries (terminal_widget_get_action_entries (), TERMINAL_WIDGET_ACTION_N);
terminal_app_load_accels (app); /* manual execution, instead of the typical idle function */
/* create and run the dialog */
dialog = terminal_preferences_dialog_new (TRUE, FALSE);
g_signal_connect_after (G_OBJECT (dialog), "destroy",
G_CALLBACK (gtk_main_quit), NULL);
gtk_window_present (GTK_WINDOW (dialog));
gtk_main ();
g_object_unref (G_OBJECT (app));
return EXIT_SUCCESS;
}
/* create a copy of the standard arguments with our additional stuff */
nargv = g_new (gchar*, argc + 5); nargc = 0;
nargv[nargc++] = g_strdup (argv[0]);
nargv[nargc++] = g_strdup ("--default-working-directory");
nargv[nargc++] = g_get_current_dir ();
/* append startup if given */
startup_id = g_getenv ("DESKTOP_STARTUP_ID");
if (G_LIKELY (startup_id != NULL))
{
nargv[nargc++] = g_strdup_printf ("--startup-id=%s", startup_id);
g_unsetenv ("DESKTOP_STARTUP_ID");
}
/* append default display if given */
display = gdk_display_get_default ();
if (G_LIKELY (display != NULL))
nargv[nargc++] = g_strdup_printf ("--default-display=%s", gdk_display_get_name (display));
/* append all given arguments */
for (n = 1; n < argc; ++n)
nargv[nargc++] = g_strdup (argv[n]);
nargv[nargc] = NULL;
if (!options.disable_server)
{
/* try to connect to an existing Terminal service */
if (terminal_gdbus_invoke_launch (nargc, nargv, &error))
{
g_strfreev (nargv);
return EXIT_SUCCESS;
}
else
{
if (g_error_matches (error, TERMINAL_ERROR, TERMINAL_ERROR_USER_MISMATCH)
|| g_error_matches (error, TERMINAL_ERROR, TERMINAL_ERROR_DISPLAY_MISMATCH))
{
/* don't try to establish another service here */
options.disable_server = 1;
g_debug ("%s mismatch when invoking remote terminal: %s",
error->code == TERMINAL_ERROR_USER_MISMATCH ? "User" : "Display",
error->message);
}
else if (g_error_matches (error, TERMINAL_ERROR, TERMINAL_ERROR_OPTIONS))
{
/* skip the GDBus prefix */
msg = strchr (error->message, ' ');
if (G_LIKELY (msg != NULL))
msg++;
else
msg = error->message;
/* options were not parsed succesfully, don't try that again below */
g_printerr ("%s: %s\n", PACKAGE_NAME, msg);
g_error_free (error);
g_strfreev (nargv);
return EXIT_FAILURE;
}
else if (error != NULL)
{
g_debug ("D-Bus reply error: %s (%s: %d)", error->message,
g_quark_to_string (error->domain), error->code);
}
g_clear_error (&error);
}
}
/* set default window icon */
gtk_window_set_default_icon_name ("org.xfce.terminal");
app = g_object_new (TERMINAL_TYPE_APP, NULL);
if (!options.disable_server)
{
if (!terminal_gdbus_register_service (app, &error))
{
g_warning ("Unable to register terminal service: %s", error->message);
g_clear_error (&error);
}
}
if (!terminal_app_process (app, nargv, nargc, &error))
{
/* parsing one of the arguments failed */
g_printerr ("%s: %s\n", PACKAGE_NAME, error->message);
g_error_free (error);
g_object_unref (G_OBJECT (app));
g_strfreev (nargv);
return EXIT_FAILURE;
}
/* free temporary arguments */
g_strfreev (nargv);
gtk_main ();
g_object_unref (G_OBJECT (app));
return EXIT_SUCCESS;
}
|