Skip to content
This repository has been archived by the owner on Dec 27, 2022. It is now read-only.

Commit

Permalink
mintty 升级到 3.2.0, launcher 升级到 0.4.1
Browse files Browse the repository at this point in the history
  • Loading branch information
riag committed Jul 27, 2020
1 parent 18a83bf commit 2d0932f
Show file tree
Hide file tree
Showing 4 changed files with 394 additions and 5 deletions.
2 changes: 1 addition & 1 deletion launcher/wsltty-launcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/mkideal/cli"
)

const version string = "0.4.0"
const version string = "0.4.1"

type DistroConfig struct {
Shell string
Expand Down
5 changes: 1 addition & 4 deletions package.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@

curr_dir = os.path.dirname(os.path.realpath(__file__))

# mintty 2.8.3 -> f5b7aa6ab9cfa79bebad5cb3c2a03949a1d24423
# mintty 2.8.4 -> ed9f0a14b679ca31daccfafa6dad2b13744ad2a6

mintty_version = '3.1.4'
mintty_version = '3.2.0'
mintty_url = 'https://github.com/mintty/mintty/archive/%s.tar.gz' % (mintty_version)
mintty_name = 'mintty-%s' % (mintty_version)

Expand Down
317 changes: 317 additions & 0 deletions scripts/mintty/3.2.0/0002-add-msys2-launcher.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,317 @@
From b40367fec8f658d74a8c74dfdd223293c7828b85 Mon Sep 17 00:00:00 2001
From: Mihail Konev <[email protected]>
Date: Sat, 4 Mar 2017 07:43:42 +0500
Subject: [PATCH 2/3] add msys2 launcher

Also makes mintty pinnable to Windows Taskbar.

Before, a pinned shortcut would have generic icon and fail to launch a
proper shell because of $MSYSTEM not being set.

The list of shells is harcoded. An editable config file in /etc would
be nice (for e.g. "MSYS2 zsh" item), but this works for now.

Usage notes:

If the taskbar cannot forget mintty's default icon, rebooting helps
(at least, non-fast-restart one).

If the taskbar cannot forget the mintty's default "Terminal" tooltip
text displayed upon mouse hover of the shorcut, deleting the

[HKEY_CLASSES_ROOT\Local Settings\Software\Microsoft\Windows\Shell\MuiCache]
"C:\\path\\to\\msys\\usr\\bin\\mintty.exe.FriendlyAppName"

registry value (or just the entire MuiCache directory) should help, at
least for the current Windows 10.
---
src/appinfo.h | 2 +-
src/launcher.c | 129 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
src/launcher.h | 12 ++++++
src/res.h | 4 ++
src/res.rc | 16 ++++++-
src/winmain.c | 34 ++++++++++++---
6 files changed, 189 insertions(+), 8 deletions(-)
create mode 100644 src/launcher.c
create mode 100644 src/launcher.h

diff --git a/src/appinfo.h b/src/appinfo.h
index eebc47a..2877d69 100644
--- a/src/appinfo.h
+++ b/src/appinfo.h
@@ -10,7 +10,7 @@
#define BUILD_NUMBER 0

// needed for res.rc
-#define APPDESC "Terminal"
+#define APPDESC "MSYS2 terminal"
#define AUTHOR "Andy Koppe / Thomas Wolff"
#define YEAR "2013/2019"

diff --git a/src/launcher.c b/src/launcher.c
new file mode 100644
index 0000000..e120708
--- /dev/null
+++ b/src/launcher.c
@@ -0,0 +1,129 @@
+#include <windows.h>
+#include <commctrl.h>
+#include "res.h"
+
+#define INSIDE_LAUNCHER
+#include "launcher.h"
+
+static char ***ret_argv_addr;
+
+int launcher_cancelled = 0;
+
+void launcher_init(char ***argv_addr) {
+ ret_argv_addr = argv_addr;
+}
+
+void launcher_free(void) {
+ return;
+}
+
+static int selected_btn = IDD_MSYS2_BTN;
+
+void launcher_setup_env(void) {
+ switch (selected_btn) {
+ case IDD_MINGW32_BTN:
+ putenv("MSYSTEM=MINGW32");
+ break;
+ case IDD_MINGW64_BTN:
+ putenv("MSYSTEM=MINGW64");
+ break;
+ default:
+ putenv("MSYSTEM=MSYS");
+ break;
+ }
+ return;
+}
+
+static char *bash_cmd[] = {
+ "/usr/bin/bash", "--login", NULL
+};
+
+void launcher_setup_argv(void) {
+ *ret_argv_addr = bash_cmd;
+}
+
+static void launcher_add_tooltip_to_window(HWND hwnd, char *text) {
+ TOOLINFO ti;
+ RECT rect;
+ HWND hwnd_tt;
+
+ hwnd_tt = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, NULL,
+ WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP,
+ 0, 0, 0, 0, hwnd, NULL, NULL, NULL );
+
+ SetWindowPos(hwnd_tt, HWND_TOPMOST, 0, 0, 0, 0,
+ SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
+
+ GetClientRect(hwnd, &rect);
+
+ ti.cbSize = sizeof(TOOLINFO);
+ ti.uFlags = TTF_SUBCLASS;
+ ti.hwnd = hwnd;
+ ti.hinst = NULL;
+ ti.uId = 0;
+ ti.lpszText = text;
+ ti.rect.left = rect.left;
+ ti.rect.top = rect.top;
+ ti.rect.right = rect.right;
+ ti.rect.bottom = rect.bottom;
+
+ SendMessage(hwnd_tt, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) &ti);
+}
+
+static void launcher_add_tooltip_to_window_by_id(HWND dialog, int id, char *text) {
+ HWND hwnd;
+
+ hwnd = GetDlgItem(dialog, id);
+ launcher_add_tooltip_to_window(hwnd, text);
+}
+
+static void launcher_add_tooltips(HWND hwnd) {
+ launcher_add_tooltip_to_window(hwnd,
+ "MSYS2 shell launcher");
+ launcher_add_tooltip_to_window_by_id(hwnd, IDD_MSYS2_BTN,
+ "The emulated shell, for running and building Msys2-specific apps.");
+ launcher_add_tooltip_to_window_by_id(hwnd, IDD_MINGW32_BTN,
+ "32-bit shell, for running and building native apps.");
+ launcher_add_tooltip_to_window_by_id(hwnd, IDD_MINGW64_BTN,
+ "64-bit shell, for running and building native apps.");
+}
+
+HICON launcher_icon;
+
+INT_PTR CALLBACK launcher_dlgproc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
+ (void) lParam;
+
+ switch (uMsg) { /* handle the messages */
+ case WM_COMMAND:
+ switch (LOWORD(wParam)) {
+ case IDCANCEL:
+ SendMessage(hwnd, WM_CLOSE, 0, 0);
+ launcher_cancelled = 1;
+ return TRUE;
+ case IDD_MSYS2_BTN:
+ case IDD_MINGW32_BTN:
+ case IDD_MINGW64_BTN:
+ DestroyWindow(hwnd);
+ selected_btn = LOWORD(wParam);
+ return TRUE;
+ default:
+ return FALSE;
+ }
+ break;
+ case WM_INITDIALOG:
+ SendMessage(hwnd, WM_SETICON, 0, (LPARAM)launcher_icon);
+ launcher_add_tooltips(hwnd);
+ return TRUE;
+ case WM_DESTROY:
+ break;
+ case WM_CLOSE:
+ DestroyWindow(hwnd);
+ launcher_cancelled = 1;
+ return TRUE;
+ default:
+ return FALSE;
+ }
+
+ return FALSE;
+}
+
diff --git a/src/launcher.h b/src/launcher.h
new file mode 100644
index 0000000..619508a
--- /dev/null
+++ b/src/launcher.h
@@ -0,0 +1,12 @@
+#ifndef INSIDE_LAUNCHER
+extern int launcher_cancelled;
+extern HICON launcher_icon;
+#endif
+
+void launcher_init(char ***argv_addr);
+void launcher_free(void);
+
+void launcher_setup_env(void);
+void launcher_setup_argv(void);
+
+INT_PTR CALLBACK launcher_dlgproc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
diff --git a/src/res.h b/src/res.h
index da4a06b..df37fa6 100644
--- a/src/res.h
+++ b/src/res.h
@@ -28,3 +28,7 @@
//#define DIALOG_FONT "Trebuchet MS"
//#define DIALOG_FONT "Lucida Sans Unicode"

