bbsmount.cc

来自「蒙特卡洛仿真源代码很有参考价值要按照步骤进行操作」· CC 代码 · 共 1,127 行 · 第 1/3 页

CC
1,127 行
字号
			FocusChangeMask | KeyPressMask | StructureNotifyMask;    pixmap.frame = getImageControl()->renderImage(rootgeometry.width, rootgeometry.height, &resource->frame.texture);    pixmap.draw = getImageControl()->renderImage(resource->app.column_width, resource->app.row_height, &resource->app.mount_texture);    pixmap.draw_pressed = getImageControl()->renderImage(resource->app.column_width, resource->app.row_height, &resource->app.mount_texture_pressed);    if (!do_reconfigure) {	rootwin = XCreateWindow(getXDisplay(), getCurrentScreenInfo()->getRootWindow(), resource->position.x, resource->position.y, rootgeometry.width,		rootgeometry.height, 0, getCurrentScreenInfo()->getDepth(), InputOutput, getCurrentScreenInfo()->getVisual(), create_mask, &attrib);    }    else	if (!withdrawn) {	    XMoveResizeWindow(getXDisplay(), rootwin, resource->position.x, resource->position.y,		   rootgeometry.width, rootgeometry.height);	}	else {	    XResizeWindow(getXDisplay(), rootwin, rootgeometry.width, rootgeometry.height);	}    wmhints.flags = IconWindowHint | StateHint;    wmhints.icon_window = rootwin;    XSetStandardProperties(getXDisplay(), rootwin, BBTOOL, BBTOOL, None,	    getArgv(), getArgc(), NULL);    XSetWMProtocols (getXDisplay(), rootwin, &wm_delete_window, 1);    XSetWMHints(getXDisplay(), rootwin, &wmhints);    if (!shape)	XSetWindowBackgroundPixmap(getXDisplay(), rootwin, pixmap.frame);    if (!do_reconfigure) {	XClearWindow(getXDisplay(), rootwin);	XMapWindow(getXDisplay(), rootwin);    }}voidToolWindow::CreateSubWindows(const bool do_reconfigure){    int col = 0, row = 0;    vector<MountPoint>::iterator pointer;    vector<MountWindow *>::iterator mwpointer = mount_windows.begin();    if (!do_reconfigure) {	for (pointer = mount_points.begin(); pointer != mount_points.end(); pointer++) {	    if (col == resource->app.columns) {		if (++row == resource->app.rows)		    break;		col = 0;	    }	    mount_windows.push_back(new MountWindow(&*pointer, getXDisplay(), rootwin, resource->frame.bevelWidth +		    col * resource->app.column_width + resource->app.button_padding * col,		    resource->frame.bevelWidth + row * resource->app.row_height +		    resource->app.button_padding * row, resource->app.column_width,		    resource->app.row_height));	    mount_windows.back()->Draw();	    col++;	}    }    else	if (!withdrawn) {	    for (; mwpointer != mount_windows.end(); mwpointer++)		delete *mwpointer;	    mount_windows.clear();	    for (pointer = mount_points.begin(); pointer != mount_points.end(); pointer++) {		if (col == resource->app.columns) {		    if (++row == resource->app.rows)			break;		    col = 0;		}		mount_windows.push_back(new MountWindow(&*pointer, getXDisplay(), rootwin, resource->frame.bevelWidth +			col * resource->app.column_width + resource->app.button_padding * col,			resource->frame.bevelWidth + row * resource->app.row_height +			resource->app.button_padding * row, resource->app.column_width,			resource->app.row_height));		mount_windows.back()->Draw();		col++;	    }	}	else {	    for (; mwpointer != mount_windows.end(); mwpointer++)		delete *mwpointer;	    mount_windows.clear();	    for (pointer = mount_points.begin(); pointer != mount_points.end(); pointer++) {		if (col == resource->app.columns) {		    if (++row == resource->app.rows)			break;		    col = 0;		}		mount_windows.push_back(new MountWindow(&*pointer, getXDisplay(), rootwin, resource->frame.bevelWidth +			col * resource->app.column_width + resource->app.button_padding * col,			resource->frame.bevelWidth + row * resource->app.row_height +			resource->app.button_padding * row, resource->app.column_width,			resource->app.row_height));		mount_windows.back()->Draw();		col++;	    }	}    XMapSubwindows(getXDisplay(), rootwin);}voidToolWindow::EventLoop(void){    XEvent event;    vector<MountWindow *>::iterator pointer;    unsigned int command;    while (!stop) {	XNextEvent(getXDisplay(), &event);	switch (event.type) {	    case Expose:		if (stop)		    return;		if (event.xexpose.window == rootwin) {		    if (event.xexpose.send_event == True) {			for (pointer = mount_windows.begin(); pointer != mount_windows.end(); pointer++) {				(*pointer)->Update();				if ((*tooltip_for_mp) == (*pointer)->GetMountPoint())				    updateTooltip();			}		    }		    else			Draw(event.xexpose.x, event.xexpose.y, event.xexpose.width, event.xexpose.height);		}		else {		    for (pointer = mount_windows.begin(); pointer != mount_windows.end(); pointer++)			if (event.xexpose.window == (*pointer)->GetWindow()) {				(*pointer)->Draw(event.xexpose.x, event.xexpose.y, event.xexpose.width,					event.xexpose.height);				break;			}		    tooltip.processEvent(event);		}		break;	    case ButtonPress:		tooltip.hide();		is_statfs_filled = false;		tooltip_for_mp = NULL;		for (pointer = mount_windows.begin(); pointer != mount_windows.end(); pointer++)		    if (event.xbutton.window == (*pointer)->GetWindow()) {			command = (*pointer)->GetMountPoint().GetCommand(event.xbutton.button, event.xbutton.state);			if (command) {			    (*pointer)->SetPressed(true);			    char *comm = (char *)malloc(sizeof(char) * (commands[command].length() + (*pointer)->GetMountPoint().GetMountPoint().length()));			    sprintf(comm, commands[command].c_str(), (*pointer)->GetMountPoint().GetMountPoint().c_str());#if DEBUG			    if (debug_level >= dbg_all_work)				printf("Executing command: `%s`\n", comm);#endif /* DEBUG */#if RUN_IN_BACKGROUND			    run_command_in_background(comm, (*pointer)->GetMountPoint());#else /* !RUN_IN_BACKGROUND */			    run_command_in_foreground(comm, (*pointer)->GetMountPoint());#endif /* !RUN_IN_BACKGROUND */			    free(comm);			}		    }		break;	    case ButtonRelease:		tooltip.hide();		is_statfs_filled = false;		tooltip_for_mp = NULL;		for (pointer = mount_windows.begin(); pointer != mount_windows.end(); pointer++)		    if (event.xbutton.window == (*pointer)->GetWindow())			(*pointer)->SetPressed(false);		break;	    case MotionNotify:		if (tooltip.getTimeout()) {		    tooltip.hide();		    is_statfs_filled = false;		    tooltip_for_mp = NULL;		    ShowTooltip(event.xmotion.window, event.xmotion.x, event.xmotion.y, event.xmotion.x_root, event.xmotion.y_root);		}		break;	    case EnterNotify:		tooltip.hide();		is_statfs_filled = false;		tooltip_for_mp = NULL;		ShowTooltip(event.xcrossing.window, event.xcrossing.x, event.xcrossing.y, event.xcrossing.x_root, event.xcrossing.y_root);		break;	    case LeaveNotify:		tooltip.hide();		is_statfs_filled = false;		tooltip_for_mp = NULL;		break;	    case ConfigureNotify:#if DEBUG		if (debug_level >= dbg_all_work)		    printf("ConfigureNotify detected.\n");#endif /* DEBUG */		if (do_reconfigure)		    return;		break;	}    }}voidToolWindow::Draw(void){    XClearWindow(getXDisplay(), rootwin);}voidToolWindow::Draw(const int x, const int y, const unsigned int width, const unsigned int height){    XClearArea(getXDisplay(), rootwin, x, y, width, height, False);}voidToolWindow::SetCommand(const int cmdidx, const string command){    if (cmdidx == (int)commands.size())	commands.push_back(command);    else	commands[cmdidx] = command;}voidToolWindow::SetImage(const int imgidx, MyImage *image){    if (imgidx == (int)images.size())	images.push_back(image);    else	images[imgidx] = image;}voidToolWindow::SetMountPoint(const int mntidx, const MountPoint &mntpoint){    if (mntidx == (int)mount_points.size())	mount_points.push_back(mntpoint);    else	mount_points[mntidx] = mntpoint;}voidToolWindow::Stop(void){    stop = true;}voidToolWindow::ShowTooltip(const Window w, const int x, const int y, const int screen_x, const int screen_y){    int space_left, space_right, rootwin_width, win_no = 0;    XWindowAttributes attrs;    vector<MountWindow *>::iterator pointer;    XGetWindowAttributes(getXDisplay(), rootwin, &attrs);    space_left = screen_x - attrs.x;    space_right = getCurrentScreenInfo()->getWidth() - screen_x - attrs.x - attrs.width ;    rootwin_width = attrs.width;    for (pointer = mount_windows.begin(); pointer != mount_windows.end(); pointer++) {	if (w == (*pointer)->GetWindow()) {	    XGetWindowAttributes(getXDisplay(), (*pointer)->GetWindow(), &attrs);	    if (space_left > space_right)		tooltip.setPosition(space_left - attrs.x - x - 1, screen_y,			(win_no / resource->app.columns == resource->app.rows - 1 ? top_left : bottom_left));	    else		tooltip.setPosition(space_left - attrs.x - x + rootwin_width + 1, screen_y,			(win_no / resource->app.columns == resource->app.rows - 1 ? top_right : bottom_right));	    tooltip.setText(getTooltip(infotexts[(*pointer)->GetMountPoint().getCurrentInfo()], (*pointer)->GetMountPoint()));	    tooltip_for_mp = &(*pointer)->GetMountPoint();	    tooltip.show();	}	win_no++;    }}voidToolWindow::updateTooltip(void) {    tooltip.setText(getTooltip(infotexts[tooltip_for_mp->getCurrentInfo()], *tooltip_for_mp, true));}voidToolWindow::reconfigure(void){    XEvent event;    do_reconfigure = true;    memset((void *)&event, 0, sizeof(XConfigureEvent));    event.type = ConfigureNotify;    event.xexpose.window = AppWindow->GetRootWindow();    event.xexpose.display = AppWindow->getXDisplay();    event.xexpose.send_event = True;    XSendEvent(AppWindow->getXDisplay(), AppWindow->GetRootWindow(), False, NoEventMask, &event);    XFlush(AppWindow->getXDisplay());}intmain(int argc, char *argv[]){    int result;    pthread_t check_thread;    void *thread_return;    struct CMDOPTIONS options;#if DEBUG    if (debug_level >= dbg_summary && i18n.multibyte())	printf("Using multibyte strings.\n");#endif    if (XInitThreads() == 0) {    	perror("bbsmount: Can't initialize X11!");    	exit(EXIT_FAILURE);    }    read_options(argc, argv, options);    AppWindow = new ToolWindow(argc, argv, &options);    AppWindow->CreateSubWindows(false);#ifdef HAVE_SIGACTION    struct sigaction act;    act.sa_handler = shutdown;    sigemptyset(&act.sa_mask);    act.sa_flags = 0;    sigaction(SIGINT, &act, 0);    sigaction(SIGTERM, &act, 0);    act.sa_handler = usersignal;    sigaction(SIGUSR1, &act, 0);#else /* !HAVE_SIGACTION */    signal(SIGINT, shutdown);    signal(SIGTERM, shutdown);    signal(SIGUSR1, usersignal);#endif /* !HAVE_SIGACTION */    do {	if (do_reconfigure) {//	    delete AppWindow;//	    AppWindow = new ToolWindow(argc, argv, &options);//	    AppWindow->CreateSubWindows(false);	    AppWindow->FreeAll();	    AppWindow->rereadResources();	    AppWindow->CreateWindow(true);	    AppWindow->configure();	    AppWindow->CreateSubWindows(true);	}	finish_checking = false;	do_reconfigure = false;	result = pthread_create(&check_thread, NULL, check_mounts, NULL);	if (result != 0) {	    perror("bbsmount: Can't create thread!");	    exit(EXIT_FAILURE);	}	tooltip.setTimeout(AppWindow->GetResources()->getTooltipTimeout());#if DEBUG	if (debug_level >= dbg_all_work)	    printf("Waiting for events.\n");#endif	AppWindow->EventLoop();#if DEBUG	if (debug_level >= dbg_all_work)	    printf("Event loop ended.\n");#endif	finish_checking = true;	result = pthread_join(check_thread, &thread_return);	if (result != 0) {	    perror("bbsmount: Can't join thread!");	    exit(EXIT_FAILURE);	}    } while (do_reconfigure);        delete AppWindow;    return EXIT_SUCCESS;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?