Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add rules #513

Merged
merged 19 commits into from Feb 4, 2022
Merged

feat: add rules #513

merged 19 commits into from Feb 4, 2022

Conversation

amrbashir
Copy link
Contributor

@amrbashir amrbashir commented Dec 30, 2021

The goal of this PR is to customize TTB behavior with rules, for example:

"maximized_window_appearance": {
	"enabled": true,
	"accent": "blur",
	"color": "#00000000",
	"show_peek": true,
	"rules": [
		{
			"process_name": "discord.exe",
			"color": "#1f1f1f",
			"accent": "opaque"
		},
		{
			"window_title": "VLC Media Player",
			"color": "#1f1f1f",
			"accent": "normal"
		}
	]
}

@amrbashir amrbashir changed the base branch from release to develop December 30, 2021 09:46
@amrbashir amrbashir marked this pull request as ready for review December 31, 2021 09:06
@amrbashir
Copy link
Contributor Author

@sylveon I am sorry to ping you but does this PR need anything to move forwards?

@sylveon
Copy link
Member

sylveon commented Jan 25, 2022

No, there isn't anything needed on your part. I've been busy with school starting up again, but will try to look at it this weekend.

@amrbashir
Copy link
Contributor Author

No, there isn't anything needed on your part. I've been busy with school starting up again, but will try to look at it this weekend.

No problem. Take care of yourself and your study. I just have some free time and wanted to work on this if there is any thing holding it back.

Copy link
Member

@sylveon sylveon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks pretty decent overall. I would suggest getting rid of Rule and instead storing something similar to WindowFilter:

std::unordered_map<std::wstring, TaskbarAppearance> m_ClassRules;
std::unordered_map<std::wstring, TaskbarAppearance> m_TitleRules;
win32::FilenameMap<TaskbarAppearance> m_FileRules;

because it will allow more efficient lookup, and also prevents the user having rules based on process name that differ only by case (and allows the case insensitive lookup to be a simple m_FileRules.find(windowFileName))

Also, you have to handle the case where settings are changed from the context menu - right now it wipes the rules when that happens. It can just be a temporary workaround for now, as I plan to add a GUI to add exclusions, so I'll be able to properly cover rules with that as well.

Common/config/config.hpp Outdated Show resolved Hide resolved
TranslucentTB/taskbar/taskbarattributeworker.cpp Outdated Show resolved Hide resolved
Common/config/optionaltaskbarappearance.hpp Outdated Show resolved Hide resolved
Common/config/optionaltaskbarappearance.hpp Outdated Show resolved Hide resolved
TranslucentTB/taskbar/taskbarattributeworker.cpp Outdated Show resolved Hide resolved
Common/config/ruledtaskbarappearance.hpp Outdated Show resolved Hide resolved
Common/config/ruledtaskbarappearance.hpp Outdated Show resolved Hide resolved
Common/config/ruledtaskbarappearance.hpp Outdated Show resolved Hide resolved
Common/config/ruledtaskbarappearance.hpp Outdated Show resolved Hide resolved
Common/config/ruledtaskbarappearance.hpp Outdated Show resolved Hide resolved
@amrbashir
Copy link
Contributor Author

amrbashir commented Jan 31, 2022

Looks pretty decent overall. I would suggest getting rid of Rule and instead storing something similar to WindowFilter:

std::unordered_map<std::wstring, TaskbarAppearance> m_ClassRules;
std::unordered_map<std::wstring, TaskbarAppearance> m_TitleRules;
win32::FilenameMap<TaskbarAppearance> m_FileRules;

because it will allow more efficient lookup, and also prevents the user having rules based on process name that differ only by case (and allows the case insensitive lookup to be a simple m_FileRules.find(windowFileName))

sorry, how would the json representation of this look like? I am having a hard time visualizing this.

Also, you have to handle the case where settings are changed from the context menu - right now it wipes the rules when that happens.

can't really find this, where is the logic of the save?

@sylveon
Copy link
Member

sylveon commented Feb 2, 2022

sorry, how would the json representation of this look like? I am having a hard time visualizing this.

The representation in JSON can stay the same, what I was thinking is changing the internal representation.

can't really find this, where is the logic of the save?

It's here, but apparently it does already work fine, so there is nothing to actually change, my bad.

static_cast<OptionalTaskbarAppearance &>(config) = optAppearance;

@amrbashir
Copy link
Contributor Author

sorry, how would the json representation of this look like? I am having a hard time visualizing this.

The representation in JSON can stay the same, what I was thinking is changing the internal representation.

Not sure if that is possible, with std::unorderd_map<std::wstring, TaskbarAppearance>, I think it will be serialized to this JSON

"maximisez_window_appearance": {
	...
	"rules": {
		"window_class": {
			"some_window_class": {
				"color": "#1f1f1f",
				...
			},
			"other_window_class": {
				"color": "#1c1c1c",
				...
			}
		}
		"window_title":  {
			"some_title": {
				"color": "#00000",
				...
			}
		}
	}
}

@amrbashir
Copy link
Contributor Author

amrbashir commented Feb 3, 2022

I pushed a commit with the unorder_map approach, it compiles fine but fails at runtime.
I tried stepping with the debugger and it failed here

for (const Window window : Window::FindEnum())
{
InsertWindow(window, false);
}

I didn't touch this part and I don't know why it is failing.

Edit: here is the output

