bool Window::MoveTo( int x, int y ) { // Send resize request. Message *msg = new Message(MOVE); msg->AddInt( "_id", m_wid ); msg->AddInt( "_x", x ); msg->AddInt( "_y", y ); Message *reply = Messenger::SendReceiveMessage( "gui_server", m_did, msg ); if ( reply == NULL ) { delete msg; return false; } delete msg; int rc = reply->rc(); if ( rc != 0 ) { delete reply; return false; } // Okay.. our move was granted. Let see what we were given. int bad = 0; if ( reply->FindRect( "_rect", &m_frame ) != 0 ) bad = -1; delete reply; if ( bad != 0 ) return false; return true; }
int GUIControl::SetMode( int video_id, int width, int height, int mode ) { Message *msg = new Message( SET ); msg->AddString( "_type", "video_mode" ); msg->AddInt( "_id", video_id ); msg->AddInt( "_width", width ); msg->AddInt( "_height", height ); msg->AddInt( "_mode", mode ); Message *reply = Messenger::SendReceiveMessage( "gui_server", 0, msg ); if ( reply == NULL ) { delete msg; return -1; } int ans = reply->rc(); if ( ans != 0 ) { if ( msg->error() != NULL ) printf("%s%s\n","error: ", msg->error() ); } delete reply; delete msg; return ans; }
int GUIControl::SetDesktopDriver( int desktop_id, int video_id ) { Message *msg = new Message( SET ); msg->AddString( "_type", "desktop_driver" ); msg->AddInt( "_id", desktop_id ); msg->AddInt( "_vid", video_id ); Message *reply = Messenger::SendReceiveMessage( "gui_server", 0, msg ); if ( reply == NULL ) { delete msg; return -1; } delete msg; int ans = reply->rc(); if ( ans != 0 ) { if ( msg->error() != NULL ) printf("%s%s\n","error: ", msg->error() ); } delete reply; return ans; }
int Window::Register() { Message *msg = new Message(REGISTER); msg->AddString( "_type", "window" ); msg->AddInt( "_port", Port() ); msg->AddString( "_title", m_title ); msg->AddRect( "_rect", Frame() ); msg->AddBool( "_visible", false ); msg->AddInt( "_flags", m_flags ); Message *reply = Messenger::SendReceiveMessage( "gui_server", 0, msg ); if ( reply == NULL ) { delete msg; return -1; } delete msg; if ( reply->rc() != 0 ) { delete reply; return -1; } // Good reply.. let's get the information. int bad = 0; if ( reply->FindInt( "_id", &m_wid ) != 0 ) bad = -1; if ( reply->FindInt( "_sid", &m_sid ) != 0 ) bad = -1; if ( reply->FindInt( "_did", &m_did ) != 0 ) bad = -1; if ( reply->FindRect( "_rect", &m_frame ) != 0 ) bad = -1; delete reply; // Accept the GUI memory and everything. int tmp_pages; unsigned int tmp_flags; if ( smk_request_shmem( m_sid, (void**)&m_buffer, &tmp_pages, &tmp_flags ) != 0 ) bad = -1; // We now have our GUI buffer, size and ID. if ( bad != 0 ) return -1; // Registered with desktop port = m_did return 0; }
int Window::Deregister() { Message *msg = new Message( DEREGISTER ); msg->AddInt( "_id", m_wid ); Message *reply = Messenger::SendReceiveMessage( "gui_server", m_did, msg ); if ( reply == NULL ) { delete msg; return -1; } delete msg; // Check response.. not that we care, really. int ans = reply->rc(); delete reply; // And... breathe... if ( m_sid >= 0 ) smk_release_shmem( m_sid ); m_buffer = NULL; m_sid = -1; m_did = 0; return ans; }
int GUIControl::DeleteDesktop( int desktop_id ) { Message *msg = new Message( DELETE ); msg->AddString( "_type", "desktop" ); msg->AddInt( "_id", desktop_id ); Message *reply = Messenger::SendReceiveMessage( "gui_server", 0, msg ); if ( reply == NULL ) { delete msg; return -1; } delete msg; if ( reply->rc() != 0 ) { if ( msg->error() != NULL ) printf("%s%s\n","error: ", msg->error() ); delete reply; return -1; } delete reply; return 0; }
/** Convenience method to sends a reply Message with a * what value of "OK", and the given "rc" and "_error" * parameters. * * \param rc The return code which will be embedded as an Int named "rc". * \param error The return string to embed as "_error". Nothing is embedded * if NULL is specified. * * \return 0 if the reply was sent successfully. */ int Message::SendRC( int rc, char *error ) { Message *msg = new Message( OK ); msg->AddInt( "rc", rc ); if ( error != NULL ) msg->AddString( "_error", error ); int ans = SendReply( msg ); delete msg; return ans; }
int GUIControl::GetDesktopMode( int desktop_id, int *video_id, int *width, int *height, int *mode ) { Message *msg = new Message( GET ); msg->AddString( "_type", "desktop_mode" ); msg->AddInt( "_id", desktop_id ); Message *reply = Messenger::SendReceiveMessage( "gui_server", 0, msg ); if ( reply == NULL ) { delete msg; return -1; } delete msg; int ans = reply->rc(); if ( ans != 0 ) { if ( msg->error() != NULL ) printf("%s%s\n","error: ", msg->error() ); } if ( reply->FindInt( "_id", video_id ) != 0 ) ans = -1; if ( reply->FindInt( "_width", width ) != 0 ) ans = -1; if ( reply->FindInt( "_height", height ) != 0 ) ans = -1; if ( reply->FindInt( "_mode", mode ) != 0 ) ans = -1; delete reply; return ans; }
bool Window::ResizeTo( int width, int height ) { // within reason. if ( (width < 5) || (height < 5) ) return false; Rect newFrame = Frame(); newFrame.right = newFrame.left + width - 1; newFrame.bottom = newFrame.top + height - 1; // Send resize request. Message *msg = new Message(RESIZE); msg->AddInt( "_id", m_wid ); msg->AddRect( "_rect", newFrame ); Message *reply = Messenger::SendReceiveMessage( "gui_server", m_did, msg ); if ( reply == NULL ) { delete msg; return false; } delete msg; if ( reply->rc() != 0 ) { delete reply; return false; } // Good reply.. let's get the information. int bad = 0; int new_sid; if ( reply->FindInt( "_sid", &new_sid ) != 0 ) bad = -1; if ( reply->FindRect( "_rect", &newFrame ) != 0 ) bad = -1; delete reply; if ( bad != 0 ) return -1; // --------- Release what used to be. if ( m_sid >= 0 ) smk_release_shmem( m_sid ); m_buffer = NULL; m_sid = new_sid; m_frame = newFrame; // Accept the GUI memory and everything. int tmp_pages; unsigned int tmp_flags; if ( smk_request_shmem( m_sid, (void**)&m_buffer, &tmp_pages, &tmp_flags) != 0 ) { // Freak out... exit(-1); } // .................... Draw(Bounds()); Sync(); // We now have our GUI buffer, size and ID. return true; }