+#define IDD_LAUNCHER 0x100
+#define IDD_MSYS2_BTN 0x101
+#define IDD_MINGW32_BTN 0x102
+#define IDD_MINGW64_BTN 0x103
diff --git a/src/res.rc b/src/res.rc
index 642b086..2373606 100644
--- a/src/res.rc
+++ b/src/res.rc
@@ -4,7 +4,7 @@

#include <winresrc.h>

-IDI_MAINICON ICON "../icon/terminal.ico"
+IDI_MAINICON ICON "/msys2.ico"

IDD_MAINBOX DIALOGEX DISCARDABLE 32, 8, DIALOG_WIDTH, DIALOG_HEIGHT
STYLE DS_SHELLFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
@@ -14,6 +14,20 @@ CLASS DIALOG_CLASS
BEGIN
END

+IDD_LAUNCHER DIALOGEX 0, 0, 100, 97
+STYLE DS_3DLOOK | DS_CENTER | DS_SYSMODAL | DS_SHELLFONT | WS_CAPTION | WS_VISIBLE | WS_POPUP | WS_SYSMENU
+EXSTYLE WS_EX_TOPMOST | WS_EX_APPWINDOW
+CAPTION "Mintty"
+FONT 8, "Ms Shell Dlg"
+{
+ GROUPBOX "Shells (bash)", 0, 3, 5, 92, 69, 0, WS_EX_LEFT
+ PUSHBUTTON "MSYS2", IDD_MSYS2_BTN, 9, 16, 44, 14, 0, WS_EX_LEFT
+ PUSHBUTTON "Mingw-w64 32 bit", IDD_MINGW32_BTN, 9, 35, 74, 14, 0, WS_EX_LEFT
+ PUSHBUTTON "Mingw-w64 64 bit", IDD_MINGW64_BTN, 9, 54, 74, 14, 0, WS_EX_LEFT
+
+ PUSHBUTTON "Cancel", IDCANCEL, 25, 78, 44, 14, NOT WS_TABSTOP, WS_EX_LEFT
+}
+
/*
* The actual VERSIONINFO resource.
*/
diff --git a/src/winmain.c b/src/winmain.c
index 7af432f..0ccca9a 100644
--- a/src/winmain.c
+++ b/src/winmain.c
@@ -53,6 +53,9 @@
#define GWL_USERDATA -21
#endif