'TranslucentTB.exe' (Win32): Loaded 'D:\dev\TranslucentTB\AppPackage\bin\x64\Debug\AppX\TranslucentTB.exe'. Symbols loaded.
'TranslucentTB.exe' (Win32): Loaded 'C:\Windows\System32\ntdll.dll'. 
'TranslucentTB.exe' (Win32): Loaded 'C:\Windows\System32\kernel32.dll'. 
'TranslucentTB.exe' (Win32): Loaded 'C:\Windows\System32\KernelBase.dll'. 
'TranslucentTB.exe' (Win32): Loaded 'C:\Windows\System32\advapi32.dll'. 
'TranslucentTB.exe' (Win32): Loaded 'C:\Windows\System32\msvcrt.dll'. 
'TranslucentTB.exe' (Win32): Loaded 'C:\Windows\System32\sechost.dll'. 
'TranslucentTB.exe' (Win32): Loaded 'C:\Windows\System32\rpcrt4.dll'. 
'TranslucentTB.exe' (Win32): Loaded 'C:\Windows\System32\gdi32.dll'. 
'TranslucentTB.exe' (Win32): Loaded 'C:\Windows\System32\win32u.dll'. 
'TranslucentTB.exe' (Win32): Loaded 'C:\Windows\System32\gdi32full.dll'. 
'TranslucentTB.exe' (Win32): Loaded 'C:\Windows\System32\msvcp_win.dll'. 
'TranslucentTB.exe' (Win32): Loaded 'C:\Windows\System32\ucrtbase.dll'. 
'TranslucentTB.exe' (Win32): Loaded 'C:\Windows\System32\user32.dll'. 
'TranslucentTB.exe' (Win32): Loaded 'C:\Windows\System32\combase.dll'. 
'TranslucentTB.exe' (Win32): Loaded 'C:\Windows\System32\SHCore.dll'. 
'TranslucentTB.exe' (Win32): Loaded 'C:\Windows\System32\shell32.dll'. 
'TranslucentTB.exe' (Win32): Loaded 'C:\Windows\System32\shlwapi.dll'. 
'TranslucentTB.exe' (Win32): Loaded 'C:\Windows\System32\oleaut32.dll'. 
'TranslucentTB.exe' (Win32): Loaded 'C:\Windows\WinSxS\amd64_microsoft.windows.common-controls_6595b64144ccf1df_6.0.22000.120_none_9d947278b86cc467\comctl32.dll'. 
'TranslucentTB.exe' (Win32): Loaded 'C:\Windows\System32\CoreMessaging.dll'. 
'TranslucentTB.exe' (Win32): Loaded 'C:\Windows\System32\dwmapi.dll'. 
'TranslucentTB.exe' (Win32): Loaded 'D:\dev\TranslucentTB\AppPackage\bin\x64\Debug\AppX\ProgramLog.dll'. Symbols loaded.
'TranslucentTB.exe' (Win32): Loaded 'C:\Windows\System32\ole32.dll'. 
'TranslucentTB.exe' (Win32): Loaded 'C:\Program Files\WindowsApps\Microsoft.VCLibs.140.00.Debug.UWPDesktop_14.0.30704.0_x64__8wekyb3d8bbwe\msvcp140d.dll'. 
'TranslucentTB.exe' (Win32): Loaded 'C:\Program Files\WindowsApps\Microsoft.VCLibs.140.00.Debug.UWPDesktop_14.0.30704.0_x64__8wekyb3d8bbwe\msvcp140d_atomic_wait.dll'. 
'TranslucentTB.exe' (Win32): Loaded 'C:\Program Files\WindowsApps\Microsoft.VCLibs.140.00.Debug.UWPDesktop_14.0.30704.0_x64__8wekyb3d8bbwe\vcruntime140d.dll'. 
'TranslucentTB.exe' (Win32): Loaded 'C:\Program Files\WindowsApps\Microsoft.VCLibs.140.00.Debug.UWPDesktop_14.0.30704.0_x64__8wekyb3d8bbwe\vcruntime140_1d.dll'. 
'TranslucentTB.exe' (Win32): Loaded 'C:\Windows\System32\ucrtbased.dll'. 
'TranslucentTB.exe' (Win32): Loaded 'C:\Windows\System32\imm32.dll'. 
The thread 0x3d20 has exited with code 0 (0x0).
'TranslucentTB.exe' (Win32): Loaded 'C:\Windows\System32\windows.storage.dll'. 
'TranslucentTB.exe' (Win32): Loaded 'C:\Windows\System32\WinTypes.dll'. 
'TranslucentTB.exe' (Win32): Loaded 'C:\Windows\System32\kernel.appcore.dll'. 
'TranslucentTB.exe' (Win32): Loaded 'C:\Windows\System32\bcryptprimitives.dll'. 
'TranslucentTB.exe' (Win32): Loaded 'C:\Windows\System32\uxtheme.dll'. 
'TranslucentTB.exe' (Win32): Loaded 'C:\Windows\System32\msctf.dll'. 
'TranslucentTB.exe' (Win32): Loaded 'C:\Users\amr\AppData\Local\Packages\TranslucentTB_99myrp4edc0yc\TempState\ExplorerHooks.dll'. Symbols loaded.
'TranslucentTB.exe' (Win32): Loaded 'C:\Windows\System32\powrprof.dll'. 
'TranslucentTB.exe' (Win32): Loaded 'C:\Windows\System32\umpdc.dll'. 
'TranslucentTB.exe' (Win32): Loaded 'C:\Windows\System32\clbcatq.dll'. 
'TranslucentTB.exe' (Win32): Loaded 'C:\Windows\System32\twinapi.dll'. 
[2022-02-03 12:23:54.964] [debug] [taskbarattributeworker.cpp:994] Resetting worker state
'TranslucentTB.exe' (Win32): Loaded 'C:\Windows\System32\OneCoreUAPCommonProxyStub.dll'. 
Exception thrown at 0x00007FF7E6618CFF in TranslucentTB.exe: 0xC0000005: Access violation reading location 0x0000121420204010.
Unhandled exception thrown: read access violation.
this->_Vec._Mypair._Myval2.**_Myfirst** was 0x111132521314122.

@sylveon sylveon merged commit 41a55f8 into TranslucentTB:develop Feb 4, 2022
@sylveon
Copy link
Member

sylveon commented Feb 4, 2022

Thanks for the contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants