Browse files

Added a xterm icon *sortof to the desktop

  • Loading branch information...
1 parent d634c01 commit 858258f3a6d004759e1c12bbf7f3f57de06aba31 anywhere-Dev01 committed Jan 21, 2013
Showing with 25 additions and 22 deletions.
  1. BIN piwm
  2. +23 −21 piwm.c
  3. BIN screenshot.png
  4. +2 −1 xinitrc
View
BIN piwm
Binary file not shown.
View
44 piwm.c
@@ -1,18 +1,14 @@
#include <X11/Xlib.h>
#include<X11/extensions/Xrandr.h>
+#include <stdio.h>
+#include <string.h>
#define max(a, b) ((a) > (b) ? (a) : (b))
-
-void spawnXterm() {
- if (fork() == 0) {
- setsid();
- execvp("xterm", NULL);
- }
-}
-
+char * programs[] = { "xterm"};
+void spawn(char *program) { if (fork() == 0) { setsid(); execvp(program, NULL);}}
int main() {
Display * display = XOpenDisplay(0x0);
char *piwm = "Piwm 0.1";
- Window root = DefaultRootWindow(display);
+ Window root_window = DefaultRootWindow(display);
XEvent event;
int num_sizes;
Rotation original_rotation;
@@ -22,29 +18,35 @@ int main() {
KeyCode F = XKeysymToKeycode(display, XStringToKeysym("F"));
KeyCode F1 = XKeysymToKeycode(display, XStringToKeysym("F1"));
XRRScreenSize *xrrs = XRRSizes(display, 0, &num_sizes);
- XRRScreenConfiguration *conf = XRRGetScreenInfo(display, root);
+ XRRScreenConfiguration *conf = XRRGetScreenInfo(display, root_window);
short original_rate = XRRConfigCurrentRate(conf);
SizeID original_size_id = XRRConfigCurrentConfiguration(conf, &original_rotation);
if (!(display)) return 1;
- XGrabKey(display, AnyKey, ControlMask, root, True, GrabModeAsync, GrabModeAsync);
- XGrabButton(display, 1, Mod1Mask, root, True, ButtonPressMask, GrabModeAsync, GrabModeAsync, None, None);
- XGrabButton(display, 3, Mod1Mask, root, True, ButtonPressMask, GrabModeAsync, GrabModeAsync, None, None);
+ XGrabKey(display, AnyKey, ControlMask, root_window, True, GrabModeAsync, GrabModeAsync);
+ XGrabButton(display, 1, Mod1Mask, root_window, True, ButtonPressMask, GrabModeAsync, GrabModeAsync, None, None);
+ XGrabButton(display, 3, Mod1Mask, root_window, True, ButtonPressMask, GrabModeAsync, GrabModeAsync, None, None);
+ XSelectInput(display, root_window, ButtonPressMask );
char dark_grey[] = "#aaaaaa";
- GC green_gc;
+ GC dark_grey_gc;
Colormap colormap;
XColor green_col;
colormap = DefaultColormap(display, 0);
- green_gc = XCreateGC(display, RootWindow(display, DefaultScreen(display)), 0, 0);
+ dark_grey_gc = XCreateGC(display, RootWindow(display, DefaultScreen(display)), 0, 0);
XParseColor(display, colormap, dark_grey, &green_col);
XAllocColor(display, colormap, &green_col);
- XSetForeground(display, green_gc, green_col.pixel);
+ XSetForeground(display, dark_grey_gc, green_col.pixel);
+ int blocks = 0;
+ char buff[5];
while (1) {
- XDrawLine(display,RootWindow(display, DefaultScreen(display)), green_gc, 0, 20, xrrs[original_size_id].width-1, 20);
- XDrawString(display, RootWindow(display, DefaultScreen(display)), green_gc, xrrs[original_size_id].width - 100, 15, piwm, strlen(piwm));
- XNextEvent(display, &event);
- if (event.type == KeyPress && event.xkey.subwindow == None) {
- if (event.xkey.keycode == t && event.xkey.state & ControlMask) spawnXterm();
+ XDrawLine(display, RootWindow(display, DefaultScreen(display)), dark_grey_gc, 0, 20, xrrs[original_size_id].width - 1, 20);
+ XDrawString(display, RootWindow(display, DefaultScreen(display)), dark_grey_gc, xrrs[original_size_id].width - 100, 15, piwm, strlen(piwm));
+ for (blocks = 0; blocks<sizeof(programs)/sizeof(programs[0]); blocks++) {
+ XDrawRectangle(display, RootWindow(display, DefaultScreen(display)), dark_grey_gc, 30, 50 + (30) * blocks, 100, 20);
+ XDrawString(display, RootWindow(display, DefaultScreen(display)), dark_grey_gc, 30 + 10, 65 + (30) * blocks, programs[blocks], strlen(programs[blocks]));
}
+ XNextEvent(display, &event);
+ if (event.type == ButtonPress) if(event.xbutton.x > 30 && event.xbutton.x < 100 && event.xbutton.y < 50 + (30) * 0 +20 && event.xbutton.y > 50 + (30) * 0) spawn("xterm");
+ if (event.type == KeyPress && event.xkey.subwindow == None) if (event.xkey.keycode == t && event.xkey.state & ControlMask) spawn("xterm");
if (event.type == KeyPress && event.xkey.subwindow != None) {
if (event.xkey.keycode == F1 && event.xkey.state & ControlMask) XRaiseWindow(display, event.xkey.subwindow);
if (event.xkey.keycode == F && event.xkey.state & ControlMask) XMoveResizeWindow(display, event.xkey.subwindow, 0, 0, xrrs[original_size_id].width, xrrs[original_size_id].height);
View
BIN screenshot.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
3 xinitrc
@@ -1,5 +1,6 @@
#!/usr/bin/env bash
xsetroot -solid "#353535"
-xrandr --output VGA1 --left-of HDMI1 # set dual screen : change based on your need
+xrandr --output VGA1 --left-of HDMI1 # set dual screen
# get a list of display from xrandr -q
+xsetroot -cursor_name left_ptr
exec /home/anywhere-dev01/NetBeansProjects/tiny/dist/Debug/GNU-Linux-x86/tiny

0 comments on commit 858258f

Please sign in to comment.