Last active
September 5, 2015 12:55
-
-
Save k-takata/ad364381d9c51ec81215 to your computer and use it in GitHub Desktop.
Patches for CLCL Ver 2.0.0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| From 4775f9b3379dee2333ed70ce4ff49596585aa89a Mon Sep 17 00:00:00 2001 | |
| From: "K.Takata" <[email protected]> | |
| Date: Sat, 5 Sep 2015 21:02:39 +0900 | |
| Subject: [PATCH 1/4] Fix that preventing multiple instances didn't work | |
| OpenMutex() shouldn't be used for this purpose, use CreateMutex() | |
| instead. | |
| --- | |
| CLCLSet/CLCLSet.c | 5 ++--- | |
| main.c | 5 ++--- | |
| 2 files changed, 4 insertions(+), 6 deletions(-) | |
| diff --git a/CLCLSet/CLCLSet.c b/CLCLSet/CLCLSet.c | |
| index f9f56bb..5dea983 100644 | |
| --- a/CLCLSet/CLCLSet.c | |
| +++ b/CLCLSet/CLCLSet.c | |
| @@ -742,9 +742,8 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine | |
| hInst = hInstance; | |
| // 2重起動チェック | |
| - if ((hMutex = OpenMutex(MUTEX_ALL_ACCESS, FALSE, MUTEX)) == NULL) { | |
| - hMutex = CreateMutex(NULL, TRUE, MUTEX); | |
| - } else { | |
| + hMutex = CreateMutex(NULL, TRUE, MUTEX); | |
| + if (GetLastError() == ERROR_ALREADY_EXISTS) { | |
| CloseHandle(hMutex); | |
| hMutex = NULL; | |
| diff --git a/main.c b/main.c | |
| index ef9a5d9..5fd9f41 100644 | |
| --- a/main.c | |
| +++ b/main.c | |
| @@ -2271,9 +2271,8 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine | |
| #ifndef _DEBUG | |
| // 2重起動チェック | |
| - if ((hMutex = OpenMutex(MUTEX_ALL_ACCESS, FALSE, MUTEX)) == NULL) { | |
| - hMutex = CreateMutex(NULL, TRUE, MUTEX); | |
| - } else { | |
| + hMutex = CreateMutex(NULL, TRUE, MUTEX); | |
| + if (GetLastError() == ERROR_ALREADY_EXISTS) { | |
| // コマンドライン処理 | |
| commnad_line_func(FindWindow(MAIN_WND_CLASS, MAIN_WINDOW_TITLE)); | |
| CloseHandle(hMutex); | |
| -- | |
| 2.5.1 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| From 6e3706f0c8544ea9e5e9b5f6c8c1d3c30e16e6f5 Mon Sep 17 00:00:00 2001 | |
| From: "K.Takata" <[email protected]> | |
| Date: Sat, 5 Sep 2015 21:09:46 +0900 | |
| Subject: [PATCH 2/4] Support surrogate pairs | |
| --- | |
| fmt_text_view.c | 44 ++++++++++++++++++++------------------------ | |
| 1 file changed, 20 insertions(+), 24 deletions(-) | |
| diff --git a/fmt_text_view.c b/fmt_text_view.c | |
| index 11be417..3f7c313 100644 | |
| --- a/fmt_text_view.c | |
| +++ b/fmt_text_view.c | |
| @@ -47,6 +47,18 @@ | |
| #define WM_THEMECHANGED 0x031A | |
| #endif | |
| +#ifndef IS_HIGH_SURROGATE | |
| +#define IS_HIGH_SURROGATE(wch) (((wch) & 0xfc00) == 0xd800) | |
| +#define IS_LOW_SURROGATE(wch) (((wch) & 0xfc00) == 0xdc00) | |
| +#define IS_SURROGATE_PAIR(hs, ls) (IS_HIGH_SURROGATE(hs) && IS_LOW_SURROGATE(ls)) | |
| +#endif | |
| + | |
| +#ifdef UNICODE | |
| +#define IS_LEAD_TBYTE(tb) IS_HIGH_SURROGATE(tb) | |
| +#else | |
| +#define IS_LEAD_TBYTE(tb) IsDBCSLeadByte(tb) | |
| +#endif | |
| + | |
| #define SWAP(a, b) {a = b - a; b -= a; a += b;} | |
| #define BUF_LEN (bf->buf_len + bf->input_len - bf->del_len - bf->ip_len) | |
| @@ -332,14 +344,10 @@ static void ensure_visible(const HWND hWnd, BUFFER *bf) | |
| */ | |
| static BOOL is_lead_byte(const BUFFER *bf, TCHAR *p) | |
| { | |
| -#ifdef UNICODE | |
| - return FALSE; | |
| -#else | |
| - if (IsDBCSLeadByte((BYTE)*p) == TRUE && char_to_index(bf, char_next(bf, p)) < BUF_LEN) { | |
| + if (IS_LEAD_TBYTE((TBYTE)*p) == TRUE && char_to_index(bf, char_next(bf, p)) < BUF_LEN) { | |
| return TRUE; | |
| } | |
| return FALSE; | |
| -#endif | |
| } | |
| /* | |
| @@ -351,13 +359,13 @@ static int get_char_extent(BUFFER *bf, TCHAR *str, int *ret_len) | |
| int ret = 0; | |
| #ifdef UNICODE | |
| - *ret_len = 1; | |
| - if (HIBYTE(*str) == 0 && *(bf->cwidth + LOBYTE(*str)) != 0) { | |
| + *ret_len = (is_lead_byte(bf, str) == TRUE) ? 2 : 1; | |
| + if (*ret_len == 1 && HIBYTE(*str) == 0 && *(bf->cwidth + LOBYTE(*str)) != 0) { | |
| ret = *(bf->cwidth + LOBYTE(*str)); | |
| } else { | |
| GetTextExtentPoint32(bf->mdc, str, *ret_len, &sz); | |
| ret = sz.cx; | |
| - if (HIBYTE(*str) == 0 && sz.cx < 256) { | |
| + if (*ret_len == 1 && HIBYTE(*str) == 0 && sz.cx < 256) { | |
| *(bf->cwidth + LOBYTE(*str)) = (BYTE)sz.cx; | |
| } | |
| } | |
| @@ -1074,7 +1082,7 @@ static BOOL string_insert(const HWND hWnd, BUFFER *bf, TCHAR *str, const int len | |
| (BUF_LEN - ((bf->cp > bf->sp) ? bf->cp - bf->sp : bf->sp - bf->cp)) + ilen > bf->limit_len) { | |
| i = bf->limit_len - (BUF_LEN - ((bf->cp > bf->sp) ? bf->cp - bf->sp : bf->sp - bf->cp)); | |
| for (ilen = 0; ilen < i; ilen++) { | |
| - if (IsDBCSLeadByte((BYTE)*(str + ilen)) == TRUE || | |
| + if (IS_LEAD_TBYTE((TBYTE)*(str + ilen)) == TRUE || | |
| (*(str + ilen) == TEXT('\r') && *(str + ilen + 1) == TEXT('\n'))) { | |
| if (ilen + 1 >= i) { | |
| break; | |
| @@ -1108,7 +1116,7 @@ static BOOL string_insert(const HWND hWnd, BUFFER *bf, TCHAR *str, const int len | |
| if (BUF_LEN + ilen > bf->limit_len) { | |
| i = bf->limit_len - BUF_LEN; | |
| for (ilen = (p - str); ilen < i; ilen++) { | |
| - if (IsDBCSLeadByte((BYTE)*(str + ilen)) == TRUE || | |
| + if (IS_LEAD_TBYTE((TBYTE)*(str + ilen)) == TRUE || | |
| (*(str + ilen) == TEXT('\r') && *(str + ilen + 1) == TEXT('\n'))) { | |
| if (ilen + 1 >= i) { | |
| break; | |
| @@ -1119,7 +1127,7 @@ static BOOL string_insert(const HWND hWnd, BUFFER *bf, TCHAR *str, const int len | |
| } | |
| break; | |
| } | |
| - if (IsDBCSLeadByte((BYTE)*p) == TRUE && (int)(p - str) < ilen) { | |
| + if (IS_LEAD_TBYTE((TBYTE)*p) == TRUE && (int)(p - str) < ilen) { | |
| if (is_lead_byte(bf, index_to_char(bf, i)) == TRUE) { | |
| // 2バイトコードに2バイトの上書き | |
| i++; | |
| @@ -1186,7 +1194,7 @@ static BOOL string_insert(const HWND hWnd, BUFFER *bf, TCHAR *str, const int len | |
| if (is_lead_byte(bf, bf->ip + bf->ip_len + ip_len) == TRUE) { | |
| ip_len++; | |
| } | |
| - if (IsDBCSLeadByte((BYTE)*p) == TRUE && (p - str) < ilen) { | |
| + if (IS_LEAD_TBYTE((TBYTE)*p) == TRUE && (p - str) < ilen) { | |
| p++; | |
| } | |
| } | |
| @@ -1299,11 +1307,9 @@ static void string_delete_char(const HWND hWnd, BUFFER *bf, DWORD st) | |
| bf->sp = bf->cp; | |
| } else { | |
| // 一文字削除 | |
| -#ifndef UNICODE | |
| if (is_lead_byte(bf, index_to_char(bf, st)) == TRUE) { | |
| i++; | |
| } | |
| -#endif | |
| if (*(index_to_char(bf, st)) == TEXT('\r') && *(index_to_char(bf, st + 1)) == TEXT('\n')) { | |
| i++; | |
| } | |
| @@ -1563,12 +1569,10 @@ static void draw_line(const HWND hWnd, const HDC mdc, BUFFER *bf, const int i, c | |
| s = char_next(bf, p); | |
| continue; | |
| } | |
| -#ifndef UNICODE | |
| if (is_lead_byte(bf, p) == TRUE && char_next(bf, p) == (p + 1)) { | |
| p = char_next(bf, p); | |
| j++; | |
| } | |
| -#endif | |
| } | |
| if (s != p && bf->ip != NULL && (p == bf->ip + bf->ip_len || p == bf->input_buf)) { | |
| r = (p == bf->input_buf) ? bf->ip : (bf->input_buf + bf->input_len); | |
| @@ -1642,12 +1646,10 @@ static int caret_char_to_caret(const HDC mdc, BUFFER *bf, const int i, const DWO | |
| s = char_next(bf, p); | |
| continue; | |
| } | |
| -#ifndef UNICODE | |
| if (is_lead_byte(bf, p) == TRUE) { | |
| p = char_next(bf, p); | |
| j++; | |
| } | |
| -#endif | |
| } | |
| if (s != p && bf->ip != NULL && (p == bf->ip + bf->ip_len || p == bf->input_buf)) { | |
| r = (p == bf->input_buf) ? bf->ip : (bf->input_buf + bf->input_len); | |
| @@ -1889,12 +1891,10 @@ static void caret_move(const HWND hWnd, BUFFER *bf, const int key) | |
| if (*p == TEXT('\r') || *p == TEXT('\n')) { | |
| break; | |
| } | |
| -#ifndef UNICODE | |
| if (is_lead_byte(bf, p) == TRUE) { | |
| p = char_next(bf, p); | |
| j++; | |
| } | |
| -#endif | |
| } | |
| bf->cp = t; | |
| break; | |
| @@ -1918,15 +1918,11 @@ static void caret_move(const HWND hWnd, BUFFER *bf, const int key) | |
| } else if (*(index_to_char(bf, bf->cp)) == TEXT('\r') || *(index_to_char(bf, bf->cp)) == TEXT('\n')) { | |
| bf->cp++; | |
| } else { | |
| -#ifdef UNICODE | |
| - bf->cp++; | |
| -#else | |
| if (is_lead_byte(bf, index_to_char(bf, bf->cp)) == TRUE) { | |
| bf->cp += 2; | |
| } else { | |
| bf->cp++; | |
| } | |
| -#endif | |
| } | |
| break; | |
| } | |
| -- | |
| 2.5.1 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| From e0046b782f3625e02ff2006de3af5108d002a943 Mon Sep 17 00:00:00 2001 | |
| From: "K.Takata" <[email protected]> | |
| Date: Sat, 5 Sep 2015 21:11:28 +0900 | |
| Subject: [PATCH 3/4] Retry five times when adding an icon to the task tray | |
| --- | |
| main.c | 9 ++++++++- | |
| 1 file changed, 8 insertions(+), 1 deletion(-) | |
| diff --git a/main.c b/main.c | |
| index 5fd9f41..4ed217f 100644 | |
| --- a/main.c | |
| +++ b/main.c | |
| @@ -409,7 +409,14 @@ static void set_tray_icon(const HWND hWnd, const HICON hIcon, const TCHAR *buf) | |
| } | |
| if (tray_message(hWnd, NIM_MODIFY, TRAY_ID, hIcon, buf) == FALSE) { | |
| // 変更できなかった場合は追加を行う | |
| - tray_message(hWnd, NIM_ADD, TRAY_ID, hIcon, buf); | |
| + int i; | |
| + for (i = 0; i < 5; i++) { | |
| + // 追加できなかった場合はリトライする | |
| + if (tray_message(hWnd, NIM_ADD, TRAY_ID, hIcon, buf)) { | |
| + break; | |
| + } | |
| + Sleep(5000); | |
| + } | |
| } | |
| } | |
| -- | |
| 2.5.1 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| From bd262b20677be5e26c8d3f392714bdc667002b3b Mon Sep 17 00:00:00 2001 | |
| From: "K.Takata" <[email protected]> | |
| Date: Sat, 5 Sep 2015 21:14:21 +0900 | |
| Subject: [PATCH 4/4] Add an icon to the task tray when Explorer is restarted | |
| --- | |
| main.c | 5 +++++ | |
| 1 file changed, 5 insertions(+) | |
| diff --git a/main.c b/main.c | |
| index 4ed217f..0900bf3 100644 | |
| --- a/main.c | |
| +++ b/main.c | |
| @@ -1348,10 +1348,12 @@ static LRESULT CALLBACK main_proc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lPa | |
| static int key_cnt, key_flag; | |
| static UINT prev_key; | |
| static BOOL save_flag = FALSE; | |
| + static UINT WM_TASKBARCREATED; | |
| switch (msg) { | |
| case WM_CREATE: | |
| // ƒEƒBƒ“ƒhƒEì¬ | |
| + WM_TASKBARCREATED = RegisterWindowMessage(TEXT("TaskbarCreated")); | |
| if (winodw_initialize(hWnd) == FALSE) { | |
| return -1; | |
| } | |
| @@ -2090,6 +2092,9 @@ static LRESULT CALLBACK main_proc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lPa | |
| return FALSE; | |
| default: | |
| + if (msg == WM_TASKBARCREATED) { | |
| + set_tray_icon(hWnd, icon_tray, MAIN_WINDOW_TITLE); | |
| + } | |
| return DefWindowProc(hWnd, msg, wParam, lParam); | |
| } | |
| return 0; | |
| -- | |
| 2.5.1 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment