Commit 2bc74163 by Jessica Hawkwell

did some stuffs

1 parent 293a9c20
[project]
name=Nitrogen
description=
base_path=./
run_cmd=
regenerate=true
type=C/C++
file_patterns=
[editor]
line_wrapping=false
line_break_column=120
auto_continue_multiline=true
[file_prefs]
final_new_line=true
ensure_convert_new_lines=true
strip_trailing_spaces=true
replace_tabs=false
[indentation]
indent_width=4
indent_type=1
indent_hard_tab_width=4
detect_indent=false
detect_indent_width=false
indent_mode=3
[long line marker]
long_line_behaviour=1
long_line_column=120
[files]
current_page=0
FILE_NAME_0=0;C++;0;EUTF-8;1;1;0;%2Fusr%2Fhome%2Fjlhawkwell%2FProjects%2FNitrogen%2Fsrc%2FNitroWin%2FNUtils.cpp;0;4
[VTE]
last_dir=/usr/home/jlhawkwell
[prjorg]
source_patterns=*.c;*.C;*.cpp;*.cxx;*.c++;*.cc;*.m;
header_patterns=*.h;*.H;*.hpp;*.hxx;*.h++;*.hh;
ignored_dirs_patterns=.*;CVS;
ignored_file_patterns=*.o;*.obj;*.a;*.lib;*.so;*.dll;*.lo;*.la;*.class;*.jar;*.pyc;*.mo;*.gmo;
generate_tag_prefs=0
external_dirs=
[build-menu]
EX_00_LB=_Execute
EX_00_CM="./test_NitroWin.sh"
EX_00_WD=
......@@ -55,7 +55,7 @@
<confs>
<conf name="Default" type="0" platformSpecific="true">
<toolsSet>
<compilerSet>default</compilerSet>
<compilerSet>CLang|CLang</compilerSet>
<platform>5</platform>
<dependencyChecking>false</dependencyChecking>
<rebuildPropChanged>false</rebuildPropChanged>
......@@ -68,6 +68,12 @@
<buildCommand>${MAKE} -f Makefile</buildCommand>
<cleanCommand>${MAKE} -f Makefile clean</cleanCommand>
<executablePath></executablePath>
<cTool>
<standard>10</standard>
</cTool>
<ccTool>
<standard>11</standard>
</ccTool>
</makeTool>
<preBuild>
<preBuildCommandWorkingDir>.</preBuildCommandWorkingDir>
......
......@@ -41,10 +41,10 @@ public:
py = y;
}
NPosition<T>(const NPosition<T>& other) {
NPosition<T>(const NPosition<T>& other) {
px = other.px;
py = other.py;
}
}
NPosition<T>& operator=(const NPosition<T>& other) {
px = other.px;
......
......@@ -25,6 +25,7 @@
*/
#include "NUtils.h"
#include <X11/Xatom.h>
void NUtils::frameWindow (Window w) {
frameWindow(w, false);
......@@ -53,6 +54,10 @@ void NUtils::frameWindow (Window w, bool pre_exist) {
XMapWindow(NWMAction::disp, frame);
(*NWMAction::clients)[w] = frame;
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, 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);
......@@ -61,6 +66,7 @@ void NUtils::frameWindow (Window w, bool pre_exist) {
void NUtils::unFrameWindow (Window w) {
if (!NWMAction::clients->count(w)) { return; }
Window frame = (*NWMAction::clients)[w];
XUnmapWindow(NWMAction::disp, frame);
......@@ -73,41 +79,51 @@ void NUtils::unFrameWindow (Window w) {
std::string NUtils::getEventName(int event) {
switch (event) {
case KeyPress: return "KeyPress"; break;
case KeyRelease: return "KeyRelease"; break;
case ButtonPress: return "ButtonPress"; break;
case ButtonRelease: return "ButtonRelease"; break;
case MotionNotify: return "MotionNotify"; break;
case EnterNotify: return "EnterNotify"; break;
case LeaveNotify: return "LeaveNotify"; break;
case FocusIn: return "FocusIn"; break;
case FocusOut: return "FocusOut"; break;
case KeymapNotify: return "KeymapNotify"; break;
case Expose: return "Expose"; break;
case GraphicsExpose: return "GraphicsExpose"; break;
case NoExpose: return "NoExpose"; break;
case VisibilityNotify: return "VisibilityNotify"; break;
case CreateNotify: return "CreateNotify"; break;
case DestroyNotify: return "DestroyNotify"; break;
case UnmapNotify: return "UnmapNotify"; break;
case MapNotify: return "MapNotify"; break;
case MapRequest: return "MapRequest"; break;
case ReparentNotify: return "ReparentNotify"; break;
case ConfigureNotify: return "ConfigureNotify"; break;
case ConfigureRequest: return "ConfigureRequest"; break;
case GravityNotify: return "GravityNotify"; break;
case ResizeRequest: return "ResizeRequest"; break;
case CirculateNotify: return "CirculateNotify"; break;
case CirculateRequest: return "CirculateRequest"; break;
case PropertyNotify: return "PropertyNotify"; break;
case SelectionClear: return "SelectionClear"; break;
case SelectionRequest: return "SelectionRequest"; break;
case SelectionNotify: return "SelectionNotify"; break;
case ColormapNotify: return "ColormapNotify"; break;
case ClientMessage: return "ClientMessage"; break;
case MappingNotify: return "MappingNotify"; break;
case GenericEvent: return "GenericEvent"; break;
case LASTEvent: return "LASTEvent"; break;
default: return "Unknown"; break;
}
case KeyPress: return "KeyPress"; break;
case KeyRelease: return "KeyRelease"; break;
case ButtonPress: return "ButtonPress"; break;
case ButtonRelease: return "ButtonRelease"; break;
case MotionNotify: return "MotionNotify"; break;
case EnterNotify: return "EnterNotify"; break;
case LeaveNotify: return "LeaveNotify"; break;
case FocusIn: return "FocusIn"; break;
case FocusOut: return "FocusOut"; break;
case KeymapNotify: return "KeymapNotify"; break;
case Expose: return "Expose"; break;
case GraphicsExpose: return "GraphicsExpose"; break;
case NoExpose: return "NoExpose"; break;
case VisibilityNotify: return "VisibilityNotify"; break;
case CreateNotify: return "CreateNotify"; break;
case DestroyNotify: return "DestroyNotify"; break;
case UnmapNotify: return "UnmapNotify"; break;
case MapNotify: return "MapNotify"; break;
case MapRequest: return "MapRequest"; break;
case ReparentNotify: return "ReparentNotify"; break;
case ConfigureNotify: return "ConfigureNotify"; break;
case ConfigureRequest: return "ConfigureRequest"; break;
case GravityNotify: return "GravityNotify"; break;
case ResizeRequest: return "ResizeRequest"; break;
case CirculateNotify: return "CirculateNotify"; break;
case CirculateRequest: return "CirculateRequest"; break;
case PropertyNotify: return "PropertyNotify"; break;
case SelectionClear: return "SelectionClear"; break;
case SelectionRequest: return "SelectionRequest"; break;
case SelectionNotify: return "SelectionNotify"; break;
case ColormapNotify: return "ColormapNotify"; break;
case ClientMessage: return "ClientMessage"; break;
case MappingNotify: return "MappingNotify"; break;
case GenericEvent: return "GenericEvent"; break;
case LASTEvent: return "LASTEvent"; break;
default: return "Unknown"; break;
}
}
char * NUtils::getName(Display *disp, Window w) {
Atom prop = XInternAtom(disp, "WM_NAME", False), type;
int form;
unsigned long remain, len;
unsigned char *list;
XGetWindowProperty(disp, w, prop, 0, 1024, False, AnyPropertyType, &type, &form, &len, &remain, &list);
return (char*)list;
}
......@@ -30,6 +30,9 @@
#define NUTILS_H
#include "NWMAction.h"
#include <X11/Xlib.h>
#include <X11/Xatom.h>
#include <X11/X.h>
#include <iostream>
class NUtils {
......@@ -38,6 +41,7 @@ public:
static void frameWindow(Window w, bool pre_exist);
static void unFrameWindow(Window w);
static std::string getEventName(int event);
static char* getName(Display *disp, Window w);
};
#endif // NUTILS_H
......@@ -34,7 +34,7 @@
#include "NWMAction.h"
#include "NUtils.h"
#include <iostream>
#include <vector>
//#include <vector>
// MOVING WINDOWS
NPosition<int> *NWMAction::drag_start_cursor;
......@@ -94,7 +94,7 @@ void NWMAction::onButtonRelease(XButtonReleasedEvent e) {
void NWMAction::onMotionNotify(XMotionEvent e) {
if (!clients->count(e.window)) { return; }
std::cout << "XMotionEvent: " << e.window;
/*std::cout << "XMotionEvent: " << e.window;
std::cout << " (" << e.x << ", " << e.y << "), (";
std::cout << e.x_root << ", " << e.y_root << ") ";
std::cout << e.state;
......@@ -112,14 +112,13 @@ void NWMAction::onMotionNotify(XMotionEvent e) {
if (e.state & Mod3Mask) { std::cout << " Mod3Mask"; }
if (e.state & Mod4Mask) { std::cout << " Mod4Mask"; }
if (e.state & Mod5Mask) { std::cout << " Mod5Mask"; }
std::cout << std::endl;
std::cout << std::endl; // */
Window frame = (*clients)[e.window];
NPosition<int> drag_pos(e.x_root, e.y_root);
NPosition<int> delta = drag_pos - *drag_start_cursor;
if (e.state & Button1Mask) { // move window
std::cout << "\tDelta: " << delta.toString() << std::endl;
NPosition<int> dest = delta + *drag_start_window;
dest.setZeroIfNegative();
XMoveWindow(disp, frame, dest.getX(), dest.getY());
......@@ -168,7 +167,8 @@ void NWMAction::onCreateNotify(XCreateWindowEvent e) {
}
void NWMAction::onDestroyNotify(XDestroyWindowEvent e) {
if (clients->count(e.window)) { NUtils::unFrameWindow(e.window); }
if (clients->count(e.event)) { NUtils::unFrameWindow(e.event); }
}
void NWMAction::onUnmapNotify(XUnmapEvent e) {
......@@ -267,11 +267,15 @@ void NWMAction::onGenericEvent(XGenericEvent e) {
}
void NWMAction::onLASTEvent(XAnyEvent e) {
onDefaultEvent(e);
}
void NWMAction::onDefaultEvent(XAnyEvent e) {
std::cout << "Event [" << NUtils::getEventName(e.type) << "] on ";
std::cout << e.window << " @ " << e.display << std::endl;
std::cout << e.window;
char* name = NUtils::getName(disp, e.window);
if (name != nullptr) { std::cout << " (" << name << ")"; }
if (clients->count(e.window)) { std::cout << " (NitroWin)"; }
std::cout << std::endl;
}
......@@ -38,8 +38,8 @@
#include <vector>
#include <unordered_map>
# include "NPosition.h"
# include "NSize.h"
#include "NPosition.h"
#include "NSize.h"
class NWMAction {
protected:
......
......@@ -29,6 +29,8 @@
#include "NUtils.h"
#include <iostream>
#include <iterator>
#include <unordered_map>
void printEventData(XEvent e);
......@@ -53,6 +55,9 @@ NWManager::NWManager() {
}
NWManager::~NWManager() {
for (auto it : (NWMAction::clients)) {
NUtils::unFrameWindow(it.first);
}
XCloseDisplay(disp);
}
......@@ -70,9 +75,18 @@ int NWManager::OnXError(Display *display, XErrorEvent *e) {
XGetErrorText(display, e->error_code, error_text, sizeof(error_text));
std::cerr << "Received X error:" << std::endl
<< " Request: " << int(e->request_code) << std::endl
<< " Error code: " << int(e->error_code)
<< " Error code: " << int(e->error_code) << "." << int(e->minor_code)
<< " - " << error_text << std::endl
<< " Resource ID: " << e->resourceid << std::endl;
for (auto it : (*NWMAction::clients)) {
std::cout << "\t" << it.first << " - " << it.second << std::endl;
}
/*NWMAction::clients->begin();
while (!NWMAction::clients->empty()) {
NWMAction::clients->
std::cout << "\t" << (*NWMAction::clients){} << std::endl;
} // */
return 0;
}
......@@ -115,45 +129,49 @@ void NWManager::run() {
while (keepGoing) {
XNextEvent(disp, &e);
switch (e.type) {
//case KeyPress: break;
//case KeyRelease: break;
case ButtonPress: NWMAction::onButtonPress(e.xbutton); break;
//case ButtonRelease: break;
case MotionNotify: NWMAction::onMotionNotify(e.xmotion); break;
//case EnterNotify: break;
//case LeaveNotify: break;
//case FocusIn: break;
//case FocusOut: break;
//case KeymapNotify: break;
//case Expose: break;
//case GraphicsExpose: break;
//case NoExpose: break;
//case VisibilityNotify: break;
//case CreateNotify: break; /* ignore this */
//case DestroyNotify: break; /* ignore this */
case UnmapNotify: NWMAction::onUnmapNotify(e.xunmap); break;
//case MapNotify: break; /* ignore this */
case MapRequest: NWMAction::onMapRequest(e.xmaprequest) ; break;
//case ReparentNotify: break; /* ignore this */
//case ConfigureNotify: break; /* ignore this */
case ConfigureRequest: NWMAction::onConfigureRequest(e.xconfigurerequest); break;
//case GravityNotify: break;
//case ResizeRequest: break;
//case CirculateNotify: break;
//case CirculateRequest: break;
//case PropertyNotify: break;
//case SelectionClear: break;
//case SelectionRequest: break;
//case SelectionNotify: break;
//case ColormapNotify: break;
//case ClientMessage: break;
//case MappingNotify: break;
//case GenericEvent: break;
//case LASTEvent: break;
default: NWMAction::onDefaultEvent(e.xany); break;
}
onLoop(e);
}
}
void NWManager::stop() { keepGoing = false; }
void NWManager::onLoop(XEvent e) {
switch (e.type) {
//case KeyPress: break;
//case KeyRelease: break;
case ButtonPress: NWMAction::onButtonPress(e.xbutton); break;
//case ButtonRelease: break;
case MotionNotify: NWMAction::onMotionNotify(e.xmotion); break;
//case EnterNotify: break;
//case LeaveNotify: break;
//case FocusIn: break;
//case FocusOut: break;
//case KeymapNotify: break;
//case Expose: break;
//case GraphicsExpose: break;
//case NoExpose: break;
//case VisibilityNotify: break;
//case CreateNotify: break; /* ignore this */
case DestroyNotify: NWMAction::onDestroyNotify(e.xdestroywindow); break; /* ignore this */
case UnmapNotify: NWMAction::onUnmapNotify(e.xunmap); break;
//case MapNotify: break; /* ignore this */
case MapRequest: NWMAction::onMapRequest(e.xmaprequest) ; break;
//case ReparentNotify: break; /* ignore this */
case ConfigureNotify: break; /* ignore this */
case ConfigureRequest: NWMAction::onConfigureRequest(e.xconfigurerequest); break;
//case GravityNotify: break;
//case ResizeRequest: break;
//case CirculateNotify: break;
//case CirculateRequest: break;
//case PropertyNotify: break;
//case SelectionClear: break;
//case SelectionRequest: break;
//case SelectionNotify: break;
//case ColormapNotify: break;
//case ClientMessage: break;
//case MappingNotify: break;
//case GenericEvent: break;
//case LASTEvent: break;
default: NWMAction::onDefaultEvent(e.xany); break;
}
}
......@@ -47,6 +47,8 @@ private:
bool keepGoing;
Display *disp;
Window *root;
static void onLoop(XEvent e);
};
#endif /* NWMANAGER_H */
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!