326 lines
8.4 KiB
Diff
326 lines
8.4 KiB
Diff
From b40367fec8f658d74a8c74dfdd223293c7828b85 Mon Sep 17 00:00:00 2001
|
|
From: Mihail Konev <k.mvc@ya.ru>
|
|
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/2016"
|
|
|
|
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
|
|
@@ -23,3 +23,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
|
|
@@ -33,6 +33,9 @@
|
|
#include <propkey.h>
|
|
#endif
|
|
|
|
+#include "res.h"
|
|
+#include "launcher.h"
|
|
+
|
|
|
|
char * home;
|
|
char * cmd;
|
|
@@ -2548,6 +2551,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),
|
|
@@ -2556,7 +2561,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,
|
|
@@ -2564,7 +2569,6 @@ main(int argc, char *argv[])
|
|
.lpszClassName = wclass,
|
|
});
|
|
|
|
-
|
|
// Initialise the fonts, thus also determining their width and height.
|
|
win_init_fonts(cfg.font.size);
|
|
|
|
@@ -2772,10 +2776,28 @@ main(int argc, char *argv[])
|
|
#endif
|
|
}
|
|
|
|
- // 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!
|
|
go_fullscr_on_max = (cfg.window == -1);
|
|
--
|
|
2.11.0
|
|
|