Skip to content

Commit

Permalink
save to --configdir config file only if it already existed (mintty/wi…
Browse files Browse the repository at this point in the history
…npty#30, ~mintty/winpty#40; reverts part of 9c21434)
  • Loading branch information
mintty committed May 19, 2017
1 parent 10bb61d commit 5fde09f
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 4 deletions.
5 changes: 5 additions & 0 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -1084,6 +1084,11 @@ load_scheme(string cs)
free(scheme);
}

// to_save:
// 0 read config from filename
// 1 use filename for saving if file exists and is writable
// 2 use filename for saving if none was previously determined
// 3 use filename for saving (override)
void
load_config(string filename, int to_save)
{
Expand Down
56 changes: 52 additions & 4 deletions src/winmain.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ trace_winsize(char * tag)
static HRESULT (WINAPI * pDwmIsCompositionEnabled)(BOOL *) = 0;
static HRESULT (WINAPI * pDwmExtendFrameIntoClientArea)(HWND, const MARGINS *) = 0;
static HRESULT (WINAPI * pDwmEnableBlurBehindWindow)(HWND, void *) = 0;
static HRESULT (WINAPI * pSetWindowCompositionAttribute)(HWND, void *) = 0;

// Helper for loading a system library. Using LoadLibrary() directly is insecure
// because Windows might be searching the current working directory first.
Expand All @@ -142,6 +143,7 @@ static void
load_dwm_funcs(void)
{
HMODULE dwm = load_sys_library("dwmapi.dll");
HMODULE user32 = load_sys_library("user32.dll");
if (dwm) {
pDwmIsCompositionEnabled =
(void *)GetProcAddress(dwm, "DwmIsCompositionEnabled");
Expand All @@ -150,6 +152,10 @@ load_dwm_funcs(void)
pDwmEnableBlurBehindWindow =
(void *)GetProcAddress(dwm, "DwmEnableBlurBehindWindow");
}
if (user32) {
pSetWindowCompositionAttribute =
(void *)GetProcAddress(user32, "SetWindowCompositionAttribute");
}
}

void *
Expand Down Expand Up @@ -704,12 +710,54 @@ win_update_blur(bool opaque)
static void
win_update_glass(bool opaque)
{
bool enabled =
cfg.transparency == TR_GLASS && !win_is_fullscreen &&
!(opaque && term.has_focus);

if (pDwmExtendFrameIntoClientArea) {
bool enabled =
cfg.transparency == TR_GLASS && !win_is_fullscreen &&
!(opaque && term.has_focus);
pDwmExtendFrameIntoClientArea(wnd, &(MARGINS){enabled ? -1 : 0, 0, 0, 0});
}

if (pSetWindowCompositionAttribute) {
enum AccentState
{
ACCENT_DISABLED = 0,
ACCENT_ENABLE_GRADIENT = 1,
ACCENT_ENABLE_TRANSPARENTGRADIENT = 2,
ACCENT_ENABLE_BLURBEHIND = 3,
ACCENT_INVALID_STATE = 4
};
enum WindowCompositionAttribute
{
WCA_ACCENT_POLICY = 19
};
struct ACCENTPOLICY
{
enum AccentState nAccentState;
int nFlags;
int nColor;
int nAnimationId;
};
struct WINCOMPATTRDATA
{
enum WindowCompositionAttribute nAttribute;
PVOID pData;
ULONG ulDataSize;
};
struct ACCENTPOLICY policy = {
enabled ? ACCENT_ENABLE_BLURBEHIND : ACCENT_DISABLED,
0,
0,
0
};
struct WINCOMPATTRDATA data = {
WCA_ACCENT_POLICY,
(PVOID)&policy,
sizeof(policy)
};

pSetWindowCompositionAttribute(wnd, &data);
}
}

/*
Expand Down Expand Up @@ -2332,7 +2380,7 @@ main(int argc, char *argv[])
else {
config_dir = strdup(optarg);
string rc_file = asform("%s/config", config_dir);
load_config(rc_file, 3);
load_config(rc_file, 2);
delete(rc_file);
}
when 'h': set_arg_option("Hold", optarg);
Expand Down

0 comments on commit 5fde09f

Please sign in to comment.