Skip to content

Commit

Permalink
new option Padding (#511)
Browse files Browse the repository at this point in the history
new option -D with impact to shortcut key behaviour (~#499)
adjusting window to font change (#429)
tweaks for printing (Media Copy)
minor tweaks
  • Loading branch information
mintty committed Jan 15, 2016
1 parent 7b1b84f commit c97db6d
Showing 1 changed file with 91 additions and 26 deletions.
117 changes: 91 additions & 26 deletions src/winmain.c
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#include <locale.h>
#include <getopt.h>
#include <pwd.h>

#include <mmsystem.h> // PlaySound for MSys
#include <shellapi.h>

#include <sys/cygwin.h>
Expand All @@ -40,7 +42,26 @@ static char **main_argv;
static int main_argc;
static ATOM class_atom;
static bool invoked_from_shortcut = false;
#if CYGWIN_VERSION_DLL_MAJOR >= 1005
static bool invoked_with_appid = false;
#endif

#if CYGWIN_VERSION_API_MINOR < 74
// needed for MSys
#define wcscpy(targ, src) memcpy(targ, src, (wcslen(src) + 1) * sizeof(wchar))
static int
wcsncmp(const wchar * s1, const wchar * s2, int len)
{
for (int i = 0; i < len; i++)
if (s1[i] < s2[i])
return -1;
else if (s1[i] > s2[i])
return 1;
else if (s1[i] == 0)
return 0;
return 0;
}
#endif

static int extra_width, extra_height, norm_extra_width, norm_extra_height;

Expand Down Expand Up @@ -198,6 +219,19 @@ win_prefix_title(const wstring prefix)
SetWindowTextW(wnd, ptitle);
}

void
win_unprefix_title(const wstring prefix)
{
int len = GetWindowTextLengthW(wnd);
wchar ptitle[len + 1];
GetWindowTextW(wnd, ptitle, len + 1);
int plen = wcslen(prefix);
if (!wcsncmp(ptitle, prefix, plen)) {
wchar * title = & ptitle[plen];
SetWindowTextW(wnd, title);
}
}

/*
* Title stack (implemented as fixed-size circular buffer)
*/
Expand Down Expand Up @@ -506,6 +540,8 @@ win_is_glass_available(void)
static void
update_blur(void)
{
// This feature is disabled in config.c as it does not seem to work,
// see https://github.com/mintty/mintty/issues/501
if (pDwmEnableBlurBehindWindow) {
bool blur =
cfg.transparency && cfg.blurred && !win_is_fullscreen &&
Expand Down Expand Up @@ -855,6 +891,29 @@ win_update_scrollbar(void)
SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
}

static void
font_cs_reconfig(bool font_changed)
{
if (font_changed) {
win_init_fonts(cfg.font.size);
trace_resize((" (win_reconfig -> win_adapt_term_size)\n"));
win_adapt_term_size(true, false);
}
win_update_scrollbar();
update_transparency();
win_update_mouse();

bool old_ambig_wide = cs_ambig_wide;
cs_reconfig();
if (term.report_font_changed && font_changed)
if (term.report_ambig_width)
child_write(cs_ambig_wide ? "\e[2W" : "\e[1W", 4);
else
child_write("\e[0W", 4);
else if (term.report_ambig_width && old_ambig_wide != cs_ambig_wide)
child_write(cs_ambig_wide ? "\e[2W" : "\e[1W", 4);
}

void
win_reconfig(void)
{
Expand All @@ -881,24 +940,8 @@ win_reconfig(void)

/* Copy the new config and refresh everything */
copy_config(&cfg, &new_cfg);
if (font_changed) {
win_init_fonts(cfg.font.size);
trace_resize((" (win_reconfig -> win_adapt_term_size)\n"));
win_adapt_term_size(true, false);
}
win_update_scrollbar();
update_transparency();
win_update_mouse();

bool old_ambig_wide = cs_ambig_wide;
cs_reconfig();
if (term.report_font_changed && font_changed)
if (term.report_ambig_width)
child_write(cs_ambig_wide ? "\e[2W" : "\e[1W", 4);
else
child_write("\e[0W", 4);
else if (term.report_ambig_width && old_ambig_wide != cs_ambig_wide)
child_write(cs_ambig_wide ? "\e[2W" : "\e[1W", 4);
font_cs_reconfig(font_changed);
}

static bool
Expand Down Expand Up @@ -951,7 +994,7 @@ confirm_exit(void)
wchar msgw[size];
cs_mbstowcs(msgw, msg, size);
wchar appn[strlen(APPNAME) + 1];
cs_mbstowcs(appn, APPNAME, sizeof appn);
cs_mbstowcs(appn, APPNAME, lengthof(appn));
ret =
MessageBoxW(
wnd, msgw,
Expand Down Expand Up @@ -1097,6 +1140,15 @@ static struct {
}
return 1;
}
when WM_THEMECHANGED:
// this would kind of handle switching off the Performance Option
// "Use visual styles on windows and borders"
// but would reduce the actual terminal size...
// also it does not handle switching on the option
//font_cs_reconfig(true);
//?win_set_chars(term.rows, term.cols);
when WM_FONTCHANGE:
font_cs_reconfig(true);
when WM_PAINT:
win_paint();
return 0;
Expand Down Expand Up @@ -1254,7 +1306,7 @@ static const char help[] =
" -V, --version Print version information and exit\n"
;

static const char short_opts[] = "+:c:C:eh:i:l:o:p:s:t:T:B:R:uw:HVd";
static const char short_opts[] = "+:c:C:eh:i:l:o:p:s:t:T:B:R:uw:HVdD";

static const struct option
opts[] = {
Expand All @@ -1277,6 +1329,7 @@ opts[] = {
{"help", no_argument, 0, 'H'},
{"version", no_argument, 0, 'V'},
{"nodaemon", no_argument, 0, 'd'},
{"daemon", no_argument, 0, 'D'},
{"nopin", no_argument, 0, ''}, // short option not enabled
{"store-taskbar-properties", no_argument, 0, ''}, // no short option
{0, 0, 0, 0}
Expand Down Expand Up @@ -1354,6 +1407,9 @@ exit_mintty()
exit(0);
}


#if CYGWIN_VERSION_DLL_MAJOR >= 1005

#include <shlobj.h>

static char *
Expand Down Expand Up @@ -1383,10 +1439,10 @@ get_shortcut_icon_location(wchar * iconfile)
char * result = 0;

if (SUCCEEDED(hres)) {
WCHAR wil[MAX_PATH];
char il[MAX_PATH * cs_cur_max];
WCHAR wil[MAX_PATH + 1];
char il[MAX_PATH * cs_cur_max + 1];
int index;
shell_link->lpVtbl->GetIconLocation(shell_link, wil, sizeof wil, &index);
shell_link->lpVtbl->GetIconLocation(shell_link, wil, lengthof(wil), &index);
cs_wcstombs(il, wil, sizeof il);
if (index) {
char _num[22];
Expand Down Expand Up @@ -1427,6 +1483,8 @@ get_shortcut_icon_location(wchar * iconfile)
return result;
}

#endif

static void
configure_taskbar()
{
Expand Down Expand Up @@ -1609,9 +1667,11 @@ main(int argc, char *argv[])
GetStartupInfoW(&sui);
cfg.window = sui.dwFlags & STARTF_USESHOWWINDOW ? sui.wShowWindow : SW_SHOW;
cfg.x = cfg.y = CW_USEDEFAULT;
#if CYGWIN_VERSION_DLL_MAJOR >= 1005
invoked_from_shortcut = sui.dwFlags & STARTF_TITLEISLINKNAME;
invoked_with_appid = sui.dwFlags & STARTF_TITLEISAPPID;
// shortcut or AppId would be found in sui.lpTitle
#endif

load_config("/etc/minttyrc", true);
string rc_file = asform("%s/.minttyrc", home);
Expand Down Expand Up @@ -1679,6 +1739,8 @@ main(int argc, char *argv[])
when '': set_arg_option("Class", optarg);
when 'd':
cfg.daemonize = false;
when 'D':
cfg.daemonize_always = true;
when 'H':
show_msg(stdout, help);
return 0;
Expand Down Expand Up @@ -1711,8 +1773,8 @@ main(int argc, char *argv[])
unsetenv("MINTTY_ICON");
}

#define dont_debug_icon
#ifdef debug_icon
#if CYGWIN_VERSION_DLL_MAJOR >= 1005
#ifdef debuglog
fprintf(mtlog, "cfgicon %s\n", cfg.icon);
fprintf(mtlog, "shorcut %d %s\n", invoked_from_shortcut, (char *)cygwin_create_path(CCP_WIN_W_TO_POSIX, sui.lpTitle));
if (invoked_from_shortcut) {
Expand All @@ -1724,6 +1786,7 @@ main(int argc, char *argv[])
cfg.icon = get_shortcut_icon_location(sui.lpTitle);
icon_is_from_shortcut = true;
}
#endif

finish_config();

Expand All @@ -1737,6 +1800,8 @@ main(int argc, char *argv[])
// disable daemonizing if started from ConEmu
if (getenv("ConEmuPID"))
daemonize = false;
if (cfg.daemonize_always)
daemonize = true;
if (daemonize) { // detach from parent process and terminal
pid_t pid = fork();
if (pid < 0)
Expand Down Expand Up @@ -1816,10 +1881,10 @@ main(int argc, char *argv[])
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_MAX_WIDTH_MASK,
0, error, 0, msg, sizeof msg, 0
);
warn("could not load icon from '%s': %s", cfg.icon, msg);
warn("Could not load icon from '%s': %s", cfg.icon, msg);
}
else
warn("could not load icon from '%s'", cfg.icon);
warn("Could not load icon from '%s'", cfg.icon);
}
delete(icon_file);
}
Expand Down

0 comments on commit c97db6d

Please sign in to comment.