+#include "res.h"
+#include "launcher.h"
+

char * home;
char * cmd;
@@ -4398,6 +4401,8 @@ main(int argc, char *argv[])
}
}

+ launcher_icon = large_icon ?: LoadIcon(inst, MAKEINTRESOURCE(IDI_MAINICON));
+
// The window class.
class_atom = RegisterClassExW(&(WNDCLASSEXW){
.cbSize = sizeof(WNDCLASSEXW),
@@ -4406,7 +4411,7 @@ main(int argc, char *argv[])
.cbClsExtra = 0,
.cbWndExtra = 0,
.hInstance = inst,
- .hIcon = large_icon ?: LoadIcon(inst, MAKEINTRESOURCE(IDI_MAINICON)),
+ .hIcon = launcher_icon,
.hIconSm = small_icon,
.hCursor = LoadCursor(null, IDC_IBEAM),
.hbrBackground = null,
@@ -4711,10 +4716,28 @@ main(int argc, char *argv[])
if (*cfg.background == '%')
scale_to_image_ratio();

- // Create child process.
- child_create(
- argv, &(struct winsize){term_rows, term_cols, term_width, term_height}
- );
+ {
+ char **argv1 = argv;
+
+ if (argc == 1) {
+ launcher_init(&argv1);
+ DialogBox(inst, MAKEINTRESOURCE(IDD_LAUNCHER), NULL, (DLGPROC)launcher_dlgproc);
+ if (launcher_cancelled) {
+ exit(1);
+ }
+ launcher_setup_env();
+ launcher_setup_argv();
+ }
+
+ // Create child process.
+ child_create(
+ argv1, &(struct winsize){term_rows, term_cols, term_width, term_height}
+ );
+
+ if (argc == 1) {
+ launcher_free();
+ }
+ }

// Finally show the window.
ShowWindow(wnd, show_cmd);
--
2.11.0

Loading

0 comments on commit 2d0932f

Please sign in to comment.