Commit 21f05b1f by Jessica Hawkwell

adding titlebar

1 parent cccdfb03
......@@ -24,6 +24,13 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* File: NUtils.cpp
* Author: jlhawkwell
*
* Created on March 10, 2018, 10:39 PM
*/
#include "NUtils.h"
#include <X11/Xatom.h>
......@@ -32,6 +39,8 @@ void NUtils::frameWindow (Window w) {
}
void NUtils::frameWindow (Window w, bool pre_exist) {
if (NWMAction::frames->count(w)) { return; }
const unsigned int BORDER_WIDTH = 3;
const unsigned long BORDER_COLOR = 0xff0000;
const unsigned long BG_COLOR = 0x0000ff;
......@@ -44,24 +53,31 @@ void NUtils::frameWindow (Window w, bool pre_exist) {
if (attrs.override_redirect || attrs.map_state != IsViewable) { return; }
}
Window frame = XCreateSimpleWindow(NWMAction::disp, *NWMAction::root, attrs.x, attrs.y, attrs.width, attrs.height, BORDER_WIDTH, BORDER_COLOR, BG_COLOR);
Window frame = XCreateSimpleWindow(NWMAction::disp, *NWMAction::root, attrs.x, attrs.y, attrs.width + 25, attrs.height, BORDER_WIDTH, BORDER_COLOR, BG_COLOR);
XSelectInput(NWMAction::disp, frame, SubstructureRedirectMask | SubstructureNotifyMask);
XAddToSaveSet(NWMAction::disp, w);
XReparentWindow(NWMAction::disp, w, frame, 0, 0);
XReparentWindow(NWMAction::disp, w, frame, 25, 0);
XMapWindow(NWMAction::disp, frame);
(*NWMAction::clients)[w] = frame;
(*NWMAction::frames)[frame] = w;
std::cout << "NitroWin window " << frame;
char *name = getName(NWMAction::disp, w);
if (name != nullptr) { std::cout << " (" << name << ")"; }
std::cout << std::endl;
XGrabButton(NWMAction::disp, Button1, 0, frame, false, ButtonPressMask | ButtonReleaseMask | ButtonMotionMask, GrabModeAsync, GrabModeAsync, None, None);
XGrabButton(NWMAction::disp, Button1, Mod2Mask, frame, false, ButtonPressMask | ButtonReleaseMask | ButtonMotionMask, GrabModeAsync, GrabModeAsync, None, None);
XGrabButton(NWMAction::disp, Button1, Mod1Mask, w, false, ButtonPressMask | ButtonReleaseMask | ButtonMotionMask, GrabModeAsync, GrabModeAsync, None, None);
XGrabButton(NWMAction::disp, Button1, Mod1Mask | Mod2Mask, w, false, ButtonPressMask | ButtonReleaseMask | ButtonMotionMask, GrabModeAsync, GrabModeAsync, None, None);
XGrabButton(NWMAction::disp, Button3, Mod1Mask, w, false, ButtonPressMask | ButtonReleaseMask | ButtonMotionMask, GrabModeAsync, GrabModeAsync, None, None);
XGrabButton(NWMAction::disp, Button3, Mod1Mask | Mod2Mask, w, false, ButtonPressMask | ButtonReleaseMask | ButtonMotionMask, GrabModeAsync, GrabModeAsync, None, None);
XMapWindow(NWMAction::disp, w);
}
......@@ -75,6 +91,7 @@ void NUtils::unFrameWindow (Window w) {
XRemoveFromSaveSet(NWMAction::disp, w);
XDestroyWindow(NWMAction::disp, frame);
NWMAction::clients->erase(w);
NWMAction::clients->erase(frame);
}
std::string NUtils::getEventName(int event) {
......@@ -127,3 +144,12 @@ char * NUtils::getName(Display *disp, Window w) {
XGetWindowProperty(disp, w, prop, 0, 1024, False, AnyPropertyType, &type, &form, &len, &remain, &list);
return (char*)list;
}
void NUtils::getName(Display *disp, Window w, char * name) {
Atom prop = XInternAtom(disp, "WM_NAME", False), type;
int form;
unsigned long remain, len;
XSetWindowProperty
XGetWindowProperty(disp, w, prop, 0, 1024, False, AnyPropertyType, &type, &form, &len, &remain, &list);
return (char*)list;
}
......@@ -26,6 +26,13 @@
*
*/
/*
* File: NUtils.h
* Author: jlhawkwell
*
* Created on March 10, 2018, 10:39 PM
*/
#ifndef NUTILS_H
#define NUTILS_H
......
......@@ -47,6 +47,7 @@ Window *NWMAction::root;
// WINDOWS
std::unordered_map<Window, Window> *NWMAction::clients;
std::unordered_map<Window, Window> *NWMAction::frames;
void NWMAction::onKeyPress(XKeyPressedEvent e) {
......@@ -57,7 +58,7 @@ void NWMAction::onKeyRelease(XKeyReleasedEvent e) {
}
void NWMAction::onButtonPress(XButtonPressedEvent e) {
if (!clients->count(e.window)) { return; }
if (!clients->count(e.window) && !frames->count(e.window)) { return; }
if (drag_start_cursor == nullptr) {
drag_start_cursor = new NPosition<int>(e.x_root, e.y_root);
}
......@@ -92,7 +93,8 @@ void NWMAction::onButtonRelease(XButtonReleasedEvent e) {
}
void NWMAction::onMotionNotify(XMotionEvent e) {
if (!clients->count(e.window)) { return; }
if (!clients->count(e.window) && !frames->count(e.window)) { return; }
std::cout << "DEBUG NWMAction:97" << std::endl;
/*std::cout << "XMotionEvent: " << e.window;
std::cout << " (" << e.x << ", " << e.y << "), (";
......@@ -114,7 +116,13 @@ void NWMAction::onMotionNotify(XMotionEvent e) {
if (e.state & Mod5Mask) { std::cout << " Mod5Mask"; }
std::cout << std::endl; // */
Window frame = (*clients)[e.window];
Window frame;
if (NWMAction::clients->count(e.window)) { frame = (*clients)[e.window]; }
else if (NWMAction::frames->count(e.window)) { frame = e.window; }
else { return; }
std::cout << "DEBUG NWMAction:124" << std::endl;
NPosition<int> drag_pos(e.x_root, e.y_root);
NPosition<int> delta = drag_pos - *drag_start_cursor;
......@@ -185,8 +193,6 @@ void NWMAction::onMapNotify(XMapEvent e) {
void NWMAction::onMapRequest(XMapRequestEvent e) {
NUtils::frameWindow(e.window);
XMapWindow(disp, e.window);
}
void NWMAction::onReparentNotify(XReparentEvent e) {
......
......@@ -55,6 +55,7 @@ public:
// WINDOWS
static std::unordered_map<Window, Window> *clients;
static std::unordered_map<Window, Window> *frames;
// EVENT METHODS
static void onKeyPress(XKeyPressedEvent e);
......
......@@ -52,6 +52,7 @@ NWManager::NWManager() {
}
clients = new std::unordered_map<Window, Window>();
frames = new std::unordered_map<Window, Window>();
}
NWManager::~NWManager() {
......@@ -123,6 +124,7 @@ void NWManager::run() {
NWMAction::disp = disp;
NWMAction::root = root;
NWMAction::clients = clients;
NWMAction::frames = frames;
// main loop
XEvent e;
......
......@@ -44,6 +44,7 @@ public:
private:
std::unordered_map<Window, Window> *clients;
std::unordered_map<Window, Window> *frames;
bool keepGoing;
Display *disp;
Window *root;
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!