diff options
Diffstat (limited to 'src/xtoq')
-rw-r--r-- | src/xtoq/XtoqController.h | 118 | ||||
-rw-r--r-- | src/xtoq/XtoqController.m | 119 |
2 files changed, 176 insertions, 61 deletions
diff --git a/src/xtoq/XtoqController.h b/src/xtoq/XtoqController.h index 5b3d3aa..f53e771 100644 --- a/src/xtoq/XtoqController.h +++ b/src/xtoq/XtoqController.h @@ -71,11 +71,34 @@ id referenceToSelf; int originalHeight; int originalWidth; NSRect imageRec; - NSString *keyFirst; + +// NSString *keyFirst; +// int originalHeight; +// int originalWidth; + } +/** + * Initialize + */ - (id) init; + +/** + * Sent by the default notification center immediately before the + * application object is initialized. + * @param A notification named NSApplicationWillFinishLaunchingNotification. + * Calling the object method of this notification returns the + * NSApplication object itself. + */ - (void) applicationWillFinishLaunching:(NSNotification *) aNotification; + +/** + * Sent by the default notification center after the application has been + * launched and initialized but before it has received its first event. + * @param A notification named NSApplicationWillFinishLaunchingNotification. + * Calling the object method of this notification returns the + * NSApplication object itself. + */ - (void) applicationDidFinishLaunching: (NSNotification *) aNotification; /** @@ -85,6 +108,12 @@ id referenceToSelf; - (void) keyDownInView: (NSNotification *) aNotification; /** + * Receive notification of a key up event from the view. + * @param an NSNotification containing an NSEvent + */ +- (void) keyUpInView: (NSNotification *) aNotification; + +/** * Receive notification of a mouse button press from the view. * @param an NSNotification containing an NSEvent */ @@ -97,99 +126,150 @@ id referenceToSelf; - (void) mouseButtonReleaseInView: (NSNotification *) aNotification; /** - * Makemenu and related selector functions for launching X applications. + * Make menu and related selector functions for launching X applications. */ - (void) makeMenu; /** * Launches the application based on filename. - * * Launches the selected application based on the filename passed in as an * argument. Uses posix_spawn() to launch the application after the arguments * have been filled in. - * * @param filename The name of the application to be run within XtoQ.app. */ - (void) launch_client: (NSString *) filename; /** * Runs xeyes. - * * Sends "xeyes" argument to the launch client function to open up the * application xeyes within XtoQ.app. - * * @param sender Only needed for functionality with Makemenu's menu system. */ - (void) runXeyes: (id) sender; /** * Runs xclock. - * * Sends "xclock" argument to the launch client function to open up the * application xclock within XtoQ.app. - * * @param sender Only needed for functionality with Makemenu's menu system. */ - (void) runXclock: (id) sender; /** * Runs xlogo. - * * Sends "xlogo" argument to the launch client function to open up the * application xlogo within XtoQ.app. - * * @param sender Only needed for functionality with Makemenu's menu system. */ - (void) runXlogo: (id) sender; + +/** + * Receive notification of mouse movement from the app + * @param aNotification A notification containing an NSEvent + */ - (void) mouseMovedInApp: (NSNotification *) aNotification; /** * Runs xterm. - * * Sends "xterm" argument to the launch client function to open up the * application xterm within XtoQ.app. - * * @param sender Only needed for functionality with Makemenu's menu system. */ - (void) runXterm: (id) sender; /** + * Runs xman + * Sends "xman" argument to the launch client function to open up the + * application xman within XtoQ.app. + * @param sender Olny needed for functionality with Makemenu's menu system. + */ +-(void) runXman: (id) sender; + +/** * Put a new image in the window / view * Send an image to the view after being notified of a damage event from * the event handler. - * @param an xcwm_context_t sent from eventHandler + * @param an xtoq_context_t sent from eventHandler */ - (void) updateImage: (xcwm_context_t *) windowContext; +/** + * Creates a new window + * @param an xtoq_context_t sent from eventHandler + */ - (void) createNewWindow: (xcwm_context_t *) windowContext; -- (void) destroyWindow: (xcwm_context_t *) windowContext; + +/** + * Closes the window + * @param an xtoq_context_t sent from eventHandler + */ +- (void) destroyWindow: (xcwm_context_t *) windowContext; + +/** + * Send request to close + * @param an NSNotification containing an NSEvent + */ +- (void) destroy:(NSNotification *) aNotification; /** * Sets the variable screen to correct display. - * * Sets class variable screen to correct display and also sets the environment * variable "DISPLAY" to correct value. - * * @param scrn This value is determined in XtoqApplication before connection * to Xorg is established. */ - (void) setScreen: (char *) scrn; -- (void)windowWillMove:(NSNotification*)notification; +//- (void)windowWillMove:(NSNotification*)notification; + +/** + * Informs the delegate that the window has been moved. + * @param notification A notification named NSWindowDidMoveNotification. + */ - (void)windowDidMove:(NSNotification*)notification; + +/** + * Informs the delegate that the window has been resized. + * @param notification A notification named NSWindowDidResizeNotification. + */ - (void)windowDidResize:(NSNotification*)notification; + +/** + * Sent by the default notification center immediately before + * the application terminates. + * @param aNotification A notification named + * NSApplicationWillTerminateNotification. Calling the + * object method of this notification returns the + * NSApplication object itself. + */ - (void)applicationWillTerminate:(NSNotification *)aNotification; + +/** + * Reshapes the window + */ - (void)reshape; +/** + * Converts the Xserver y value to the OSX coordinate system + * @param yValue an int value of the y coordinat + * @param windowH int value of the window eight + * @return an int that has been converted + */ - (int) xserverToOSX:(int)yValue windowHeight:(int)windowH; + +/** + * Converts the OSX y value to the Xserver coordinate system + * @param yValue an int value of the y coordinat + * @param windowH int value of the window eight + * @return an int that has been converted + */ - (int) osxToXserver:(int)yValue windowHeight:(int)windowH; @end - /** - * Callback function that will receive events from the xcwm event loop + * Callback function that will receive events from the xtoq event loop * once it is started. * @param event The event received. */ diff --git a/src/xtoq/XtoqController.m b/src/xtoq/XtoqController.m index fb3b6a5..3e8e4f3 100644 --- a/src/xtoq/XtoqController.m +++ b/src/xtoq/XtoqController.m @@ -36,7 +36,6 @@ #import "XtoqController.h" #define WINDOWBAR 22 -#define FILEBAR 23 @implementation XtoqController @@ -63,7 +62,7 @@ } - (void)applicationWillFinishLaunching:(NSNotification *)aNotification { - + // setup X connection and get the initial image from the server rootContext = xcwm_init(screen); @@ -99,8 +98,8 @@ // set the initial image in the window //[ourView setImage:image]; - originalWidth = [image getWidth]; - originalHeight = [image getHeight]; + // originalWidth = [image getWidth]; + // originalHeight = [image getHeight]; //[ourView setPartialImage:imageNew]; NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; @@ -113,6 +112,11 @@ object: nil]; [nc addObserver: self + selector: @selector(keyUpInView:) + name: @"XTOQviewKeyUpEvent" + object: nil]; + + [nc addObserver: self selector: @selector(mouseButtonDownInView:) name: @"XTOQmouseButtonDownEvent" object: nil]; @@ -121,7 +125,7 @@ selector: @selector(mouseButtonReleaseInView:) name: @"XTOQmouseButtonReleaseEvent" object: nil]; - + [nc addObserver: self selector: @selector(mouseMovedInApp:) name: @"MouseMovedEvent" @@ -133,12 +137,12 @@ name: @"XTOQdestroyTheWindow" object: nil]; - // regester for window will/did movement notification + /* // regester for window will/did movement notification [nc addObserver:self selector:@selector(windowWillMove:) name:NSWindowWillMoveNotification object:nil]; - + */ [nc addObserver:self selector:@selector(windowDidMove:) name:NSWindowDidMoveNotification @@ -165,7 +169,6 @@ const char *spawn[4]; pid_t child; - int error = 0; spawn[0] = "/usr/bin/killall"; spawn[1] = "-9"; @@ -177,11 +180,6 @@ - (void) applicationDidFinishLaunching: (NSNotification *) aNotification { - [xcwmWindow makeKeyAndOrderFront: self]; - - //hide window - [xcwmWindow orderOut:self]; - // Start the event loop and set the handler function xcwm_start_event_loop(rootContext, (void *) eventHandler); } @@ -191,22 +189,16 @@ //CGFloat heightFloat; NSDictionary *mouseMoveInfo = [aNotification userInfo]; NSEvent * event = [mouseMoveInfo objectForKey: @"1"]; - NSNumber * xVal = [NSNumber alloc]; - NSNumber * yVal = [NSNumber alloc]; - xVal = [mouseMoveInfo objectForKey: @"2"]; - yVal = [mouseMoveInfo objectForKey: @"3"]; - - float height = [[NSScreen mainScreen] frame].size.height; - - int yInt = height - FILEBAR - [yVal intValue]; - yVal = [[NSNumber alloc] initWithInt:yInt]; - - NSLog(@"Mouse x = %i, y = %i", [xVal intValue], [yVal intValue]); + NSNumber *xNum = [mouseMoveInfo objectForKey: @"2"]; + NSNumber *yNum = [mouseMoveInfo objectForKey: @"3"]; + int height = [[NSScreen mainScreen] frame].size.height; + dispatch_async(xcwmDispatchQueue, ^{ xcwm_mouse_motion (rootContext, - [xVal intValue], - [yVal intValue], + [xNum intValue], + //Converting OSX coordinates to X11 + height - WINDOWBAR - [yNum intValue], (int)[event windowNumber], 0);;}); @@ -227,6 +219,15 @@ ^{ xcwm_key_press(rootContext, (int)[event windowNumber], aChar + 8) ;}); +} + +- (void) keyUpInView: (NSNotification *) aNotification +{ + NSDictionary *keyInfo = [aNotification userInfo]; + // note this keyInfo is the key in <key, value> not the key pressed + NSEvent * event = [keyInfo objectForKey: @"1"]; + unsigned short aChar = [event keyCode]; + dispatch_async(xcwmDispatchQueue, ^{ xcwm_key_release(rootContext, (int)[event windowNumber], @@ -246,16 +247,18 @@ NSNumber * heightAsNumber = [NSNumber alloc]; heightAsNumber = [mouseDownInfo objectForKey: @"2"]; heightFloat = [heightAsNumber floatValue]; + + NSNumber * mouseButton = [NSNumber alloc]; + mouseButton = [mouseDownInfo objectForKey:@"3"]; + int buttonInt = [mouseButton intValue]; //NSLog(@"Mouse Info: %@", [mouseDownInfo objectForKey: @"2"]); - float height = [[NSScreen mainScreen] frame].size.height; - dispatch_async(xcwmDispatchQueue, ^{ xcwm_button_press (rootContext, 0, 0, (int)[event windowNumber], - 0);;}); + buttonInt);;}); } // on this side all I have is a xcwm_context , on the library side I need @@ -272,19 +275,23 @@ heightFloat = [heightAsNumber floatValue]; //NSLog(@"Mouse Info: %@", [mouseDownInfo objectForKey: @"2"]); - float height = [[NSScreen mainScreen] frame].size.height; + NSNumber * mouseButton = [NSNumber alloc]; + mouseButton = [mouseReleaseInfo objectForKey:@"3"]; + int buttonInt = [mouseButton intValue]; dispatch_async(xcwmDispatchQueue, ^{ xcwm_button_release (rootContext, 0, 0, (int)[event windowNumber], - 0);;}); + buttonInt);;}); } - (void) setScreen:(char *)scrn { - screen = scrn; + free(screen); + screen = strdup(scrn); + setenv("DISPLAY", screen, 1); } - (void) makeMenu { @@ -362,6 +369,15 @@ [startXMenu addItem:xtermMenuItem]; [startXApps setSubmenu:startXMenu]; + // Run Xman + NSMenuItem *xmanMenuItem; + xTitle = @"Run Xman"; + xmanMenuItem = [[NSMenuItem alloc] initWithTitle:xTitle + action:@selector(runXman:) + keyEquivalent:@""]; + [startXMenu addItem:xmanMenuItem]; + [startXApps setSubmenu:startXMenu]; + // Adding all the menu items to the main menu for XtoQ. [menubar addItem:appMenuItem]; [menubar addItem:startXApps]; @@ -372,14 +388,28 @@ int status; pid_t child; const char *file_name = [filename UTF8String]; - const char *newargv[4]; + const char *newargv[6]; + + // Xman Special case + if ([filename isEqualToString:@"xman"]) { + const char *manpath = "/opt/local/share/man:/usr/share/man:/usr/local/share/man:/opt/X11/share/man:/usr/X11/man:/usr/local/git/share/man"; + setenv("MANPATH", manpath, 1); + } - asprintf(&newargv[0], "/usr/X11/bin/%s", file_name); + newargv[0] = file_name; newargv[1] = "-display"; newargv[2] = screen; - newargv[3] = NULL; - status = posix_spawn(&child, newargv[0], NULL, NULL, (char * const *) newargv, environ); + if ([filename isEqualToString:@"xclock"]) { + newargv[3] = "-update"; + newargv[4] = "1"; + newargv[5] = NULL; + } + else { + newargv[3] = NULL; + } + + status = posix_spawnp(&child, newargv[0], NULL, NULL, (char * const *) newargv, environ); if(status) { NSLog(@"Error spawning file for launch."); } @@ -397,6 +427,9 @@ - (void) runXterm:(id) sender { [self launch_client:@"xterm"]; } +-(void) runXman:(id) sender { + [self launch_client:@"xman"]; +} // create a new window - (void) createNewWindow: (xcwm_context_t *) windowContext { @@ -468,9 +501,6 @@ }); } -- (void) windowWillMove:(NSNotification*)notification { - //NSLog(@"window will move"); -} - (void) updateImage:(xcwm_context_t *) windowContext { float y_transformed; @@ -484,7 +514,11 @@ XtoqView *localView = (XtoqView *)[(XtoqWindow *)windowContext->local_data contentView]; [ localView setPartialImage:newDamageRect]; } - +/* +- (void) windowWillMove:(NSNotification*)notification { + // do nothing +} +*/ - (void) windowDidMove:(NSNotification*)notification { [self reshape]; } @@ -505,8 +539,9 @@ windowHeight:moveContext->height] - WINDOWBAR; int width = (int)moveFrame.size.width; int height = (int)moveFrame.size.height - WINDOWBAR; - NSLog(@"Call xcwm_configure_window(moveContext, x = %i, y = %i, height = %i, width = %i)", x, y, height, width); - xcwm_configure_window(moveContext, x, y - height, height, width); + // NSLog(@"Call xtoq_configure_window(moveContext, x = %i, y = %i, height = %i, width = %i)", x, y, height, width); + xcwm_configure_window(moveContext, x, y - height, height, width); + [[moveWindow contentView] setNeedsDisplay: YES]; } } |