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

Added helpers.h, centerpixel.c to tests #373

Merged
merged 1 commit into from
Jul 29, 2024
Merged
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
62 changes: 62 additions & 0 deletions tests/centerpixel.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@


#include <X11/Xlib.h>
#include <X11/X.h>
#include "helper.h"







int
jnzjmp(void)
{
__test__start_basic();


XEvent ev;
GC gc = XCreateGC(dpy, win, 0, NULL);
int x = 0;
int y = 0;
int w = 0;
int h = 0;
XSelectInput(dpy, win, StructureNotifyMask|SubstructureNotifyMask|ExposureMask);
XSetForeground(dpy, gc, 0);
XSync(dpy, screen);
while(!XNextEvent(dpy, &ev))
{
unsigned int sqw;
unsigned int sqh;
int sqx;
int sqy;
switch(ev.type)
{
case ConfigureNotify:
x = ev.xconfigure.x;
y = ev.xconfigure.y;
w = ev.xconfigure.width;
h = ev.xconfigure.height;
case Expose:
XFillRectangle(dpy, win, gc, 0, 0, w, h);
XSetForeground(dpy, gc, ~0);
sqw = sw / 10;
sqh = sw / 10;
//unsigned int sqx = w / 2 - sqw / 2;
//unsigned int sqy = h / 2 - sqh / 2;
//sqx = (((sw / 2) - sqw) - x) + sqw / 2;
//sqy = (((sh / 2) - sqh) - y) + sqh / 2;
sqx = ((sw / 2)) - sqw / 2 - x;
sqy = ((sh / 2)) - sqh / 2 - y;
XFillArc(dpy, win, gc, sqx, sqy, sqw, sqh, 1 * 64, 360 * 64);
//XFillRectangle(dpy, win, gc, sqx, sqy, sqw, sqh);
XSetForeground(dpy, gc, 0);
break;
}
}



return 0;
}
42 changes: 42 additions & 0 deletions tests/helper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include <X11/Xatom.h>
#include <X11/X.h>
#include <X11/Xlib.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>


Display *dpy;
int screen;
int sw;
int sh;
Window win;
Window root;

static void
__test__start_basic(void)
{
dpy = XOpenDisplay(NULL);
if(!dpy)
{
printf("Could not load display\n");
exit(1);
}
screen = DefaultScreen(dpy);
sw = DisplayWidth(dpy, screen);
sh = DisplayHeight(dpy, screen);


root = DefaultRootWindow(dpy);

XSetWindowAttributes wa =
{
.bit_gravity = NorthWestGravity,
///NorthWestGravity,
.backing_store = WhenMapped,
};
unsigned int mask = CWBitGravity|CWBackingStore;
win = XCreateWindow(dpy, root, 0, 0, sw, sh, 0, DefaultDepth(dpy, screen), InputOutput, 0, mask, &wa);
XMapWindow(dpy, win);
}