* Rewrote terminal ID code to use a temporary file - this fixes bug #1174.
* Tried to fix the usual deadlock on quit, but suspending the thread (to interrupt read()) doesn't have the expected outcome (might be a kernel bug). * Removed superfluous MENU_FILE_QUIT and send a B_QUIT_REQUESTED instead. * Cleanup. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20816 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
+128
-120
@@ -1,38 +1,42 @@
|
|||||||
/*
|
/*
|
||||||
|
* Copyright 2001-2007, Haiku.
|
||||||
* Copyright (c) 2003-2004 Kian Duffy <[email protected]>
|
* Copyright (c) 2003-2004 Kian Duffy <[email protected]>
|
||||||
* Copyright (C) 1998,99 Kazuho Okui and Takashi Murai.
|
* Copyright (C) 1998,99 Kazuho Okui and Takashi Murai.
|
||||||
*
|
*
|
||||||
* Distributed unter the terms of the MIT license.
|
* Distributed unter the terms of the MIT license.
|
||||||
*/
|
*/
|
||||||
#include <stdio.h>
|
|
||||||
#include <signal.h>
|
|
||||||
#include <sys/wait.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <malloc.h>
|
|
||||||
|
|
||||||
#include <storage/Path.h>
|
|
||||||
#include <NodeInfo.h>
|
#include "TermApp.h"
|
||||||
#include <Roster.h>
|
|
||||||
|
#include "CodeConv.h"
|
||||||
|
#include "PrefHandler.h"
|
||||||
|
#include "spawn.h"
|
||||||
|
#include "TermBuffer.h"
|
||||||
|
#include "TermWindow.h"
|
||||||
|
#include "TermConst.h"
|
||||||
|
|
||||||
#include <Alert.h>
|
#include <Alert.h>
|
||||||
|
#include <NodeInfo.h>
|
||||||
|
#include <Path.h>
|
||||||
|
#include <Roster.h>
|
||||||
#include <Screen.h>
|
#include <Screen.h>
|
||||||
#include <String.h>
|
#include <String.h>
|
||||||
#include <TextView.h>
|
#include <TextView.h>
|
||||||
|
|
||||||
#include "TermApp.h"
|
#include <signal.h>
|
||||||
#include "TermBuffer.h"
|
#include <stdio.h>
|
||||||
#include "TermWindow.h"
|
#include <stdlib.h>
|
||||||
#include "TermConst.h"
|
#include <sys/wait.h>
|
||||||
#include "spawn.h"
|
|
||||||
#include "PrefHandler.h"
|
|
||||||
#include "CodeConv.h"
|
|
||||||
|
|
||||||
// Preference temporary
|
// Preference temporary
|
||||||
extern PrefHandler *gTermPref;
|
extern PrefHandler *gTermPref;
|
||||||
extern char gWindowName[];
|
extern char gWindowName[];
|
||||||
|
|
||||||
bool usage_requested = false;
|
bool gUsageRequested = false;
|
||||||
bool geometry_requested = false;
|
bool gGeometryRequested = false;
|
||||||
bool color_requested = false;
|
bool gColorRequested = false;
|
||||||
|
|
||||||
struct standard_args {
|
struct standard_args {
|
||||||
char *name;
|
char *name;
|
||||||
@@ -71,23 +75,22 @@ const ulong MSG_TERM_IS_MINIMIZE = 'mtim';
|
|||||||
|
|
||||||
|
|
||||||
TermApp::TermApp()
|
TermApp::TermApp()
|
||||||
: BApplication(TERM_SIGNATURE)
|
: BApplication(TERM_SIGNATURE),
|
||||||
|
fStartFullscreen(false),
|
||||||
|
fWindowNumber(-1),
|
||||||
|
fTermWindow(NULL)
|
||||||
{
|
{
|
||||||
fWindowNumber = FindTerminalId();
|
fWindowTitle = "Terminal";
|
||||||
|
_RegisterTerminal();
|
||||||
|
|
||||||
char title[256];
|
if (fWindowNumber > 0)
|
||||||
snprintf(title, sizeof(title), "Terminal %d", fWindowNumber);
|
fWindowTitle << " " << fWindowNumber;
|
||||||
fWindowTitle = title;
|
|
||||||
fStartFullscreen = false;
|
|
||||||
|
|
||||||
int i = fWindowNumber / 16;
|
int i = fWindowNumber / 16;
|
||||||
int j = fWindowNumber % 16;
|
int j = fWindowNumber % 16;
|
||||||
|
int k = (j * 16) + (i * 64) + 50;
|
||||||
|
int l = (j * 16) + 50;
|
||||||
|
|
||||||
int k =(j * 16) + (i * 64) + 50;
|
|
||||||
int l =(j * 16) + 50;
|
|
||||||
|
|
||||||
fTermWindow = NULL;
|
|
||||||
fAboutPanel = NULL;
|
|
||||||
fTermFrame.Set(k, l, k + 50, k + 50);
|
fTermFrame.Set(k, l, k + 50, k + 50);
|
||||||
|
|
||||||
gTermPref = new PrefHandler();
|
gTermPref = new PrefHandler();
|
||||||
@@ -96,7 +99,6 @@ TermApp::TermApp()
|
|||||||
|
|
||||||
TermApp::~TermApp()
|
TermApp::~TermApp()
|
||||||
{
|
{
|
||||||
// delete gTermPref;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -104,10 +106,10 @@ void
|
|||||||
TermApp::ReadyToRun()
|
TermApp::ReadyToRun()
|
||||||
{
|
{
|
||||||
// Prevent opeing window when option -h is given.
|
// Prevent opeing window when option -h is given.
|
||||||
if (usage_requested)
|
if (gUsageRequested)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
status_t status = MakeTermWindow(fTermFrame);
|
status_t status = _MakeTermWindow(fTermFrame);
|
||||||
|
|
||||||
// failed spawn, print stdout and open alert panel
|
// failed spawn, print stdout and open alert panel
|
||||||
if (status < B_OK) {
|
if (status < B_OK) {
|
||||||
@@ -118,7 +120,6 @@ TermApp::ReadyToRun()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// using BScreen::Frame isn't enough
|
// using BScreen::Frame isn't enough
|
||||||
if (fStartFullscreen)
|
if (fStartFullscreen)
|
||||||
BMessenger(fTermWindow).SendMessage(FULLSCREEN);
|
BMessenger(fTermWindow).SendMessage(FULLSCREEN);
|
||||||
@@ -128,11 +129,13 @@ TermApp::ReadyToRun()
|
|||||||
void
|
void
|
||||||
TermApp::Quit()
|
TermApp::Quit()
|
||||||
{
|
{
|
||||||
if (!usage_requested){
|
if (!gUsageRequested){
|
||||||
int status;
|
int status;
|
||||||
|
|
||||||
kill(-sh_pid, SIGHUP);
|
kill(-sh_pid, SIGHUP);
|
||||||
wait(&status);
|
wait(&status);
|
||||||
|
|
||||||
|
_UnregisterTerminal();
|
||||||
}
|
}
|
||||||
|
|
||||||
delete gTermPref;
|
delete gTermPref;
|
||||||
@@ -166,7 +169,7 @@ TermApp::MessageReceived(BMessage* msg)
|
|||||||
{
|
{
|
||||||
switch (msg->what) {
|
switch (msg->what) {
|
||||||
case MENU_SWITCH_TERM:
|
case MENU_SWITCH_TERM:
|
||||||
SwitchTerm();
|
_SwitchTerm();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MSG_ACTIVATE_TERM:
|
case MSG_ACTIVATE_TERM:
|
||||||
@@ -204,8 +207,8 @@ TermApp::ArgvReceived(int32 argc, char **argv)
|
|||||||
|
|
||||||
// Print usage
|
// Print usage
|
||||||
if (argmatch(argv, argc, "-help", "--help", 3, NULL, &skip_args)) {
|
if (argmatch(argv, argc, "-help", "--help", 3, NULL, &skip_args)) {
|
||||||
Usage(argv[0]);
|
_Usage(argv[0]);
|
||||||
usage_requested = true;
|
gUsageRequested = true;
|
||||||
PostMessage(B_QUIT_REQUESTED);
|
PostMessage(B_QUIT_REQUESTED);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -230,14 +233,14 @@ TermApp::ArgvReceived(int32 argc, char **argv)
|
|||||||
|| width >= 256 || height >= 256 || xpos >= 2048 || ypos >= 2048) {
|
|| width >= 256 || height >= 256 || xpos >= 2048 || ypos >= 2048) {
|
||||||
fprintf(stderr, "%s: invalid geometry format or value.\n", argv[0]);
|
fprintf(stderr, "%s: invalid geometry format or value.\n", argv[0]);
|
||||||
fprintf(stderr, "Try `%s --help' for more information.\n", argv[0]);
|
fprintf(stderr, "Try `%s --help' for more information.\n", argv[0]);
|
||||||
usage_requested = true;
|
gUsageRequested = true;
|
||||||
PostMessage(B_QUIT_REQUESTED);
|
PostMessage(B_QUIT_REQUESTED);
|
||||||
}
|
}
|
||||||
gTermPref->setInt32(PREF_COLS, width);
|
gTermPref->setInt32(PREF_COLS, width);
|
||||||
gTermPref->setInt32(PREF_ROWS, height);
|
gTermPref->setInt32(PREF_ROWS, height);
|
||||||
|
|
||||||
fTermFrame.Set(xpos, ypos, xpos + 50, ypos + 50);
|
fTermFrame.Set(xpos, ypos, xpos + 50, ypos + 50);
|
||||||
geometry_requested = true;
|
gGeometryRequested = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
@@ -248,7 +251,7 @@ TermApp::ArgvReceived(int32 argc, char **argv)
|
|||||||
status_t status = inFile.SetTo("/etc/rgb.txt", B_READ_ONLY);
|
status_t status = inFile.SetTo("/etc/rgb.txt", B_READ_ONLY);
|
||||||
if (status != B_OK) {
|
if (status != B_OK) {
|
||||||
fprintf(stderr, "%s: Can't open /etc/rgb.txt file.\n", argv[0]);
|
fprintf(stderr, "%s: Can't open /etc/rgb.txt file.\n", argv[0]);
|
||||||
usage_requested = true;
|
gUsageRequested = true;
|
||||||
PostMessage(B_QUIT_REQUESTED);
|
PostMessage(B_QUIT_REQUESTED);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -278,7 +281,7 @@ TermApp::ArgvReceived(int32 argc, char **argv)
|
|||||||
if (*argv[skip_args] == '-') {
|
if (*argv[skip_args] == '-') {
|
||||||
fprintf(stderr, "%s: invalid option `%s'\n", argv[0], argv[skip_args]);
|
fprintf(stderr, "%s: invalid option `%s'\n", argv[0], argv[skip_args]);
|
||||||
fprintf(stderr, "Try `%s --help' for more information.\n", argv[0]);
|
fprintf(stderr, "Try `%s --help' for more information.\n", argv[0]);
|
||||||
usage_requested = true;
|
gUsageRequested = true;
|
||||||
PostMessage(B_QUIT_REQUESTED);
|
PostMessage(B_QUIT_REQUESTED);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -290,25 +293,9 @@ TermApp::ArgvReceived(int32 argc, char **argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//void
|
|
||||||
//TermApp::AboutRequested(void)
|
|
||||||
//{
|
|
||||||
// if(fAboutPanel) {
|
|
||||||
// fAboutPanel->Activate();
|
|
||||||
// }
|
|
||||||
// else {
|
|
||||||
// BRect rect(0, 0, 350 - 1, 170 - 1);
|
|
||||||
// rect.OffsetTo(fTermWindow->Frame().LeftTop());
|
|
||||||
// rect.OffsetBy(100, 100);
|
|
||||||
|
|
||||||
// fAboutPanel = new AboutDlg(rect, this);
|
|
||||||
// fAboutPanel->Show();
|
|
||||||
// }
|
|
||||||
|
|
||||||
//}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TermApp::RefsReceived(BMessage *message)
|
TermApp::RefsReceived(BMessage* message)
|
||||||
{
|
{
|
||||||
// Works Only Launced by Double-Click file, or Drags file to App.
|
// Works Only Launced by Double-Click file, or Drags file to App.
|
||||||
if (!IsLaunching())
|
if (!IsLaunching())
|
||||||
@@ -345,7 +332,7 @@ TermApp::RefsReceived(BMessage *message)
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
TermApp::MakeTermWindow(BRect &frame)
|
TermApp::_MakeTermWindow(BRect &frame)
|
||||||
{
|
{
|
||||||
const char *encoding = gTermPref->getString(PREF_TEXT_ENCODING);
|
const char *encoding = gTermPref->getString(PREF_TEXT_ENCODING);
|
||||||
|
|
||||||
@@ -385,10 +372,9 @@ TermApp::MakeTermWindow(BRect &frame)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TermApp::ActivateTermWindow(team_id id)
|
TermApp::_ActivateTermWindow(team_id id)
|
||||||
{
|
{
|
||||||
BMessenger app(TERM_SIGNATURE, id);
|
BMessenger app(TERM_SIGNATURE, id);
|
||||||
|
|
||||||
if (app.IsTargetLocal())
|
if (app.IsTargetLocal())
|
||||||
fTermWindow->Activate();
|
fTermWindow->Activate();
|
||||||
else
|
else
|
||||||
@@ -397,7 +383,7 @@ TermApp::ActivateTermWindow(team_id id)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TermApp::SwitchTerm()
|
TermApp::_SwitchTerm()
|
||||||
{
|
{
|
||||||
team_id myId = be_app->Team(); // My id
|
team_id myId = be_app->Team(); // My id
|
||||||
BList teams;
|
BList teams;
|
||||||
@@ -418,73 +404,98 @@ TermApp::SwitchTerm()
|
|||||||
do {
|
do {
|
||||||
if (--i < 0)
|
if (--i < 0)
|
||||||
i = numTerms - 1;
|
i = numTerms - 1;
|
||||||
} while (IsMinimize(reinterpret_cast<team_id>(teams.ItemAt(i))));
|
} while (_IsMinimized(reinterpret_cast<team_id>(teams.ItemAt(i))));
|
||||||
|
|
||||||
// Activate switched terminal.
|
// Activate switched terminal.
|
||||||
ActivateTermWindow(reinterpret_cast<team_id>(teams.ItemAt(i)));
|
_ActivateTermWindow(reinterpret_cast<team_id>(teams.ItemAt(i)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
TermApp::IsMinimize(team_id id)
|
TermApp::_IsMinimized(team_id id)
|
||||||
{
|
{
|
||||||
BMessenger app(TERM_SIGNATURE, id);
|
BMessenger app(TERM_SIGNATURE, id);
|
||||||
|
|
||||||
if (app.IsTargetLocal())
|
if (app.IsTargetLocal())
|
||||||
return fTermWindow->IsMinimized();
|
return fTermWindow->IsMinimized();
|
||||||
|
|
||||||
BMessage reply;
|
BMessage reply;
|
||||||
bool hidden;
|
|
||||||
|
|
||||||
if (app.SendMessage(MSG_TERM_IS_MINIMIZE, &reply) != B_OK)
|
if (app.SendMessage(MSG_TERM_IS_MINIMIZE, &reply) != B_OK)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
bool hidden;
|
||||||
reply.FindBool("result", &hidden);
|
reply.FindBool("result", &hidden);
|
||||||
return hidden;
|
return hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int32
|
void
|
||||||
TermApp::FindTerminalId()
|
TermApp::_UpdateRegistration(bool set)
|
||||||
{
|
{
|
||||||
BList teams;
|
if (set)
|
||||||
be_roster->GetAppList(TERM_SIGNATURE, &teams);
|
fWindowNumber = -1;
|
||||||
int32 count = teams.CountItems();
|
else if (fWindowNumber < 0)
|
||||||
int32 numbers[count];
|
return;
|
||||||
thread_info info;
|
|
||||||
get_thread_info(find_thread(NULL), &info);
|
|
||||||
|
|
||||||
for (int32 i=0; i<count; i++) {
|
int fd = open("/tmp/terminal_ids", O_RDWR | O_CREAT);
|
||||||
numbers[i] = 0;
|
if (fd < 0)
|
||||||
team_id id = (team_id)teams.ItemAt(i);
|
return;
|
||||||
if (id == info.team)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
BMessage msg(B_GET_PROPERTY);
|
struct flock lock;
|
||||||
BMessage reply;
|
lock.l_type = F_WRLCK;
|
||||||
msg.AddSpecifier("Title");
|
lock.l_whence = SEEK_CUR;
|
||||||
msg.AddSpecifier("Window", (int32)0);
|
lock.l_start = 0;
|
||||||
if (BMessenger(TERM_SIGNATURE, id).SendMessage(&msg, &reply) != B_OK)
|
lock.l_len = -1;
|
||||||
continue;
|
fcntl(fd, F_SETLKW, &lock);
|
||||||
BString title;
|
|
||||||
if (reply.FindString("result", &title)!=B_OK)
|
uint8 windows[256];
|
||||||
continue;
|
ssize_t length = read_pos(fd, 0, windows, sizeof(windows));
|
||||||
sscanf(title.String(), "Terminal %ld", &numbers[i]);
|
if (length < 0) {
|
||||||
|
close(fd);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
if (length > (ssize_t)sizeof(windows))
|
||||||
|
length = sizeof(windows);
|
||||||
|
|
||||||
for (int32 i=1; i<count; i++) {
|
if (set) {
|
||||||
bool found = false;
|
int32 i;
|
||||||
for (int32 j=0; j<count; j++) {
|
for (i = 0; i < length; i++) {
|
||||||
if (i == numbers[j]) {
|
if (!windows[i]) {
|
||||||
found = true;
|
windows[i] = true;
|
||||||
|
fWindowNumber = i + 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!found)
|
if (i == length) {
|
||||||
return i;
|
if (length >= (ssize_t)sizeof(windows)) {
|
||||||
|
close(fd);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
windows[length] = true;
|
||||||
|
length++;
|
||||||
|
fWindowNumber = length;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// update information and write it back
|
||||||
|
windows[fWindowNumber - 1] = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return count;
|
write_pos(fd, 0, windows, length);
|
||||||
|
close(fd);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TermApp::_UnregisterTerminal()
|
||||||
|
{
|
||||||
|
_UpdateRegistration(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TermApp::_RegisterTerminal()
|
||||||
|
{
|
||||||
|
_UpdateRegistration(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -510,35 +521,32 @@ TermApp::FindTerminalId()
|
|||||||
// be_roster->ActivateApp(be_roster->TeamFor(B_NETPOSITIVE_APP_SIGNATURE));
|
// be_roster->ActivateApp(be_roster->TeamFor(B_NETPOSITIVE_APP_SIGNATURE));
|
||||||
//}
|
//}
|
||||||
|
|
||||||
#define PR(a) fprintf(stderr, a)
|
|
||||||
|
|
||||||
// Display usage to stderr
|
|
||||||
void
|
void
|
||||||
TermApp::Usage(char *name)
|
TermApp::_Usage(char *name)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "\n");
|
fprintf(stderr, "Haiku Terminal\n"
|
||||||
fprintf(stderr, "Haiku Terminal\n");
|
"Copyright 2001-2007 Haiku, Inc.\n"
|
||||||
fprintf(stderr, "Copyright 2004 Haiku, Inc.\n");
|
"Copyright(C) 1999 Kazuho Okui and Takashi Murai.\n"
|
||||||
fprintf(stderr, "Parts Copyright(C) 1999 Kazuho Okui and Takashi Murai.\n");
|
"\n"
|
||||||
fprintf(stderr, "\n");
|
"Usage: %s [OPTION] [SHELL]\n", name);
|
||||||
fprintf(stderr, "Usage: %s [OPTION] [SHELL]\n", name);
|
|
||||||
|
|
||||||
PR(" -p, --preference load preference file\n");
|
fprintf(stderr, " -p, --preference load preference file\n"
|
||||||
PR(" -t, --title set window title\n");
|
" -t, --title set window title\n"
|
||||||
PR(" -geom, --geometry set window geometry\n");
|
" -geom, --geometry set window geometry\n"
|
||||||
PR(" An example of geometry is \"80x25+100+100\"\n");
|
" An example of geometry is \"80x25+100+100\"\n");
|
||||||
#if 0
|
#if 0
|
||||||
PR(" -fg, --text-fore-color set window foreground color\n");
|
fprintf(stderr, " -fg, --text-fore-color set window foreground color\n"
|
||||||
PR(" -bg, --text-back-color set window background color\n");
|
" -bg, --text-back-color set window background color\n"
|
||||||
PR(" -curfg, --cursor-fore-color set cursor foreground color\n");
|
" -curfg, --cursor-fore-color set cursor foreground color\n"
|
||||||
PR(" -curbg, --cursor-back-color set cursor background color\n");
|
" -curbg, --cursor-back-color set cursor background color\n"
|
||||||
PR(" -selfg, --select-fore-color set selection area foreground color\n");
|
" -selfg, --select-fore-color set selection area foreground color\n"
|
||||||
PR(" -selbg, --select-back-color set selection area background color\n");
|
" -selbg, --select-back-color set selection area background color\n"
|
||||||
PR(" Examples of color are \"#FF00FF\" and \"purple\"\n");
|
" Examples of color are \"#FF00FF\" and \"purple\"\n");
|
||||||
#endif
|
#endif
|
||||||
PR("\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
text_to_rgb(char *name, rgb_color *color, char *buffer)
|
text_to_rgb(char *name, rgb_color *color, char *buffer)
|
||||||
{
|
{
|
||||||
|
|||||||
+37
-45
@@ -1,4 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
|
* Copyright 2001-2007, Haiku.
|
||||||
* Copyright (c) 2003-4 Kian Duffy <[email protected]>
|
* Copyright (c) 2003-4 Kian Duffy <[email protected]>
|
||||||
* Parts Copyright (C) 1998,99 Kazuho Okui and Takashi Murai.
|
* Parts Copyright (C) 1998,99 Kazuho Okui and Takashi Murai.
|
||||||
*
|
*
|
||||||
@@ -27,13 +28,14 @@
|
|||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
#ifndef TERM_APP_H
|
||||||
|
#define TERM_APP_H
|
||||||
|
|
||||||
#ifndef TERMAPP_H
|
|
||||||
#define TERMAPP_H
|
|
||||||
|
|
||||||
#include <app/Application.h>
|
#include <Application.h>
|
||||||
#include <String.h>
|
#include <String.h>
|
||||||
|
|
||||||
|
|
||||||
extern int gPfd;
|
extern int gPfd;
|
||||||
extern char *ptyname;
|
extern char *ptyname;
|
||||||
|
|
||||||
@@ -42,51 +44,41 @@ class TermParse;
|
|||||||
class BRect;
|
class BRect;
|
||||||
class AboutDlg;
|
class AboutDlg;
|
||||||
|
|
||||||
class TermApp : public BApplication
|
class TermApp : public BApplication {
|
||||||
{
|
public:
|
||||||
public:
|
TermApp();
|
||||||
TermApp();
|
virtual ~TermApp();
|
||||||
~TermApp();
|
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
/*
|
void ReadyToRun();
|
||||||
* Hook functions
|
void Quit();
|
||||||
*/
|
void AboutRequested();
|
||||||
void ReadyToRun();
|
void MessageReceived(BMessage* message);
|
||||||
void Quit();
|
void RefsReceived(BMessage* message);
|
||||||
void AboutRequested();
|
void ArgvReceived(int32 argc, char** argv);
|
||||||
void MessageReceived(BMessage* msg);
|
|
||||||
void RefsReceived(BMessage *message);
|
|
||||||
void ArgvReceived(int32 argc, char **argv);
|
|
||||||
|
|
||||||
/*
|
private:
|
||||||
* Public Member functions.
|
status_t _MakeTermWindow(BRect& frame);
|
||||||
*/
|
void _SwitchTerm();
|
||||||
status_t MakeTermWindow (BRect &frame);
|
void _ActivateTermWindow(team_id id);
|
||||||
void SwitchTerm(void);
|
bool _IsMinimized(team_id id);
|
||||||
void ActivateTermWindow(team_id id);
|
void _UpdateRegistration(bool set);
|
||||||
|
void _UnregisterTerminal();
|
||||||
|
void _RegisterTerminal();
|
||||||
|
|
||||||
void Usage(char *name);
|
void _Usage(char *name);
|
||||||
|
|
||||||
private:
|
|
||||||
bool IsMinimize (team_id);
|
|
||||||
int32 FindTerminalId();
|
|
||||||
|
|
||||||
int fRows, fCols, fXpos, fYpos;
|
|
||||||
bool fStartFullscreen;
|
|
||||||
BString fWindowTitle;
|
|
||||||
int fWindowNumber;
|
|
||||||
rgb_color fFg, fBg, fCurFg, fCurBg, fSelFg, fSelbg;
|
|
||||||
rgb_color fImfg, fImbg, fImSel;
|
|
||||||
|
|
||||||
TermWindow *fTermWindow;
|
|
||||||
TermParse *fTermParse;
|
|
||||||
BRect fTermFrame;
|
|
||||||
AboutDlg *fAboutPanel;
|
|
||||||
|
|
||||||
BString CommandLine;
|
|
||||||
|
|
||||||
|
port_id fRegistrationPort;
|
||||||
|
int32 fRows, fCols, fXpos, fYpos;
|
||||||
|
bool fStartFullscreen;
|
||||||
|
BString fWindowTitle;
|
||||||
|
int32 fWindowNumber;
|
||||||
|
rgb_color fFg, fBg, fCurFg, fCurBg, fSelFg, fSelbg;
|
||||||
|
rgb_color fImfg, fImbg, fImSel;
|
||||||
|
TermWindow* fTermWindow;
|
||||||
|
TermParse* fTermParse;
|
||||||
|
BRect fTermFrame;
|
||||||
|
BString CommandLine;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif // TERM_APP_H
|
||||||
|
|
||||||
|
|||||||
@@ -44,7 +44,6 @@
|
|||||||
const uint32 MENU_SWITCH_TERM = 'MSWT';
|
const uint32 MENU_SWITCH_TERM = 'MSWT';
|
||||||
const uint32 MENU_NEW_TERM = 'MNTE';
|
const uint32 MENU_NEW_TERM = 'MNTE';
|
||||||
const uint32 MENU_PREF_OPEN = 'MPre';
|
const uint32 MENU_PREF_OPEN = 'MPre';
|
||||||
const uint32 MENU_FILE_QUIT = 'MFqu';
|
|
||||||
const uint32 MENU_CLEAR_ALL = 'MCAl';
|
const uint32 MENU_CLEAR_ALL = 'MCAl';
|
||||||
const uint32 MENU_HELP = 'Mhlp';
|
const uint32 MENU_HELP = 'Mhlp';
|
||||||
const uint32 MENU_COMMAND_HELP = 'Mchp';
|
const uint32 MENU_COMMAND_HELP = 'Mchp';
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2001-2005, Haiku, Inc.
|
* Copyright 2001-2007, Haiku, Inc.
|
||||||
* Copyright (c) 2003-4 Kian Duffy <[email protected]>
|
* Copyright (c) 2003-4 Kian Duffy <[email protected]>
|
||||||
* Parts Copyright (C) 1998,99 Kazuho Okui and Takashi Murai.
|
* Parts Copyright (C) 1998,99 Kazuho Okui and Takashi Murai.
|
||||||
* Distributed under the terms of the MIT license.
|
* Distributed under the terms of the MIT license.
|
||||||
@@ -48,10 +48,9 @@ int gNowCoding = M_UTF8;
|
|||||||
#define DEFAULT -1
|
#define DEFAULT -1
|
||||||
#define NPARAM 10 // Max parameters
|
#define NPARAM 10 // Max parameters
|
||||||
|
|
||||||
/*
|
|
||||||
* Constructor and Destructor.
|
TermParse::TermParse(int fd, TermWindow *inWinObj, TermView *inViewObj,
|
||||||
*/
|
CodeConv *inConvObj)
|
||||||
TermParse::TermParse(int fd, TermWindow *inWinObj, TermView *inViewObj, CodeConv *inConvObj)
|
|
||||||
:
|
:
|
||||||
fFd(fd),
|
fFd(fd),
|
||||||
fViewObj(inViewObj),
|
fViewObj(inViewObj),
|
||||||
@@ -77,6 +76,9 @@ TermParse::~TermParse()
|
|||||||
delete_sem(fReaderSem);
|
delete_sem(fReaderSem);
|
||||||
delete_sem(fReaderLocker);
|
delete_sem(fReaderLocker);
|
||||||
|
|
||||||
|
//suspend_thread(fReaderThread);
|
||||||
|
// TODO: interrupt read() - doesn't work for whatever reason
|
||||||
|
|
||||||
status_t dummy;
|
status_t dummy;
|
||||||
wait_for_thread(fReaderThread, &dummy);
|
wait_for_thread(fReaderThread, &dummy);
|
||||||
wait_for_thread(fParseThread, &dummy);
|
wait_for_thread(fParseThread, &dummy);
|
||||||
@@ -101,10 +103,7 @@ TermParse::StartThreads()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
//! Get data from pty device.
|
||||||
// PtyReader ... Get character from pty device.
|
|
||||||
//
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
int32
|
int32
|
||||||
TermParse::PtyReader()
|
TermParse::PtyReader()
|
||||||
{
|
{
|
||||||
@@ -124,13 +123,15 @@ TermParse::PtyReader()
|
|||||||
// Read PTY
|
// Read PTY
|
||||||
uchar buf[READ_BUF_SIZE];
|
uchar buf[READ_BUF_SIZE];
|
||||||
int nread = read(fFd, buf, READ_BUF_SIZE - (read_p - fParser_p));
|
int nread = read(fFd, buf, READ_BUF_SIZE - (read_p - fParser_p));
|
||||||
if (nread <= 0) {
|
if (nread <= 0) {
|
||||||
be_app->PostMessage(B_QUIT_REQUESTED);
|
be_app->PostMessage(B_QUIT_REQUESTED);
|
||||||
exit_thread(B_ERROR);
|
exit_thread(B_ERROR);
|
||||||
}
|
}
|
||||||
int left = READ_BUF_SIZE - (read_p % READ_BUF_SIZE);
|
|
||||||
int mod = read_p % READ_BUF_SIZE;
|
// Copy read string to PtyBuffer.
|
||||||
// Copy read string to PtyBuffer.
|
|
||||||
|
int left = READ_BUF_SIZE - (read_p % READ_BUF_SIZE);
|
||||||
|
int mod = read_p % READ_BUF_SIZE;
|
||||||
|
|
||||||
if (nread >= left) {
|
if (nread >= left) {
|
||||||
memcpy(fReadBuf + mod, buf, left);
|
memcpy(fReadBuf + mod, buf, left);
|
||||||
@@ -141,19 +142,15 @@ TermParse::PtyReader()
|
|||||||
read_p += nread;
|
read_p += nread;
|
||||||
|
|
||||||
// Release semaphore. Number of semaphore counter is nread.
|
// Release semaphore. Number of semaphore counter is nread.
|
||||||
release_sem_etc(fReaderSem, nread, 0);
|
release_sem_etc(fReaderSem, nread, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
fReaderThread = -1;
|
fReaderThread = -1;
|
||||||
exit_thread(B_OK);
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
//! Get char from pty reader buffer.
|
||||||
// GetReaderBuf ... Get char pty reader buffer.
|
|
||||||
//
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
|
||||||
status_t
|
status_t
|
||||||
TermParse::GetReaderBuf(uchar &c)
|
TermParse::GetReaderBuf(uchar &c)
|
||||||
{
|
{
|
||||||
@@ -163,15 +160,15 @@ TermParse::GetReaderBuf(uchar &c)
|
|||||||
} while (status == B_INTERRUPTED);
|
} while (status == B_INTERRUPTED);
|
||||||
|
|
||||||
if (status == B_TIMED_OUT) {
|
if (status == B_TIMED_OUT) {
|
||||||
fViewObj->ScrollAtCursor();
|
fViewObj->ScrollAtCursor();
|
||||||
fViewObj->UpdateLine();
|
fViewObj->UpdateLine();
|
||||||
|
|
||||||
// Reset cursor blinking time and turn on cursor blinking.
|
// Reset cursor blinking time and turn on cursor blinking.
|
||||||
fCursorUpdate->SetInterval (1000000);
|
fCursorUpdate->SetInterval (1000000);
|
||||||
fViewObj->SetCurDraw (CURON);
|
fViewObj->SetCurDraw (CURON);
|
||||||
|
|
||||||
// wait new input from pty.
|
// wait new input from pty.
|
||||||
do {
|
do {
|
||||||
status = acquire_sem(fReaderSem);
|
status = acquire_sem(fReaderSem);
|
||||||
} while (status == B_INTERRUPTED);
|
} while (status == B_INTERRUPTED);
|
||||||
if (status < B_OK)
|
if (status < B_OK)
|
||||||
@@ -185,39 +182,34 @@ TermParse::GetReaderBuf(uchar &c)
|
|||||||
fParser_p++;
|
fParser_p++;
|
||||||
// If PtyReader thread locked, decrement counter and unlock thread.
|
// If PtyReader thread locked, decrement counter and unlock thread.
|
||||||
if (fLockFlag != 0) {
|
if (fLockFlag != 0) {
|
||||||
if (--fLockFlag == 0)
|
if (--fLockFlag == 0)
|
||||||
release_sem(fReaderLocker);
|
release_sem(fReaderLocker);
|
||||||
}
|
}
|
||||||
|
|
||||||
fViewObj->SetCurDraw(CUROFF);
|
fViewObj->SetCurDraw(CUROFF);
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
//! Initialize and spawn EscParse thread.
|
||||||
// InitTermParse ... Initialize and spawn EscParse thread.
|
|
||||||
//
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
|
||||||
status_t
|
status_t
|
||||||
TermParse::InitTermParse()
|
TermParse::InitTermParse()
|
||||||
{
|
{
|
||||||
if (fParseThread >= 0)
|
if (fParseThread >= 0)
|
||||||
return B_ERROR; // we might want to return B_OK instead ?
|
return B_ERROR; // we might want to return B_OK instead ?
|
||||||
|
|
||||||
|
BMessage cursor(MSGRUN_CURSOR);
|
||||||
fCursorUpdate = new BMessageRunner(BMessenger(fViewObj),
|
fCursorUpdate = new BMessageRunner(BMessenger(fViewObj),
|
||||||
new BMessage(MSGRUN_CURSOR), 1000000);
|
&cursor, 1000000);
|
||||||
|
|
||||||
fParseThread = spawn_thread(_escparse_thread, "EscParse", B_DISPLAY_PRIORITY, this);
|
fParseThread = spawn_thread(_escparse_thread, "EscParse",
|
||||||
|
B_DISPLAY_PRIORITY, this);
|
||||||
|
|
||||||
return resume_thread(fParseThread);
|
return resume_thread(fParseThread);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
//! Initialize and spawn PtyReader thread.
|
||||||
// InitPtyReader ... Initialize and spawn PtyReader thread.
|
|
||||||
//
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
|
||||||
thread_id
|
thread_id
|
||||||
TermParse::InitPtyReader()
|
TermParse::InitPtyReader()
|
||||||
{
|
{
|
||||||
@@ -234,7 +226,8 @@ TermParse::InitPtyReader()
|
|||||||
return fReaderLocker;
|
return fReaderLocker;
|
||||||
}
|
}
|
||||||
|
|
||||||
fReaderThread = spawn_thread(_ptyreader_thread, "PtyReader", B_NORMAL_PRIORITY, this);
|
fReaderThread = spawn_thread(_ptyreader_thread, "PtyReader",
|
||||||
|
B_NORMAL_PRIORITY, this);
|
||||||
if (fReaderThread < 0) {
|
if (fReaderThread < 0) {
|
||||||
delete_sem(fReaderSem);
|
delete_sem(fReaderSem);
|
||||||
delete_sem(fReaderLocker);
|
delete_sem(fReaderLocker);
|
||||||
@@ -869,16 +862,14 @@ TermParse::EscParse()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* static */
|
/*static*/ int32
|
||||||
int32
|
|
||||||
TermParse::_ptyreader_thread(void *data)
|
TermParse::_ptyreader_thread(void *data)
|
||||||
{
|
{
|
||||||
return reinterpret_cast<TermParse *>(data)->PtyReader();
|
return reinterpret_cast<TermParse *>(data)->PtyReader();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* static */
|
/*static*/ int32
|
||||||
int32
|
|
||||||
TermParse::_escparse_thread(void *data)
|
TermParse::_escparse_thread(void *data)
|
||||||
{
|
{
|
||||||
return reinterpret_cast<TermParse *>(data)->EscParse();
|
return reinterpret_cast<TermParse *>(data)->EscParse();
|
||||||
|
|||||||
@@ -27,14 +27,15 @@
|
|||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef TERMPARSE_H
|
#ifndef TERMPARSE_H
|
||||||
#define TERMPARSE_H
|
#define TERMPARSE_H
|
||||||
|
|
||||||
|
|
||||||
|
#include "TermConst.h"
|
||||||
|
|
||||||
#include <OS.h>
|
#include <OS.h>
|
||||||
#include <MessageRunner.h>
|
#include <MessageRunner.h>
|
||||||
|
|
||||||
#include "TermConst.h"
|
|
||||||
|
|
||||||
class TermView;
|
class TermView;
|
||||||
class CodeConv;
|
class CodeConv;
|
||||||
|
|||||||
@@ -228,7 +228,7 @@ TermWindow::SetupMenu(void)
|
|||||||
fFilemenu->AddSeparatorItem();
|
fFilemenu->AddSeparatorItem();
|
||||||
fFilemenu->AddItem(new BMenuItem("About Terminal...", new BMessage(B_ABOUT_REQUESTED)));
|
fFilemenu->AddItem(new BMenuItem("About Terminal...", new BMessage(B_ABOUT_REQUESTED)));
|
||||||
fFilemenu->AddSeparatorItem();
|
fFilemenu->AddSeparatorItem();
|
||||||
fFilemenu->AddItem(new BMenuItem("Quit", new BMessage(MENU_FILE_QUIT), 'Q'));
|
fFilemenu->AddItem(new BMenuItem("Quit", new BMessage(B_QUIT_REQUESTED), 'Q'));
|
||||||
fMenubar->AddItem(fFilemenu);
|
fMenubar->AddItem(fFilemenu);
|
||||||
|
|
||||||
// Make Edit Menu.
|
// Make Edit Menu.
|
||||||
@@ -247,7 +247,6 @@ TermWindow::SetupMenu(void)
|
|||||||
fEditmenu->AddItem (fFindForwardMenuItem);
|
fEditmenu->AddItem (fFindForwardMenuItem);
|
||||||
fFindForwardMenuItem->SetEnabled(false);
|
fFindForwardMenuItem->SetEnabled(false);
|
||||||
|
|
||||||
|
|
||||||
fMenubar->AddItem (fEditmenu);
|
fMenubar->AddItem (fEditmenu);
|
||||||
|
|
||||||
// Make Help Menu.
|
// Make Help Menu.
|
||||||
@@ -370,7 +369,7 @@ TermWindow::MessageReceived(BMessage *message)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Enable the menu items Find Forward and Find Backward
|
// Enable the menu items Find Forward and Find Backward
|
||||||
fFindBackwardMenuItem->SetEnabled(true);
|
fFindBackwardMenuItem->SetEnabled(true);
|
||||||
fFindForwardMenuItem->SetEnabled(true);
|
fFindForwardMenuItem->SetEnabled(true);
|
||||||
break;
|
break;
|
||||||
@@ -393,14 +392,10 @@ TermWindow::MessageReceived(BMessage *message)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MSG_FIND_CLOSED: {
|
case MSG_FIND_CLOSED:
|
||||||
fFindPanel = NULL;
|
fFindPanel = NULL;
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
case MENU_FILE_QUIT: {
|
|
||||||
be_app->PostMessage(B_QUIT_REQUESTED);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case MENU_ENCODING: {
|
case MENU_ENCODING: {
|
||||||
message->FindInt32 ("op", &coding_id);
|
message->FindInt32 ("op", &coding_id);
|
||||||
gNowCoding = coding_id;
|
gNowCoding = coding_id;
|
||||||
@@ -600,35 +595,16 @@ TermWindow::WindowActivated (bool )
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////
|
|
||||||
// Quit (void)
|
|
||||||
// Quit Application.
|
|
||||||
////////////////////////////////////////////////////////////////////////////
|
|
||||||
//void
|
|
||||||
//TermWindow::colRequested() {
|
|
||||||
// colWindow *colW=new colWindow("Colours for Terminal");
|
|
||||||
// colW->Show();
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
TermWindow::Quit()
|
|
||||||
{
|
|
||||||
BWindow::Quit();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
TermWindow::QuitRequested(void)
|
TermWindow::QuitRequested()
|
||||||
{
|
{
|
||||||
return BWindow::QuitRequested();
|
be_app->PostMessage(B_QUIT_REQUESTED);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////
|
//! Get Machine Timezone.
|
||||||
// int GetTimeZone (void)
|
|
||||||
// Get Machine Timezone.
|
|
||||||
////////////////////////////////////////////////////////////////////////////
|
|
||||||
int
|
int
|
||||||
TermWindow::GetTimeZone()
|
TermWindow::GetTimeZone()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -50,28 +50,27 @@ class FindWindow;
|
|||||||
class TermWindow : public BWindow {
|
class TermWindow : public BWindow {
|
||||||
public:
|
public:
|
||||||
TermWindow(BRect frame, const char* title, int gPfd);
|
TermWindow(BRect frame, const char* title, int gPfd);
|
||||||
~TermWindow();
|
virtual ~TermWindow();
|
||||||
|
|
||||||
void Quit (void);
|
void TermWinActivate();
|
||||||
bool QuitRequested (void);
|
|
||||||
void TermWinActivate (void);
|
|
||||||
status_t GetSupportedSuites (BMessage *msg);
|
|
||||||
BHandler* ResolveSpecifier (BMessage *msg, int32 index,
|
|
||||||
BMessage *specifier, int32 form,
|
|
||||||
const char *property);
|
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
void InitWindow (void);
|
virtual void MessageReceived(BMessage *message);
|
||||||
void SetupMenu (void);
|
virtual void WindowActivated(bool);
|
||||||
// void colRequested (void);
|
virtual void MenusBeginning(void);
|
||||||
void MessageReceived (BMessage *message);
|
virtual bool QuitRequested();
|
||||||
void WindowActivated (bool);
|
|
||||||
int GetTimeZone (void);
|
status_t GetSupportedSuites(BMessage *msg);
|
||||||
void MenusBeginning(void);
|
BHandler* ResolveSpecifier(BMessage *msg, int32 index,
|
||||||
// void doShowHelp (uint32 command);
|
BMessage *specifier, int32 form,
|
||||||
// Printing
|
const char *property);
|
||||||
status_t DoPageSetup (void);
|
|
||||||
void DoPrint (void);
|
private:
|
||||||
|
void InitWindow();
|
||||||
|
void SetupMenu();
|
||||||
|
int GetTimeZone();
|
||||||
|
status_t DoPageSetup();
|
||||||
|
void DoPrint();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* data member
|
* data member
|
||||||
|
|||||||
Reference in New Issue
Block a user