Full Code of dasJ/spotifywm for AI

master 8624f5395499 cached
4 files
4.5 KB
1.3k tokens
3 symbols
1 requests
Download .txt
Repository: dasJ/spotifywm
Branch: master
Commit: 8624f5395499
Files: 4
Total size: 4.5 KB

Directory structure:
gitextract_e3sarxo0/

├── LICENSE
├── Makefile
├── README.md
└── spotifywm.cpp

================================================
FILE CONTENTS
================================================

================================================
FILE: LICENSE
================================================
Copyright (c) 2016 Janne Heß
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


================================================
FILE: Makefile
================================================
CXX = g++
CPPFLAGS = -Wall -Wextra
LDFLAGS = -O3 -shared -fPIC -static-libgcc -lX11

all: spotifywm

spotifywm: spotifywm.so

spotifywm.so: spotifywm.cpp
	$(CXX) $(CPPFLAGS) $(LDFLAGS) -DSONAME="$@" -o $@ $^

clean:
	rm spotifywm.so


================================================
FILE: README.md
================================================
# spotifywm

Makes spotify more friendly to window managers by settings a class name before opening the window.
This allows WMs like i3 to correctly discover the window and fit it into a prepared layout.

Inspired by [steamwm](https://github.com/dscharrer/steamwm).

# Installation

```
$ make
```

# Usage

```
LD_PRELOAD=/path/to/spotifywm.so /path/to/spotify/binary
```

Under Arch Linux, do not run the wrapper script in /usr/bin, it will override `LD_PRELOAD`.
Use `/usr/share/spotify/spotify` instead.


================================================
FILE: spotifywm.cpp
================================================
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif /* _GNU_SOURCE */

#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <dlfcn.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xproto.h>		/* to declare xEvent */
#include <xcb/xproto.h>
#include <xcb/xcb.h>
#include <xcb/xcbext.h>

#define STR_(x) # x
#define STR(x)  STR_(x)

extern "C" {
	extern char * program_invocation_short_name; // provided by glibc
}

void spotifywm_init(void) __attribute__((constructor));
void spotifywm_init(void) {
	// Prevent spotifywm.so from being attached to processes started by steam
	const char *envname = "LD_PRELOAD";
	const char *oldenv = getenv(envname);
	if (oldenv && false) {
		char *env = strdup(oldenv);
		char *pos = strstr(env, STR(SONAME));
		if (pos) {
			size_t len1 = strlen(STR(SONAME));
			size_t len2 = strlen(pos + len1);
			memmove(pos, pos + len1, len2);
			*(pos + len2) = '\0';
			setenv(envname, env, 1);
		}
		free(env);
	}
	fprintf(stderr, "[spotifywm] attached to spotify\n");
}

#define BASE_NAME(SymbolName) base_ ## SymbolName
#define TYPE_NAME(SymbolName) SymbolName ## _t
#define INTERCEPT(ReturnType, SymbolName, ...) \
		typedef ReturnType (*TYPE_NAME(SymbolName))(__VA_ARGS__); \
	static void * const BASE_NAME(SymbolName) = dlsym(RTLD_NEXT, STR(SymbolName)); \
	extern "C" ReturnType SymbolName(__VA_ARGS__)
#define BASE(SymbolName) ((TYPE_NAME(SymbolName))BASE_NAME(SymbolName))

INTERCEPT(int, XMapWindow,
	Display * dpy,
	Window    w
) {
	XClassHint* classHint;

	fprintf(stderr, "[spotifywm] spotify window %lx found\n", w);
	classHint = XAllocClassHint();
	if (classHint) {
		classHint->res_name = (char*)"spotify";
		classHint->res_class = (char*)"Spotify";
		XSetClassHint(dpy, w, classHint);
		XFree(classHint);
	}
	return BASE(XMapWindow)(dpy, w);
}

INTERCEPT(unsigned int, xcb_send_request,
	xcb_connection_t *c,
	int flags,
	struct iovec *vector,
	const xcb_protocol_request_t *request 
) {
	// Check if we are sending a MapWindow request
	// This code is called from chromium's source code:
	// ui/gfx/x/generated_protos/xproto.cc in XProto::MapWindow
	if(request->count >= 1 && vector[0].iov_len >= 8 && ((uint8_t*)vector[0].iov_base)[0] == 8) {
		uint32_t window_id = ((uint32_t*)vector[0].iov_base)[1];

		fprintf(stderr, "[spotifywm] spotify window %x found\n", window_id);
		
		// Don't use the same XCB connection as spotify is checking the returned number
		Display* dpy = XOpenDisplay(NULL);
		XClassHint* classHint = XAllocClassHint();
		if (classHint) {
			classHint->res_name = (char*)"spotify";
			classHint->res_class = (char*)"Spotify";
			XSetClassHint(dpy, window_id, classHint);
			XFree(classHint);
		}
		XCloseDisplay(dpy);
	}
	
	return BASE(xcb_send_request)(c, flags, vector, request);
}
Download .txt
gitextract_e3sarxo0/

├── LICENSE
├── Makefile
├── README.md
└── spotifywm.cpp
Download .txt
SYMBOL INDEX (3 symbols across 1 files)

FILE: spotifywm.cpp
  function spotifywm_init (line 24) | void spotifywm_init(void) {
  function INTERCEPT (line 51) | INTERCEPT(int, XMapWindow,
  function INTERCEPT (line 68) | INTERCEPT(unsigned int, xcb_send_request,
Condensed preview — 4 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (5K chars).
[
  {
    "path": "LICENSE",
    "chars": 1050,
    "preview": "Copyright (c) 2016 Janne Heß\nPermission is hereby granted, free of charge, to any person obtaining a copy of this softwa"
  },
  {
    "path": "Makefile",
    "chars": 233,
    "preview": "CXX = g++\nCPPFLAGS = -Wall -Wextra\nLDFLAGS = -O3 -shared -fPIC -static-libgcc -lX11\n\nall: spotifywm\n\nspotifywm: spotifyw"
  },
  {
    "path": "README.md",
    "chars": 508,
    "preview": "# spotifywm\n\nMakes spotify more friendly to window managers by settings a class name before opening the window.\nThis all"
  },
  {
    "path": "spotifywm.cpp",
    "chars": 2770,
    "preview": "#ifndef _GNU_SOURCE\n#define _GNU_SOURCE\n#endif /* _GNU_SOURCE */\n\n#include <stdlib.h>\n#include <string.h>\n#include <stdi"
  }
]

About this extraction

This page contains the full source code of the dasJ/spotifywm GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 4 files (4.5 KB), approximately 1.3k tokens, and a symbol index with 3 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.

Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.

Copied to clipboard!