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

Update window title with (on <client_machine>) if client is remote #790

Open
wants to merge 2 commits into
base: icewm-1-4-BRANCH
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/wmtitle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,12 @@ void YFrameTitleBar::paint(Graphics &g, const YRect &/*r*/) {
}

mstring title = getFrame()->getTitle();
char *client_machine = getFrame()->client()->fetchClientMachine();
if (client_machine != nullptr && strncmp(client_machine, xapp->getLocalHostname(), strlen(client_machine)) != 0) {
title = title + " (on " + client_machine + ")";
free(client_machine);
}

int const fontHeight = titleFont ? titleFont->height() : 8;
int const fontAscent = titleFont ? titleFont->ascent() : 6;
int const yPos(int(height() - fontHeight) / 2 +
Expand Down
12 changes: 12 additions & 0 deletions src/ywindow.cc
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,18 @@ bool YWindow::fetchTitle(char** title) {
return XFetchName(xapp->display(), handle(), title);
}

char* YWindow::fetchClientMachine() {
XTextProperty prop;
int ret = XGetTextProperty(xapp->display(), handle(), &prop, XA_WM_CLIENT_MACHINE);
if (ret) {
char *retval = (char *)malloc(sizeof(char)*prop.nitems + 1);
strncpy(retval, (const char *)prop.value, prop.nitems + 1);
XFree(prop.value);
return retval;
}
return nullptr;
}

void YWindow::setClassHint(char const * rName, char const * rClass) {
XClassHint wmclass;
wmclass.res_name = const_cast<char *>(rName);
Expand Down
1 change: 1 addition & 0 deletions src/ywindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ class YWindow : protected YWindowList, private YWindowNode {
void setWindowFocus(Time timestamp = CurrentTime);

bool fetchTitle(char** title);
char* fetchClientMachine();
void setTitle(char const * title);
void setClassHint(char const * rName, char const * rClass);

Expand Down
11 changes: 11 additions & 0 deletions src/yxapp.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "ywindow.h"
#include "ycursor.h"
#include <X11/Xutil.h>
#include <unistd.h>

#define KEY_MODMASK(x) ((x) & (xapp->KeyMask))

Expand Down Expand Up @@ -102,6 +103,16 @@ class YXApplication: public YApplication {
YXApplication(int *argc, char ***argv, const char *displayName = nullptr);
virtual ~YXApplication();

char localHostname[256] = {};
char * getLocalHostname() {
if (localHostname[0] == 0) {
gethostname(localHostname, sizeof(localHostname));
}

return localHostname;
}


Display * display() const { return fDisplay; }
int screen() const { return fScreen; }
Window root() const { return fRoot; }
Expand Down