Skip to content

Commit

Permalink
add support for processname (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
prabirshrestha committed Nov 10, 2021
1 parent f0a8d7b commit ae50de2
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 39 deletions.
37 changes: 18 additions & 19 deletions config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,24 @@ static const wchar_t tags[][MAXTAGLEN] = { L"1", L"2", L"3", L"4", L"5", L"6", L
static unsigned int tagset[] = {1, 1}; /* after start, first tag is selected */

static Rule rules[] = {
/* class title tags mask isfloating ignoreborder */
{ L"MultitaskingViewFrame", NULL, 0, true, true },
{ L"MSCTFIME UI", NULL, 0, true, true },
{ L"Microsoft-Windows-SnipperToolbar", L"Snipping Tool", 0, true, true },
{ L"Microsoft Text Input Application", NULL, 0, true, true },
{ L"MSO_BORDEREFFECT_WINDOW_CLASS", NULL, 0, true, true },
{ L"CASCADIA_HOSTING_WINDOW_CLASS", NULL, 0, false, true },
{ L"ThumbnailDeviceHelperWnd", NULL, 0, true, true },
{ L"EdgeUiInputTopWndClass", NULL, 0, true, true },
{ L"CabinetWClass", NULL, 0, false, true }, /* file explorer */
{ L"OperationStatusWindow", NULL, 0, false, true }, /* explorer copy window */
{ L"XLMAIN", NULL, 0, false, true }, /* Excel */
{ NULL, L"MSO_BORDEREFFECT_WINDOW_CLASS", 0, false, true }, /* Excel */
{ L"PPTFrameClass", NULL, 0, false, true }, /* PowerPoint */
{ L"OpusApp", NULL, 0, false, true }, /* Word */
{ NULL, L"OneNote", 0, false, true }, /* OneNote */
{ NULL, L"Snip & Sketch", 0, true, true },
{ L"Chrome_WidgetWin_1", L"Google Chrome", 0, false, true },
{ NULL, L"vimrun.exe", 0, true, true },
/* class title processname tags mask isfloating ignoreborder */
{ L"MultitaskingViewFrame", NULL, NULL, 0, true, true },
{ L"MSCTFIME UI", NULL, NULL, 0, true, true },
{ L"Microsoft-Windows-SnipperToolbar", L"Snipping Tool", NULL, 0, true, true },
{ L"Microsoft Text Input Application", NULL, NULL, 0, true, true },
{ L"MSO_BORDEREFFECT_WINDOW_CLASS", NULL, NULL, 0, true, true },
{ L"CASCADIA_HOSTING_WINDOW_CLASS", NULL, NULL, 0, false, true },
{ L"ThumbnailDeviceHelperWnd", NULL, NULL, 0, true, true },
{ L"EdgeUiInputTopWndClass", NULL, NULL, 0, true, true },
{ L"CabinetWClass", NULL, NULL, 0, false, true }, /* file explorer */
{ L"OperationStatusWindow", NULL, NULL, 0, false, true }, /* explorer copy window */
{ NULL, NULL, L"EXCEL.EXE", 1, false, true }, /* Excel */
{ L"PPTFrameClass", NULL, NULL, 0, false, true }, /* PowerPoint */
{ L"OpusApp", NULL, NULL, 0, false, true }, /* Word */
{ NULL, L"OneNote", NULL, 0, false, true }, /* OneNote */
{ NULL, L"Snip & Sketch", NULL, 0, true, true },
{ L"Chrome_WidgetWin_1", L"Google Chrome", NULL, 0, false, true },
{ NULL, L"vimrun.exe", NULL, 0, true, true },
};

/* layout(s) */
Expand Down
46 changes: 26 additions & 20 deletions src/dwm-win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@

#define die(...) if (TRUE) { eprint(true, __VA_ARGS__); eprint(true, L"Win32 Last Error: %d", GetLastError()); cleanup(NULL); exit(EXIT_FAILURE); }


#define EVENT_OBJECT_CLOAKED 0x8017
#define EVENT_OBJECT_UNCLOAKED 0x8018

Expand Down Expand Up @@ -105,9 +104,6 @@ struct Client {
HWND hwnd;
HWND parent;
HWND root;
DWORD threadid;
DWORD processid;
const wchar_t *processname;
int x, y, w, h;
int bw; // XXX: useless?
unsigned int tags;
Expand Down Expand Up @@ -139,6 +135,7 @@ typedef struct {
typedef struct {
const wchar_t *class;
const wchar_t *title;
const wchar_t *processname;
unsigned int tags;
bool isfloating;
bool ignoreborder;
Expand All @@ -164,6 +161,7 @@ static void movestack(const Arg *arg);
static Client *getclient(HWND hwnd);
LPWSTR getclientclassname(HWND hwnd);
LPWSTR getclienttitle(HWND hwnd);
LPWSTR getclientprocessname(HWND hwnd);
HWND getroot(HWND hwnd);
static void grabkeys(HWND hwnd);
static void killclient(const Arg *arg);
Expand Down Expand Up @@ -241,7 +239,8 @@ applyrules(Client *c) {
for (i = 0; i < LENGTH(rules); i++) {
r = &rules[i];
if ((!r->title || wcsstr(getclienttitle(c->hwnd), r->title))
&& (!r->class || wcsstr(getclientclassname(c->hwnd), r->class))) {
&& (!r->class || wcsstr(getclientclassname(c->hwnd), r->class))
&& (!r->processname || wcsstr(getclientprocessname(c->hwnd), r->processname))) {
c->isfloating = r->isfloating;
c->ignoreborder = r->ignoreborder;
c->tags |= r->tags & TAGMASK ? r->tags & TAGMASK : tagset[seltags];
Expand Down Expand Up @@ -640,6 +639,25 @@ getclienttitle(HWND hwnd) {
return buf;
}

LPWSTR
getclientprocessname(HWND hwnd) {
DWORD processid = 0;
DWORD buf_size = MAX_PATH;
static wchar_t buf[MAX_PATH];
GetWindowThreadProcessId(hwnd, &processid);
HANDLE hProc = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, processid);
if (hProc) {
if (QueryFullProcessImageNameW(hProc, 0, buf, &buf_size)) {
CloseHandle(hProc);
return buf;
} else {
CloseHandle(hProc);
}
}
return NULL;
}


HWND
getroot(HWND hwnd) {
HWND parent, deskwnd = GetDesktopWindow();
Expand Down Expand Up @@ -803,24 +821,11 @@ manage(HWND hwnd) {
die(L"fatal: could not calloc() %u bytes for new client\n", sizeof(Client));

c->hwnd = hwnd;
c->threadid = GetWindowThreadProcessId(hwnd, NULL);
c->parent = GetParent(hwnd);
c->root = getroot(hwnd);
c->isalive = true;
c->processname = L"";
c->iscloaked = iscloaked(hwnd);

GetWindowThreadProcessId(hwnd, &c->processid);
HANDLE hProc = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, c->processid);
if (hProc) {
DWORD buf_size = MAX_PATH;
wchar_t buf[MAX_PATH];
if (QueryFullProcessImageNameW(hProc, 0, buf, &buf_size)) {
c->processname = buf;
}
CloseHandle(hProc);
}

static WINDOWPLACEMENT wp = {
.length = sizeof(WINDOWPLACEMENT),
.showCmd = SW_RESTORE,
Expand Down Expand Up @@ -942,6 +947,7 @@ LRESULT CALLBACK barhandler(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
}


int i = 0;

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
Expand Down Expand Up @@ -1324,8 +1330,8 @@ void
showclientinfo(const Arg *arg) {
HWND hwnd = GetForegroundWindow();
wchar_t buffer[5000];
swprintf(buffer, sizeof(buffer), L"ClassName: %s\nTitle: %s", getclientclassname(hwnd), getclienttitle(hwnd));
MessageBoxW(NULL, buffer, L"Window class", MB_OK);
swprintf(buffer, sizeof(buffer), L"ClassName: %s\nTitle: %s\nProcessName: %s", getclientclassname(hwnd), getclienttitle(hwnd), getclientprocessname(hwnd));
MessageBoxW(NULL, buffer, L"dwm-win32 debug", MB_OK);
}

void
Expand Down

0 comments on commit ae50de2

Please sign in to comment.