From: Alexander Wilms <f.alexander.wilms@outlook.com> --- programs/winecfg/resource.h | 6 ++ programs/winecfg/theme.c | 185 +++++++++++++++++++++++++++++------- programs/winecfg/winecfg.rc | 51 +++++----- 3 files changed, 186 insertions(+), 56 deletions(-) diff --git a/programs/winecfg/resource.h b/programs/winecfg/resource.h index b7b237221b0..0d900f31566 100644 --- a/programs/winecfg/resource.h +++ b/programs/winecfg/resource.h @@ -45,6 +45,9 @@ #define IDS_SHELL_FOLDER 16 #define IDS_LINKS_TO 17 #define IDS_WINECFG_TITLE_APP 18 /* App specific title */ +#define IDS_FILEDIALOG_PORTAL_AUTO 19 +#define IDS_FILEDIALOG_PORTAL_ALWAYS 20 +#define IDS_FILEDIALOG_PORTAL_NEVER 21 #define IDI_WINECFG 100 #define IDI_LOGO 102 #define IDD_ABOUTCFG 107 @@ -180,6 +183,9 @@ #define IDC_SYSPARAM_COLOR 1419 #define IDC_SYSPARAM_FONT 1420 #define IDC_ENABLE_FILE_ASSOCIATIONS 1421 +#define IDC_FILEDIALOG_PORTAL 1422 +#define IDC_FILEDIALOG_GROUP 1423 +#define IDC_FILEDIALOG_PORTAL_LABEL 1424 #define IDC_SYSPARAMS_BUTTON 8400 #define IDC_SYSPARAMS_BUTTON_TEXT 8401 diff --git a/programs/winecfg/theme.c b/programs/winecfg/theme.c index cc1a3c66820..1172f69ddbb 100644 --- a/programs/winecfg/theme.c +++ b/programs/winecfg/theme.c @@ -31,6 +31,7 @@ #include <windows.h> #include <commdlg.h> #include <shellapi.h> +#include <shobjidl.h> #include <uxtheme.h> #include <tmschema.h> #include <shlobj.h> @@ -485,6 +486,89 @@ static void update_dialog (HWND dialog) updating_ui = FALSE; } +static void init_portal_file_dialog(HWND dialog) +{ + static const UINT portal_mode_ids[] = + { + IDS_FILEDIALOG_PORTAL_AUTO, + IDS_FILEDIALOG_PORTAL_ALWAYS, + IDS_FILEDIALOG_PORTAL_NEVER, + }; + WCHAR mode_text[64]; + WCHAR *buf; + int i, mode = 0; + + SendDlgItemMessageW(dialog, IDC_FILEDIALOG_PORTAL, CB_RESETCONTENT, 0, 0); + for (i = 0; i < ARRAY_SIZE(portal_mode_ids); i++) + if (LoadStringW(GetModuleHandleW(NULL), portal_mode_ids[i], mode_text, ARRAY_SIZE(mode_text))) + SendDlgItemMessageW(dialog, IDC_FILEDIALOG_PORTAL, CB_ADDSTRING, 0, (LPARAM)mode_text); + + buf = get_reg_key(config_key, keypath(L"X11 Driver"), L"FileDialogPortal", L"auto"); + if (buf) + { + if (!wcscmp(buf, L"always")) + mode = 1; + else if (!wcscmp(buf, L"never")) + mode = 2; + free(buf); + } + + SendDlgItemMessageW(dialog, IDC_FILEDIALOG_PORTAL, CB_SETCURSEL, mode, 0); +} + +static BOOL show_portal_file_dialog_policy(void) +{ + WCHAR key[sizeof("System\\CurrentControlSet\\Control\\Video\\{}\\0000") + 40]; + WCHAR *driver; + UINT guid_atom; + BOOL show; + + show = TRUE; + + guid_atom = HandleToULong(GetPropW(GetDesktopWindow(), L"__wine_display_device_guid")); + if (guid_atom) + { + wcscpy(key, L"System\\CurrentControlSet\\Control\\Video\\{"); + if (GlobalGetAtomNameW(guid_atom, key + wcslen(key), 40)) + { + wcscat(key, L"}\\0000"); + if ((driver = get_reg_key(HKEY_LOCAL_MACHINE, key, L"GraphicsDriver", NULL))) + { + if (!wcscmp(driver, L"winemac.drv")) + show = FALSE; + free(driver); + } + } + } + + return show; +} + +static void update_portal_file_dialog_ui(HWND dialog) +{ + BOOL show = show_portal_file_dialog_policy(); + INT cmd = show ? SW_SHOW : SW_HIDE; + + ShowWindow(GetDlgItem(dialog, IDC_FILEDIALOG_GROUP), cmd); + ShowWindow(GetDlgItem(dialog, IDC_FILEDIALOG_PORTAL_LABEL), cmd); + ShowWindow(GetDlgItem(dialog, IDC_FILEDIALOG_PORTAL), cmd); + + if (show) + init_portal_file_dialog(dialog); +} + +static void on_portal_file_dialog_changed(HWND dialog) +{ + static const WCHAR *values[] = { L"auto", L"always", L"never" }; + int sel; + + if (updating_ui) return; + + sel = SendDlgItemMessageW(dialog, IDC_FILEDIALOG_PORTAL, CB_GETCURSEL, 0, 0); + if (sel >= 0 && sel < ARRAY_SIZE(values)) + set_reg_key(config_key, keypath(L"X11 Driver"), L"FileDialogPortal", values[sel]); +} + static void on_theme_changed(HWND dialog) { int index; @@ -634,43 +718,73 @@ static void do_parse_theme(WCHAR *file) free(keyName); } +static BOOL pick_theme_file(HWND dialog, WCHAR *path, size_t path_len) +{ + COMDLG_FILTERSPEC filters[] = + { + { L"Theme files", L"*.msstyles;*.theme" }, + { L"All files", L"*.*" } + }; + IFileOpenDialog *fod = NULL; + IShellItem *item = NULL; + WCHAR title[100]; + HRESULT hr; + BOOL ret = FALSE; + + if (!path || !path_len) return FALSE; + path[0] = 0; + + LoadStringW(GetModuleHandleW(NULL), IDS_THEMEFILE_SELECT, title, ARRAY_SIZE(title)); + + hr = CoCreateInstance(&CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER, + &IID_IFileOpenDialog, (void **)&fod); + if (FAILED(hr)) goto done; + + hr = IFileOpenDialog_SetFileTypes(fod, ARRAY_SIZE(filters), filters); + if (FAILED(hr)) goto done; + hr = IFileOpenDialog_SetFileTypeIndex(fod, 1); + if (FAILED(hr)) goto done; + + DWORD opts = 0; + if (SUCCEEDED(IFileOpenDialog_GetOptions(fod, &opts))) + { + opts |= FOS_FILEMUSTEXIST | FOS_PATHMUSTEXIST | FOS_FORCEFILESYSTEM; + IFileOpenDialog_SetOptions(fod, opts); + } + + IFileOpenDialog_SetTitle(fod, title); + + hr = IFileOpenDialog_Show(fod, dialog); + if (hr != S_OK) goto done; + + if (FAILED(IFileOpenDialog_GetResult(fod, &item))) goto done; + + { + PWSTR selected = NULL; + hr = IShellItem_GetDisplayName(item, SIGDN_FILESYSPATH, &selected); + if (SUCCEEDED(hr) && selected) + { + lstrcpynW(path, selected, path_len); + CoTaskMemFree(selected); + ret = TRUE; + } + } + +done: + if (item) IShellItem_Release(item); + if (fod) IFileOpenDialog_Release(fod); + return ret; +} + static void on_theme_install(HWND dialog) { - static const WCHAR filterMask[] = L"\0*.msstyles;*.theme\0"; - OPENFILENAMEW ofn; - WCHAR filetitle[MAX_PATH]; WCHAR file[MAX_PATH]; - WCHAR filter[100]; - WCHAR title[100]; - - LoadStringW(GetModuleHandleW(NULL), IDS_THEMEFILE, filter, ARRAY_SIZE(filter) - ARRAY_SIZE(filterMask)); - memcpy(filter + lstrlenW (filter), filterMask, sizeof(filterMask)); - LoadStringW(GetModuleHandleW(NULL), IDS_THEMEFILE_SELECT, title, ARRAY_SIZE(title)); - - ofn.lStructSize = sizeof(OPENFILENAMEW); - ofn.hwndOwner = dialog; - ofn.hInstance = 0; - ofn.lpstrFilter = filter; - ofn.lpstrCustomFilter = NULL; - ofn.nMaxCustFilter = 0; - ofn.nFilterIndex = 0; - ofn.lpstrFile = file; - ofn.lpstrFile[0] = '\0'; - ofn.nMaxFile = ARRAY_SIZE(file); - ofn.lpstrFileTitle = filetitle; - ofn.lpstrFileTitle[0] = '\0'; - ofn.nMaxFileTitle = ARRAY_SIZE(filetitle); - ofn.lpstrInitialDir = NULL; - ofn.lpstrTitle = title; - ofn.Flags = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_ENABLESIZING; - ofn.nFileOffset = 0; - ofn.nFileExtension = 0; - ofn.lpstrDefExt = NULL; - ofn.lCustData = 0; - ofn.lpfnHook = NULL; - ofn.lpTemplateName = NULL; - - if (GetOpenFileNameW(&ofn)) + WCHAR filetitle[MAX_PATH]; + + file[0] = '\0'; + filetitle[0] = '\0'; + + if (pick_theme_file(dialog, file, ARRAY_SIZE(file))) { WCHAR themeFilePath[MAX_PATH]; SHFILEOPSTRUCTW shfop; @@ -685,6 +799,7 @@ static void on_theme_install(HWND dialog) return; } + lstrcpynW(filetitle, PathFindFileNameW(file), ARRAY_SIZE(filetitle)); PathRemoveExtensionW (filetitle); /* Construct path into which the theme file goes */ @@ -1175,6 +1290,7 @@ ThemeDlgProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) update_shell_folder_listview(hDlg); read_sysparams(hDlg); init_mime_types(hDlg); + update_portal_file_dialog_ui(hDlg); init_dialog(hDlg); break; @@ -1197,6 +1313,7 @@ ThemeDlgProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) case IDC_THEME_COLORCOMBO: /* fall through */ case IDC_THEME_SIZECOMBO: theme_dirty = TRUE; break; case IDC_SYSPARAM_COMBO: on_sysparam_change(hDlg); return FALSE; + case IDC_FILEDIALOG_PORTAL: on_portal_file_dialog_changed(hDlg); break; } SendMessageW(GetParent(hDlg), PSM_CHANGED, 0, 0); break; diff --git a/programs/winecfg/winecfg.rc b/programs/winecfg/winecfg.rc index 73a189aa5ed..e567b3bea4d 100644 --- a/programs/winecfg/winecfg.rc +++ b/programs/winecfg/winecfg.rc @@ -45,6 +45,9 @@ BEGIN IDS_THEMEFILE_SELECT "Select a theme file" IDS_SHELL_FOLDER "Folder" IDS_LINKS_TO "Links to" + IDS_FILEDIALOG_PORTAL_AUTO "Use portal when possible" + IDS_FILEDIALOG_PORTAL_ALWAYS "Always use portal" + IDS_FILEDIALOG_PORTAL_NEVER "Never use portal" END STRINGTABLE @@ -170,22 +173,21 @@ IDD_GRAPHCFG DIALOG 0, 0, 260, 220 STYLE WS_CHILD | WS_DISABLED FONT 8, "MS Shell Dlg" BEGIN - GROUPBOX "Window settings",IDC_STATIC,8,4,244,84 - CONTROL "Automatically capture the &mouse in full-screen windows",IDC_FULLSCREEN_GRAB,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,15,20,230,10 - CONTROL "Allow the window manager to &decorate the windows",IDC_ENABLE_DECORATED,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,15,32,230,10 - CONTROL "Allow the &window manager to control the windows",IDC_ENABLE_MANAGED,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,15,44,230,10 - CONTROL "&Emulate a virtual desktop",IDC_ENABLE_DESKTOP,"Button", - BS_AUTOCHECKBOX | WS_TABSTOP,15,56,230,10 - LTEXT "Desktop &size:",IDC_DESKTOP_SIZE,15,70,64,16,WS_DISABLED - LTEXT "#msgctxt#do not translate#X",IDC_DESKTOP_BY,129,70,8,8,WS_DISABLED - EDITTEXT IDC_DESKTOP_WIDTH,84,68,40,12,ES_AUTOHSCROLL | ES_NUMBER | WS_DISABLED - EDITTEXT IDC_DESKTOP_HEIGHT,137,68,40,12,ES_AUTOHSCROLL | ES_NUMBER | WS_DISABLED - - GROUPBOX "Screen resolution",IDC_STATIC,8,95,244,84 - CONTROL "", IDC_RES_TRACKBAR, "msctls_trackbar32",WS_TABSTOP,12,105,171,15 - EDITTEXT IDC_RES_DPIEDIT,188,105,23,13,ES_NUMBER|WS_TABSTOP - LTEXT "#msgctxt#unit: dots/inch#dpi",IDC_STATIC,215,107,30,8 - LTEXT "This is a sample text using 10 point Tahoma",IDC_RES_FONT_PREVIEW,15,124,230,49 + GROUPBOX "Window settings",IDC_STATIC,8,4,244,84 + CONTROL "Automatically capture the &mouse in full-screen windows",IDC_FULLSCREEN_GRAB,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,15,20,230,10 + CONTROL "Allow the window manager to &decorate the windows",IDC_ENABLE_DECORATED,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,15,32,230,10 + CONTROL "Allow the &window manager to control the windows",IDC_ENABLE_MANAGED,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,15,44,230,10 + CONTROL "&Emulate a virtual desktop",IDC_ENABLE_DESKTOP,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,15,56,230,10 + LTEXT "Desktop &size:",IDC_DESKTOP_SIZE,15,70,64,16,WS_DISABLED + LTEXT "#msgctxt#do not translate#X",IDC_DESKTOP_BY,129,70,8,8,WS_DISABLED + EDITTEXT IDC_DESKTOP_WIDTH,84,68,40,12,ES_AUTOHSCROLL | ES_NUMBER | WS_DISABLED + EDITTEXT IDC_DESKTOP_HEIGHT,137,68,40,12,ES_AUTOHSCROLL | ES_NUMBER | WS_DISABLED + + GROUPBOX "Screen resolution",IDC_STATIC,8,95,244,84 + CONTROL "", IDC_RES_TRACKBAR, "msctls_trackbar32",WS_TABSTOP,12,105,171,15 + EDITTEXT IDC_RES_DPIEDIT,188,105,23,13,ES_NUMBER|WS_TABSTOP + LTEXT "#msgctxt#unit: dots/inch#dpi",IDC_STATIC,215,107,30,8 + LTEXT "This is a sample text using 10 point Tahoma",IDC_RES_FONT_PREVIEW,15,124,230,49 END IDD_DLLCFG DIALOG 0, 0, 260, 220 @@ -286,7 +288,7 @@ BEGIN COMBOBOX IDC_SPEAKERCONFIG_SPEAKERS,110,200,135,60,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP END -IDD_DESKTOP_INTEGRATION DIALOG 0, 0, 260, 220 +IDD_DESKTOP_INTEGRATION DIALOG 0, 0, 260, 258 STYLE WS_CHILD | WS_DISABLED FONT 8, "MS Shell Dlg" BEGIN @@ -312,12 +314,17 @@ BEGIN CONTROL "Manage file and protocol &associations",IDC_ENABLE_FILE_ASSOCIATIONS,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,15,105,230,10 PUSHBUTTON "&Font...",IDC_SYSPARAM_FONT,190,75,55,13,WS_DISABLED - GROUPBOX "Folders",IDC_STATIC,8,120,244,94 + + GROUPBOX "Folders",IDC_STATIC,8,122,244,92 CONTROL "",IDC_LIST_SFPATHS,"SysListView32",LVS_REPORT | LVS_AUTOARRANGE | LVS_ALIGNLEFT | - LVS_SINGLESEL | WS_BORDER | WS_TABSTOP, 15,132,230,58 - CONTROL "&Link to:",IDC_LINK_SFPATH,"Button",BS_AUTOCHECKBOX|WS_TABSTOP|WS_DISABLED,15,195,65,13 - EDITTEXT IDC_EDIT_SFPATH,80,195,110,13,ES_AUTOHSCROLL|WS_TABSTOP|WS_DISABLED - PUSHBUTTON "B&rowse...",IDC_BROWSE_SFPATH,195,195,50,13,WS_DISABLED + LVS_SINGLESEL | WS_BORDER | WS_TABSTOP, 15,134,230,50 + CONTROL "&Link to:",IDC_LINK_SFPATH,"Button",BS_AUTOCHECKBOX|WS_TABSTOP|WS_DISABLED,15,196,65,13 + EDITTEXT IDC_EDIT_SFPATH,80,196,110,13,ES_AUTOHSCROLL|WS_TABSTOP|WS_DISABLED + PUSHBUTTON "B&rowse...",IDC_BROWSE_SFPATH,195,196,50,13,WS_DISABLED + + GROUPBOX "File dialogs",IDC_FILEDIALOG_GROUP,8,216,244,28 + LTEXT "XDG Desktop Portal &policy:",IDC_FILEDIALOG_PORTAL_LABEL,15,228,90,8 + COMBOBOX IDC_FILEDIALOG_PORTAL,110,226,135,14,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP END LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/10060