fix window_x11
This commit is contained in:
parent
9ad84c447b
commit
542b271c6d
@ -40,7 +40,7 @@ static int find_window(Display *d, Window *w, const char *contains) {
|
||||
for(int i = 0; i < numItems; i++) {
|
||||
status = XGetWMName(d, list[i], &windowName);
|
||||
if(status >= Success) {
|
||||
if(windowName.value && strstr(windowName.value, contains)) {
|
||||
if(windowName.value && strstr((const char*) windowName.value, contains)) {
|
||||
*w = list[i];
|
||||
found = 1;
|
||||
break;
|
||||
@ -86,11 +86,11 @@ static int window_perform(CHiPubNode *n) {
|
||||
w->ximg = XShmCreateImage(d, attrs.visual, 32, ZPixmap, NULL, &w->shminfo, attrs.width, attrs.height);
|
||||
stride = ((w->ximg->bytes_per_line + 15) & ~15);
|
||||
w->shminfo.shmid = shmget(IPC_PRIVATE, stride * w->ximg->height, IPC_CREAT | 0777);
|
||||
w->shminfo.shmaddr = w->ximg->data = shmat(w->shminfo.shmid, 0, 0);
|
||||
w->shminfo.shmaddr = w->ximg->data = (char*) shmat(w->shminfo.shmid, 0, 0);
|
||||
w->shminfo.readOnly = False;
|
||||
XShmAttach(d, &w->shminfo);
|
||||
|
||||
w->vcache = CHi_Image_New(2, 4, 8 * attrs.width, attrs.width, attrs.height, NULL);
|
||||
w->vcache = CHi_Image_New(2, 4, (8 * attrs.width + 15) & ~15, attrs.width, attrs.height, NULL);
|
||||
} else {
|
||||
stride = ((w->ximg->bytes_per_line + 15) & ~15);
|
||||
}
|
||||
@ -100,12 +100,17 @@ static int window_perform(CHiPubNode *n) {
|
||||
|
||||
XShmGetImage(d, w->xcache, w->ximg, 0, 0, AllPlanes);
|
||||
|
||||
bool ignoreAlpha = CHi_Crawl(&w->pub.sinks[1])->data.vec4[0] != 0;
|
||||
|
||||
// Turn u8 image to u16
|
||||
#pragma omp parallel for
|
||||
for(size_t y = 0; y < w->vcache->height; y++) {
|
||||
for(size_t x = 0; x < w->vcache->width; x += 2) {
|
||||
__m128i c = _mm_loadu_si128((__m128i*) ((uintptr_t) w->ximg->data + y * w->ximg->bytes_per_line + x * 4));
|
||||
c = _mm_shuffle_epi8(c, _mm_set_epi8(7, -128, 6, -128, 5, -128, 4, -128, 3, -128, 2, -128, 1, -128, 0, -128));
|
||||
if(ignoreAlpha) {
|
||||
c = _mm_or_si128(c, _mm_set_epi16(0xFFFF, 0, 0, 0, 0xFFFF, 0, 0, 0));
|
||||
}
|
||||
c = apply_gamma_epi16(c, _mm_set_ps(1, 2.2f, 2.2f, 2.2f));
|
||||
_mm_storeu_si128((__m128i*) ((uintptr_t) w->vcache->data16 + y * w->vcache->stride + x * 8), c);
|
||||
}
|
||||
@ -120,7 +125,7 @@ static int window_perform(CHiPubNode *n) {
|
||||
}
|
||||
|
||||
static void window_destroy(CHiPubNode *pubn) {
|
||||
CHiWindowNode *n = (void*) pubn;
|
||||
CHiWindowNode *n = (CHiWindowNode*) pubn;
|
||||
|
||||
if(n->vcache) {
|
||||
XShmDetach(d, &n->shminfo);
|
||||
@ -137,15 +142,15 @@ CUTIVIS CHiPubNode *CHi_Window() {
|
||||
root = RootWindow(d, DefaultScreen(d));
|
||||
}
|
||||
|
||||
CHiWindowNode *n = calloc(1, sizeof(*n));
|
||||
CHiWindowNode *n = (CHiWindowNode*) calloc(1, sizeof(*n));
|
||||
n->pub.type = CUTIHI_T('CWin','dow ');
|
||||
n->pub.Start = n->pub.Stop = NULL;
|
||||
n->pub.Perform = window_perform;
|
||||
n->pub.Destroy = window_destroy;
|
||||
n->pub.sinkCount = 1;
|
||||
n->pub.sinks = calloc(sizeof(*n->pub.sinks), 1);
|
||||
n->pub.sinks = (CHiValue*) calloc(sizeof(*n->pub.sinks), 2);
|
||||
n->pub.sourceCount = 1;
|
||||
n->pub.sources = calloc(sizeof(*n->pub.sources), 1);
|
||||
n->pub.sources = (CHiValue*) calloc(sizeof(*n->pub.sources), 1);
|
||||
|
||||
n->xcache = 0;
|
||||
n->vcache = NULL;
|
||||
@ -155,22 +160,11 @@ CUTIVIS CHiPubNode *CHi_Window() {
|
||||
|
||||
// All of the following are ews
|
||||
|
||||
CUTIVIS size_t CHi_Window_GetSourceCount() {
|
||||
Atom atom = XInternAtom(d, "_NET_CLIENT_LIST", 1);
|
||||
Atom actualType;
|
||||
int format;
|
||||
unsigned long numItems, bytesAfter;
|
||||
|
||||
Window *list;
|
||||
|
||||
int status = XGetWindowProperty(d, root, atom, 0L, ~0L, 0, AnyPropertyType, &actualType, &format, &numItems, &bytesAfter, (unsigned char**) &list);
|
||||
|
||||
//XFree(list);
|
||||
|
||||
return status >= Success ? numItems : 0;
|
||||
}
|
||||
|
||||
CUTIVIS const char *CHi_Window_GetSourceName(size_t idx) {
|
||||
struct WindowListDatum {
|
||||
Window handle;
|
||||
char name[128];
|
||||
};
|
||||
CUTIVIS size_t CHi_Window_GetList(void **buf) {
|
||||
int found = 0;
|
||||
Atom atom = XInternAtom(d, "_NET_CLIENT_LIST", 1);
|
||||
Atom actualType;
|
||||
@ -183,36 +177,35 @@ CUTIVIS const char *CHi_Window_GetSourceName(size_t idx) {
|
||||
int status = XGetWindowProperty(d, root, atom, 0L, ~0L, 0, AnyPropertyType, &actualType, &format, &numItems, &bytesAfter, (unsigned char**) &list);
|
||||
|
||||
if(status >= Success) {
|
||||
//XFree(list);
|
||||
WindowListDatum *data = (WindowListDatum*) calloc(numItems, sizeof(*data));
|
||||
size_t successfulWindows = 0;
|
||||
|
||||
status = XGetWMName(d, list[idx], &windowName);
|
||||
if(status >= Success) {
|
||||
found = 1;
|
||||
for(size_t i = 0; i < numItems; i++) {
|
||||
status = XGetWMName(d, list[i], &windowName);
|
||||
if(status >= Success) {
|
||||
data[successfulWindows].handle = list[i];
|
||||
strncpy(data[successfulWindows].name, (char*) windowName.value, sizeof(data[successfulWindows].name));
|
||||
|
||||
successfulWindows++;
|
||||
}
|
||||
}
|
||||
|
||||
XFree(list);
|
||||
|
||||
*buf = data;
|
||||
return successfulWindows;
|
||||
}
|
||||
|
||||
return found ? strdup(windowName.value ? windowName.value : "") : NULL;
|
||||
}
|
||||
|
||||
CUTIVIS uintptr_t CHi_Window_GetSourceData(size_t idx) {
|
||||
Atom atom = XInternAtom(d, "_NET_CLIENT_LIST", 1);
|
||||
Atom actualType;
|
||||
int format;
|
||||
unsigned long numItems, bytesAfter;
|
||||
|
||||
Window *list;
|
||||
|
||||
int status = XGetWindowProperty(d, root, atom, 0L, ~0L, 0, AnyPropertyType, &actualType, &format, &numItems, &bytesAfter, (unsigned char**) &list);
|
||||
|
||||
if(status >= Success) {
|
||||
Window ret = list[idx];
|
||||
//XFree(list);
|
||||
return ret;
|
||||
}
|
||||
|
||||
*buf = nullptr;
|
||||
return 0;
|
||||
}
|
||||
|
||||
CUTIVIS size_t CHi_Window_GetNextSource(size_t i) {
|
||||
return i + 1;
|
||||
CUTIVIS const char *CHi_Window_GetName(void *buf, size_t i) {
|
||||
return ((WindowListDatum*) buf)[i].name;
|
||||
}
|
||||
CUTIVIS size_t CHi_Window_GetHandle(void *buf, size_t i) {
|
||||
return ((WindowListDatum*) buf)[i].handle;
|
||||
}
|
||||
CUTIVIS void CHi_Window_FreeList(void *buf) {
|
||||
free(buf);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user